Skip to content

fix(mock): clear the interceptors that legacy global fetch uses in cleanMocks() - #6014

Open
Anoesj wants to merge 1 commit into
nodejs:mainfrom
Anoesj:fix/mock-clean-mocks-legacy-global-fetch
Open

Anoesj wants to merge 1 commit into
nodejs:mainfrom
Anoesj:fix/mock-clean-mocks-legacy-global-fetch

Conversation

@Anoesj

@Anoesj Anoesj commented Oct 14, 2026

Copy link
Copy Markdown

This relates to...

Fixes #6013

Rationale

Since #5648, MockAgent shares a pool's kDispatches array with the ${origin}#http1-only dispatcher that legacy global dispatcher consumers (like Node.js' bundled fetch) use. cleanMocks() replaced that array, so the #http1-only dispatcher kept the old interceptors and never saw new ones.

Changes

Features

N/A

Bug Fixes

  • MockPool.cleanMocks() and MockClient.cleanMocks() empty the interceptors array in place (and reset its total dispatch count) instead of replacing it, so every dispatcher that shares it sees the change.
  • Tests in test/node-test/global-dispatcher-version.js for both, through Node.js' global fetch.

Breaking Changes and Deprecations

N/A

Status

🤖 Generated with Claude Code

…eanMocks()

Since nodejs#5648, MockAgent shares a pool's interceptors array with the
`${origin}#http1-only` dispatcher that legacy global dispatcher consumers,
like Node.js' bundled fetch, use. `cleanMocks()` replaced that array, so
that dispatcher kept the old interceptors and never saw new ones. Empty it
in place instead.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

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

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

MockPool/MockClient cleanMocks() doesn't clear the interceptors that Node.js global fetch uses

2 participants