-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
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
No coverage when running in watch mode #7331
Comments
also happens on ubuntu 18.04 |
Also hitting this issue even though there are changed tests that ran:
|
@MurakamiKennzo what do you expect "correct coverage" to be? All |
@SimenB I updated my comment above to be more clear. Tests are ran and coverage works when all tests are ran, but in watch more coverage is not collected even for the files that are affected. |
@villelahdenvuo that's a separate issue from the OP, please include a reproduction (maybe in a new issue) |
@SimenB How is it different from the OP? According to the example repo included in the OP the issue appears in watch mode after adding a new test. That is my case as well, at first I had no coverage as expected, but then I added a new tests to those two files shown and it still says coverage Unknown. |
Ah, sorry, I missed the step editing the test while watch mode was running. @stipsan thoughts on how to fix this? You're my goto "coverage in watch mode" guy :D |
I agree what @villelahdenvuo said. please follow the step and you will understand what i mean. |
I'll have to look into it more but on top of my head it sounds like the problem is related to the collectCoverageFrom patterns that are added in the runner: https://github.com/facebook/jest/blob/c01b4c75a2f65e9fa122adf69b0ac11875f1fc74/packages/jest-cli/src/runJest.js#L163-L188 So my theory is that it's generating a too exclusive pattern on the first run that is persisted through the second run with the added test. |
Same issue here. When I launch Jest with If I press If I edit a file, the tests run and again, the coverage is But! If I hit |
I'm getting the same bug, or a variant of it. When I first run |
It seems like jest doesn't really respect As a workaround I found that you can use |
Recently converted to Jest, and this is the only thing missing from my old Karma / jasmine setup. Not having coverage is a pain point for interactive test development. Being able to watch the coverage and gradually increase it through additional tests and IDE extensions that show coverage inline is a huge win if it could work like it does in Karma. |
It'd be great to have this, is there any update? Is anyone working on a fix? With a little guidance I'd be happy to contribute to a solution for this. |
I was able to get everything working fine by simply starting jest with watchAll. Then if I want to see the coverage for a single test I just use 'p' to match the pattern of the file name. Works great. Just confusing to know to use watchAll. |
For those who may actually have a different problem: I fixed mine by simply changing |
Just in case this helps anyone else who does still want to run tests using i.e.
I tried moving the unwanted glob file patterns from
before collectCoverageFrom: [
'src/**/*.{js,vue}',
'!src/main.js',
'!**/node_modules/**',
'!src/vendor/**/*'
] after collectCoverageFrom: [
'src/**/*.{js,vue}'
],
coveragePathIgnorePatterns: [
'src/main.js',
'/node_modules/',
'src/vendor/'
] This should probably be in the Jest docs somewhere due to some change that is causing the problem but 🤷♀️. In addition, if this helps anyone on linux: we use Docker - and sometimes it makes sudo chown -R user:group test/unit/coverage
|
Any updates on this? |
But this returns coverage for all files for every file change. |
Can you outline the exact order of the commands you're typing in order to get this to work? I tried your workaround but I get the same result: unknown coverage report. |
yeah.. but i guess that's the limitation with jest, watch and coverage 🤷♀️ |
Seems like it's back to not working for me, unsure if a release broke it or something, no idea 🤷♀️. I can confirm what others say though |
I'm experiencing the same behavior, |
Add scripts for CI and for local code coverage - test:ci for CI - test:cov to see code coverage locally. Because running with coverage slows down the test suite, this was added as an optional script. The --watchAll flag was added to `test:cov` because there is an issue where coverage reports 0/0% when tests run in interactive mode. jestjs/jest#7331 jest-community/vscode-jest#433 Have ESLint and Git ignore the coverage output Add tests for the App component Update README with unit test instructions
Add scripts for CI and for local code coverage - test:ci for CI - test:cov to see code coverage locally. Because running with coverage slows down the test suite, this was added as an optional script. The --watchAll flag was added to `test:cov` because there is an issue where coverage reports 0/0% when tests run in interactive mode. jestjs/jest#7331 jest-community/vscode-jest#433 Have ESLint and Git ignore the coverage output Add tests for the App component Update README with unit test instructions
Add scripts for CI and for local code coverage - test:ci for CI - test:cov to see code coverage locally. Because running with coverage slows down the test suite, this was added as an optional script. The --watchAll flag was added to `test:cov` because there is an issue where coverage reports 0/0% when tests run in interactive mode. jestjs/jest#7331 jest-community/vscode-jest#433 Have ESLint and Git ignore the coverage output Add tests for the App component Update README with unit test instructions
Add scripts for CI and for local code coverage - test:ci for CI - test:cov to see code coverage locally. Because running with coverage slows down the test suite, this was added as an optional script. The --watchAll flag was added to `test:cov` because there is an issue where coverage reports 0/0% when tests run in interactive mode. jestjs/jest#7331 jest-community/vscode-jest#433 Have ESLint and Git ignore the coverage output Add tests for the App component Update README with unit test instructions
Add scripts for CI and for local code coverage - test:ci for CI - test:cov to see code coverage locally. Because running with coverage slows down the test suite, this was added as an optional script. The --watchAll flag was added to `test:cov` because there is an issue where coverage reports 0/0% when tests run in interactive mode. jestjs/jest#7331 jest-community/vscode-jest#433 Have ESLint and Git ignore the coverage output Add tests for the App component Update README with unit test instructions
In order to generate the coverage report, the test script must be: test --watchAll --collect-coverage |
All of these comments saying to use the For example, let's say some files have been changed a few commits ago. You run your unit tests and generate coverage for changed files (i.e, using Perhaps what would be useful is a flag to tell jest to generate coverage for files that have changed since the last time a coverage report was generated. Perhaps in this mode, jest could associate a coverage report with a commit hash. The next time you generate a coverage report, it will do a diff between your current HEAD and that older commit, and rerun tests for any files that have changed since then. If there is no coverage report at all, we run the entire test suite. The flag could be something like:
The name could probably be something better but you get the idea. This would fit my use case but I'm not sure about everyone else. The motivation behind it for me is that some of our bigger test suites can take a long time to run. It's annoying to have to run all of your tests to check the coverage of the files you've been working on. |
I don't prefer having to resort to I agree that we should just be able to watch specific file changes only for coverage. Alas, Jest don't allow for this. My comments are just to aid those that need coverage and watch to work for them given the current Jest api/options, that's all. |
Previously I also had the problem of coverage not showing. So my folder structure was like this:
I've done various configurations as suggested above, as well as what I found on Stack Over Flow, but the coverage results are still not showing up. After a day looking for a way and couldn't find it, I took the initiative to publish the repo to Github, then clone it to D:/, and Voillaaaaa. the coverage result appears. Then out of curiosity, I cut the clone results to the I did a few experiments, and it turns out that all the code in the After I changed it again to May this issue occur because of the directory that contains a square bracket([]). |
If it is that simple, by using |
@tomavic You don't want to run all the tests every time you execute the tests for the first time. I guess it's fine if your tests suits executes in a few seconds. If it's more than 10 secondes it's start to be annoying. |
@tomavic I personally don't care about coverage for all files when i'm working on just one or a select few. Thus why |
Yes I see. Now I can understand why we should consider Although, it's weird that it is an opened issue since 2018!! P.S What make me came here at first place, I am migrating from Jasmine to Jest, I have 296 test case 😅 I've tried
But it didn't generate the coverage. |
This issue is stale because it has been open for 1 year with no activity. Remove stale label or comment or this will be closed in 30 days. |
Don't think this should be closed. The workflow of test coverage with --watchAll is pretty terrible. Is this prioritized? |
Any updates on this? My team recently stopped using |
@rafaelrozon As a workaround you can use |
This issue is stale because it has been open for 1 year with no activity. Remove stale label or comment or this will be closed in 30 days. |
|
🐛 Bug Report
when I run jest --watch, I see unknown coverage.
To Reproduce
see Link repo.
Expected behavior
show correct coverage.
Link to repl or repo (highly encouraged)
jest-watch-coverage-bug
Run
npx envinfo --preset jest
Paste the results here:
System: OS: macOS 10.14 CPU: x64 Intel(R) Core(TM) m3-6Y30 CPU @ 0.90GHz Binaries: Node: 9.10.1 - /usr/local/bin/node npm: 6.4.1 - /usr/local/bin/npm npmPackages: jest: ^23.6.0 => 23.6.0
The text was updated successfully, but these errors were encountered: