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

Add ReadableStream to Jest integration. #336

Closed

Conversation

kenjim83
Copy link

Copy link

vercel bot commented Dec 31, 2023

@kenjim83 is attempting to deploy a commit to the MSW Team on Vercel.

A member of the Team first needs to authorize it.

@@ -24,11 +24,12 @@ Create a `jest.polyfills.js` file next to your `jest.config.js` with the followi
* you don't want to deal with this.
*/

const { TextDecoder, TextEncoder } = require('node:util')
const { TextDecoder, TextEncoder, ReadableStream } = require('node:util')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

node:util doesn't export ReadableStream, node:streams/web does.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

node:stream/web

@kettanaito
Copy link
Member

Hi, @kenjim83. Reaching back to you to provide additional context on ReadableStream in Jest.

As I have since learned, the JSDOM environment in Jest doesn't rely on the jest-environment-node (which is a rather big oversight), and instead uses core-js to polyfill already existing Node.js globals, like ReadableStream. The core-js module just throws whenever it tries to call structuredClone() on a ReadableStream instance because it's not implemented there.

TL;DR There's no way to get ReadableStream to work in Jest unless Jest (or core-js) itself addresses the issue. No polyfills on your end will be respected by Jest (one has to polyfill structuredClone() and Node.js doesn't expose its implementation, it's an internal C++ binding).

@kettanaito kettanaito closed this Jan 17, 2024
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.

3 participants