Importing Stripe via ES Modules does not respect monkey-patching 'http'
Problem
Describe the bug When trying to mock responses made with stripe-node in a Node.js enviroment, the requests hit the real server instead of getting caught by MSW. To Reproduce You can copy and paste the code below. (Either write actual handlers for your `stripeHandlers`, or you can leave them out, as we did below. If you want to try it out with handlers, simply spread them into `setupServer`.) Sine we configured `onUnhandledRequest: 'warn'` MSW should log out to the console when requests are uncaught. The manual method with `axios` works correctly and logs out this warning / reacts when you configure handlers. However, the second (in the code blocked `skip`ped) test does NOT log out this warning and simply hits the servers. [code block] [code block] Expected behavior MSW can intercept the Stripe requests. I assume this library does HTTP requests somehow esoterically, so it would be nice to learn how it does it, so that we can get MSW to work. Code snippets _No response_ OS macOS Node version 18.6.0 Library version stripe-node v12.12.0 API version 2022-11-15 Additional context _No response_
Unverified for your environment
Select your OS to check compatibility.
1 Fix
Solution: Importing Stripe via ES Modules does not respect monkey-patching 'http'
Turns out https://github.com/stripe/stripe-node/pull/1854 is not viable because `esModuleInterop: true` is a breaking change and not recommended for libraries to enable. I think we can still find a way to make a similar idea work but we won't land it today as expected.
Trust Score
2 verifications
- 1
Turns out https://github.com/stripe/stripe-node/pull/1854 is not viable because
Turns out https://github.com/stripe/stripe-node/pull/1854 is not viable because `esModuleInterop: true` is a breaking change and not recommended for libraries to enable.
- 2
I think we can still find a way to make a similar idea work but we won't land it
I think we can still find a way to make a similar idea work but we won't land it today as expected.
Validation
Resolved in stripe/stripe-node GitHub issue #1844. Community reactions: 1 upvotes.
Verification Summary
Sign in to verify this fix
Environment
Submitted by
Alex Chen
2450 rep