Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jest watch with code coverage not working

I'm trying to run jest --coverage --watch so that I only get the coverage for whatever component I'm writing tests for and I can see the increased coverage as I write more tests. But while the modified tests are successfully picked up and run, the coverage report comes up empty.

----------|----------|----------|----------|----------|-------------------|
File      |  % Stmts | % Branch |  % Funcs |  % Lines | Uncovered Line #s |
----------|----------|----------|----------|----------|-------------------|
All files |        0 |        0 |        0 |        0 |                   |
----------|----------|----------|----------|----------|-------------------|


Test Suites: 2 passed, 2 total
Tests:       2 passed, 2 total
Snapshots:   0 total
Time:        5.599s
Ran all test suites related to changed files.

The documentation on this is almost zero, but it seems like it should work according to this pr: https://github.com/facebook/jest/pull/5601

like image 906
codemon Avatar asked Mar 15 '26 23:03

codemon


1 Answers

Here is a solution Create a jest.config.js and add the following content

  • jest.config.js
module.exports = {
    collectCoverage: true,
    coverageReporters: [
        "html"
    ]
};

And in package.json:

"scripts": {
    "test": "jest --watchAll"
}
like image 94
Peter Egbujie Avatar answered Mar 17 '26 14:03

Peter Egbujie