refactor: replace node-fetch/nock with undici#2837
Open
sjinks wants to merge 4 commits into
Open
Conversation
Contributor
Dependency ReviewThe following issues were found:
License Issuespackage.json
OpenSSF Scorecard
Scanned Files
|
- Remove node-fetch, nock, and fetch-retry dependencies - Add undici as the sole fetch/mock runtime - Migrate all runtime fetch calls (api/http, analytics, dev-environment-core, client-file-uploader) to undici fetch - Replace CommonJS fetch-retry wrapper with a local exponential backoff helper in client-file-uploader - Use node:timers/promises setTimeout in retry.ts and client-file-uploader (eliminates manual Promise wrapping) - Add src/lib/http/proxy-dispatcher.ts for undici-compatible proxy support (ProxyAgent) - Replace jest.setup.js nock setup with undici MockAgent as global dispatcher; add test-utils/undici-mock.js helper - Migrate all nock-based tests to undici MockPool interceptors - Remove nock lifecycle calls from devenv e2e specs
Contributor
There was a problem hiding this comment.
Pull request overview
This PR migrates VIP CLI’s HTTP stack from node-fetch + nock to undici for both runtime fetches and test-time request mocking, and introduces an undici-compatible proxy dispatcher.
Changes:
- Replace
node-fetchusage across runtime codepaths withundici.fetch, including proxy support via a newcreateProxyDispatcher(). - Replace
nock-based Jest test mocking with an undiciMockAgentglobal dispatcher andMockPoolinterceptors. - Remove
fetch-retryand implement a local retry helper (plusnode:timers/promisesusage) for upload operations.
Reviewed changes
Copilot reviewed 29 out of 30 changed files in this pull request and generated 8 comments.
Show a summary per file
| File | Description |
|---|---|
| test-utils/undici-mock.js | Adds helpers to access/reset the global undici mock dispatcher/pools in tests. |
| src/lib/tracker.ts | Removes node-fetch import while keeping analytics tracking plumbing. |
| src/lib/retry.ts | Switches delay implementation to node:timers/promises setTimeout. |
| src/lib/http/proxy-dispatcher.ts | New undici ProxyAgent-based dispatcher factory for proxy support. |
| src/lib/dev-environment/dev-environment-core.ts | Migrates WordPress versions manifest fetch to undici + dispatcher proxy support. |
| src/lib/client-file-uploader.ts | Migrates to undici fetch and replaces fetch-retry with a local retry loop. |
| src/lib/api/http.ts | Migrates API HTTP wrapper from node-fetch to undici + proxy dispatcher. |
| src/lib/api.ts | Removes FetchError dependency and adjusts retry predicate for connection-refused errors. |
| src/lib/analytics/index.ts | Removes node-fetch type import while keeping analytics aggregation logic. |
| src/lib/analytics/clients/tracks.ts | Migrates Tracks client to undici fetch and keeps Response typing local. |
| src/lib/analytics/clients/pendo.ts | Removes node-fetch type import for Pendo client. |
| src/lib/analytics/clients/client.ts | Removes node-fetch type import from the analytics client interface. |
| package.json | Drops node-fetch, nock, fetch-retry; adds undici. |
| npm-shrinkwrap.json | Updates lockfile to reflect dependency removals/additions (including undici). |
| jest.setup.js | Replaces nock global setup with undici MockAgent dispatcher + proxy env cleanup. |
| tests/lib/validations/sql.js | Removes node-fetch mocking previously used in this suite. |
| tests/lib/validations/is-multisite-domain-mapped.js | Migrates GraphQL request mocking from nock to undici MockPool. |
| tests/lib/search-and-replace.js | Removes node-fetch mocking previously used in this suite. |
| tests/lib/dev-environment/dev-environment-cli.js | Replaces nock-based versions manifest mocking with a getVersionList spy. |
| tests/lib/api-retry.ts | Updates retry tests to no longer depend on FetchError. |
| tests/lib/analytics/clients/tracks.js | Migrates Tracks client tests from nock to undici MockPool assertions. |
| tests/devenv-e2e/002-destroy.spec.js | Removes nock lifecycle calls from dev-env E2E spec. |
| tests/devenv-e2e/003-start.spec.js | Removes nock lifecycle calls from dev-env E2E spec. |
| tests/devenv-e2e/004-stop.spec.js | Removes nock lifecycle calls from dev-env E2E spec. |
| tests/devenv-e2e/006-list.spec.js | Removes nock lifecycle calls from dev-env E2E spec. |
| tests/devenv-e2e/007-info.spec.js | Removes nock lifecycle calls from dev-env E2E spec. |
| tests/devenv-e2e/008-exec.spec.js | Removes nock lifecycle calls from dev-env E2E spec. |
| tests/devenv-e2e/010-import-sql.spec.js | Removes nock lifecycle calls from dev-env E2E spec. |
| tests/devenv-e2e/011-logs.spec.js | Removes nock lifecycle calls from dev-env E2E spec. |
| tests/devenv-e2e/012-shell.spec.js | Removes nock lifecycle calls from dev-env E2E spec. |
Files not reviewed (1)
- npm-shrinkwrap.json: Language not supported
Member
Author
|
This will close #2821 |
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



Description
nockis unreliable and does not play well with Jest. There is an unresolved issue: nock/nock#2802, and we're fighting with nock in Automattic/vip-go-api#7153 and #2821.We remove
nockandnode-fetchin favor ofundici. The best thing aboutundiciis that it comes with built-in testing capabilities, and we don't need another dependency that may or may not work with our test setup.node-fetch,nock, andfetch-retrydependenciesundicias the sole fetch/mock runtimeapi/http,analytics,dev-environment-core,client-file-uploader) toundicifetchfetch-retrywrapper with a local exponential backoff helper inclient-file-uploadernode:timers/promisessetTimeoutinretry.tsandclient-file-uploader(eliminates manualPromisewrapping)src/lib/http/proxy-dispatcher.tsfor undici-compatible proxy support (ProxyAgent)jest.setup.jsnocksetup with undiciMockAgentas a global dispatcher; addtest-utils/undici-mock.jshelperundiciMockPoolinterceptorsnocklifecycle calls from DevEnv E2E specsPull request checklist
New release checklist
Steps to Test
Surprisingly, CI must pass.