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.

Is there a lifecycle module that's called before each story in a browser only?

See original GitHub issue

Hey 👋 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:closed
  • Created 3 years ago
  • Reactions:1
  • Comments:17 (6 by maintainers)

github_iconTop GitHub Comments

4reactions
tmeasdaycommented, Aug 13, 2020

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

1reaction
kettanaitocommented, Feb 12, 2021

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Page Lifecycle API - Chrome Developers
The Page Lifecycle API brings app lifecycle features common on mobile operating systems to the web. Browsers are now able to safely freeze ......
Read more >
Learn React: Lifecycle Methods Cheatsheet | Codecademy
React supports one unmounting lifecycle method, componentWillUnmount , which will be called right before a component is removed from the DOM.
Read more >
What Is the Software Testing Life Cycle? A Complete Guide
The software testing life cycle is the sequence of activities that happen during software testing. By employing a sane software testing life ......
Read more >
What is Defect/Bug Life Cycle in Software Testing? Defect Life ...
Answer: A defect that is not occurring repeatedly in every execution and is producing only at some instances and whose steps as proof...
Read more >
Express/Node introduction - Learn web development | MDN
In fact, exports is just a variable that gets initialized to the value of module.exports before the module is evaluated.
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