MCPcopy Create free account
hub / github.com/fontsource/fontsource / mockUpstreamResponses

Function mockUpstreamResponses

api/tests/network.ts:188–205  ·  view source on GitHub ↗
(
	responses: Record<string, Response | (() => Response | Promise<Response>)>,
)

Source from the content-addressed store, hash-verified

186afterAll(() => network.disable());
187
188export const mockUpstreamResponses = (
189 responses: Record<string, Response | (() => Response | Promise<Response>)>,
190) => {
191 network.resetHandlers(...handlers);
192 network.use(
193 ...Object.entries(responses).map(([url, response]) =>
194 http.get(
195 new URL(url).origin + new URL(url).pathname,
196 async ({ request }) => {
197 if (request.url !== url) return;
198 return typeof response === 'function'
199 ? await response()
200 : response.clone();
201 },
202 ),
203 ),
204 );
205};

Callers 3

open-graph.test.tsFile · 0.90
cdn.test.tsFile · 0.90
stats.test.tsFile · 0.90

Calls 3

useMethod · 0.80
getMethod · 0.65
cloneMethod · 0.65

Tested by

no test coverage detected