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

chore(msw-addon): fix api mocking for storybook #1046

Merged
merged 1 commit into from
Feb 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions ui/.storybook/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ const config: StorybookConfig = {
'@storybook/addon-links',
'@storybook/addon-essentials',
'@storybook/addon-interactions',
'msw-storybook-addon',
],
framework: {
name: '@storybook/react-webpack5',
Expand All @@ -19,7 +18,7 @@ const config: StorybookConfig = {
},
staticDirs: ['../src/public'],
webpackFinal: async (config) => {
const alias = config.resolve.alias || {};
const alias = config.resolve?.alias || {};
return {
...config,
resolve: {
Expand Down
35 changes: 26 additions & 9 deletions ui/.storybook/preview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,20 +24,37 @@ const preview: Preview = {
disable: true,
},
msw: {
handlers: [
...serverHandlers,
http.get(`globalConfig.json`, () =>
HttpResponse.json({
pages: {},
meta: {},
})
),
],
handlers: {
common: [
...serverHandlers,
http.get(`globalConfig.json`, () =>
HttpResponse.json({
pages: {},
meta: {},
})
),
http.post(`/servicesNS/:user/-/:serviceName`, async ({ request }) =>
HttpResponse.json(
{
messages: [
{
text: `Submitted body: ${decodeURIComponent(
await request.text()
)}`,
},
],
},
{ status: 500 }
)
),
],
},
},
controls: {
sort: 'requiredFirst',
},
},
loaders: [mswLoader],
decorators: [withSplunkThemeToolbar],
};

Expand Down
6 changes: 4 additions & 2 deletions ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,8 @@
"yarn": "^1.22.21"
},
"msw": {
"workerDirectory": "src/public"
"workerDirectory": [
"src/public"
]
}
}
}
8 changes: 0 additions & 8 deletions ui/src/components/CheckboxGroup/checkboxGroupMocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,4 @@ export const serverHandlers = [
],
})
),
http.post(`/servicesNS/:user/-/:serviceName`, async ({ request }) =>
HttpResponse.json(
{
messages: [{ text: `Submitted body: ${decodeURIComponent(await request.text())}` }],
},
{ status: 500 }
)
),
];
1 change: 1 addition & 0 deletions ui/src/mocks/globalConfigMock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ const globalConfigMock: z.input<typeof GlobalConfigSchema> = {
type: 'singleSelect',
label: 'Account to use',
options: {
createSearchChoice: true,
referenceName: 'account',
},
help: 'Account to use for this input.',
Expand Down
4 changes: 2 additions & 2 deletions ui/src/public/mockServiceWorker.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
/* tslint:disable */

/**
* Mock Service Worker (2.0.11).
* Mock Service Worker (2.1.5).
* @see https://github.com/mswjs/msw
* - Please do NOT modify this file.
* - Please do NOT serve this file on production.
*/

const INTEGRITY_CHECKSUM = 'c5f7f8e188b673ea4e677df7ea3c5a39'
const INTEGRITY_CHECKSUM = '223d191a56023cd36aa88c802961b911'
const IS_MOCKED_RESPONSE = Symbol('isMockedResponse')
const activeClientIds = new Set()

Expand Down
Loading