Add combined coverage threshold for directories #4885
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
Right now you can specify a global threshold in Jest and a threshold for files that match a glob pattern. But you can't specify a threshold for a given directory. This pull request adds that functionality without taking away any functionality from before. With this pull request there will be three possible ways to set a coverage threshold:
global
applies the threshold to every covered file.path
applies the threshold to a path (either a directory or a file).glob
applies the threshold to any file matching a glob pattern.For example, before you could do:
And this would apply a threshold separately...
"./src/components/**/*.js"
glob pattern"./src/api/very-important-module.js"
fileglobal
threshold).But what if you want to set a threshold for the entire components directory? That is, what if you don't care about the threshold of each individual
.js
file in the components directory, but you do want to set a combined coverage threshold for all your components. Something like:And this would apply a threshold separately...
"./src/components"
directory (combined coverage for each file under the directory)."./src/reducers/**/*.js"
glob pattern."./src/api/very-important-module.js"
fileglobal
threshold).Test plan
I added a few unit tests that tests this new functionality. I left every other test in the test suite alone to demonstrate that there are no regressions in functionality. Let me know if you think we need to add some more tests, or if there are some integration test that I can create/update.