mirror of
https://github.com/oven-sh/bun
synced 2026-02-10 02:48:50 +00:00
This is feature flagged and will not activate until Bun 1.3 - Makes `test.only()` throw an error in CI - Unless `--update-snapshots` is passed: - Makes `expect.toMatchSnapshot()` throw an error instead of adding a new snapshot in CI - Makes `expect.toMatchInlineSnapshot()` throw an error instead of filling in the snapshot value in CI --------- Co-authored-by: Claude Bot <claude-bot@bun.sh> Co-authored-by: Claude <noreply@anthropic.com> Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
43 lines
1.1 KiB
TypeScript
43 lines
1.1 KiB
TypeScript
import { expect, test } from "bun:test";
|
|
import { bunEnv, bunExe, tmpdirSync } from "harness";
|
|
import { join } from "path";
|
|
|
|
test("snapshots will recognize existing entries", async () => {
|
|
const testDir = tmpdirSync();
|
|
await Bun.write(
|
|
join(testDir, "test.test.js"),
|
|
`
|
|
test("snapshot test", () => {
|
|
expect("foo").toMatchSnapshot();
|
|
});
|
|
`,
|
|
);
|
|
|
|
let proc = Bun.spawnSync({
|
|
cmd: [bunExe(), "test", "./test.test.js"],
|
|
cwd: testDir,
|
|
env: { ...bunEnv, CI: "false" },
|
|
stdout: "pipe",
|
|
stderr: "pipe",
|
|
});
|
|
|
|
expect(proc.stderr.toString()).toContain("1 added");
|
|
expect(proc.exitCode).toBe(0);
|
|
|
|
const newSnapshot = await Bun.file(join(testDir, "__snapshots__", "test.test.js.snap")).text();
|
|
|
|
// Run the same test, make sure another entry isn't added
|
|
proc = Bun.spawnSync({
|
|
cmd: [bunExe(), "test", "./test.test.js"],
|
|
cwd: testDir,
|
|
env: { ...bunEnv, CI: "false" },
|
|
stdout: "pipe",
|
|
stderr: "pipe",
|
|
});
|
|
|
|
expect(proc.stderr.toString()).not.toContain("1 added");
|
|
expect(proc.exitCode).toBe(0);
|
|
|
|
expect(newSnapshot).toBe(await Bun.file(join(testDir, "__snapshots__", "test.test.js.snap")).text());
|
|
});
|