Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Default Node httpClient configuration does not get mocked by MSW nor upcoming Nock version #2211

Open
kanadgupta opened this issue Oct 21, 2024 · 1 comment
Labels

Comments

@kanadgupta
Copy link

kanadgupta commented Oct 21, 2024

Describe the bug

Hi there. I'm using nock@beta and it is no longer able to intercept requests from this library when using the default Node.js httpClient settings (i.e., this HTTP client).

This is because nock is adding support for native fetch and now uses @mswjs/interceptors to intercept requests (which is also used by msw).

The workaround is fairly trivial — configure the Stripe SDK to use fetch (see the workaround section here). But once nock@14 is released, it will not support this library without additional end user configuration. Based on a handful of issues in this repo, I cannot imagine this is the desired behavior:

#1844
#1854
#1866

To Reproduce

See https://github.com/kanadgupta/nock-beta-stripe-sdk

Expected behavior

The current Nock beta and its underlying interceptor library (@mswjs/interceptors) should be able to mock requests from the Stripe SDK without having to set the httpClient configuration option.

Code snippets

No response

OS

macOS

Node version

Node v20.16.0

Library version

stripe-node 17.2.1

API version

2024-09-30.acacia

Additional context

I initially filed a bug report in the nock repo: nock/nock#2785

It appears that this is happening due to a known limitation where @mswjs/interceptors is unable to intercept certain requests with node:http. The maintainer documented a way to fix this here: mswjs/msw#2259 (comment)

@xavdid-stripe
Copy link
Member

@kanadgupta thanks for the super detailed report! We'll take a look and see what our options are here. The fix seems straightforward, but we don't want to break anything else in the process.

(filed internally as: http://go/j/DEVSDK-2261)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants