'Disable Coverage on Untested Files - Jest
When using @vue/cli-plugin-unit-jest, I am receiving coverage reports each time I run my unit tests, regardless of whether I have the --coverage
flag in the execution line or not. I do not want to receive coverage reports on all of my untested files. When searching for an answer online, there are numerous questions about how to turn that feature on, not turn it off. I can't find it in the documentation either.
How do you disable the Coverage on Untested Files
feature in Jest?
Solution 1:[1]
Disabling coverage similar to enabling it, just prefix the pattern with an !
like so:
{
"collectCoverageFrom": [
"**/*.{js,jsx}",
"!**/node_modules/**",
"!**/folder-with-untested-files/**"
]
}
Or disable coverage all together with "collectCoverage": false
.
If that does not work, then you have this params overridden somewhere in your code.
Solution 2:[2]
"collectCoverage": false
in jest.config.js
Solution 3:[3]
You can also suppress coverage from the command line. The package I'm working with provides a test script, and I was able to pass the collectCoverage
option in as a flag. The relative path here works because my test runner is called by npm and that should set the working directory to the root of my project:
npm run test -- path/to/your.spec.js --collectCoverage=false
And the other way around, you can specific a single file to collect coverage from. It'll override any broad-ranging glob you may have already defined in your project's test config files. One reminder, you collect coverage from your source file, not your spec file. And one other reminder, you can list pretty much any file you want in that coverage option, so make sure you get it right:
npm run test -- path/to/your.spec.js --collectCoverageFrom=path/to/your/source/file.js
Solution 4:[4]
"collectCoverage": false
in package.json, will disable coverage, collection,
As mentioned by @Herman
you can also put !
before file pattern in value of property collectCoverageFrom
in package.json
Solution 5:[5]
Package.json
testw": "jest --watch --collectCoverage=false"
watches the test files for change
npm command
npm run testw Yourfilename.js
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Herman Starikov |
Solution 2 | Irteza Asad |
Solution 3 | worc |
Solution 4 | Akshay Vijay Jain |
Solution 5 | Ashish Singh Rawat |