-
-
Notifications
You must be signed in to change notification settings - Fork 579
Description
Prerequisites
- I confirm my issue is not in the opened issues
- I confirm the Frequently Asked Questions didn't contain the answer to my issue
Environment check
- I'm using the latest
mswversion - I'm using Node.js version 20 or higher
Browsers
Chromium (Chrome, Brave, etc.)
Reproduction repository
https://github.com/spocke/mswjs-stop-bug/tree/bug/404-after-stop
Reproduction steps
This one is very simple to reproduce just start one mock, then stop that mock then start another and that mock now returns a 404 even if it has a valid mock handler in place.
- Clone the repo and go to the 404-after-stop branch
- Install the npm dependencies using
npm i - Start the server using
npm start - Open the Chrome or Safari and go to go to
http://localhost:3000 - Load the page
- Observe that second mock request produces a 404 error
This is the code to reproduce the issue we just setup a worker1 do a mocked plain text request then stop that worker. Then we setup a second worker and do another mock request this one produces a 404.
const worker1 = setupWorker(...[
http.get('/foo', async ({ request }) => HttpResponse.text('hello 1', { status: 200 }))
]);
await worker1.start({
serviceWorker: {
url: '/mockServiceWorker.js'
}
});
await fetch('/foo').then(res => res.text()).then(console.log);
worker1.stop();
const worker2 = setupWorker(...[
http.get('/foo', async ({ request }) => HttpResponse.text('hello 2', { status: 200 }))
]);
await worker2.start({
serviceWorker: {
url: '/mockServiceWorker.js'
}
});
await fetch('/foo').then(res => res.text()).then(console.log); // This will produce a 404
worker2.stop();
It can be reproduced in Chrome, Firefox and Safari using the latest 2.11.3 version.
Current behavior
The second request produces a 404 error even if it's a valid mocked request.
Expected behavior
That the second request returns a properly mocked response like the first request but with the new expected response from the new mock handler.