-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Coverage thresholds can be set up for individual files #4185
Coverage thresholds can be set up for individual files #4185
Conversation
we've had this idea for a while, but there's too many things that we need to design properly before we can do this (config format, what exactly happens when the threshold is not met, what happens if we run only a subset of tests, etc..) |
}, undefined); | ||
|
||
const errors = [].concat( | ||
...Object.keys(globalConfig.coverageThreshold) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mixing array concat and spread. For now just use concat, because we're not transforming array spreading (not supported on Node 4, that's why Circle fails)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do I use [].concat.apply([], arrays);
then?
return testReporter | ||
.onRunComplete(new Set(), {}, mockAggResults) | ||
.then(() => { | ||
expect(testReporter.getLastError()).toBeTruthy(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be nice to at least once assert on what's the content of the error, what do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Absolutely agree, will do.
} else { | ||
summary = fileCov.toSummary(); | ||
} | ||
return summary; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return summary !== undefined && summary !== null
? summary.merge(fileCov.toSummary())
: fileCov.toSummary()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wasn't sure if I may use ternary in this code base. Now I am :)
} else { | ||
return [ | ||
`Jest: Coverage data for ${thresholdKey} was not found.`, | ||
]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wonder if we could push these logic branches into check
function?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like check
function being unaware of such details and just sticking to comparing numbers. I can add move this to check
as a two distinct conditions if actuals
or thresholds
do not contain given key respectively. What do you think?
@aaronabramov LGTM! Also think it's a good start and we can follow this up with glob support. |
Yep, agree that this should have glob support. |
Codecov Report
@@ Coverage Diff @@
## master #4185 +/- ##
========================================
Coverage ? 56.6%
========================================
Files ? 184
Lines ? 6284
Branches ? 6
========================================
Hits ? 3557
Misses ? 2724
Partials ? 3
Continue to review full report at Codecov.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Neeeds glob support if we are going to add this to 21.
c4e335b
to
b71ccdb
Compare
…re currently setup for 'global'. Supports globs along absolute and relative paths. Each path expanded from a glob gets assigned the threshold from a glob. Tests now use mock-fs to mock filesystem for glob testing. If match is not found, thresholds would not be met.
b71ccdb
to
7e4686f
Compare
@cpojer hi! I added glob support a while ago. Did I misunderstand you and it is not what you meant? |
Also, after I rebased on latest master to resolve conflicts, CI is failing with
but 'glob' is in |
@krishnagoth |
@cpojer too bad there's no "d'oh" reaction emoticon. |
Thanks for this diff. @krishnagoth: would you like to send a follow-up PR to extend the documentation with this feature? (See the |
Will do @cpojer |
This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
Currently only global coverage threshold is available which is convenient when a team can allow themselves 100 coverage all over the codebase right off the bat. Unfortunately it's not always possible, including times where significant design changes are required to get files and testing harnesses up to the standard. My goal is to provide teams with the ability to exclude certain files from 'global' threshold and allow their coverage to be managed separately.
When file paths or globs (which are then expanded to full file paths) are added to
coverageThreshold
config, reporter subtracts their coverage stats from global coverage and applies thresholds separately to global and to each file individually. If threshold file has no coverage data, error is returned as well, indicating misconfiguration. Until paths are added, coverage is calculated as usual.The behaviour can be illustrated by the following sequence.
in this example this threshold is not met and returns an error:
Now let's add files to
coverageThreshold
which expands to
the errors are now
Since these files have been excluded from summary, they are no longer counted towards global coverage and global threshold is met.