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.

mock service worker integration in storybook-build

See original GitHub issue

First of all, thanks for creating this addon, It’s being really useful overall. However, I have a specific use case where when building storybook with the default build-storybook command, which generates the storybook-static folder, I want to be able to get data from the mock service provider. Right now, when the build finishes, the mock service provider doesn’t work (can’t fetch any data).

How could I make it work within the build?

I want this behaviour because I can just send to my clients a link to check how the frontend is looking right now, which is the storybook build, and having no mocks in it will provide them nothing useful.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:19 (7 by maintainers)

github_iconTop GitHub Comments

2reactions
tomcarter17commented, Jun 23, 2022

A colleague pointed out an unfortunate mistake to me, in that you can see above the build-storybook command doesn’t make use of -s .storybook/public. Adding this made it work, which makes pretty obvious sense as to why the worker file wasn’t in the build 🤦🏻 looks like I was only checking for the -s flag in the serve command.

In any case, thanks for your responses, and for the work on this addon!

1reaction
yannbfcommented, Jun 23, 2022

Great to know you figured that out @tomcarter17! I’d recommend using the new notation of staticDirs which would have avoided such issue in the first place, as it’s shared between dev and build in Storybook!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Using Storybook and Mock Service Worker for mocked API ...
In this tutorial, you can learn about the synergy between Storybook and Mock Service Worker and how to integrate them together seamlessly.
Read more >
MSW Storybook Addon - Mock Service Worker
Generate service worker for MSW in your public folder. If you already use MSW in your project, you have likely done this before...
Read more >
How to mock APIs in Storybook with MSW (Mock Service ...
Create a Storybook public folder; Install Mock Service Worker (MSW); Create a mock in a story; Bonus: use local images in your stories ......
Read more >
Storybook and Mock Service Worker, a match made in heaven
And as you'll know if you read my blog post about integration testing, Mock Service Worker is also a very powerful tool for...
Read more >
Integration stories: elevating Storybook with Mock Service ...
Enter Mock Service Worker. Mock by intercepting requests on the network level. Seamlessly reuse the same mock definition for testing, ...
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