1// Run by `bun test ./<path>` from Bun.test.ts — the `.fixture.ts` suffix
2// keeps alchemy-test from collecting it. Exercises `alchemy/Test/Bun`'s
3// teardown guard: bun:test stops running later `afterAll` hooks once one
4// throws, so the adapter must run its fallback cleanup (closing the shared
5// scope and sidecar) itself before rethrowing — otherwise a failing
6// teardown assertion leaks them for the rest of the process.
7import * as Effect from "effect/Effect";
8import * as Layer from "effect/Layer";
9import * as Test from "@/Test/Bun.ts";
10
11const { test, beforeAll, afterAll } = Test.make({
12 providers: Layer.empty as never,
13});
14
15// Attaches to the adapter's shared scope (provided to every hook/test by
16// `Core.toEffect`), so this line printing proves the fallback cleanup ran.
17beforeAll(
18 Effect.addFinalizer(() =>
19 Effect.sync(() => console.log("BUN_GUARD:shared-scope-finalizer-ran")),
20 ),
21);
22
23afterAll(
24 Effect.sync(() => {
25 console.log("BUN_GUARD:user-afterAll-throws");
26 }).pipe(Effect.andThen(Effect.fail(new Error("teardown-assertion-failed")))),
27);
28
29test("body", Effect.void);