jest: --coverage option is not compatible with --watch option

when you use them together tests still run after each change but test failures are no longer visible.

After each test, the console clears to the following

Using Jest CLI v13.2.3, jasmine2, babel-jest

You’d need to scroll up in the terminal buffer in order to view test failures, which makes --watch much harder to use.

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Comments: 19 (8 by maintainers)

Most upvoted comments

Hi, I’m really interest in --watch and --coverage together. Why? Because I try always to have a good coverage and I have a lots of tests in this project that I’m working on. I Like to see the progress of the coverage and every time that I write some test I want to run the coverage and I’ve to wait a long time to receive the result.

Is there any chance to implement this feature? If not can you explain me why? Do you have any solution to my problem?

Thank you in advance

Hi there and thanks for your awesome efforts for making jest a wonderful testing framework. Just related to using --watch --coverage, my use case is I want to generate a “coverage-final.json” whenever there is a re-run tests, so I the vscode plugin “Code Coverage Highlighter” will show me, what other methods that are still don’t have tests.

This is sure if you practice TDD, you can run jest with coverage on a separate terminal (not using --watch), because with TDD you will have a very good coverage usually, but if this is not the case and you wrote a lot of code then the combination of --watch --coverage + using a plugin for the IDE can help.

Also using --watch --coverage can increase the productivity instead of returning to the terminal and rerun the command line every time you do some tests.

Thanks again for your efforts

I finally got a working configuration.

When the configuration is set in the package.json it won’t work. Therefore, I had to create jest.config.js file with the following contents:

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

And in package.json:

"scripts": {
    "test": "jest --watchAll" // It doesn't work with --watch
}

Ok, let’s do this: instead of erroring, show a message on the top that says “coverage is enabled through the config but not active during --watch”. People might have collectCoverage: true in their config and I don’t want the process to throw if that is the case.

So if I have coverage enabled via my config, is there a way to disable it when trying to run watch in command line?