Testing
A test builds the graph the way the app does and hands it a runtime and a request, so it exercises the wiring that ships.
A test builds the graph the way the app does and hands it the same two things — a runtime and a request — so it exercises the wiring that ships rather than a second path around it. Stubs are layers, because that is where the app's services live too.
import { testRuntime } from "@athanor/alembic/testing";
const Athanor = define<Ctx>();
const Widget = Athanor.Node(…).pipe(Athanor.Auth.Public);
const { runtime, request, nextRequest } = testRuntime(Layer.succeed(Pricer, stub));
const { query } = Athanor.build({
Query: Athanor.Query((f) => ({ widget: f.node(Widget, (ctx) => ctx.widgetId) })),
types: [Widget],
context: () => Effect.succeed(ctx),
runtime,
request,
});
const data = await collect(Athanor.execute(Q, {}));nextRequest() is the only knob: two execute calls on either side of it are two requests with
two loader maps, and two without it are one request that batches — which mirrors what
React.cache does for the app, and is what makes the batching claim testable at all.
An app whose nodes bind to its builder cannot build a second graph, so give it an
AsyncLocalStorage seam that build({ request }) consults:
request: () => graphOverride() ?? Layer.mergeAll(Viewer, RequestCache),and a test replaces the lot for one call tree:
await withGraphLayer(
Layer.mergeAll(
clientServiceStub,
viewerLayer("org-own"),
Layer.succeed(RequestCache, makeRequestCache()),
),
() => collect(Athanor.execute(ClientDetailQuery, { clientId: "CLT_1" })),
);Because cachedLoad is gated on Next's flag, tests take the batched-loader path — deterministic,
and it lets you assert on batching:
expect(loads).toHaveLength(1); // three fragments, one load
expect(loads[0]).toEqual(["CLT_1"]);Components take props, so component tests are pure.