jest
jest copied to clipboard
collectCoverageFrom didn't work in react components
🐛 Bug Report
when i set jest config in package.json like this
"jest": {
"verbose": true,
"collectCoverage": true,
"globals": {},
"testEnvironment": "jest-environment-jsdom-global",
"moduleFileExtensions": [
"js",
"jsx",
"json"
],
"moduleNameMapper": {
"^@/(.*)$": "<rootDir>/src/$1",
"\\.(css|less)$": "<rootDir>/__mocks__/styleMock.js"
},
"transform": {
"^.+\\.(js|jsx)$": "<rootDir>/node_modules/babel-jest",
"\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$": "<rootDir>/__mocks__/fileTransformer.js"
},
"transformIgnorePatterns": [
"<rootDir>/node_modules/"
],
"setupFiles": [
"jest-canvas-mock"
],
"testMatch": [
"<rootDir>/**/*.(test|spec).js"
],
"coverageDirectory": "<rootDir>/test/unit/coverage",
"collectCoverageFrom": [
"<rootDir>/**/util.js"
],
"coveragePathIgnorePatterns": [
"<rootDir>/node_modules/",
"<rootDir>/test",
"<rootDir>/tasks",
"<rootDir>/config"
]
},
when i run yarn run jest
, i get this
To Reproduce

Expected behavior
is should only collect util.js , but it collect react components, i set react components test
it('renders correctly', () => {
expect(toJson(wrapper)).toMatchSnapshot();
});
is this impact collectCoverageFrom
Link to repl or repo (highly encouraged)
sorry,i can't provided it
envinfo
System:
OS: macOS High Sierra 10.13.4
CPU: x64 Intel(R) Core(TM) i7-7700K CPU @ 4.20GHz
Binaries:
Node: 10.15.3
Yarn: 1.16.0
npm: 6.4.1
npmPackages:
jest:
wanted: ^23.2.0
installed: 23.6.0
Can you try on the latest version of Jest? Also please try to form the issue a bit clearer, because I have troubles understanding :<
i have update jest 24.9.0 version, it also has this problem.
the problem is collectCoverageFrom didn't work.
i set jest config
collectCoverageFrom: ['<rootDir>/**/util.js']
so i want to collect Coverage the files named 'util.js' ,
but it collect all the files
I have the same issue, have you found a solution?
@vcheeney not yet
@z2014 - I guess your regex is not working correctly not sure with your code. but I am able to ignore files using below code .
collectCoverageFrom: ['<rootDir>/src//*.{js,jsx,ts,tsx}', '!<rootDir>/src//*css.ts'],
try add in collectCoverageFrom: ['<rootDir>/src/**/*util.js'],
@SunilSalve
['/src//*.{js,jsx,ts,tsx}', '!/src//*css.ts']
is css.ts
right ?
can you provide a complete code, thanks
collectCoverageFrom
still doesn't collect coverage for React components? I'm trying it with "src/**/*.{ts,tsx}"
and it indeed doesn't cover React components. 🤷🏻♂️
This issue is stale because it has been open for 1 year with no activity. Remove stale label or comment or this will be closed in 30 days.
This issue was closed because it has been stalled for 30 days with no activity. Please open a new issue if the issue is still relevant, linking to this one.
This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.