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)

Most upvoted comments

Our use case is: 1) coverage threshold set, and 2) prepush hook that runs Jest with --changedSince=master to 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-coverage because meeting our coverage threshold is important if tests are run.

However, I would expect --passWithNoTests to 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-coverage flag 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 the coverageThresholds set 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 setting coverageThreshold: {}, in the jest.config.ts file 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 --coverageThreshold although it’ll be a very ugly script šŸ˜›.

[Edit]: My solution is to have

jest --coverage --changedSince=master --passWithNoTests --coverageThreshold='$(cat coverage.json)'

with coverage.json being an object with my thresholds