question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. ItĀ collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

jest --watch doesn't show coverage in Vue

See original GitHub issue

šŸ› 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

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:9
  • Comments:14

github_iconTop GitHub Comments

9reactions
theonlydalekingcommented, May 16, 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.

7reactions
cXiaofcommented, 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Ā® Coreā„¢ 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

Read more comments on GitHub >

github_iconTop Results From Across the Web

Jest does not collect coverage from vue files (nuxt)
For me, there is no logical explanation why coverage is collected from JavaScript files but not from vue files.
Read more >
Jest+Vue: no coverage shown for .vue files that don't include ...
According to the code, it happens when nothing executed in a file. It's possible to set a breakpoint there (in node_modules/istanbul-lib-source-maps/lib/Ā ...
Read more >
No coverage for .vue files when using Jest - Get Help
I'm using vue-test-utils with Jest to test single-file Vue components. ... included in the coverage report, just the format used to display.
Read more >
Configuring Jest
js"] will not exclude __tests__ because the negation is overwritten with the second pattern. In order to make the negated glob work in...
Read more >
vscode-jest - Visual Studio Marketplace
Help debug jest tests in vscode. Show coverage information in files being tested. Supports monorepo, react, react-native, vue and variousĀ ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found