The best way to control Claude Code, Codex and more from any computer or phone

main
ts 38 lines 1.6 KB
Raw
1 import { fileURLToPath } from "node:url";
2 import { describe, expect, test } from "@alchemy.run/test";
3
4 const fixturesDir = fileURLToPath(new URL("./fixtures/", import.meta.url));
5
6 describe("Bun adapter fallback cleanup", { tags: ["unit", "local"] }, () => {
7 test(
8 "closes the shared scope when a user afterAll throws",
9 async () => {
10 // bun:test stops the afterAll chain on the first throw, so without
11 // the adapter's teardown guard the microtask-registered fallback
12 // (which closes the shared scope + sidecar) never runs. The fixture's
13 // shared-scope finalizer printing proves the guard closed the scope;
14 // the non-zero exit proves the teardown failure still fails the run.
15 const child = Bun.spawn(["bun", "test", "./bun-teardown-guard.fixture.ts"], {
16 cwd: fixturesDir,
17 stdout: "pipe",
18 stderr: "pipe",
19 env: { ...process.env, NO_COLOR: "1", ALCHEMY_DEV: "" },
20 });
21 const [exitCode, stdout, stderr] = await Promise.all([
22 child.exited,
23 new Response(child.stdout).text(),
24 new Response(child.stderr).text(),
25 ]);
26 const output = `${stdout}\n${stderr}`;
27
28 expect(exitCode).not.toBe(0);
29 expect(output).toContain("teardown-assertion-failed");
30 const userHook = output.indexOf("BUN_GUARD:user-afterAll-throws");
31 const finalizer = output.indexOf("BUN_GUARD:shared-scope-finalizer-ran");
32 expect(userHook).toBeGreaterThanOrEqual(0);
33 // The cleanup ran, and ran after the failing user teardown.
34 expect(finalizer).toBeGreaterThan(userHook);
35 },
36 { timeout: 60_000 },
37 );
38 });