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

main
ts 52 lines 1.4 KB
Raw
1 import * as Effect from "effect/Effect";
2 import * as Layer from "effect/Layer";
3 import { describe } from "vitest";
4 import { make } from "../src/Vitest.ts";
5
6 const seen: Array<string> = [];
7
8 const { afterAll, test } = make({ providers: Layer.empty });
9
10 // Fails if the shared scope is already closed when the hook runs: a finalizer
11 // added to a closed scope runs immediately, before `finished` is set.
12 const assertScopeOpen = (name: string) =>
13 Effect.gen(function* () {
14 let finished = false;
15 yield* Effect.addFinalizer(() =>
16 Effect.sync(() => {
17 if (!finished) {
18 throw new Error(`shared scope closed before afterAll "${name}" finished`);
19 }
20 }),
21 );
22 seen.push(name);
23 finished = true;
24 });
25
26 // Run under both `sequence.hooks: "stack"` (default) and `"list"`; see
27 // vitest.config.ts. The cleanup hook must follow both, whichever order applies.
28 afterAll(assertScopeOpen("first"));
29 afterAll(assertScopeOpen("second"));
30
31 describe("scoped", () => {
32 afterAll(
33 Effect.sync(() => {
34 seen.push("scoped");
35 }),
36 );
37 test(
38 "runs",
39 Effect.sync(() => undefined),
40 );
41 });
42
43 describe("after scoped", () => {
44 test(
45 "a describe's afterAll runs when that describe finishes",
46 Effect.sync(() => {
47 if (seen.join(",") !== "scoped") {
48 throw new Error(`expected only the scoped afterAll to have run, saw: ${seen.join(",")}`);
49 }
50 }),
51 );
52 });