Is there a lifecycle module that's called before each story in a browser only?
See original GitHub issueHey 👋 Thanks for an awesome project! I’ve been using Storybook for years and I love it.
I’m maintaining a usage example of Mock Service Worker library with Storybook, and I have a question about the best way to integrate those two.
Integration
The point of the integration is to call the setupWorker
function before each story in a browser. setupWorker
cannot be called in a Node environment (that includes DOM-like environments like jsdom).
Current behavior
I’m placing my logic into .storybook/preview.js
, which is promised to run before each story. While it does do so in a browser, it’s also run in Node when I test my stories.
You can verify that by checking out the examples repository mentioned below, and running the following command:
$ yarn test
Expected behavior
Is there a configuration module that’s executed before each story, but only in a browser environment?
Reproduction repository
Please refer to the Storybook usage example repository to play around with this setup by yourself. I’d be thankful for any guidance and suggestion in this. Exciting to bring an awesome example of a usage with Storybook!
Issue Analytics
- State:
- Created 3 years ago
- Reactions:1
- Comments:17 (6 by maintainers)
Top GitHub Comments
We’ve added some docs in the 6.0 release that are probably relevant to this issue: https://storybook.js.org/docs/react/workflows/build-pages-with-storybook
Hi, @tmeasday. Forgive me for some of the misleading terminologies.
When I try to run Storybook there seems to be no issue, it must have been some quirks on my setup’s side. Let me investigate it further and come back with the updates. Thanks.