-
-
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
Missing function coverage when transform prepends code right before the function #7130
Comments
The 2nd one is because the lines with vitest/packages/coverage-v8/src/provider.ts Lines 34 to 35 in 178f515
vitest/packages/coverage-v8/src/provider.ts Line 402 in 178f515
|
I think this is a bug in coverage conversion and probably we can fix it. I made a simpler reproduction with user land transform plugin. https://github.com/hi-ogawa/reproductions/tree/main/vitest-7130-prepended-function-coverage Probably the issue is that istanbul fails to filter out "injected function" from the coverage when it lives in the same line which has mappings. https://github.com/istanbuljs/v8-to-istanbul/blob/46b972458b40ea0d628c80dd60223cc909f81cd0/lib/v8-to-istanbul.js#L144-L149 For example, for the following generated code, istanbul shows // source
console.log("x");
// generated
function prepended(){};console.log("x");
function appended(){}; Hmm, actually the reason why |
The issue might be actually same for istanbul provider based on the same simple reproduction of #7130 (comment). Probably relevant coverage filtering logic on istanbul is here https://github.com/istanbuljs/istanbuljs/blob/06eec782dc8a248f0516cdba06b280c410515890/packages/istanbul-lib-source-maps/lib/transformer.js#L34-L62. |
This patch only affects line coverage of source files. Lines of transformed files do not affect that patch. |
Describe the bug
EDIT: I made a simpler reproduction with user land transform #7130 (comment).
related:
After vitejs/vite#19004, a following code is transformed in this way (source map vis)
input
output
This seems to cause function
f
to be considered not covered even whenf
is executed. I confirmed Vite commit right before vitejs/vite#19004 didn't have this issue.Independently from vitejs/vite#19004, I'm trying to hoist
Object.defineProperty
in vitejs/vite#18983 and that seems to cause a similar missing coverage.Transform works like this (source map vis)
input
output
People usually don't write
import
after theexport
like the first case and we didn't have a test case for that, so I didn't notice it when reviewing vitejs/vite#19004. While testing my PR #7096, this just got caught because it broke the coverage test, which has this pattern (export function
at the first line):vitest/test/coverage-test/fixtures/src/math.ts
Line 1 in 178f515
Reproduction
https://github.com/hi-ogawa/reproductions/tree/main/vitest-function-coverage-vite-19004
https://github.com/hi-ogawa/reproductions/tree/main/vitest-function-coverage-prepend-transform
System Info
Used Package Manager
pnpm
Validations
The text was updated successfully, but these errors were encountered: