mirror of
https://github.com/oven-sh/bun
synced 2026-02-12 11:59:00 +00:00
Co-authored-by: Jarred Sumner <jarred@jarredsumner.com> Co-authored-by: dave caruso <me@paperdave.net>
57 lines
1.3 KiB
TypeScript
57 lines
1.3 KiB
TypeScript
import { test, expect } from "bun:test";
|
|
import { tempDirWithFiles, bunExe, bunEnv } from "harness";
|
|
import path from "path";
|
|
import { readFileSync } from "node:fs";
|
|
|
|
test("coverage crash", () => {
|
|
const dir = tempDirWithFiles("cov", {
|
|
"demo.test.ts": `class Y {
|
|
#hello
|
|
}`,
|
|
});
|
|
const result = Bun.spawnSync([bunExe(), "test", "--coverage"], {
|
|
cwd: dir,
|
|
env: {
|
|
...bunEnv,
|
|
},
|
|
stdio: ["inherit", "inherit", "inherit"],
|
|
});
|
|
expect(result.exitCode).toBe(0);
|
|
expect(result.signalCode).toBeUndefined();
|
|
});
|
|
|
|
test("lcov coverage reporter", () => {
|
|
const dir = tempDirWithFiles("cov", {
|
|
"demo2.ts": `
|
|
import { Y } from "./demo1";
|
|
|
|
export function covered() {
|
|
// this function IS covered
|
|
return Y;
|
|
}
|
|
|
|
export function uncovered() {
|
|
// this function is not covered
|
|
return 42;
|
|
}
|
|
|
|
covered();
|
|
`,
|
|
"demo1.ts": `
|
|
export class Y {
|
|
#hello;
|
|
};
|
|
`,
|
|
});
|
|
const result = Bun.spawnSync([bunExe(), "test", "--coverage", "--coverage-reporter", "lcov", "./demo2.ts"], {
|
|
cwd: dir,
|
|
env: {
|
|
...bunEnv,
|
|
},
|
|
stdio: ["inherit", "inherit", "inherit"],
|
|
});
|
|
expect(result.exitCode).toBe(0);
|
|
expect(result.signalCode).toBeUndefined();
|
|
expect(readFileSync(path.join(dir, "coverage", "lcov.info"), "utf-8")).toMatchSnapshot();
|
|
});
|