t3-code-android-nightly/.repos/alchemy-effect/packages/alchemy/test/Test/Bun.test.ts
Julius Marminge 6f9cea00ae
chore(refs): sync Effect and Alchemy references to 4.0.1 and beta.80 (#16170)
Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-05 13:22:30 -07:00

41 lines
1.6 KiB
TypeScript

import { describe, expect, test } from "alchemy-test";
import { fileURLToPath } from "node:url";
const fixturesDir = fileURLToPath(new URL("./fixtures/", import.meta.url));
describe("Bun adapter fallback cleanup", { tags: ["unit", "local"] }, () => {
test(
"closes the shared scope when a user afterAll throws",
async () => {
// bun:test stops the afterAll chain on the first throw, so without
// the adapter's teardown guard the microtask-registered fallback
// (which closes the shared scope + sidecar) never runs. The fixture's
// shared-scope finalizer printing proves the guard closed the scope;
// the non-zero exit proves the teardown failure still fails the run.
const child = Bun.spawn(
["bun", "test", "./bun-teardown-guard.fixture.ts"],
{
cwd: fixturesDir,
stdout: "pipe",
stderr: "pipe",
env: { ...process.env, NO_COLOR: "1", ALCHEMY_DEV: "" },
},
);
const [exitCode, stdout, stderr] = await Promise.all([
child.exited,
new Response(child.stdout).text(),
new Response(child.stderr).text(),
]);
const output = `${stdout}\n${stderr}`;
expect(exitCode).not.toBe(0);
expect(output).toContain("teardown-assertion-failed");
const userHook = output.indexOf("BUN_GUARD:user-afterAll-throws");
const finalizer = output.indexOf("BUN_GUARD:shared-scope-finalizer-ran");
expect(userHook).toBeGreaterThanOrEqual(0);
// The cleanup ran, and ran after the failing user teardown.
expect(finalizer).toBeGreaterThan(userHook);
},
{ timeout: 60_000 },
);
});