Skip to content

chore: update msw to 2.5.0 #17124

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

Closed
wants to merge 2 commits into from
Closed

chore: update msw to 2.5.0 #17124

wants to merge 2 commits into from

Conversation

sreya
Copy link
Collaborator

@sreya sreya commented Mar 27, 2025

  • Fixes a transitive High severity dependency in path-to-regexp

TLDR:
The solution is to either:

  1. set testEnvironment: 'node' in the Jest config
  2. Polyfill the Web Streams API in JSDOM

option 1 is not possible because the current tests require access top the DOM

AI explanation of issue:

What changed between versions 2.3.5 and 2.5.0 that might cause TransformStream errors in Jest?

Several changes shipped in MSW’s version 2.5.x. One of the notable changes was more thorough usage of the Web Streams API (which includes classes like TransformStream). The Web Streams API is natively available in modern browsers and in newer versions of Node.js (≥ 18). In older environments (or certain test runners), the TransformStream global may not exist by default, leading to the error:

ReferenceError: TransformStream is not defined

Why does this happen in Jest?
• Jest’s default test environment (which is often jest-environment-jsdom) may not include the TransformStream global.
• If you’re using an older version of Node.js (like Node 14 or 16) along with Jest, you may also be missing the global Web Streams classes.

As of MSW 2.5.x, the library expects TransformStream (and possibly other parts of the Web Streams API) to be present. If it’s not, you’ll see the ReferenceError.

Even though you’re on Node 20 (which natively supports the Web Streams API), you can still get ReferenceError: TransformStream is not defined if your test environment (usually JSDOM in Jest) doesn’t expose the TransformStream global. In other words, Node itself may have TransformStream, but JSDOM (or another test environment) might not.

@sreya sreya requested a review from jaaydenh March 27, 2025 05:35
- Fixes a transitive High severity dependency in path-to-regexp
@sreya sreya changed the title chore: update msw to 2.3.5 chore: update msw to 2.5.0 Mar 27, 2025
Copy link
Contributor

@jaaydenh jaaydenh 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 and seems like the only available solution at the moment.

I added some context around what the problem is and why this solution is the correct one.

@jaaydenh jaaydenh self-requested a review March 27, 2025 13:10
@jaaydenh
Copy link
Contributor

Looks like I approved too soon as this doesn't resolve be able to run the tests.

@BrunoQuaresma
Copy link
Collaborator

Closing in favor of #17135

BrunoQuaresma added a commit that referenced this pull request Mar 27, 2025
Fixes a transitive High severity dependency in path-to-regexp. 

We've tried to [upgrade to
2.5.0](#17124) (currently, the latest
version) but there are some known bugs related to polyfills as [this
one](mswjs/msw#2288). As shared in the
comments, the latest version without this issue is 2.4.3.
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