vue-jest: Coverage report incorrect
I’ve been trying to get jest to work properly with a Vue 2 + Vite project. Jest reports pass/fail as I would expect, but the coverage report seems incorrect. Link to the repro here: https://github.com/qkjosh/vue-jest-coverage
package.json
"devDependencies": {
"@babel/core": "7.18.5",
"@babel/preset-env": "^7.18.2",
"@vue/test-utils": "^1.2.2",
"@vue/vue2-jest": "^28.0.0",
"babel-jest": "28.1.1",
"jest": "28.1.1",
"jest-environment-jsdom": "28.1.1",
"vite": "2.9.12",
"vite-plugin-vue2": "^2.0.1"
}
Given an incomplete test suite, the coverage report indicates 100% coverage and seems to treat the whole SFC component as one statement. Do I have something completely misconfigured, or is the coverage report broken?


About this issue
- Original URL
- State: open
- Created 4 years ago
- Reactions: 23
- Comments: 37 (1 by maintainers)
Is there any other workaround? Downgrading
@babel/coreand@babel/generatordidn’t work for me, the coverage is still incorrect. Downgradingjestand@vue/vue2-jestto versions28solves it partly, it generates valid coverage, but some files are missing for some reason…EDIT: Installing
jest@28and@vue/vue2-jest@28along with addingcoverageProvider:v8to jest config did the trick for me.Using yarn we were able to fix this by locking both versions of
@babel/coreand@babel/generatorto7.17.9(thanks to the suggestion from @udebella )We only use babel for jest so this doesn’t have any other side effects for us, YMMV.
This issue is not relevant to this topic at all !!!
This solved my issue https://github.com/vuejs/vue-jest/issues/522, probably worth trying here as well?
Upgrading couple of packages and editing jest.config.ts fixed the issue with coverage.
package.json
jest.config.ts
works on vue3 too. thx @GrRivero @rklos
My coworker noticed this issue still persists with
"@vue/vue3-jest": "^29.2.6". Our team was able to fix the odd coverage behavior by adding"coverageProvider": "v8"to our app’s Jest config fileThis fix has stopped working quite time ago. With step by step method I have found that the recent update of the
istanbul-lib-instrumenthad broken something (there is an issue: https://github.com/istanbuljs/istanbuljs/issues/707).So the next iteration of the workaround is (for npm >= 8):
Yea, v8 works when it comes to coverage, but it is a huge tradeoff in favor of test speed and coverage report accuracy… would be really great to fix babel provider.
@Envoy49 This topic talks about fixes for coverage reports. After following one of many fixes from this topic, the coverage reports issue was gone. I updgraded Jest from v27 to v28 || v29, and this error
TypeError: Cannot read properties of undefined (reading 'testEnvironmentOptions')started. If it happened to me, it will surelly happen to other people. I had to rollback Jest to v27 because installingjest-environment-jsondid not fix the issue, as explained in jest’s official migration doc.Why Im I seeing this error message
TypeError: Cannot read properties of undefined (reading 'testEnvironmentOptions')It makes no sense, because I installedjest-environment-jsdomupdate jest and @vue/vue2-jest to version 28.1.0 also did the trick for me
Waiting for the fix, in the package.json:
Any update on it?
I’m also having this issue. Is the above PR being considered for a resolution here?
Downgrading to 7.17.9 does not work because in
@babel/corethey did not freeze their dependencies. If you have a project that work, just make sure you don’t upgrade@babel/coredependencies: removing and recreating yourpackage-lock.jsonleads to issue. 😦My really ugly workaround is to to prevent
@babel/generatorto update to a buggy version. So I added inside mypackage.json:Then doing an
npm installfixes brokenpackage-lock.json. Be careful with this fix, because it forces a version of one dependency inside@babel/corewhich seems to rely on consistent versions : this workaround could not work or break your project: don’t forget to remove the override part from yourpackage.jsonwhen this issue is fixed.Maybe knowing where the issue comes from more precisely will help maintainers?
Edit: This solution works only for npm > 8.3.0 as overrides were introduced in this version. If you still use an older version, you can use @AnthonyRuelle solution If you use yarn, you can use @BenShelton solution
I have downgraded my
@babel/coreto 7.17.9 just before switched to@jridgewell/gen-mappingon 7.17.10 but it seems no luckAnyone with a proposed solution much appreciated