question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

MSW leaves cypress component test runner in a loop

See original GitHub issue

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.2
  • nodejs: 14.14.0
  • npm: 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

  1. yarn
  2. yarn cy
  3. Select Login.test.jsx
  4. 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 start of 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

2021-05-22 at 23 00 45 - Amber Beaver

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:5
  • Comments:28 (10 by maintainers)

github_iconTop GitHub Comments

3reactions
roryschadlercommented, Aug 4, 2022

I’m having the same problem, and none of the above workarounds have worked for me. I’d really love to be able to use MSW in my Cypress tests, is there any progress on this issue?

2reactions
lmiller1990commented, Dec 16, 2022

Ok thanks @kettanaito and @the-ult. I’ll poke around Cypress a bit, it probably won’t be until next week though. I’m fairly sure something is getting muddled up in the routing for CT.

The CT specific routes are here https://github.com/cypress-io/cypress/blob/develop/packages/server/lib/routes-ct.ts The shared routes are https://github.com/cypress-io/cypress/blob/develop/packages/server/lib/routes.ts

Small files, so this should not be too hard to debug.

Read more comments on GitHub >

github_iconTop Results From Across the Web

A brand new website interface for an even better experience!
MSW leaves cypress component test runner in a loop.
Read more >
Introducing the Cypress Component Test Runner
We're proud to announce the alpha release of Cypress's dedicated Component Test Runner. It's a brand new test runner that's designed to replace ......
Read more >
Mock Service Worker on Twitter: "@sunpietro Hello, Piotr. We could ...
Describe the bug Cypress 7 recently released an interesting feature called component test runner. It allows to mount a component and run it...
Read more >
Loading fixture with component test - cypress - Stack Overflow
Alises are cleared down between tests. You can change the hook to beforeEach() to allow all tests to see the data. Note that...
Read more >
Avoid Nesting when you're Testing - Kent C. Dodds
Here's a React component that I want to test: ... For our simple Login component here, I'd probably leave the test as-is, but...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found