In my React/Redux application, my team has decided we do not want to include containers in our jest coverage reports.
We have been successful with excluding directories, but unsuccessful when excluding files.
Does anyone have any suggestions about how to exclude files that end with the word Container in our jest configurations? ex: exampleComponentContainer.jsx should be exluded
In my React/Redux application, my team has decided we do not want to include containers in our jest coverage reports.
We have been successful with excluding directories, but unsuccessful when excluding files.
Does anyone have any suggestions about how to exclude files that end with the word Container in our jest configurations? ex: exampleComponentContainer.jsx should be exluded
Share Improve this question edited Jan 25, 2019 at 9:04 skyboyer 23.7k7 gold badges62 silver badges71 bronze badges asked Jan 24, 2019 at 17:56 Burns BeaverBurns Beaver 711 gold badge1 silver badge2 bronze badges2 Answers
Reset to default 11You can use collectCoverageFrom
inside your package.json
jest
configuration to exclude *Container.jsx
files from code coverage.
"jest": {
"collectCoverage": true,
"collectCoverageFrom": [
"**/*.{js,jsx}",
"!**/node_modules/**",
"!**/*Container.jsx"
]
}
If you use create-react-app
remove the line "collectCoverage": true,
which is not supported.
Source: https://jestjs.io/docs/en/configuration.html#collectcoveragefrom-array
For someone trying to something similar in 2022..
In my storybook create-react-app I do this for excluding all .stories files (e.g. "somestory.stories.tsx") from my coverage via the package.json
"jest": { "coveragePathIgnorePatterns": ["^.*\\.stories\\.[jt]sx?$"] }