jest: jest --watch doesn't show coverage in Vue
đ Bug Report
Running jest --watch
in a Vue project with collectCoverage: true
and collectCoverageFrom: ['src/**/*.{js,vue}']
doesnât show coverage.
It works as expected when running just jest
, but problem arises when running jest --watch
To Reproduce
Run jest
& jest --watch
in the reproduction repo
Expected behavior
jest
works as expected, shows coverage info
> jest
PASS src/test.js
test
â test (3ms)
------------|----------|----------|----------|----------|-------------------|
File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s |
------------|----------|----------|----------|----------|-------------------|
All files | 57.14 | 50 | 0 | 57.14 | |
src | 0 | 100 | 100 | 0 | |
index.js | 0 | 100 | 100 | 0 | 2,3,5 |
src/App | 72.73 | 50 | 0 | 72.73 | |
index.vue | 72.73 | 50 | 0 | 72.73 | 7,8,11 |
------------|----------|----------|----------|----------|-------------------|
Test Suites: 1 passed, 1 total
Tests: 1 passed, 1 total
Snapshots: 0 total
Time: 5.748s
Ran all test suites.
jest --watch
does not show any coverage
> jest --watch
PASS src/test.js
test
â test (7ms)
----------|----------|----------|----------|----------|-------------------|
File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s |
----------|----------|----------|----------|----------|-------------------|
All files | 0 | 0 | 0 | 0 | |
----------|----------|----------|----------|----------|-------------------|
Test Suites: 1 passed, 1 total
Tests: 1 passed, 1 total
Snapshots: 0 total
Time: 5.985s
Ran all test suites.
Watch Usage: Press w to show more.
Link to repl or repo (highly encouraged)
Repro: https://github.com/laggingreflex/repro-vue-jest-template
Run npx envinfo --preset jest
System:
OS: Windows 10
CPU: (8) x64 Intel(R) Core(TM) i7-7700HQ CPU @ 2.80GHz
Binaries:
Node: 10.15.0
npm: 6.4.1
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Reactions: 9
- Comments: 17
at this stage, I think this is actually a feature.
âwatch is meant to run tests only on files that both:
âwatchAll runs all tests on every file change.
IMO itâs just a little confusing for newbies (like myself) when using --watch and seeing no output. Perhaps this is an opportunity for clarification in the docs to make it absolutely obvious?? at this stage, i donât think itâs a bug. In fact itâs actually quite smart as it wont waste time running tests on files that have not changed.
Same here in React after upgrade react-scripts 2.1.8 => 3.0.0
And I try to use create-react-app to creat an new app, copy my code and paste in new-app folder. Run âreact-scripts test --coverageâ again. It works!?
Then I copy all code include ânode_modulesâ in new-app folder and paste in my old object. No coverage again, always be empty
???
envinfo
I notice that jest only tests files that are not in a git commit. To test files that regardless of git status i used --watchAll to get around this.
I was having the same issue. With Jest version 24.9.0 if I add --watchAll=false or --watchAll=false it works. Apparently is the only presence of --watchAll flag, at least for me.
Iâm experiencing this as well in a vanilla NodeJS project.
When run with
--watch
note that coverage forindex.js
is not reported.Interestingly, when using
--watch
, if I make a change inindex.js
that causes a test to fail then coverage forindex.js
will be reported. However, if I instead make a change in__tests__/index.js
that causes a test to fail then coverage forindex.js
is not reported.envinfo