【发布时间】:2022-10-02 17:28:48
【问题描述】:
试图忽略所有索引文件,特别是 src/index.jsx 和 src/reportWebVitals.js 文件,但是我的覆盖命令仍然显示被覆盖的行。
My Github repo在正确的dev 分支上,这是一个问题。
根据文档,它应该像将文件添加到coveragePathIgnorePatterns 和testPathIgnorePatterns 一样简单。
jest.config
module.exports = {
testEnvironment: \'node\',
testEnvironmentOptions: {
NODE_ENV: \'test\',
},
restoreMocks: true,
coveragePathIgnorePatterns: [
\'node_modules\',
\'index.js\',
\'index.jsx\',
\'server/src/config\',
\'server/src/app.js\',
\'src/index.jsx\',
\'src/reportWebVitals.js\',
\'tests\',
],
coverageReporters: [\'text\', \'lcov\', \'clover\', \'html\'],
testPathIgnorePatterns: [\'index.js\', \'index.jsx\', \'src/index.jsx\', \'src/reportWebVitals.js\'],
roots: [\'<rootDir>/server/tests\'],
};
还在这里尝试了更长的版本:
module.exports = {
testEnvironment: \'node\',
testEnvironmentOptions: {
NODE_ENV: \'test\',
},
restoreMocks: true,
collectCoverageFrom: [
\'src/{!(index),}.jsx\',
\'src/{!(reportWebVitals),}.js\',
\'src/{!(store),}.js\'
],
coveragePathIgnorePatterns: [
\'node_modules\',
\'index.js\',
\'index.jsx\',
\'server/src/config\',
\'server/src/app.js\',
\'index.jsx\',
\'reportWebVitals.js\',
\'store.js\',
\'tests\',
],
coverageReporters: [\'text\', \'lcov\', \'clover\', \'html\'],
modulePathIgnorePatterns: [
\'node_modules\',
\'index.js\',
\'index.jsx\',
\'server/src/config\',
\'server/src/app.js\',
\'index.jsx\',
\'reportWebVitals.js\',
\'store.js\',
\'tests\',
],
watchPathIgnorePatterns: [
\'node_modules\',
\'index.js\',
\'index.jsx\',
\'server/src/config\',
\'server/src/app.js\',
\'index.jsx\',
\'reportWebVitals.js\',
\'store.js\',
\'tests\',
],
testPathIgnorePatterns: [
\'node_modules\',
\'index.js\',
\'index.jsx\',
\'server/src/config\',
\'server/src/app.js\',
\'index.jsx\',
\'reportWebVitals.js\',
\'store.js\',
\'tests\',
],
roots: [\'<rootDir>/server/tests\'],
};
我的 package.json 脚本
\"client-dev\": \"react-scripts start\",
\"client-build\": \"react-scripts build\",
\"client-test\": \"react-scripts test ./src\",
\"client-coverage\": \"react-scripts test ./src --coverage\",
更新:我注意到一件有趣的事情,我从 jest.config.js 中删除了所有忽略规则,并且覆盖范围仍然相同,node_modules 在覆盖范围中不是问题......所以现在探索我的项目是否正在挑选上配置。
module.exports = {
testEnvironment: \'node\',
testEnvironmentOptions: {
NODE_ENV: \'test\',
},
restoreMocks: true,
coverageReporters: [\'text\', \'lcov\', \'clover\', \'html\'],
};
-
我不确定,但我认为您可以在 jest config 中对这些文件使用 glob 模式。尝试
src/**/index.{js,jsx}忽略src目录中的所有index.js和index.jsx文件。 -
@h-sifat 有哪些规则?
标签: javascript reactjs jestjs