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

jest --watch doesn't show coverage in Vue #8364

Closed
laggingreflex opened this issue Apr 23, 2019 · 17 comments
Closed

jest --watch doesn't show coverage in Vue #8364

laggingreflex opened this issue Apr 23, 2019 · 17 comments

Comments

@laggingreflex
Copy link

🐛 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
@cXiaof
Copy link

cXiaof commented Apr 23, 2019

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:\nodejs\node.EXE
Yarn: 1.12.3 - C:\Users\DELL\AppData\Roaming\npm\yarn.CMD
npm: 6.4.1 - D:\nodejs\npm.CMD

@michaelsbradleyjr
Copy link

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

@theonlydaleking
Copy link

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.

@amaankulshreshtha
Copy link

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

@theonlydaleking
Copy link

theonlydaleking commented May 15, 2019

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.

@abierbaum
Copy link

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.

@theonlydaleking
Copy link

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

@abierbaum
Copy link

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

@theonlydaleking
Copy link

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

@abierbaum
Copy link

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

@thymikee
Copy link
Collaborator

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

@GHMT
Copy link

GHMT commented Sep 10, 2019

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.

@LironHazan
Copy link

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

@juliusdejon
Copy link

juliusdejon commented Feb 25, 2020

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

@github-actions
Copy link

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.

@github-actions github-actions bot added the Stale label Feb 17, 2023
@github-actions
Copy link

This issue was closed because it has been stalled for 30 days with no activity. Please open a new issue if the issue is still relevant, linking to this one.

@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Mar 19, 2023
@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 Apr 19, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests