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

Update jest-missing-globals.mdx #353

Closed
wants to merge 1 commit into from
Closed

Conversation

barisbll
Copy link

ReadableStream also have to be added in order this solution to work

In this discussion it is written clearly mswjs/msw#1934 (comment)

ReadableStream also have to be added in order this solution to work

In this discussion it is written clearly mswjs/msw#1934 (comment)
Copy link

vercel bot commented Jan 22, 2024

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

A member of the Team first needs to authorize it.

@@ -24,15 +24,16 @@ 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
Contributor

Choose a reason for hiding this comment

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

I think we should keep quotes as they are

Suggested change
const { TextDecoder, TextEncoder, ReadableStream } = require("node:util")
const { TextDecoder, TextEncoder, ReadableStream } = require('node:util')

Comment on lines +35 to +36
const { Blob, File } = require("node:buffer")
const { fetch, Headers, FormData, Request, Response } = require("undici")
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
const { Blob, File } = require("node:buffer")
const { fetch, Headers, FormData, Request, Response } = require("undici")
const { Blob, File } = require('node:buffer')
const { fetch, Headers, FormData, Request, Response } = require('undici')

@@ -24,15 +24,16 @@ 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

@kettanaito kettanaito Feb 13, 2024

Choose a reason for hiding this comment

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

This is incorrect though. Must be imported from node:stream/web. That's the correct implementation of web's ReadableStream. We've already had issues with people trying to polyfill the stream from node:utils and it fails.

@kettanaito
Copy link
Member

There's also a fundamental problem of polyfilling ReadableStream. If you polyfill it, it will start requiring built-in Node.js modules, likes structuredClone(), which will be polyfilled in Jest, and polyfilled incorrectly, breaking your tests pretty much forever.

See more details here: mswjs/msw#1916 (comment).

This is why recommending polyfilling ReadableStream to everyone by default is dangerous.

@kettanaito
Copy link
Member

Fixed by #419.

@kettanaito kettanaito closed this Sep 26, 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