Fix MSW and storybook setup (#2976)

* Fix MSW and storybook setup

* Fix

* Fix

* Fixes

* Fix

* Fix

* Fix
This commit is contained in:
Charles Bochet
2023-12-13 14:37:55 +01:00
committed by GitHub
parent 34b5bfc34f
commit 9182efc57a
6 changed files with 260 additions and 280 deletions

View File

@ -1,12 +1,9 @@
<link
href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600&display=swap"
rel="stylesheet"
href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600&display=swap"
rel="stylesheet"
/>
<script src="https://cdnjs.cloudflare.com/ajax/libs/iframe-resizer/4.3.7/iframeResizer.contentWindow.min.js"></script>
<!-- <script>
window.global = window;
</script> -->
<style type="text/css">
body {

View File

@ -1,7 +1,7 @@
import { ThemeProvider } from '@emotion/react';
import { Preview, ReactRenderer } from '@storybook/react';
import { withThemeFromJSXProvider } from "@storybook/addon-themes";
import { initialize, mswLoader } from 'msw-storybook-addon';
import { initialize, mswDecorator } from 'msw-storybook-addon';
import { RootDecorator } from '../src/testing/decorators/RootDecorator';
import { mockedUserJWT } from '../src/testing/mock-data/jwt';
@ -9,7 +9,20 @@ import { mockedUserJWT } from '../src/testing/mock-data/jwt';
import { lightTheme, darkTheme } from '../src/modules/ui/theme/constants/theme';
import 'react-loading-skeleton/dist/skeleton.css';
initialize({ onUnhandledRequest: 'bypass' });
initialize({
onUnhandledRequest: async (request: Request) => {
const fileExtensionsToIgnore = /\.(ts|tsx|js|jsx|svg|css|png)(\?v=[a-zA-Z0-9]+)?/;
if (fileExtensionsToIgnore.test(request.url)) {
return;
}
const requestBody = await request.json();
console.warn(`Unhandled ${request.method} request to ${request.url}
with payload ${JSON.stringify(requestBody)}\n
This request should be mocked with MSW`);
},
});
const preview: Preview = {
decorators: [
@ -22,6 +35,7 @@ const preview: Preview = {
Provider: ThemeProvider,
}),
RootDecorator,
mswDecorator,
],
parameters: {
actions: { argTypesRegex: '^on[A-Z].*' },
@ -39,7 +53,6 @@ const preview: Preview = {
cookie: {
tokenPair: `{%22accessToken%22:{%22token%22:%22${mockedUserJWT}%22%2C%22expiresAt%22:%222023-07-18T15:06:40.704Z%22%2C%22__typename%22:%22AuthToken%22}%2C%22refreshToken%22:{%22token%22:%22${mockedUserJWT}%22%2C%22expiresAt%22:%222023-10-15T15:06:41.558Z%22%2C%22__typename%22:%22AuthToken%22}%2C%22__typename%22:%22AuthTokenPair%22}`,
},
loaders: [mswLoader],
},
};