vuejs / vue-jest

Jest Vue transformer
MIT License
746 stars 157 forks source link

chore(vue3-jest): add missing code coverage e2e for #422 #423

Closed wopian closed 2 years ago

wopian commented 2 years ago

See https://github.com/vuejs/vue-jest/issues/422 for details on the issue.

This minimal reproduction reproduces the bug I see in our project, with SFC Vue files that are imported in test files vanish from coverage reports. Untested SFC Vue files are reported correctly with no code coverage.

Both Basic.vue and Untested.vue are identical and use the current SFC <script setup> syntax as of Vue 3.2.22

Screenshot 2021-12-03 at 15 14 23
wopian commented 2 years ago

Should the following be added to jest.config.js to deliberately fail the test script when coverage from Basic.vue is not collected? (it should be somewhere between 25-50% as the method function is unused, but 1% works too)

  coverageThreshold: {
    global: {
      lines: 1
    }
  }
wopian commented 2 years ago

@lmiller1990 this appears to be an issue between Vue Jest and the default (babel) coverage provider used by Jest.

Running these tests (and in production repo) with the experimental v8 engine as the coverage provider correctly outputs coverage data for SFC Vue files - --coverageProvider=v8

Though I'm unable to use that as a temporary client-side fix in GitHub Actions as V8 is 6x slower to run (and without increasing heap size to 4GB, also crashes from OOM)

lmiller1990 commented 2 years ago

I see. What's the next step here, then, to get this fixed and merged?

jolting commented 2 years ago

Related? https://github.com/facebook/jest/issues/11776

wopian commented 2 years ago

Unfortunately I do not have the available time to investigate why and what package between vue-jest, jest and whichever babel package is responsible for coverage is causing the issue.

Related? facebook/jest#11776

Checking that issue, it seems to be the exact opposite behaviour of this issue - no (javascript) coverage with v8 and coverage with the default babel coverage provider.

Here, there's no Vue SFC coverage (javascript is covered fine) with the default babel coverage provider, but v8 coverage provider has Vue SFC coverage.

Roriz commented 2 years ago

@lmiller1990 this appears to be an issue between Vue Jest and the default (babel) coverage provider used by Jest.

Running these tests (and in production repo) with the experimental v8 engine as the coverage provider correctly outputs coverage data for SFC Vue files - --coverageProvider=v8

Though I'm unable to use that as a temporary client-side fix in GitHub Actions as V8 is 6x slower to run (and without increasing heap size to 4GB, also crashes from OOM)

Thank you for this workaround, it works just fine in my specific case.

If helps anyone in the future, my setup:

  "@vue/cli-service": "5.0.4",
  "@vue/vue3-jest": "28.0.0",
  "babel-jest": "28.1.0",
  "jest": "28.1.0"