MCPcopy Create free account
hub / github.com/UsefulSoftwareCo/executor / makeFetchHarness

Function makeFetchHarness

apps/cloud/src/analytics/ema-rollout.test.ts:50–75  ·  view source on GitHub ↗
(
  respond: (request: CapturedRequest) => Response | Promise<Response>,
)

Source from the content-addressed store, hash-verified

48 * from it models a transport failure, and an aborted signal models the timeout.
49 */
50const makeFetchHarness = (
51 respond: (request: CapturedRequest) => Response | Promise<Response>,
52): FetchHarness => {
53 const requests: CapturedRequest[] = [];
54 const detached: Promise<unknown>[] = [];
55 return {
56 requests: () => requests,
57 settle: async () => {
58 await Promise.all(detached);
59 },
60 waitUntil: (work) => {
61 detached.push(work);
62 },
63 fetch: async (input, init) => {
64 const raw = typeof init?.body === "string" ? init.body : "{}";
65 const captured: CapturedRequest = {
66 url: String(input),
67 // oxlint-disable-next-line executor/no-json-parse -- boundary: test fixture reads back the exact JSON body the gate serialized for PostHog
68 body: JSON.parse(raw) as Record<string, unknown>,
69 signal: init?.signal instanceof AbortSignal ? init.signal : null,
70 };
71 requests.push(captured);
72 return respond(captured);
73 },
74 };
75};
76
77const jsonResponse = (body: unknown, status = 200): Response =>
78 new Response(JSON.stringify(body), {

Callers 1

Calls 2

pushMethod · 0.80
respondFunction · 0.50

Tested by

no test coverage detected