Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

--coverage option is not compatible with --watch option #1284

Closed
tonyxiao opened this issue Jul 12, 2016 · 19 comments
Closed

--coverage option is not compatible with --watch option #1284

tonyxiao opened this issue Jul 12, 2016 · 19 comments

Comments

@tonyxiao
Copy link

tonyxiao commented Jul 12, 2016

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.

@cpojer
Copy link
Member

cpojer commented Jul 13, 2016

cc @DmitriiAbramov

Maybe we should have a short summary only (overall coverage) when using coverage and watch?

@aaronabramov
Copy link
Contributor

wait... why would you use --watch and --coverage at the same time? i used to throw an error in this case before, because the coverage will never be accurate

@cpojer
Copy link
Member

cpojer commented Jul 13, 2016

I have asked this question myself but people seem to want it.

@tonyxiao
Copy link
Author

Hmm fair question. @DmitriiAbramov . Maybe we should document the fact that --watch and --coverage should not be used together?

@aaronabramov
Copy link
Contributor

@tonyxiao i think if there is any valid use for it, we should make it work. But if not, i think it's better to just throw an error and kill the process. Wrong information is worse than no information :)

@tonyxiao
Copy link
Author

@DmitriiAbramov agreed. I'd be totally happy if we throw error and kill the process. The problem was not knowing that they shouldn't be used together and expecting it to work.

@cpojer
Copy link
Member

cpojer commented Jul 13, 2016

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.

@tonyxiao
Copy link
Author

That would work too. 👍

@calclavia
Copy link

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

@cpojer
Copy link
Member

cpojer commented Aug 30, 2016

Fixed in #1515 for Jest 15.

@cpojer cpojer closed this as completed Aug 30, 2016
@dsifford
Copy link

dsifford commented Nov 23, 2016

Was @calclavia's question even answered? I'm curious about this as well.

--no-coverage doesn't seem to work.

@cpojer
Copy link
Member

cpojer commented Nov 29, 2016

You are right, --no-coverage isn't currently supported. If you'd like to add it, please send us a PR! :)

@ninahaack
Copy link

ninahaack commented Feb 23, 2018

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

@SimenB
Copy link
Member

SimenB commented Feb 24, 2018

See #5601

@sant123
Copy link

sant123 commented Mar 29, 2019

See #7331

@arkanmgerges
Copy link

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

@Abadii
Copy link

Abadii commented Mar 16, 2020

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
}

@penchef
Copy link

penchef commented Sep 9, 2020

Thanks @Abadii!

jest --watchAll --collect-coverage

does the job. TDD FTW!

@github-actions
Copy link

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.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 11, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests