(
handler: (url: string, init: RequestInit) => { status?: number; body: unknown },
)
| 25 | type FetchInput = Parameters<typeof globalThis.fetch>[0]; |
| 26 | |
| 27 | function makeFetch( |
| 28 | handler: (url: string, init: RequestInit) => { status?: number; body: unknown }, |
| 29 | ): typeof globalThis.fetch { |
| 30 | return (async (input: FetchInput, init: RequestInit = {}) => { |
| 31 | const url = |
| 32 | typeof input === 'string' |
| 33 | ? input |
| 34 | : input instanceof URL |
| 35 | ? input.toString() |
| 36 | : (input as { url: string }).url; |
| 37 | const { status = 200, body } = handler(url, init); |
| 38 | return new Response(JSON.stringify(body), { |
| 39 | status, |
| 40 | headers: { 'content-type': 'application/json' }, |
| 41 | }); |
| 42 | }) as typeof globalThis.fetch; |
| 43 | } |
| 44 | |
| 45 | function makeCreds( |
| 46 | apiKey = 'sk-user-test', |
no test coverage detected