MSW seems to be unreliably working with Cypress
See original GitHub issueHi there,
after struggling for too long with this … asking here
Describe the bug
The worker sometimes starts sometimes not, and the request are sometimes intercepted others not.
This only happen when the app is tested with cypress
I’m only using a simple cy.visit('/')
and the console sometimes shows the
sometimes not
other times it show the worker has started but the requests are not intercepted
ie. this does not show
I’m starting the worker like this :
if (process.env.NODE_ENV === 'development') {
const { worker } = require('./services/mocks');
worker.start();
}
Note: the requests I’m mentioning are requests that are sent when the React App (CRA) starts
Environment
msw:0.19.4
nodejs: 14.1
npm: 6.14
Please also provide your browser version.
chrome 83
Expected behavior
Consistent starting and interceptin of requests while working w/ Cypress
thanks a lot
Issue Analytics
- State:
- Created 3 years ago
- Comments:7 (6 by maintainers)
Top Results From Across the Web
Cypress issues when using window.msw #1052 - GitHub
MSW is working as the app runs with a correctly mocked response. However, in my Cypress test I am trying to override the...
Read more >MSW Runtime request handler not working in Cypress (NextJs ...
The MSW handlers in the worker setup (in NextJs) is intercepting the request from the Cypress test run without any issue.
Read more >Cypress cy.intercept Problems - Gleb Bahmutov
Once the page is loaded, the application fetches the todo items, and everything is working as expected. The intercept works correctly. The bonus ......
Read more >Easy mocking of API Requests in Cypress with Mock Service ...
The cy.intercept API is fantastic. However, it is an API that is specific to Cypress. When using MSW, we do lose some functionality...
Read more >pactflow - Pact (Contract Testing)
See https://github.com/pactflow/example-consumer-cypress for an example ... which still doesn't appear to work with an arbitrary UUID for a version tag.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Hi All,
I have been facing the same issue. MSW indicated it was enabled but the requests were only caught with a force refresh and when the service worker was installed.
It turns out the issue was likely coming from the default
registerServiceWorker
provided in create-react-app. It was set toserviceWorker.unregister()
and thus was callingI’m no expert in service workers but I assume it was messing up with MSW.
TL;DR: remove or comment out the default registerWorker from CRA:
Hi,
I’m sorry
I have ahed to switch to other matters and have had no time at all
I will have to come back to it but I don’t know when that will be
feel free to close if that’s convenient for you, I’ll re-open or make another issue when I can
thanks!
On Fri, Jul 3, 2020 at 10:06 AM Artem Zakharchenko notifications@github.com wrote: