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

fix: add TransformStream #20

Merged
merged 2 commits into from
Nov 3, 2024

Conversation

ghernandez345
Copy link
Contributor

@ghernandez345 ghernandez345 commented Oct 31, 2024

When trying to upgrade to msw v2 I ran into an issue with the TransformStream global being undefined:

 ReferenceError: TransformStream is not defined

Adding this locally fixed the issue so wanted to add it into the jest-fixed-dom package.

@ilbertt
Copy link

ilbertt commented Oct 31, 2024

While we wait for this PR to be merged, I managed to solve the issue using the web-streams-polyfill package in the Jest setup file:

// jest.setup.ts

import { TransformStream } from "web-streams-polyfill";

global.TransformStream = TransformStream;

@yanndinendal
Copy link

yanndinendal commented Oct 31, 2024

Thanks @ghernandez345, hope it gets merged. :)

Thanks @ilbertt: I did the same but without the need to install a polyfill:

import { TransformStream } from 'node:stream/web';

(seen in mswjs/msw#1934 (reply in thread))

index.test.js Outdated
test('exposes "TransformStream"', () => {
expect(globalThis).toHaveProperty('TransformStream')
const channel = new TransformStream()
expect(channel).toBeInstanceOf(TransformStream)
Copy link
Member

Choose a reason for hiding this comment

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

For instance comparison, we need to make sure it's the instance of Node's TransformStream. For that, it's a good idea to import this class directly from node:stream/web, I believe.

I can add this fix.

@kettanaito
Copy link
Member

I think we are reaching the point of this package where we may as well re-set all the builtin modules on the global scope. Need to raise this as a separate issue.

Copy link
Member

@kettanaito kettanaito left a comment

Choose a reason for hiding this comment

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

Looks good, thank you, @ghernandez345!

@kettanaito kettanaito merged commit 87ea373 into mswjs:main Nov 3, 2024
1 check passed
@kettanaito
Copy link
Member

Released: v0.0.8 🎉

This has been released in v0.0.8!

Make sure to always update to the latest version (npm i jest-fixed-jsdom@latest) to get the newest features and bug fixes.


Predictable release automation by @ossjs/release.

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.

4 participants