jest
jest copied to clipboard
Feature request: CLI: Unset 'collectCoverageFrom' to default
🚀 Feature Proposal
Continuing from #2831, I would like to have the ability to unset collectCoverageFrom
so that it works like it is undefined
Motivation
In package.json
, we have collectCoverageFrom
set so that we generate coverage against files that are not touched by tests. However, when running a subset of tests locally, I would like the default behavior of only seeing coverage by affected files.
Currently, I must comment out the respective lines in package.json
to leverage this behavior.
I've tried the following flags:
--collectCoverageFrom
--collectCoverageFrom 'undefined'
--collectCoverageFrom '[]'
Example
Perhaps an empty argument of --collectCoverageFrom
would use undefined
behavior?
Looks like this line here filters out undefined
: https://github.com/facebook/jest/blob/master/packages/jest-config/src/setFromArgv.ts#L18
One option would be to allow undefined
for whitelisted keys?
Would a PR along the lines of this be acceptable?
const undefinedWhitelist = ['coverage'];
// ...snip
const argvToOptions = Object.keys(argv)
.filter(
key =>
(argv[key] !== undefined || undefinedWhitelist.includes(key)) &&
specialArgs.indexOf(key) === -1,
)
.reduce((options: Record<string, unknown>, key) => {
bah, I suppose that would break it for anyone who doesn't explicitly provide --coverageFrom
option, then..
This issue is stale because it has been open for 1 year with no activity. Remove stale label or comment or this will be closed in 14 days.
Unstale
we should support overriding if empty string is provided. wanna send a PR?
I was trying to get the same behavior today (i.e. reset collectCoverageFrom
to the default empty state). I believe this does in fact work today without any changes by using:
npx jest --collectCoverageFrom='[]' --coverageThreshold='{}'
Although coverageThreshold
was not in the original request, that might be a common enough requirement to reset in this same situation that its worth noting.
The main difference between this syntax and what @quicksnap tried originally is the placement of the =
after the flag. Without the =
this does not work.
Run without any flags
Run with flags
In both runs it collects coverage for both tested
and untestedUsed
because tested
imports from untestedUsed
. In only the first run does it add untestedUnused
to the coverage report and also triggers a coverage failure. In the second run with the flags set it will not add the modules which weren't in the test's code path (i.e. untestedUnused
) and also isn't triggering a coverage failure.
This issue is stale because it has been open for 1 year with no activity. Remove stale label or comment or this will be closed in 30 days.
This issue was closed because it has been stalled for 30 days with no activity. Please open a new issue if the issue is still relevant, linking to this one.
This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.