vuejs / vue-jest

Jest Vue transformer
MIT License
748 stars 156 forks source link

SFC Vue files with tests disappear from test coverage reports #422

Open wopian opened 2 years ago

wopian commented 2 years ago

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
lmiller1990 commented 2 years ago

Odd, definitely a bug. Is this something you might be interested in looking into? I'd recommend trying to reproduce it in this repo next, then we can easily debug, test and deploy a fix. You could add a test project here: https://github.com/vuejs/vue-jest/tree/master/e2e/3.x

wopian commented 2 years ago

I've added a more minimal reproduction project there, though I don't know if I will have the free time to investigate further due to work commitments

lucassonsinlima commented 2 years ago

Facing the same here, I'm trying to find out something that could cause this but I not went so far

vue: ^3.2.26
@vue/cli-plugin-unit-jest: ^5.0.0-rc.1
@vue/vue3-jest: ^27.0.0-alpha.4
lmiller1990 commented 2 years ago

If anyone wants to take a look at this, it would be great! I'm too busy to look at vue-jest bugs at this point in time.

jonsalvas commented 2 years ago

for those who are interested: we had the same issue in our project and as workaround we returned to

"vue-jest": "^5.0.0-alpha.10",

for now until this issue is fixed.

lmiller1990 commented 2 years ago

Interesting, we should find out the different between the code in v5 and @vue/vue3-jest@27 - they are very similar, it's just between the two, we moved from semantic versioning to matching the Jest version and a monorepo. The actual code is quite similar, so if someone can track down what broke and port it to @vue/vue3-jest@27, that'd be great.

kinoli commented 2 years ago

We had the same issue, switching the reporter to V8 fixed it.

websmurf commented 2 years ago

I'm not entirely certain if it's related, but we're seeing 'weird' things in coverage as well. (vue2 + vue-jest) I've gone back in our pipeline and narrowed it down to this upgrade:

image

Difference in coverage: image

adholland commented 2 years ago

Seeing exactly the same with recent version of (vue2 + vue-jest). Vue2 version 4.5.17, Vue-jest version 3.0.7.

websmurf commented 2 years ago

After my last comment, we've tried to reconstruct the coverage by downgrading. In the end, we also needed to downgrade @babel/core to version ^7.16.7 in order to make coverage working again.

So we are now in the situation that coverage is working again but with vue-jest@^3.0.7 and @babel/core@^7.16.7 on Jest 28.

kinoli commented 2 years ago

Why don't you just use V8?

wopian commented 2 years ago

Why don't you just use V8?

V8 is incredibly slow on a GitHub Actions runner and runs into OOM errors for large projects

https://github.com/vuejs/vue-jest/pull/423#issuecomment-990940792

AnthonyRuelle commented 2 years ago

Hey,

Is there a date announced for the correction of this bug?

I'm waiting for this fix because on my application I have 100% coverage everywhere and it's really very annoying.

I tried to revert to previous versions and without success.

The update of the lock package following an audit fix was fatal for me

Thx !

joshua-farmlink commented 2 years ago

Can anyone share a working set of npm packages that gives correct coverage for Vue 2? We were previously using jest@26.6.3 with vue-jest@3.0.7 and upgraded to v28 with @vue/vue2-jest, now our coverage numbers are completely wrong. Jest is showing 1 statement for the entire SFC instead of any methods/computed properties/etc inside the Githubissues.

  • Githubissues is a development platform for aggregating issues.