jest: Do not fail on 'Jest: Coverage data for ... was not found.' or make `coverageThreshold` configurable on the cli
š Feature Proposal
We are using one jest.config.js per application and using Bazel as the build/testing tool. The setup there works that each test file will be invoked in isolation/sandboxed via jest. So as soon as I have coverageThreshold: { './some/path/': {...} } some of these test will fail with Jest: Coverage data for ... was not found. Now I could point them all to their individual config, but then I would have to create many many more file which all would be identical apart from the coverageThreshold.
So it would be great to either get a passWithNoCoverage flag or similar, or make coverageThreshold configurable on the cli, so I could just pass that in for each individual jest invocations
Motivation
So I do not have to have duplicate jest.config files
Example
either:
jest --passWithNoCoverage --config=path/to/config.js --runTestsByPath=path/to/test.js
or
jest --coverageThreshold='{\"global\":{\"statements\":90}' --config=path/to/config.js --runTestsByPath=path/to/test.js
Pitch
One of the proposals might even be a bug report, see: https://github.com/facebook/jest/issues/7509 and the addition of the new flag would imo be a good fit to complement the already existing --passWithNoTests flag.
About this issue
- Original URL
- State: open
- Created 8 years ago
- Reactions: 9
- Comments: 17 (1 by maintainers)
Our use case is: 1) coverage threshold set, and 2) prepush hook that runs Jest with
--changedSince=masterto reduce test execution time, since the prepush hook is about getting quick feedback before a full CI run, and 3) not an option for us to run with--no-coveragebecause meeting our coverage threshold is important if tests are run.However, I would expect
--passWithNoTeststo also imply that Jest should pass with no coverage, since thereās no way that a coverage threshold could ever be met if no tests ran.Absolutely still an issue.
The
--no-coverageflag isnāt an option for my use case because what Iām looking to do is be able to run a subset of my test suite, with coverage and thecoverageThresholdsset in the main configuration of the test framework, so that I can see if for my subset of tests in the suite, I am going to be decreasing or breaking coverage.I think this use case is completely valid in that locally you donāt want to have to run the full test suite when youāre developing in a specific area, and you also want your tests to run as close to CI as possible so that you arenāt surprised if CI breaks when you push up to remote.
Please pay attention to this issue that has been public for a long time š When I want to perform incremental checks while submitting code, if the files for incremental testing do not hit the directories with set coverage thresholds, an error is thrown. This frustrates me, and I have to write an extra script to dynamically change the coverageThreshold based on the input test files.
Chiming in here, with different example.
When using Nx, it comes with a Jest preset in the root of the project where you can define thresholds for certain glob patterns (e.g. all files matching
'**/*.effects.ts'). That preset is then used by all the apps and libs Nx generated. But some of the apps and libs donāt have files matching that pattern. We work around that now, by settingcoverageThreshold: {},in thejest.config.tsfile of the specific app, but that would result in also losing all other patterns from the preset.Having a configuration option to not error on missing coverage data for some of the patterns defined, would be very helpful for this.
Have the same query! Trying to only run changed files and itāll fail with
Jest: Coverage data for ... was not found.when thereās a coverage threshold in the config. Iāll look into--coverageThresholdalthough itāll be a very ugly script š.[Edit]: My solution is to have
with
coverage.jsonbeing an object with my thresholds