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.

SFC Vue files with tests disappear from test coverage reports

See original GitHub issue

I have Jest setup to test files with @vue/vue3-jest and it runs all of the Vue tests just fine, however I came across a peculiar issue regarding test coverage - it was going down in our CI dashboard as I was testing more components.

SFC Vue files without a *.spec.js test show up in the Jest coverage summary with zero coverage as expected. After adding a *.spec.js for a component, it will no longer collect or be listed in the coverage summary in our project.

Regular JavaScript files are unaffected and report coverage as expected.

I have a demo repository setup, however it only partially reproduces our issue - @components/Demo.vue is missing, but the two components in @components/demo/ show up fine (which doesn’t happen in our project). Removing the @components/Demo.spec.js makes it show up again with zero coverage.

~~Demo: https://github.com/wopian/jest-coverage-demo~~

Demo moved to PR: https://github.com/vuejs/vue-jest/pull/423

With Demo.spec.js, coverage unreported

Screenshot 2021-11-29 at 11 45 43

With Demo.spec.js.old, (zero) coverage reported

Screenshot 2021-11-29 at 11 44 19
vue: ^3.2.23
jest: ^27.3.1
@vue/vue3-jest: ^27.0.0-alpha.4

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:5
  • Comments:36 (9 by maintainers)

github_iconTop GitHub Comments

4reactions
kaangokdemircommented, Nov 28, 2022

We have a news from other post:

#480

I applied the workaround and works more less fine.

The coverage its god but in my case i can’t use breakpoints in script vue:

#480 (comment)

The workaround for me in npm is:

"overrides": {
  "@babel/core": "7.17.9",
  "@babel/generator": "7.17.9",
  "istanbul-lib-instrument": "5.2.0"
}

Thank you for the idea. This versions did not work but I rollbacked into the:

 "overrides": {
    "@babel/core": "7.12.10",
    "@babel/generator": "7.12.11",
    "istanbul-lib-instrument": "4.0.3"
  }

then run jest --clearCache

Now I have my coverage backs and could continue with this intermediate solution.

3reactions
jrtituscommented, Jul 2, 2022

I noticed something strange while testing with Vue 3. If the Vue SFC does not import anything itself, the test coverage is reported correctly.

image

If there are any import statements in the SFC (even import {ref} from 'vue'), the file goes missing from test coverage.

image

jest.config.js

module.exports = {
  preset: '@vue/cli-plugin-unit-jest',
  collectCoverageFrom: ['src/**/*.{vue,js}']
}

Does anyone else see the same behavior?

"vue": "3.2.37",
"@vue/cli-plugin-unit-jest": "5.0.6",
"@vue/test-utils": "2.0.0",
"@vue/vue3-jest": "27.0.0", 
"babel-jest": "27.5.1", 
"jest": "27.5.1", 

EDIT: Switching the coverageProvider setting to "v8", as mentioned by someone in an earlier comment resolves the issue, so it’s definitely a problem related to babel, I think.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Is there a vue-jest config that allows jest to coverage .vue SFC ...
I'm using Nuxtjs on a project and testing with jest. Recently I found out that vue-jest do not coverage SFC without methods (JS...
Read more >
Guide to Unit Testing Vue Components - TestDriven.io
This article serves as a guide for unit testing Vue components. ... the code coverage of your unit tests; Structure your unit test...
Read more >
quasar/quasar-app-extension-testing-unit-jest - npm package
They have been replaced by the installQuasarPlugin helper, which you should call at the very top of your test files. Import Jest helpers...
Read more >
No coverage for .vue files using vue-jest and vue-test-utils
However, this is not reported in the in the test coverage report generated by Jest, as can be seen below. For the simplified...
Read more >
Code coverage with Storybook test runner - JS.ORG
Get story coverage to find missing edge cases. ... I'm excited to share that Storybook test runner now generates coverage reports.
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