Allow for precedence in coverageThreshold file glob patterns
See original GitHub issue🚀 Feature Proposal
Motivation
We have the following configuration which our codebase adheres to but, although the accumulated coverage of the codebase fulfills it, there are individual files with coverage that falls below these thresholds.
coverageThreshold: {
global: {
branches: 95,
// I will omit these to keep code snippets short
// functions: 95,
// lines: 95,
// statements: 95
}
}
We could add the following, but it would mean every file needing its coverage improving immediately for builds to pass.
coverageThreshold: {
global: {
branches: 95,
},
'./src/**/*.+(js|jsx)': {
branches: 95,
}
}
Instead we want to set a rising watermark for files with insufficient coverage, so they can’t get any worse, then gradually raise and remove them as they are improved.
Example
Given a file at ./src/some-file.js
which has 60% branch coverage and this configuration:
coverageThreshold: {
global: {
branches: 95,
},
'./src/**/*.js': {
branches: 95
},
'./src/some-file.js': {
branches: 60
}
}
My request is that the pattern "./src/some-file.js"
takes precedence over "./src/**/*.js"
and
resolves to a coverageThreshold of 60% being applied to ./src/some-file.js
. Currently all patterns
are checked independently of one another, which results in an error being thrown for the pattern
"./src/**/*.js"
setting a threshold of 95% (which is violated by ./src/some-file.js
having
branch coverage of 60%).
The pattern './src/some-file.js'
allows for leniency on files known to need improvement, while
'./src/**/*.js'
ensures any new files being added to the project are caught straight away and made
to meet the desired threshold.
Precedence is defined by the order of the keys in the object, so in this example where I have
swapped './src/some-file.js'
and './src/**/*.js'
around, './src/**/*.js'
wins because it
appears later.
coverageThreshold: {
global: {
branches: 95
},
'./src/some-file.js': {
branches: 60
},
'./src/**/*.js': {
branches: 95
}
}
This change would only apply to patterns which refer to files, the "global"
pattern and those
which point to directories would be unaffected.
Pitch
This is a change to an existing Jest feature.
Issue Analytics
- State:
- Created 5 years ago
- Reactions:1
- Comments:7 (2 by maintainers)
Any update on this?
I’m not yet convinced which is better, but I would lean towards paths being always more specific than globs. We could solve this by checking if globbing over string produces a single or multiple output, and act accordingly. Obvious shortcoming is when glob returns just one file, but it seems kind of an edge case where users should re-consider their config.
cc @rickhanlonii @SimenB