Skip to content

test: replace global fetch overrides with nock - #58

Closed
erunion wants to merge 1 commit into
mainfrom
erunion/nock-fetch-mocks-4024
Closed

erunion wants to merge 1 commit into
mainfrom
erunion/nock-fetch-mocks-4024

Conversation

@erunion

@erunion erunion commented Oct 22, 2026

Copy link
Copy Markdown
Member

The import unit tests were stubbing globalThis.fetch with hand-rolled responses. Those stubs never exercised Node's native fetch, so redirect behavior (response.url after a hop) was faked by returning a different URL from the mock.

This switches those tests to nock (devDependency). test/mock-fetch.js registers one persistent interceptor per origin and still accepts the same route maps the tests already used:

  • a string body is HTTP 200
  • an Error fails the request
  • finalUrl is a real 302, so fetch follows it and response.url is the landed URL
  • unknown paths on an intercepted origin are 404s
  • any other host is refused

npm test (oxlint, oxfmt, and the full Vitest suite) passes.

Open in Web Open in Cursor 

Intercept the import unit tests' HTTP calls with nock so they go through
Node's native fetch instead of a stubbed globalThis.fetch.

Co-authored-by: Jon Ursenbach <[email protected]>
@erunion erunion added the refactor Issues about tackling technical debt label Oct 22, 2026
@erunion erunion self-assigned this Oct 22, 2026
@greptile-apps

greptile-apps Bot commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5

[Low impact] The PR appears safe to merge; no actionable bugs were established.

Reviews (1) · Last reviewed commit: "test: replace global fetch overrides wit..." · Reviewed by Greptile

@erunion erunion closed this Oct 22, 2026
@erunion
erunion deleted the erunion/nock-fetch-mocks-4024 branch October 22, 2026 19:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

refactor Issues about tackling technical debt

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants