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
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
b106c13
Breaking change: Support MSW 2.0
yannbf Oct 23, 2023
19a6e68
update example to use MSW 2.0 handlers
yannbf Oct 24, 2023
b3ed3b1
temporarily disable tests in release workflow
yannbf Oct 24, 2023
06f0c92
update jest config to pass tests
mattcosta7 Nov 28, 2023
e28f7b7
Merge remote-tracking branch 'upstream/main' into feat/support-msw-2.0
mattcosta7 Nov 28, 2023
7ea6645
fix path
mattcosta7 Nov 28, 2023
f80e255
worker
mattcosta7 Nov 28, 2023
15257ac
alias msw/native
mattcosta7 Nov 28, 2023
c7c8a80
update peer dependency range
yannbf Jan 4, 2024
bf62ea8
upgrade example storybook
yannbf Jan 4, 2024
37dfc82
fix: use conditional exports (#134)
kettanaito Jan 29, 2024
3cfb456
bring back tests
yannbf Jan 29, 2024
9cedceb
Filter requests that are not relevant to the user
yannbf Jan 29, 2024
0f49e5c
make sure to reset the handlers
yannbf Jan 29, 2024
7ca8425
feat!(msw-addon): fix package exports and generate esm build (#138)
ChristianMurphy Feb 21, 2024
7f91bea
fix(loader.ts): fix possible undefined (#141)
AlexMunoz Mar 6, 2024
49f8028
update auto
yannbf Mar 6, 2024
dd2c917
update to yarn 4
yannbf Mar 6, 2024
c14e003
upgrade chromatic
yannbf Mar 6, 2024
4c6d953
upgrade CI actions
yannbf Mar 6, 2024
7a608cc
fix return types
yannbf Mar 27, 2024
cad5197
add yarn binary
yannbf Mar 27, 2024
68fe0ce
fix jest script
yannbf Mar 27, 2024
a97567c
fix chromatic script
yannbf Mar 27, 2024
9f4c631
fix chromatic script
yannbf Mar 27, 2024
a5256b9
update package.json files
yannbf Mar 27, 2024
dc531d0
refactor tsup config
yannbf Mar 27, 2024
fd4358f
remove unnecessary dependency
yannbf Mar 27, 2024
dfa57d7
temp: downgrade to yarn1
yannbf Mar 27, 2024
dcca74c
export applyRequestHandlers
yannbf Mar 27, 2024
513090e
update docs [skip ci]
yannbf Mar 27, 2024
60b211e
update tests
yannbf Apr 14, 2024
61d20b7
upgrade to Storybook 8
yannbf Apr 15, 2024
691d424
improve documentation on portable stories
yannbf Apr 15, 2024
c4f877b
deprecate mswDecorator
yannbf Apr 15, 2024
133be34
deprecate msw parameter as an array
yannbf Apr 15, 2024
42db187
migrate docs example to vite (#128)
yannbf Apr 16, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/chromatic.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:
- name: Setup Node.js
uses: actions/setup-node@v2
with:
node-version: 16
node-version: 18.x

- name: Install dependencies
uses: bahmutov/npm-install@v1
Expand Down
9 changes: 5 additions & 4 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,18 @@ jobs:
- name: Setup Node.js
uses: actions/setup-node@v2
with:
node-version: 16
node-version: 18.x

- name: Install dependencies
uses: bahmutov/npm-install@v1

- name: Build
run: yarn build

- name: Test
working-directory: ./packages/docs
run: yarn test
# TODO: bring this back once https://github.com/mswjs/msw-storybook-addon/pull/125 is merged
# - name: Test
# working-directory: ./packages/docs
# run: yarn test
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can probably bring this back, tests work now


- name: Release
run: |
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
{
"private": true,
"name": "msw-storybook-addon",
"name": "msw-storybook-addon-workspace",
"workspaces": [
"packages/*"
],
"scripts": {
"storybook": "yarn workspace msw-storybook-docs storybook",
"msw:dev": "yarn workspace msw-storybook-addon dev",
"start": "npm-run-all --parallel storybook msw:dev",
"build": "yarn workspace msw-storybook-addon build && yarn workspace msw-storybook-docs storybook-build"
"build": "yarn workspace msw-storybook-addon build && yarn workspace msw-storybook-docs build-storybook"
},
"devDependencies": {
"npm-run-all": "^4.1.5"
Expand Down
8 changes: 8 additions & 0 deletions packages/docs/.prettierrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
module.exports = {
trailingComma: 'es5',
tabWidth: 2,
semi: false,
singleQuote: true,
printWidth: 100,
bracketSpacing: true,
}
7 changes: 5 additions & 2 deletions packages/docs/.storybook/main.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
const path = require('path')
/**
* @type {import('@storybook/react-webpack5').StorybookConfig}
*/
Expand All @@ -8,13 +9,15 @@ const config = {
'@storybook/addon-essentials',
'@storybook/addon-a11y',
'@storybook/preset-create-react-app',
'@storybook/addon-storysource',
],
staticDirs: ['../public'],
webpackFinal: async (config) => {
config.resolve = config.resolve || {}
config.resolve.alias = {
...config.resolve.alias,
'msw/native': require.resolve(
path.resolve(__dirname, '../../../node_modules/msw/lib/native/index.mjs')
),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is necessary because the export conditions aren't finding this package, likely because it lacks a browser export

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In my case the error is with msw/node (using storybook with vite builder) in this line:

const { setupServer } = nodeRequire('msw/node')

but I'd find it hard to sell that consumers of this plugin (or really, consumers wanting to use storybook + jest + jsdom + msw) need to do this 👇

      'msw/native': require.resolve(
        path.resolve(__dirname, '../../../node_modules/msw/lib/native/index.mjs')
      ),
      'msw/node': require.resolve(
        path.resolve(__dirname, '../../../node_modules/msw/lib/node/index.mjs')
      ),

But I also know there is a lot of push back about those conditional exports 😞

'msw-storybook-addon': require.resolve('../../msw-addon/dist'),
}
return config
Expand All @@ -28,4 +31,4 @@ const config = {
},
}

export default config;
export default config
2 changes: 1 addition & 1 deletion packages/docs/.storybook/preview.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const preview = {
parameters: {
actions: { argTypesRegex: '^on[A-Z].*' },
},
loaders: [mswLoader]
loaders: [mswLoader],
};

export default preview;
Expand Down
28 changes: 28 additions & 0 deletions packages/docs/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
module.exports = {
yannbf marked this conversation as resolved.
Show resolved Hide resolved
clearMocks: false,
moduleFileExtensions: [
'web.js',
'js',
'web.ts',
'ts',
'web.tsx',
'tsx',
'json',
'web.jsx',
'jsx',
'node',
],
moduleNameMapper: { '^.+\\.module\\.(css|sass|scss)$': 'identity-obj-proxy' },
resetMocks: true,
resetModules: false,
restoreMocks: false,
setupFiles: ['./src/fetch-polyfill.js'],
setupFilesAfterEnv: ['./src/setupTests.js'],
testEnvironment: 'jsdom',
transform: {
'^.+\\.(js|jsx|mjs|cjs|ts|tsx)$': 'react-scripts/config/jest/babelTransform.js',
'^.+\\.css$': 'react-scripts/config/jest/cssTransform.js',
'^(?!.*\\.(js|jsx|mjs|cjs|ts|tsx|css|json)$)': 'react-scripts/config/jest/fileTransform.js',
},
transformIgnorePatterns: ['node_modules/(?!@bundled-es-modules)/'],
}
28 changes: 14 additions & 14 deletions packages/docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"test": "jest",
"eject": "react-scripts eject",
"storybook": "storybook dev -p 6006",
"storybook-build": "storybook build",
"build-storybook": "storybook build",
"msw:update": "msw init public"
},
"eslintConfig": {
Expand Down Expand Up @@ -56,18 +56,18 @@
"web-vitals": "^0.2.4"
},
"devDependencies": {
"@storybook/addon-a11y": "^7.0.7",
"@storybook/addon-actions": "^7.0.7",
"@storybook/addon-essentials": "^7.0.7",
"@storybook/addon-links": "^7.0.7",
"@storybook/addon-storysource": "^7.0.7",
"@storybook/node-logger": "^7.0.7",
"@storybook/preset-create-react-app": "^7.0.7",
"@storybook/react": "^7.0.7",
"@storybook/react-webpack5": "^7.0.7",
"chromatic": "^5.5.0",
"msw": "^1.2.1",
"storybook": "^7.0.7",
"@storybook/addon-a11y": "^7.5.1",
"@storybook/addon-actions": "^7.5.1",
"@storybook/addon-essentials": "^7.5.1",
"@storybook/addon-links": "^7.5.1",
"@storybook/node-logger": "^7.5.1",
"@storybook/preset-create-react-app": "^7.5.1",
"@storybook/react": "^7.5.1",
"@storybook/react-webpack5": "^7.5.1",
"chromatic": "^7.5.0",
"msw": "^2.0.9",
"storybook": "^7.5.1",
"undici": "^5.28.1",
"webpack": "5"
},
"msw": {
Expand Down