Skip to content

Serve self-signed HTTPS fetches in dev-middleware tests through undici - #60362

Draft
ide wants to merge 1 commit into
react:mainfrom
expo:@ide/dev-middleware-self-signed-fetch
Draft

ide wants to merge 1 commit into
react:mainfrom
expo:@ide/dev-middleware-self-signed-fetch

Conversation

@ide

@ide ide commented Nov 28, 2026

Copy link
Copy Markdown
Contributor

Summary:

On Node 26, one dev-middleware test fails over HTTPS:

inspector proxy CDP rewriting hacks over HTTPS › Debugger.getScriptSource › fetches source from server
  - "scriptSource": "foo",
  + "error": { "message": "Failed to fetch source url \"https://localhost:…/source\" for scriptId script1: fetch failed" },

withFetchSelfSignedCertsForAllTests spies on the global fetch and passes it an Agent from the undici package (6.23.0) that accepts the test server's self-signed certificate. The global fetch runs on the undici bundled with Node, which is 8.x on Node 26. It calls the dispatcher with a handler interface that undici 6 rejects, so the request fails with InvalidArgumentError: invalid onError method.

This change answers the spied fetch calls with the undici package's request, which the other helpers in FetchUtils.js already use, and wraps the status and body text in a Response. The helper no longer calls the original fetch, so its fetchOriginal parameter is removed. The Flow definition for undici gains body.text().

The undici package's own fetch would be a smaller change, but it throws markResourceTiming is not a function under Jest, whose performance global lacks that method.

Changelog:

[INTERNAL] [FIXED] - Fix the dev-middleware HTTPS tests on Node 26

Test Plan:

Run on Node 26.12.0 against 94aee19ac9:

yarn jest --runInBand packages/dev-middleware
  • main: 1 of 143 tests fails ("fetches source from server" over HTTPS, as above); 11 of 12 suites pass.
  • This branch: 12 suites and 143 tests pass.

The cause reproduces outside Jest: on Node 26, fetch(url, {dispatcher: new (require('undici').Agent)()}) rejects with fetch failed, caused by InvalidArgumentError: invalid onError method from undici 6's Agent.dispatch.

yarn flow-check reports no errors. yarn eslint --max-warnings 0 and prettier --check pass on the three changed files. I did not run the suite on Node 22 or 24.

🤖 Generated with Claude Code

On Node 26, InspectorProxyCdpRewritingHacks-test.js fails over HTTPS:
"Debugger.getScriptSource fetches source from server" gets
`fetch failed` instead of the script source.

`withFetchSelfSignedCertsForAllTests` spies on the global `fetch` and
passes it an `Agent` from the undici package (6.x) that accepts
self-signed certificates. The global `fetch` runs on the undici bundled
with Node, which is 8.x on Node 26 and calls the dispatcher with a
handler interface that undici 6 rejects ("invalid onError method").

Answer the spied `fetch` calls with the undici package's `request`,
which the other helpers in FetchUtils.js already use, and wrap the
status and body text in a `Response`. The package's own `fetch` is not
an option: it throws under Jest because the environment's `performance`
has no `markResourceTiming`. The helper no longer calls the original
`fetch`, so its `fetchOriginal` parameter is removed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Nov 28, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant