-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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(coverage): exclude injected functions without mapping #7192
base: main
Are you sure you want to change the base?
Conversation
@@ -349,6 +350,29 @@ export class V8CoverageProvider extends BaseCoverageProvider<ResolvedCoverageOpt | |||
// If file was executed by vite-node we'll need to add its wrapper | |||
const wrapperLength = sources.isExecuted ? WRAPPER_LENGTH : 0 | |||
|
|||
// filter out functions without mappings, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All code that is not present on source maps should already be excluded from final coverage report. Bundlers tend to inject plenty of helpers, generators and polyfills that are not present on source maps - these should be automatically be excluded.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All code that is not present on source maps should already be excluded from final coverage report.
Was it the case even before having this patch #5457? I agree that should be the expected behavior of v8-to-istanbul in any cases, but there's still an edge case even after the patch when the injected code's line overlaps with original code as in the reproduction #7130 (comment):
// source
console.log("x");
// generated ("prepended" doesn't get excluded from coverage)
function prepended(){};console.log("x");
function appended(){};
Also it turned out this is also the case for istanbul provider too as seen in the new snapshot test/coverage-test/test/injected-functions.test.ts
, which is not fixed in this PR and haven't investigated yet.
This looks to me a bug, which is fixable either Vitest side or v8-to-istanbul eventually. I'm wondering how you see this issue in general. We want to land ssr transform fix vitejs/vite#18983, which can cause this edge case more often, so I would like to know your opinions on whether it's fine to land or wait until we get a better understanding of the issue.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I did some manual testing with this and see now why this work-around is required. To me this looks like a bug in v8-to-istanbul
. Ideally we should file a bug report there with minimal repro and PR later on. Or even better, not use v8-to-istanbul
at all and roll our own V8 coverage processing.
The #5457 is only about line coverage and does not affect function coverage at all. The v8-to-istanbul
has some special handing for line coverage that is not done for function coverage.
I see that VITE_EXPORTS_LINE_PATTERN
is now conflicting when using Vite version from the PR. Can we remove that and be backwards compatible?
✅ Deploy Preview for vitest-dev ready!Built without sensitive environment variables
To edit notification comments on pull requests, go to your Netlify site configuration. |
Description
This PR filters v8 functions coverage on Vitest side. The idea sounds similar to istanbuljs/v8-to-istanbul#244, but this seems necessary to properly exclude coverage of injected functions at the same line as the original code as seen in the reproduction.
Please don't delete this checklist! Before submitting the PR, please make sure you do the following:
pnpm-lock.yaml
unless you introduce a new test example.Tests
pnpm test:ci
.Documentation
pnpm run docs
command.Changesets
feat:
,fix:
,perf:
,docs:
, orchore:
.