- Notifications
You must be signed in to change notification settings - Fork927
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Conversation
- Fixes a transitive High severity dependency in path-to-regexp
There was a problem hiding this 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.
Looks like I approved too soon as this doesn't resolve be able to run the tests. |
Closing in favor of#17135 |
Fixes a transitive High severity dependency in path-to-regexp. We've tried to [upgrade to2.5.0](#17124) (currently, the latestversion) but there are some known bugs related to polyfills as [thisone](mswjs/msw#2288). As shared in thecomments, the latest version without this issue is 2.4.3.
Uh oh!
There was an error while loading.Please reload this page.
TLDR:
The solution is to either:
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.