Global and single file coverage thresholds
See original GitHub issueDo you want to request a feature or report a bug?
Feature
What is the current behavior?
Currently, when using both global
and path/glob
thresholds, the global
config combines the coverage for remaining files only (as documented).
What is the expected behavior?
I’ll describe my use case. A global threshold is configured as following:
coverageThreshold: {
global: {
statements: 85,
branches: 80,
functions: 85,
lines: 85
}
}
This makes it possible to commit completely untested files as long as the overall coverage is fulfilled. To solve this issue I would like to enforce every file being tested for at least 50%:
coverageThreshold: {
global: {
statements: 85,
branches: 80,
functions: 85,
lines: 85
},
"app/**/*.js": {
statements: 50,
branches: 50,
functions: 50,
lines: 50
}
}
However, this won’t work as expected. First, running this config will fail if app/
and global
point to the same files (which is expected as “If the file specified by path is not found, error is returned.”). Second, now the global threshold is overruled by the “local” threshold.
It would be great to have an option to use a global threshold which always applies to all files in addition to glob/path thresholds for single file thresholds.
Please provide your exact Jest configuration and mention your Jest, node, yarn/npm version and operating system.
- Windows 7
- jest v22.1.4
- node v8.9.1
- npm v5.6.0
- example repository
Issue Analytics
- State:
- Created 6 years ago
- Reactions:16
- Comments:16 (1 by maintainers)
Top GitHub Comments
@averath Because what we need is to have both checks in place, e.g.:
a) The total coverage should be at least 90% b) The per-file coverage should be at least 50%
In other words, it’s okay if a single file does not meet the 90% coverage (as long as the overall coverage is at least 90%), but it’s not okay if a single file has no coverage at all.
@antoniosZ I think the
Coverage data for global was not found
was a different issue. I could not reproduce it with my example anymore.However, the main issue is still valid and reproducible both on Windows and a Mac. With the following configuration:
… this example should fail:
Jest reports a successful result, even though the overall branch coverage does not fulfill the
global
threshold (80%). As discussed, the reason is that Jest usesglobal
for “all files that are unmatched by other threshold patterns” (in this example, there are no other files). In other words,global
rather meanseverythingElse
orunmatched
.