Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion packages/dev-middleware/src/__tests__/FetchUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import type {JSONSerializable} from '../inspector-proxy/types';
import type {RequestOptions} from 'undici';

import {STATUS_CODES} from 'node:http';
import {Agent, request} from 'undici';

/**
Expand Down Expand Up @@ -80,12 +81,19 @@ export function withFetchSelfSignedCertsForAllTests(
// accept a dispatcher from the undici package: Node 26 rejects one from
// undici 6. The package's own `fetch` throws under Jest, whose
// `performance` global lacks `markResourceTiming`.
// The mock answers what these tests ask: a URL, and a response with a
// body. It follows no redirects, takes no `Request` object, and keeps no
// headers; a 204 or 304 response would throw, since a `Response` with
// those statuses cannot have a body.
fetchSpy.mockImplementation(async (url, options) => {
const {statusCode, body} = await request(url.toString(), {
...options,
dispatcher: selfSignedCertDispatcher,
});
return new Response(await body.text(), {status: statusCode});
return new Response(await body.text(), {
status: statusCode,
statusText: STATUS_CODES[statusCode] ?? '',
});
});
});

Expand Down
Loading