Replies: 1 comment 1 reply
-
Hey, @cellog. Thanks for reaching out. Let me start by saying that integration with various tools is still an area we're actively exploring, and developers come up with great approaches to their problems and share them with us so they can become a common practice. That being said, I'll try to recommend to you how to approach MSW setup in your circumstances. ClarificationsFirst, I'd like to learn more about your usage.
What makes these requests, if it's not your application? No page load means no JavaScript downloaded, parsed, and executed. Is it your testing setup? Please, share the code that makes these requests, it'll help me understand your usage better.. SuggestionCan you achieve what you want by introducing mocks in the The load order of the stories would then be:
The add-on should integrate with your story so that the requests happening on the initial page load are also intercepted. |
Beta Was this translation helpful? Give feedback.
-
Hello, please redirect if there is a proper forum or other support mechanism I missed, thank you.
I am trying to implement MSW inside our application. Currently we use Storybook as the source for integration tests using Cypress. As such, many existing tests use request mocking to intercept requests, mock the responses, and then test. Because this is an application, we have some components that make network requests on startup.
I have 3 goals with introducing MSW:
The first point is solved by introducing msw and msw-storybook-addon, but the second point results in a conundrum. I need to be able to intercept requests before the page loads, but Cypress won't have access to the msw on window until the page has actually loaded, which introduces a race condition.
What do you think is the best approach here?
There are a couple of ways I can imagine to solve this:
migrate all cypress mocking to MSW mocking
Instead of mocking in Cypress, instead create separate storybook stories for each scenario and use these as the source for each cypress test. Long-term this is the solution I want to use
The drawback: it's going to be a huge pull request, and migration becomes much trickier since we can't spread it out over time, and have to do it all at once.
Figure out some way to properly intercept MSW and turn off mocking
I tried
This turned off mocking, but then something (probably storybook) turned it right back on, and the browser hung because MSW was looking for handlers that no longer existed and I had to force quit it. Yikes.
???
What do you think? Is my only real option the ginormous pull request option?
Beta Was this translation helpful? Give feedback.
All reactions