Running with coverage option throws "Cannot find module 'lcov'"
See original GitHub issue🐛 Bug Report
Running with jest --coverage throws the following error:
yarn run v1.19.1
$ jest --coverage
PASS src/index.test.js
add
✓ should work (3ms)
----------|---------|----------|---------|---------|-------------------
File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s
----------|---------|----------|---------|---------|-------------------
All files | 100 | 100 | 100 | 100 |
index.js | 100 | 100 | 100 | 100 |
----------|---------|----------|---------|---------|-------------------
Failed to write coverage reports:
ERROR: Error: Cannot find module 'lcov'
Require stack:
- /Users/shihsyuanyan/Desktop/test/jest-coverage-issue/node_modules/istanbul-reports/index.js
- /Users/shihsyuanyan/Desktop/test/jest-coverage-issue/node_modules/@jest/reporters/build/coverage_reporter.js
- /Users/shihsyuanyan/Desktop/test/jest-coverage-issue/node_modules/@jest/reporters/build/index.js
- /Users/shihsyuanyan/Desktop/test/jest-coverage-issue/node_modules/@jest/core/build/TestScheduler.js
- /Users/shihsyuanyan/Desktop/test/jest-coverage-issue/node_modules/@jest/core/build/jest.js
- /Users/shihsyuanyan/Desktop/test/jest-coverage-issue/node_modules/jest-cli/build/cli/index.js
- /Users/shihsyuanyan/Desktop/test/jest-coverage-issue/node_modules/jest-cli/bin/jest.js
- /Users/shihsyuanyan/Desktop/test/jest-coverage-issue/node_modules/jest/bin/jest.js
STACK: Error: Cannot find module 'lcov'
Require stack:
- /Users/shihsyuanyan/Desktop/test/jest-coverage-issue/node_modules/istanbul-reports/index.js
- /Users/shihsyuanyan/Desktop/test/jest-coverage-issue/node_modules/@jest/reporters/build/coverage_reporter.js
- /Users/shihsyuanyan/Desktop/test/jest-coverage-issue/node_modules/@jest/reporters/build/index.js
- /Users/shihsyuanyan/Desktop/test/jest-coverage-issue/node_modules/@jest/core/build/TestScheduler.js
- /Users/shihsyuanyan/Desktop/test/jest-coverage-issue/node_modules/@jest/core/build/jest.js
- /Users/shihsyuanyan/Desktop/test/jest-coverage-issue/node_modules/jest-cli/build/cli/index.js
- /Users/shihsyuanyan/Desktop/test/jest-coverage-issue/node_modules/jest-cli/bin/jest.js
- /Users/shihsyuanyan/Desktop/test/jest-coverage-issue/node_modules/jest/bin/jest.js
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:892:15)
at Function.Module._load (internal/modules/cjs/loader.js:785:27)
at Module.require (internal/modules/cjs/loader.js:956:19)
at require (internal/modules/cjs/helpers.js:74:18)
at Object.create (/Users/shihsyuanyan/Desktop/test/jest-coverage-issue/node_modules/istanbul-reports/index.js:19:20)
at /Users/shihsyuanyan/Desktop/test/jest-coverage-issue/node_modules/@jest/reporters/build/coverage_reporter.js:300:20
at Array.forEach (<anonymous>)
at CoverageReporter.onRunComplete (/Users/shihsyuanyan/Desktop/test/jest-coverage-issue/node_modules/@jest/reporters/build/coverage_reporter.js:298:25)
at ReporterDispatcher.onRunComplete (/Users/shihsyuanyan/Desktop/test/jest-coverage-issue/node_modules/@jest/core/build/ReporterDispatcher.js:71:10)
at TestScheduler.scheduleTests (/Users/shihsyuanyan/Desktop/test/jest-coverage-issue/node_modules/@jest/core/build/TestScheduler.js:280:5)
Test Suites: 1 passed, 1 total
Tests: 1 passed, 1 total
Snapshots: 0 total
Time: 0.48s, estimated 1s
Ran all test suites.
To Reproduce
- Create a new folder and initialize with
yarn init yarn add --dev jestyarn run jest --init- write some tests
yarn run jest --coverage- It throws errors
Expected behavior
I checked the coverageReports option in the documentation. It should generate lcov related reports without any error, I guess?
Link to repl or repo (highly encouraged)
jest-coverage-issue. Simply run yarn run test:cov to reproduce the error.
envinfo
System:
OS: macOS Mojave 10.14.1
CPU: (8) x64 Intel(R) Core(TM) i7-4770HQ CPU @ 2.20GHz
Binaries:
Node: 13.1.0 - ~/.nvm/versions/node/v13.1.0/bin/node
Yarn: 1.19.1 - /usr/local/bin/yarn
npm: 6.12.1 - ~/.nvm/versions/node/v13.1.0/bin/npm
npmPackages:
jest: ^25.1.0 => 25.1.0
Issue Analytics
- State:
- Created 3 years ago
- Reactions:2
- Comments:6
Top Results From Across the Web
Jest passing tests but --covering option not picking up files
I have written two tests for a typescript class. Those two tests pass so jest successfully retrieves the test files. I then use...
Read more >Configuring Jest
The bail config option can be used here to have Jest stop running tests ... Add "text" or "text-summary" to see a coverage...
Read more >Code Coverage - Cypress Documentation
This guide explains how to find what parts of your application code are covered by Cypress tests so you can have 100% confidence...
Read more >Configuring Jest
If Jest is taking a long time to calculate coverage at the end of a test run, try setting this option to false...
Read more >istanbul | Yarn - Package Manager
This module is no longer maintained, try this instead: npm i nyc Visit ... Istanbul - a JS code coverage tool written in...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

That’s weird, some bug in node then? Closing, but can reopen if it’s reproducible in current versions of node
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.