jest: Coverage in HTML view is broken
🐛 Bug Report
To Reproduce
Steps to reproduce the behavior: (same as: https://jestjs.io/docs/en/getting-started)
- Create a new folder
- Init a new npm project with
npm init
- Add Jest as a dependency
npm install --save-dev jest
- Created a
src
folder with amain.js
file and amain.spec.js
test file (one containing sum function and the other the tests as in the Jest docs) - Added a test script in
package.json
. - Run the script with
npm test -- --coverage
- When opening the
coverage/lcov-report/index.html
the HTML does not show the coverage report numbers.
GIT repo here: https://github.com/adyz/jest-coverage-bug-no-ts
Expected behavior
The coverage/lcov-report/index.html
should show the actual report numbers
Link to repl or repo (highly encouraged)
https://github.com/adyz/jest-coverage-bug-no-ts
envinfo
npx: installed 1 in 1.36s
System:
OS: macOS 10.15.2
CPU: (16) x64 Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz
Binaries:
Node: 13.6.0 - /usr/local/bin/node
Yarn: 1.12.3 - ~/.yarn/bin/yarn
npm: 6.13.4 - /usr/local/bin/npm
npmPackages:
jest: ^24.9.0 => 24.9.0
Let me know if I should send this to the istanbul.js as well or just there. Not sure where to go from here. I’ve also noticed that on old projects the report is fine until I remove the node_modules and reinstall.
Thanks a ton!
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Reactions: 3
- Comments: 24 (14 by maintainers)
Commits related to this issue
- Updating package lock to address jest issue 9388. https://github.com/facebook/jest/issues/9388 — committed to sandialabs/slycat by alexsielicki 4 years ago
- fix(coverage): update istanbul-reports to fix HTML coverage reports Per https://github.com/facebook/jest/issues/9388#issuecomment-573371732. — committed to votingworks/bmd by eventualbuddha 4 years ago
- fix(coverage): update istanbul-reports to fix HTML coverage reports Per https://github.com/facebook/jest/issues/9388#issuecomment-573371732. — committed to votingworks/vxsuite by eventualbuddha 4 years ago
Deleting the existing
istanbul-reports
from your lockfile and re-runningnpm
oryarn
should fix the issue. It works in the project I tested, so I think we’re good to go 👍Jest upgraded to istanbul v2 as part of the Jest v24 release (in #7016, to be exact), so upgrading to v24 should fix your issue (as it’ll pull in the fixed version of istanbul-reports@2)
This seems like a bug in istanbul somewhere, as the text reporter works correctly.
@coreyfarrell have you seen this before?
Note that it works correctly on Jest master (which is using the new major of istanbul deps)
@springfred istanbul-reports@1.5.1 is no longer maintained (current version is 3.0.0). The best fix is to upgrade your dependencies so istanbul-reports@2.2.7 or above is used. If this is not an option you will need to pin handlebars in your own package.json to 4.5.3 then perform a fresh
npm install
.I’ve quickly opened up https://github.com/wycats/handlebars.js/issues/1636 upstream linking back to this issue for the reproduction
I’ve posted this bug for a project that now is working perfectly!
I’ve removed the
node_modules
folder and thepackage-lock.json
file.Thank you! 🥳🥳🥳
@adyz thanks for the update. No further testing is needed. I’m planning to release a new version of istanbul-reports@2 soon. Will comment again when that is complete.
BTW you’ll want to remove
package-lock.json
, not package.json. I’m guessing that was just a typo here.