-
-
Notifications
You must be signed in to change notification settings - Fork 517
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
msw 1.1.0 regresses tests with Testing Library, React and Jest: "The current testing environment is not configured to support act(...)" #1563
Comments
Same problem for me so I used v0.49.3 at the moment. I hope it will be resolved in the latest one. |
MSW 1.1.0 and 1.1.1 break most of my tests that use mocks. I'm on node 16 using |
I had similar regression with 1.1.0 version and then came here. The new version adds a new interceptor to Previously I mocked Agree with previous comments that 1.1.0 is a breaking change. |
Any updates on this one? I am having the same issue, I used to polyfill my |
About workaround measures I also encountered this problem today. I would like to leave the workaround measures at that time here, so I would appreciate it if you could refer to it. ※The comments below were very helpful in my research. thank you! prerequisite
I believe these issues are the FetchInterceptor used internally by msw. Construct the SetupServerApi in your own setup file like the code below. // your setup server typescript file.
import { ClientRequestInterceptor } from '@mswjs/interceptors/lib/interceptors/ClientRequest/index.js'
import { XMLHttpRequestInterceptor } from '@mswjs/interceptors/lib/interceptors/XMLHttpRequest/index.js'
import { SetupServerApi ,SetupServer } from 'msw/node'
import { handlers } from './my-handlers'
export const server: SetupServer = new SetupServerApi(
// do not use FetchInterceptors
// Use something like whatwg-fetch in setupAfterEnv etc.
// ex: https://github.com/mswjs/examples/blob/master/examples/with-jest/jest.setup.js#L1-L2
[ClientRequestInterceptor, XMLHttpRequestInterceptor],
...handlers,
)
beforeAll(() => server.listen())
afterEach(() => server.resetHandlers())
afterAll(() => server.close()) |
So... I'm using jest, msw, and graphql-upload. I need the latest msw version to fix an issue with graphql-upload. Side note, with the latest version of msw, graphql-upload breaks the fetch polyfill, a completely different package. Which, I can patch, so no biggie there. Just interesting. (JakeChampion/fetch#460) Craziness. All this to test file upload with graphql. Anywho, I'm hoping this can get resolved soon. :) |
Thanks for reporting this. I will share my thoughts on this below.
This is correct. MSW 1.x uses the older versions of Interceptors that are not based on the Fetch API primitives. MSW 2.x uses the latest version of Interceptors that are. No updates are necessary on this end.
We are aware of the missing Help with reviewing that pull request is highly welcome! So, as I understand, the issue was introduced by the addition of What to do now?Pin your I will look into the issue but it's nowhere on my priority list right now. You are also welcome to dive into it, review pull requests, contribute tests, and improve MSW together. The beauty of open source. You also have another option: migrate to |
I'm triaging a bit and I found the smoking gun, although I don't fully understand it at this point. Thought I'd share though. Normal execution for multiple tests would be:
With the
Where test 2 is asserting If there was a synchronous way to call EDIT: I've dug a little further and it seems the only way to get the ArrayBuffer from the Request is to use an asynchronous operation. Things are NOT coming up Milhouse today. EDIT2: The bug shows up only when I use |
Hi there, i've try to migrate for the 2.X.X of MSW but same problem here, to be full node 18+ compatible, this is the last piece I need.
|
@kettanaito are there any estimates for a backport (and is it something still planned)? It seems it is not possible to use MSW with AbortController support and Node 16 at the moment. Node 16 might be not the biggest issue (as it's anyway EoL by now), however v2 integration with Jest is also far from being seamless which complicates things.
|
ConclusionI'm sorry for any inconvenience this may cause. There are no plans for any backporting to 1.x. That version of the library is no longer maintained due to the lack of people to do that. My effort is focused on 2.0 and the future of the library. Spending effort of patching unsupported versions of Node.js and old tools is draining and I'd rather see that energy spent on better things. How to fix this issue then?Migrate to There's also a Codemod that can boost your migration speed drastically. Thanks for understanding. |
Prerequisites
Environment check
msw
versionNode.js version
v16.19.1 (and v18.13.0)
Reproduction repository
https://github.com/TheRealCuran/bugs-reproducer-msw110
Reproduction steps
The reproducing repository contains a stripped down version of a React component and a bare bones test, that show the issue for me with the Node.js versions named above. Downgrading
msw
to 1.0.1 fixes the issue again.Run
yarn install && yarn msw-bug-test
to reproduce.Current behavior
Running our test suite with msw 1.1.0 leads to (error message as seen as in our test suite, the reproducer test creates a little bit different output due to different fields in the state and differing line numbers; identifying names have been replaced):
This in turn leads to the state not being updated properly and thus the test failure.
Downgrading to 1.0.1 restores functionality again. Looking at the changelog I suspect it has to be #1543, which is causing this.
Side note:
msw
pulls in@mswjs/interceptors
at version 0.17.9, the repository here on GitHub shows 0.22.7 as the latest version. Maybe it's only the dependency, that needs to be updated?Expected behavior
I expect our tests to run through as before with msw 1.0.1 (or a clear documentation, which is indicating the breaking change and what to do to migrate – though I would have expected a major version change then).
So far this looks like a regression to me.
The text was updated successfully, but these errors were encountered: