Compare commits

...

1 Commits

Author SHA1 Message Date
Ashcon Partovi
0410685578 fix: automatically enable coverage when --coverage-reporter is specified
Fixes #17502

This change ensures that when a user specifies --coverage-reporter, coverage is automatically enabled, improving the user experience by not requiring an explicit --coverage flag.
2025-02-26 15:50:24 -08:00
2 changed files with 36 additions and 0 deletions

View File

@@ -539,6 +539,9 @@ pub const Arguments = struct {
}
if (args.options("--coverage-reporter").len > 0) {
// Enable coverage automatically if a coverage reporter is specified
ctx.test_options.coverage.enabled = true;
ctx.test_options.coverage.reporters = .{ .text = false, .lcov = false };
for (args.options("--coverage-reporter")) |reporter| {
if (bun.strings.eqlComptime(reporter, "text")) {

View File

@@ -0,0 +1,33 @@
import { expect, test } from "bun:test";
import { bunEnv, bunExe } from "harness";
import { tempDirWithFiles } from "harness";
test("--coverage-reporter automatically enables --coverage", () => {
const dir = tempDirWithFiles("cov-reporter-auto-enables", {
"demo.test.ts": `
export function sum(a, b) {
return a + b;
}
test("sum", () => {
expect(sum(1, 2)).toBe(3);
});
`,
});
// Only specify --coverage-reporter without --coverage
const result = Bun.spawnSync([bunExe(), "test", "--coverage-reporter", "text", "./demo.test.ts"], {
cwd: dir,
env: {
...bunEnv,
},
stdio: [null, null, "pipe"],
});
// If coverage is enabled, we should see coverage output
expect(result.stderr.toString("utf-8")).toContain("File");
expect(result.stderr.toString("utf-8")).toContain("% Funcs");
expect(result.stderr.toString("utf-8")).toContain("% Lines");
expect(result.exitCode).toBe(0);
expect(result.signalCode).toBeUndefined();
});