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

BREAKING CHANGE: Support MSW 2.0 #122

Merged
merged 37 commits into from Apr 17, 2024
Merged

BREAKING CHANGE: Support MSW 2.0 #122

merged 37 commits into from Apr 17, 2024

Conversation

yannbf
Copy link
Collaborator

@yannbf yannbf commented Oct 23, 2023

Issue: #121

Release notes

MSW required version is now ^2.0.0

The addon now requires your MSW version to be 2.0.0 or higher. This means you will have to change the format of your handlers as well. More info on how to migrate to MSW 2.0.0: https://mswjs.io/docs/migrations/1.x-to-2.x/

mswDecorator is deprecated in favor of mswLoader

Using MSW in a decorator worked for most scenarios, but there's a slight chance the service worker will not get registered in time. As a result, a story that requests data might actually request real data. Since v1.7.0, this addon provided a mswLoader to use instead of the mswDecorator. Loaders get executed before a story renders, differently than decorators, which execute as the story renders.

Please replace your mswDecorator with mswLoader, as the mswDecorator will be removed in the next major release. It works the same, respecting the parameters you set, so there's no need to change anything else in your codebase.

// .storybook/preview.js
-import { initialize, mswDecorator } from 'msw-storybook-addon'
+import { initialize, mswLoader } from 'msw-storybook-addon'

initialize()

const preview = {
-  decorators: [mswDecorator]
+  loaders: [mswLoader]
}

export default preview

parameters.msw Array notation deprecated in favor of Object notation

Since v1.5.0, this addon started supporting the parameters.msw.handlers object format instead of using parameters.msw as an Array. This change was done to follow convention for Storybook addon parameters, but also allows for more advanced usage and make the addon more future proof for upcoming features. You can find more information here.

Please migrate to this format, and the previous format will be removed in the next major release.

// ❌ Instead of defining the msw parameter like so:
export const MyStory = {
  parameters: {
    msw: [...] // some handlers here
  }
}

// ✅ You should set them like so:
export const MyStory = {
  parameters: {
    msw: {
      handlers: [...] // some handlers here
    }
  }
}
// ✅ Or like so:
export const MyStory = {
  parameters: {
    msw: {
      handlers: {
        someHandlerName: [...] // some handlers here
      }
    }
  }
}
📦 Published PR as canary version: 2.0.0--canary.122.133be34.0

✨ Test out this PR locally via:

npm install msw-storybook-addon@2.0.0--canary.122.133be34.0
# or 
yarn add msw-storybook-addon@2.0.0--canary.122.133be34.0

@yannbf yannbf added the major Increment the major version when merged label Oct 23, 2023
@vercel
Copy link

vercel bot commented Oct 23, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
msw-storybook-addon ✅ Ready (Inspect) Visit Preview 💬 Add feedback Apr 16, 2024 0:35am

Co-authored-by: Gert Hengeveld <info@ghengeveld.nl>
@jakubriedl
Copy link

Thanks @yannbf for your great work,
I've tested the canary release in our (quite big) setup and it seems to work great. Is there something I can help with to get this finished and released?

@filiphazardous
Copy link

I'd like to add my thanks. I also use the canary in our (smaller) setup. Works nicely with our graphql calls!

@csantos1113
Copy link

Hey @yannbf thanks for your work getting this released.

It works nicely for Storybook in the browser, but I'm unfortunately facing a similar issue to the one you have in https://github.com/mswjs/msw-storybook-addon/actions/runs/6625684339/job/17997112847?pr=122 😢

jest + storybook composeStories

@the-ult
Copy link

the-ult commented Apr 10, 2024

Would it be an idea to combine forces? With @offbeat-dev ?

https://github.com/offbeat-dev/storybook-msw-addon

@kettanaito
Copy link
Member

@the-ult, that would be amazing! I have a chat with them on Discord but haven't got to reply just yet. Been extremely busy couple of weeks. Will get back to the convo and, hopefully, we will make the add-on even better.

* migrate docs example to vite

* migrate from jest to vitest

* add rollup workaround

* migrate example to Typescript
@yannbf yannbf changed the title WIP: Support MSW 2.0 BREAKING CHANGE: Support MSW 2.0 Apr 17, 2024
@yannbf yannbf merged commit 4e94e82 into main Apr 17, 2024
8 checks passed
@yannbf yannbf deleted the feat/support-msw-2.0 branch April 17, 2024 10:45
@kettanaito
Copy link
Member

🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
major Increment the major version when merged
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet