开玩笑地忽略文件模式以进行代码覆盖 [英] Jest ignore file pattern for code coverage
问题描述
在经过Jest测试的项目中,我有*.entity.ts
个文件.我不希望这些文件包含在覆盖测试中.
In my Jest tested project I have *.entity.ts
files. I don't want these files to be included in my coverage test.
根据 https://facebook上的文档.github.io/jest/docs/en/configuration.html#coveragepathignorepatterns-array-string 中有一个coveragePathIgnorePatterns
设置,您可以在package.json
According to the documentation at https://facebook.github.io/jest/docs/en/configuration.html#coveragepathignorepatterns-array-string there is a coveragePathIgnorePatterns
setting which you can use in the package.json
我已经尝试过正则表达式和文件模式,但是没有一个会忽略最终报告中的*.entity.ts
文件.
I've tried regex and file patterns but none of these just ignores the *.entity.ts
files in the final report.
例如,当我添加"coveragePathIgnorePatterns": ["common"]
时,我的测试将不再运行.
When I add for example "coveragePathIgnorePatterns": ["common"]
my tests won't even run anymore.
是否有任何关于如何使Jest跳过覆盖测试中的*.entity.ts
的想法?
Any thoughts on how I can make Jest skip the *.entity.ts
in the coverage tests?
package.json中的我的Jest部分如下:
My Jest section in the package.json looks like:
{
"moduleFileExtensions": [
"js",
"json",
"ts"
],
"rootDir": "src",
"testRegex": ".spec.ts$",
"transform": {
"^.+\\.(t|j)s$": "ts-jest"
},
"coverageDirectory": "../coverage"
}
推荐答案
我使用外部JSON文件保存Jest配置,并使用npm从package.json
运行它:jest --config jest.config.json --no-cache
I use an external JSON file to hold my Jest configuration and run it from my package.json
using npm: jest --config jest.config.json --no-cache
jest.config.json
jest.config.json
{
"collectCoverage": true,
"collectCoverageFrom": [
"src/**/*.ts"
],
"coveragePathIgnorePatterns": [
"node_modules",
"test-config",
"interfaces",
"jestGlobalMocks.ts",
".module.ts",
"<rootDir>/src/app/main.ts",
".mock.ts"
],
"coverageDirectory": "<rootDir>/coverage/",
"coverageThreshold": {
"global": {
"branches": 20,
"functions": 30,
"lines": 50,
"statements": 50
}
},
"mapCoverage": true,
"preset": "jest-preset-angular",
"setupTestFrameworkScriptFile": "<rootDir>/src/setupJest.ts",
"transformIgnorePatterns": [
"<rootDir>/node_modules/(?!@ionic-native|@ionic|@ngrx|angular2-ui-switch|angularfire2|jest-cli)"
],
"verbose": false
}
我的报道不包括"coveragePathIgnorePatterns"中列出的文件.也许源行"/src/app/main.ts"就是您需要的条目.
My coverage does not include the files listed in the "coveragePathIgnorePatterns". Maybe the source line "/src/app/main.ts" is the entry you need.
这篇关于开玩笑地忽略文件模式以进行代码覆盖的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!