Skip to content

chore(internal): resolve node-fetch to the SDK shim in resource tests - #236

Open
spicysouvlaki wants to merge 1 commit into
mainfrom
william/cb-591-test-response-import
Open

spicysouvlaki wants to merge 1 commit into
mainfrom
william/cb-591-test-response-import

Conversation

@spicysouvlaki

Copy link
Copy Markdown
Collaborator

New generated resource tests import Response from node-fetch and fail toBeInstanceOf against the native Response the client returns. A jest resolver maps that import to the SDK shim for tests/api-resources only, so a new resource no longer turns main red.

Test-only: nothing in the published package changes.

🤖 Generated with Claude Code

stlc writes every new resource test with
`import { Response } from 'node-fetch'`. Since #191 the client prefers
the native fetch on modern Node, so `asResponse()` returns the native
Response and `expect(rawResponse).toBeInstanceOf(Response)` fails
against node-fetch's class. Each new resource has turned main red until
someone patched its test by hand: webhooks, navigation policies, labels
(#232), downloads (#233).

A jest resolver now points `node-fetch` at `src/_shims/index` for files
under tests/api-resources only, which is the import those hand patches
used. tests/index.test.ts and src/_shims keep the real node-fetch, so
the fallback transport is still tested.

Measured locally on Node 24.19 with labels.test.ts switched back to the
generator's import: 4 of 9 tests fail without the resolver
("Expected constructor: Response / Received constructor: Response"),
9 of 9 pass with it. Full suite: 27 suites, 201 tests pass.

The existing hand patches stay; removing them is a separate change.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@spicysouvlaki
spicysouvlaki marked this pull request as ready for review November 12, 2026 23:38
@spicysouvlaki
spicysouvlaki requested a review from a team as a code owner November 12, 2026 23:38
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.

1 participant