collectCoverage do nothing when using projects configs.
global jest.config.js
module.exports = {
"projects": [
"<rootDir>/src/client/test/jest.config.js",
"<rootDir>/src/server/test/jest.config.js"
]
};
client jest.config.js
module.exports = {
"displayName": "client",
"rootDir": "../../../",
"globals": {
"__MODE__": "test",
"ts-jest": {
"tsConfigFile": "src/client/test/tsconfig.json"
}
},
"transform": {
".(js|jsx|ts|tsx)": "<rootDir>/node_modules/ts-jest/preprocessor.js"
},
"moduleNameMapper": {
"^.+\\.(css|less|png|svg|jpg)$": "<rootDir>/src/client/test/css-modules-stub.ts"
},
"testMatch": [
"**/src/client/**/?(*.)+(spec|test).[jt]s?(x)",
],
"transformIgnorePatterns": [
"/node_modules/(?!lego-on-react).+\\.js$"
],
"moduleFileExtensions": [
"ts",
"tsx",
"js",
"jsx",
"json"
],
"modulePaths": [
"<rootDir>/src",
"<rootDir>/node_modules"
],
"setupFiles": [
"<rootDir>/src/client/test/tests-setup.tsx",
"jest-localstorage-mock"
],
"setupFilesAfterEnv": [
"jest-extended",
"<rootDir>/src/client/test/test-framework-setup.ts"
],
"collectCoverage": true,
"collectCoverageFrom": [
"<rootDir>/src/client/**/*.{ts,tsx}"
],
"coveragePathIgnorePatterns": [
".*\\.d\\.ts",
"<rootDir>/src/client/**/enums/**/*.ts"
],
"coverageDirectory": "<rootDir>/.jest-coverage",
"coverageReporters": ["jest-html-reporter"]
};
Code above. Jest run through CLI with command like npm test -- someTests
I was trying to debug the jest and in places where jest uses collectCoverage option it trying to access it from globalConfig that pointed to root jest.config.js
When i moved all coverage options from project config to root config - coverage working.
collectCoverage option should work.
No link, sorry.
npx envinfo --preset jestPaste the results here:
System:
OS: macOS Sierra 10.12.6
CPU: (4) x64 Intel(R) Core(TM) i5-5250U CPU @ 1.60GHz
Binaries:
Node: 10.11.0 - ~/.nvm/versions/node/v10.11.0/bin/node
npm: 6.9.0 - ~/.nvm/versions/node/v10.11.0/bin/npm
npmPackages:
jest: ^24.8.0 => 24.8.0
Yeah, collectCoverage is a global config option, so setting it in a project does nothing... https://github.com/facebook/jest/blob/33e2d5ce454554363198c8d8a673793222955dbc/packages/jest-types/src/Config.ts#L294
That probably should be a project one (and setting the flag from the CLI would just set it to true for every project).
We'll be revisiting config and its validation as part of Jest 25 where we'll either fix this somehow or at the very least provide good error messages if fields are added where they don't belong (#7185 is a tracking issue for this work)