Jest is "stuck" on only generating coverage for tested files, instead of all files
See original GitHub issueš Bug Report
I recently setup codecov, and then setup jest to generate coverage reports for it.
Initially, it was setup to collect coverage from all files via the jest config (see below).
Later, I wanted to have a separate jest command minus the coverage report, so I moved the collect coverage command from the jest options to the cli (see below).
After doing this, jest no longer gives coverage for the entire src folder, but only for the files tested. Okay, no problem, Iāll just undo this change.
Hereās where I am getting frustrated - no attempts to revert this seem to work. I can revert to the previous config, and it no longer works for all files, only the ones being tested. Same config, different results. Iāve tried running it with --clearCache
or --no-cache
and neither work. Iāve tried creating a whole new config, one with coverage and one without, and then just running the base command, and that doesnāt work either.
When running, it takes much longer than it used, displays the āgenerating coverage for untested filesā message, and then still only returns the coverage for tested files only.
To Reproduce
I had a config with the following (this worked fine):
with a command that looked like this:
I removed the collectCoverage
and collectCoverageFrom
options from the jest config, and created a separate command that looked like this:
I realize now that the above command never worked for all files. Regardless, after reverting to the original setup, jest no longer works the way it used to, and is instead āstuckā on just reporting coverage for the tested files only. Even though it displays the āgenerating coverage for untested filesā message.
Expected behavior
I would expect that when coverage is set to true, and collectCoverage is passed a glob for all files in the repo, that the generated coverage report would be for all files. I would expect this behavior to be consistent.
Run npx envinfo --preset jest
Paste the results here:
System:
OS: macOS 10.14.4
CPU: (4) x64 Intel(R) Core(TM) i5-6267U CPU @ 2.90GHz
Binaries:
Node: 8.12.0 - ~/.nvm/versions/node/v8.12.0/bin/node
Yarn: 1.7.0 - /usr/local/bin/yarn
npm: 6.4.1 - ~/.nvm/versions/node/v8.12.0/bin/npm
npmPackages:
jest: ~24.1.0 => 24.7.1
Issue Analytics
- State:
- Created 4 years ago
- Comments:19
Hey guys, I think I find the answer. I encountered with this issue. And I found my directory structure as:
Ā· tests/
Ā· src/
Ā· jest.config.js
The test files is listed outside of source files. However, my previous jest configās roots property only had the tests/ directory. When I added the src/ directory to roots. Jest gave coverage of all wanted files in src/. I hope this would help.
@cyphernull Thank for helping, following is my package.jsonconfig that worked