( respond: (request: CapturedRequest) => Response | Promise<Response>, )
| 48 | * from it models a transport failure, and an aborted signal models the timeout. |
| 49 | */ |
| 50 | const 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 | |
| 77 | const jsonResponse = (body: unknown, status = 200): Response => |
| 78 | new Response(JSON.stringify(body), { |
no test coverage detected