Files
bun.sh/test/cli/test/coverage.test.ts
TATSUNO “Taz” Yasuhiro 4830e2d817 Implement initial LCOV reporter (no function names support) (#11883)
Co-authored-by: Jarred Sumner <jarred@jarredsumner.com>
Co-authored-by: dave caruso <me@paperdave.net>
2024-06-22 02:03:19 -07:00

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();
});