Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: fix incorect coverage reporting (fix #375) #655

Merged
merged 16 commits into from Feb 1, 2022

Conversation

Demivan
Copy link
Member

@Demivan Demivan commented Jan 28, 2022

This reverts #584 - runtime coverage is not reporting functions that are not used as not covered.

Added manual soucemap adjustments because Vitest is prepending code to every file.

Fixes #375

image

@Demivan Demivan requested a review from antfu January 28, 2022 18:50
@netlify
Copy link

netlify bot commented Jan 28, 2022

✔️ Deploy Preview for vitest-dev ready!

🔨 Explore the source changes: 725cb58

🔍 Inspect the deploy log: https://app.netlify.com/sites/vitest-dev/deploys/61f510615a70f20008030668

😎 Browse the preview: https://deploy-preview-655--vitest-dev.netlify.app

Copy link
Contributor

@mitchelvanbever mitchelvanbever left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested it agains a local branch but playing around with my test files did not result in different coverage and there is one line always uncovered no matter what test I write to accomodate for covering that line.

@Demivan
Copy link
Member Author

Demivan commented Jan 28, 2022

@mitchelvanbever can you share a repo?

@mitchelvanbever
Copy link
Contributor

@mitchelvanbever can you share a repo?

Just tried with the example folder react-testing-lib and it shows the same behaviour. The other node project is private, but I can try it with another public repo I have

@Demivan
Copy link
Member Author

Demivan commented Jan 28, 2022

This change fixed coverage for coverage-test test. And tested coverage with fluent-vue - it is correct now.

@Demivan
Copy link
Member Author

Demivan commented Jan 29, 2022

Just tried with the example folder react-testing-lib and it shows the same behaviour. The other node project is private, but I can try it with another public repo I have

Tested with react-testing-lib example after skipping error test, error branch is now not covered:

image

@mitchelvanbever
Copy link
Contributor

Just tried with the example folder react-testing-lib and it shows the same behaviour. The other node project is private, but I can try it with another public repo I have

Tested with react-testing-lib example after skipping error test, error branch is now not covered:

image

I feel really stupid 🙈 I think I just didn't configure the coverage properly yesterday when trying it out. I was too excited about it 😬 I tried again on the example dir, with the proper configuration and I can confirm to have the same result as you show.

@antfu
Copy link
Member

antfu commented Feb 1, 2022

Epic, awesome work @Demivan!

// This is a magic number. It corresponds to the amount of code
// that we add in packages/vite-node/src/client.ts:114 (vm.runInThisContext)
// TODO: Include our transformations in soucemaps
const offset = 190
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Later we should calculate this number based on the length of the arguments, but I am fine to have the magic number for now.

@patak-dev patak-dev merged commit 5ef622a into vitest-dev:main Feb 1, 2022
@cexbrayat
Copy link
Contributor

FYI, the introduction of takeCoverage makes it incompatible with node < v14.18
As Stackblitz uses v14.16, the runnable examples can no longer launch the code coverage in WebContainers:

❯ npm run coverage
$ vitest run --coverage
(node:56) UnhandledPromiseRejectionWarning: file:///home/projects/vitest-dev-vitest-ilb2yu/node_modules/vitest/dist/create-a1bc541a.js:13
import { takeCoverage } from 'v8';
         ^^^^^^^^^^^^

@Demivan
Copy link
Member Author

Demivan commented Feb 3, 2022

@cexbrayat Yeah, we have issue about this already #670. Not sure what is the best solution. Without takeCoverage coverage will be incomplete.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Wrong coverage report
6 participants