Closed Roy412 closed 2 weeks ago
That script URL looks broken to me. The worker should be registered at http://localhost:64812/mockServiceWorker.js
once to affect all the nested tests (notice that each test is served under a randomly generated path. Instead, it looks like each test serves its own worker, and registers it only under the test's path.
Please refer to the TestCafe's docs to learn how to serve the worker script at the root of your test application. There has also been a ton of changes to MSW since this issue was filed, so please upgrade the library before trying anything else. Thanks.
Prerequisites
Environment check
msw
versionBrowsers
Chromium (Chrome, Brave, etc.)
Reproduction repository
https://github.com/Roy412/msw-testcafe-error/tree/msw_mock_issue
Reproduction steps
yarn
yarn testcafe
The second test fails because MSW service worker is not registered. https://github.com/Roy412/msw-testcafe-error/blob/5ba82e4e7ce516caab9ad551691db83a0e5737d3/app/pages/_app.js#L18
Current behavior
There're two tests that are exactly the same. The MSW service worker is registered successfully at the first test while it is not enabled for the second one. When there is only one test, it passes successfully and from the second test, it will fail. On the second test, following code returns the multiple available
existingStates
. https://github.com/mswjs/msw/blob/7380011de47460212065ca41be1b5a1c60ed1b98/src/setupWorker/start/utils/getWorkerByRegistration.ts#L17And it returns the first one which was used at the first test. It should return the second one.
Expected behavior
The MSW service worker should be registered correctly for the second test too.