-
-
Notifications
You must be signed in to change notification settings - Fork 503
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
MSW + Jest: Transferring of ReadableStream cannot be properly polyfilled in this engine #1931
Comments
It looks like the problem I have too : #1915 |
Hi. Thanks for reporting this. @chawax, thanks for the extensive discussion. Let's get to the bottom of this. Root causeFirst, let's see why the request fails. If we inspect the actual error preserved by Undici, we see this:
This hints that Jest is having serious trouble with This error is caused by To be more specific, this is what happens:
// node_modules/undici/lib/fetch/body.js:277:21
const out2Clone = structuredClone(out2, { transfer: [out2] })
// node_modules/core-js/modules/web.structured-clone.js:485:9
switch (type) {
...
case 'MediaSourceHandle':
case 'MessagePort':
case 'OffscreenCanvas':
case 'ReadableStream':
case 'TransformStream':
case 'WritableStream':
throwUnpolyfillable(type, TRANSFERRING);
} This is a bold statement, especially since we polyfill The solution seems to be, once again, force Jest to use the platform, to use Node.js where things function correctly. |
Jest depends on There's literally nothing I can do here. Jest doesn't respect your environment. I highly recommend you migrate away from Jest to tools like Vitest and forget about these sorts of errors. I know it's not ideal, I know migrations take time, but it's either one-time migration or lifetime of dealing with this shenanigans that nobody but Jest can properly address. |
Some folks are having success by downgrading undici to v5: #1934 (reply in thread). This may be a temporary option for those who cannot migrate to other testing frameworks as of now. |
Yes, migrating to Vitest is definitely the only long term solution |
Also a note of warning: this seems to be specific to JSDOM. |
Well, I was using HappyDOM in my project, and it looks like that was the reason why downgrading Undici didn't work for me. Using Jest Environement JSDom solved instead of HappyDOM solved my problem indeed. |
Prerequisites
Environment check
msw
versionNode.js version
v21.4.0
Reproduction repository
https://github.com/Samflyn/msw-react
Reproduction steps
Running the App test should replicate the issue
Current behavior
There are two requests in App, where in one with payload and the other without, the request with payload is not intercepted by msw handler while the one without payload is intercepted fine.
Expected behavior
The request with payload should be intercepted by msw handler
The text was updated successfully, but these errors were encountered: