jest --watch doesn't show coverage in Vue

Created on 23 Apr 2019  ·  14Comments  ·  Source: facebook/jest

🐛 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
Bug Report Needs Repro Needs Triage

Most helpful comment

at this stage, I think this is actually a feature.

--watch is meant to run tests only on files that both:

  1. has a test(s)
  2. have been changed

--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.

All 14 comments

Same here in React after upgrade
react-scripts 2.1.8 => 3.0.0

react-scripts test --coverage

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

Test Suites: 56 passed, 56 total
Tests: 308 passed, 308 total
Snapshots: 0 total
Time: 20.996s, estimated 21s
Ran all test suites.

Watch Usage: Press w to show more.

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!?

File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s |
-----------------------|----------|----------|----------|----------|-------------------|
All files | 100 | 100 | 100 | 100 | |
components/App | 100 | 100 | 100 | 100 | |
...... | 100 | 100 | 100 | 100 | |

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

Then I copy all code include "node_modules" in new-app folder and paste in my old object.
No coverage again, always be empty

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


envinfo

System:
OS: Windows 10
CPU: (4) x64 Intel(R) Core(TM) i5-7500 CPU @ 3.40GHz
Binaries:
Node: 8.14.0 - D:nodejsnode.EXE
Yarn: 1.12.3 - C:UsersDELLAppDataRoamingnpmyarn.CMD
npm: 6.4.1 - D:nodejsnpm.CMD

I'm experiencing this as well in a vanilla NodeJS project.

$ npx jest
 PASS  __tests__/index.js
 PASS  __tests__/compat.js
-----------|----------|----------|----------|----------|-------------------|
File       |  % Stmts | % Branch |  % Funcs |  % Lines | Uncovered Line #s |
-----------|----------|----------|----------|----------|-------------------|
All files  |    31.25 |    10.34 |    53.85 |       35 |                   |
 compat.js |     17.5 |      3.7 |    33.33 |    21.21 |... 60,61,77,78,82 |
 index.js  |      100 |      100 |      100 |      100 |                   |
-----------|----------|----------|----------|----------|-------------------|

Test Suites: 2 passed, 2 total
Tests:       6 passed, 6 total
Snapshots:   0 total
Time:        2.298s
Ran all test suites.
$ npx jest --watch
 PASS  __tests__/compat.js
 PASS  __tests__/index.js
-----------|----------|----------|----------|----------|-------------------|
File       |  % Stmts | % Branch |  % Funcs |  % Lines | Uncovered Line #s |
-----------|----------|----------|----------|----------|-------------------|
All files  |     17.5 |      3.7 |    33.33 |    21.21 |                   |
 compat.js |     17.5 |      3.7 |    33.33 |    21.21 |... 60,61,77,78,82 |
-----------|----------|----------|----------|----------|-------------------|

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

When run with --watch note that coverage for index.js is not reported.

Interestingly, when using --watch, if I make a change in index.js that causes a test to fail then coverage for index.js will be reported. However, if I instead make a change in __tests__/index.js that causes a test to fail then coverage for index.js is not reported.

envinfo

npx envinfo --preset jest
npx: installed 1 in 1.469s

  System:
    OS: macOS High Sierra 10.13.6
    CPU: (8) x64 Intel(R) Core(TM) i7-3820QM CPU @ 2.70GHz
  Binaries:
    Node: 10.15.3 - ~/.local/nodeenv/lts/bin/node
    Yarn: 1.15.2 - ~/.local/nodeenv/lts/bin/yarn
    npm: 6.9.0 - ~/.local/nodeenv/lts/bin/npm
  npmPackages:
    jest: 24.7.1 => 24.7.1

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.

Do you mean that these files should be untracked for jest to work properly? (without the workaround)

at this stage, I think this is actually a feature.

--watch is meant to run tests only on files that both:

  1. has a test(s)
  2. have been changed

--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.

I think the core problem here is that as far as I can tell there is no workable way to use coverage with watch. This makes it very difficult to iteratively adjust tests to cover areas that are missed. This has proven to be a huge pain point for our team as we moved away from Karma which did support this usecase very well.

@abierbaum how do you mean? Coverage and watch work well together. What isn’t working for you?

@theonlydaleking Maybe I am doing something wrong, but if I start up jest with --watch and --coverage, I don't get any coverage details. It will run tests but won't show coverage.

What I would like is to be able to use --watch and have any tests that are run on a change get updated coverage information that is output.

Try —watchAll @abierbaum like I was saying before. Watch only runs tests on changed files

@theonlydaleking Ok. Just tried that again and it appears to be working. My use case is actually to run watch and then immediately set a pattern with 'p' to zero in on the spec or subsystem I am actually working on testing. I didn't think that was working before, but appears to be now. Thanks for the pointer in the right direction.

Looks like a bug. Is anyone interesting in getting a deep dive and fixing it? :)

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 also having that issue (just that I'm working with the Angular preset) and adding --watchAll=false didn't work for me.. :(

It will show coverage when

1) you remove the --watch
2) replace it by --watchAll or --watchman

perhaps the use case of the --watch is to run tests on changed files only, which kinda make sense that it doesn't produce coverage for all your files.

but I think the best behavior for --watch + coverage, that it should somehow show the coverage of the changed files and not an All files with 0 coverage

Was this page helpful?
0 / 5 - 0 ratings

Related issues

RyanCCollins picture RyanCCollins  ·  93Comments

seibelj picture seibelj  ·  116Comments

sterpe picture sterpe  ·  70Comments

eldh picture eldh  ·  84Comments

vitalibozhko picture vitalibozhko  ·  138Comments