MSW leaves cypress component test runner in a loop
Author: yannbfCreated May 22, 2021Updated Sep 29, 2026
Labelsbugscope:browserwith:cypress
Describe the bug
Cypress 7 recently released an interesting feature called component test runner. It allows to mount a component and run it in isolation, rather than having to run the entire application. I was trying to use it with MSW (which would be awesome!), but for some reason, starting the service worker makes the test behave weirdly, becoming flaky, sometimes looping and causing trouble.
Environment
msw: 0.28.2nodejs: 14.14.0npm: 6.4.8- browser: Chromium opened by cypress
To Reproduce
Steps to reproduce the behavior:
before, check this repro: https://github.com/yannbf/msw-cypress-component-issue
- yarn
- yarn cy
- Select Login.test.jsx
- Check the comments in https://github.com/yannbf/msw-cypress-component-issue/blob/main/src/components/Login.test.jsx#L9. As soon as you remove the
startof the service worker, the tests flow naturally. When you add them, there's something weird that results in cypress runner looping.
Expected behavior
MSW should not impact cypress
Screenshots

Source: mswjs/msw