-
-
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
coverage-v8 issues with calculation of branch coverage #6300
Comments
Related c8 bug bcoe/c8#541 |
This is same as bcoe/c8#172, also mentioned in the description of #4309. Here's reproduction with just Node without Vitest, import { writeFileSync } from "node:fs";
import inspector from "node:inspector";
writeFileSync(
"./source-file.mjs",
`
export function comp(a, b) {
if (a === b) {
return 0;
} else if (a > b) {
return 1;
} else {
return -1;
}
}
`.trim(),
"utf8"
);
const session = new inspector.Session();
session.connect();
session.post("Profiler.enable");
session.post("Profiler.startPreciseCoverage", {
callCount: true,
detailed: true,
});
const { comp } = await import("./source-file.mjs");
comp(1, 1);
comp(1, 0);
// comp(0, 1);
const coverage = await collectCoverage("source-file.mjs");
console.log(JSON.stringify(coverage, null, 2));
async function collectCoverage(filename) {
return new Promise((resolve, reject) => {
session.post("Profiler.takePreciseCoverage", async (error, coverage) => {
if (error) return reject(error);
const result = coverage.result.filter((entry) =>
entry.url.includes(filename)
);
resolve({ result });
});
});
} |
I got a hint in different thread. It seems https://github.com/cenfun/monocart-coverage-reports can handle those cases correctly |
Yup, it does this by AST analysis. Similar how There's still a bug/feature in V8/Node that causes this branch count issue. |
I created extended comparison https://github.com/stereobooster/test-coverage-calculation if anybody is curios |
Describe the bug
I have following code
and following test
it shows branch coverage 2/3 - which is correct. But If I add missing test
It shows branch coverage 4/4. Which seems to be incorrect
If I change code to
It shows branch coverage 5/5. Which seems to be incorrect.
PS 1 I checked it with istanbul, and istanbul numbers are more consistent. So I guess this is the issue with
c8
PS 2 I checked using
c8
(^10.1.2
) directly and results are different, so there is a bugReproduction
https://github.com/stereobooster/vitest-coverage-v8
System Info
Used Package Manager
pnpm
Validations
The text was updated successfully, but these errors were encountered: