SFC Vue files with tests disappear from test coverage reports
See original GitHub issueI 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
With Demo.spec.js.old, (zero) coverage reported
vue: ^3.2.23
jest: ^27.3.1
@vue/vue3-jest: ^27.0.0-alpha.4
Issue Analytics
- State:
- Created 2 years ago
- Reactions:5
- Comments:36 (9 by maintainers)
Top GitHub Comments
Thank you for the idea. This versions did not work but I rollbacked into the:
then run
jest --clearCache
Now I have my coverage backs and could continue with this intermediate solution.
I noticed something strange while testing with Vue 3. If the Vue SFC does not import anything itself, the test coverage is reported correctly.
If there are any import statements in the SFC (even
import {ref} from 'vue'
), the file goes missing from test coverage.jest.config.js
Does anyone else see the same behavior?
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 tobabel
, I think.