Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unify the setup and usage of msw in stories #34450

Open
ravicious opened this issue Nov 10, 2023 · 1 comment
Open

Unify the setup and usage of msw in stories #34450

ravicious opened this issue Nov 10, 2023 · 1 comment
Labels
developer-experience Addressing these issues will improve the experience of developers working on Teleport ui

Comments

@ravicious
Copy link
Member

Currently, we use msw both from window.msw (example) and by importing it from the msw package (example).

The version from the window seems to work only over local IP. If ctx.delay is used in the msw handlers, it seems to have no effect – the responses are returned immediately.

The version from the msw package works only over localhost. It requires a different setup which is currently done per story, but according to the docs it should be done globally in preview.js. ctx.delay seems to work with this version with no problems.

This causes problems when viewing stories because some work only in localhost and some work only over local IP.

I haven't tried to understand the use case behind the window version of msw, but since ctx.delay doesn't seem to work with it, I believe we should migrate to the second approach. Perhaps it's possible to make it support both the local IP and localhost, so that no matter how someone launches the storyybook, the stories will work.

@ravicious ravicious added ui developer-experience Addressing these issues will improve the experience of developers working on Teleport labels Nov 10, 2023
@ravicious
Copy link
Member Author

msw-storybook-addon seems to have problems with resetting the handlers between rendering stories, see mswjs/msw-storybook-addon#82.

In the PollingSuccess story in Discover/ConnectMyComputer/SetupConnect/SetupConnect.story.tsx, I register two separate handlers, one for the first response and one for subsequent responses. If you switch between stories, the handlers do not get reset which causes the story to be in an incorrect state if you switch back to it. The workaround would be to refresh the page with the story, but perhaps we can somehow instruct Storybook to call the equivalent of worker.resetHandlers between rendering stories.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
developer-experience Addressing these issues will improve the experience of developers working on Teleport ui
Projects
None yet
Development

No branches or pull requests

1 participant