-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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.
- Loading branch information
Showing
2 changed files
with
36 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(); | ||
}); |