Skip to content

Commit 6188239

Browse files
committed
fix: upgraded and auto migrated storybook and related dependencies
Upgraded and auto migrated storybook and related dependencies HCRC-178. The Storybook related files and dependencies were updated with ```shell npx storybook@latest upgrade ``` It ran a automated migration script that resulted to following: ``` ◇ Checking the health of your project(s).. │ │ Your Storybook project looks good! │ ◇ The upgrade is complete! │ │ Your project(s) have been upgraded successfully! 🎉 │ │ If you want to learn more about the automigrations that executed in your │ project(s), please check the following links: │ │ • upgrade-storybook-related-dependencies │ • addon-globals-api │ • consolidated-imports │ • remove-addon-interactions │ • renderer-to-framework │ • remove-essential-addons │ │ For a full list of changes, please check our migration guide: │ https://storybook.js.org/docs/releases/migration-guide?ref=upgrade ``` ---- fix: exports, storybook, babel, jest and msw synergy 1. Install a new storybook (to fix critical security issues reported by Dependabot). Used `npx storybook@latest upgrade` to run an automated migration tool. 2. Storybook upgrade and migration resulted in some type issues and issues starting the storybook. Export clauses needed "type" addition to the statement when the re-exported object was a type. 3. MSW needed an update in order to fix the Storybook issues. Upgraded MSW and migrated the old mocks to support new syntax and rules. 4. Some new linting issues and deprecation warnings appeared and also the JEST environment needed some reconfiguration. Jest now had some problems with JSDom / ESM overlapping in same project. Fixed the type issues. 5. In order to fix the Jest environment, babel needed some reconfiguration.
1 parent ee140a3 commit 6188239

72 files changed

Lines changed: 691 additions & 943 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.babelrc

Lines changed: 0 additions & 12 deletions
This file was deleted.

.storybook/main.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,6 @@ module.exports = {
1111
addons: [
1212
'@storybook/addon-a11y',
1313
'@storybook/addon-links',
14-
'@storybook/addon-essentials',
15-
'@storybook/addon-interactions',
16-
'@storybook/addon-viewport',
1714
{
1815
name: '@storybook/preset-scss',
1916
options: {
@@ -30,6 +27,7 @@ module.exports = {
3027
},
3128
},
3229
'@storybook/addon-webpack5-compiler-babel',
30+
'@storybook/addon-docs',
3331
],
3432

3533
framework: {

.storybook/preview.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// Enable hds-design-tokens in storybook
22
import 'hds-design-tokens/lib/all.min.css';
3-
import { INITIAL_VIEWPORTS } from '@storybook/addon-viewport';
3+
import { INITIAL_VIEWPORTS } from 'storybook/viewport';
44
import { initialize as mswInitialize, mswDecorator } from 'msw-storybook-addon';
55

66
// Enable HelsinkiGrotesk font in storybook
@@ -16,8 +16,7 @@ export const parameters = {
1616
},
1717
},
1818
viewport: {
19-
defaultViewport: 'extraSmall',
20-
viewports: INITIAL_VIEWPORTS,
19+
options: INITIAL_VIEWPORTS,
2120
},
2221
};
2322

@@ -27,3 +26,10 @@ mswInitialize();
2726
// Provide the MSW addon decorator globally
2827
export const decorators = [mswDecorator];
2928
export const tags = ['autodocs', 'autodocs'];
29+
30+
export const initialGlobals = {
31+
viewport: {
32+
value: 'extraSmall',
33+
isRotated: false,
34+
},
35+
};

README.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ The general requirements for new Component development:
4444

4545
### Available scripts
4646

47-
4847
| Name | Purpose | Useful Options |
4948
| ----------------------- | -------------------------------------------------------------------------------------------------------------------------- | ----------------------------- |
5049
| `yarn dev` | Starts storybook environment that can be used for developing components. | |
@@ -62,7 +61,6 @@ The general requirements for new Component development:
6261

6362
**NOTE: To manually publish a new version to the NPM, you will need the credentials that can be found from the City of Helsinki Culture and Leisure's Vault-service.**
6463

65-
6664
### Development environments
6765

6866
You can use docker local environment for development:

babel.config.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
module.exports = {
2+
presets: [
3+
'@babel/preset-env',
4+
// It's also a good practice to set the new JSX runtime
5+
['@babel/preset-react', { runtime: 'automatic' }],
6+
'@babel/preset-typescript',
7+
],
8+
env: {
9+
test: {
10+
plugins: ['@babel/plugin-transform-runtime'],
11+
},
12+
},
13+
};

jest-setup.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
1-
// eslint-disable-next-line import/no-extraneous-dependencies
21
import '@testing-library/jest-dom';
3-
4-
// eslint-disable-next-line import/no-extraneous-dependencies
52
import { toHaveNoViolations } from 'jest-axe';
6-
// eslint-disable-next-line import/no-extraneous-dependencies
73
import fetchMock from 'jest-fetch-mock';
84
import { loadErrorMessages, loadDevMessages } from '@apollo/client/dev';
95
import { hideConsoleMessages } from './src/tests/hideConsoleMessages';

jest.config.js

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,23 @@ module.exports = {
1212
// return a mock css module
1313
'\\.(css|less|scss|sss|styl)$': 'identity-obj-proxy',
1414
'^lodash-es$': 'lodash',
15+
// This forces Jest to use the correct CommonJS version of uuid
16+
// instead of the ESM one hds-react is trying to import.
17+
'^uuid$': require.resolve('uuid'),
1518
},
1619

1720
setupFilesAfterEnv: ['<rootDir>/jest-setup.ts'],
1821

19-
// The test environment that will be used for testing
20-
// We have react-script as a dependency for our storybook build. This
21-
// package forces our jsdom version into an older one, regardless of
22-
// jest being at version 26. To circumvent, we are telling jest to
23-
// use jsdom sixteen here.
24-
testEnvironment: 'jest-environment-jsdom',
22+
// Fix the issue "Request/Response/TextEncoder is not defined (Jest)". See more: https://mswjs.io/docs/migrations/1.x-to-2.x#frequent-issues.
23+
testEnvironment: 'jest-fixed-jsdom',
24+
25+
transform: {
26+
'^.+\\.(t|j)sx?$': 'babel-jest',
27+
},
28+
transformIgnorePatterns: [
29+
'/node_modules/(?!(hds-react|uuid|until-async)/)',
30+
'\\.pnp\\.[^\\/]+$',
31+
],
2532

2633
// An array of regexp pattern strings that are matched against all test paths, matched tests are skipped
2734
testPathIgnorePatterns: ['<rootDir>/(build|dist|temp)/'],

package.json

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@
6464
"@babel/preset-env": "^7.26.0",
6565
"@babel/preset-react": "^7.25.9",
6666
"@babel/preset-typescript": "^7.26.0",
67-
"@chromatic-com/storybook": "^3",
67+
"@chromatic-com/storybook": "^4.1.2",
6868
"@graphql-codegen/cli": "^5.0.3",
6969
"@graphql-codegen/typescript": "^4.1.1",
7070
"@graphql-codegen/typescript-operations": "^4.3.1",
@@ -73,18 +73,14 @@
7373
"@rollup/plugin-commonjs": "^28.0.1",
7474
"@rollup/plugin-json": "^6.1.0",
7575
"@rollup/plugin-node-resolve": "^15.3.0",
76-
"@storybook/addon-a11y": "^8.4.2",
77-
"@storybook/addon-actions": "^8.4.2",
78-
"@storybook/addon-essentials": "^8.4.2",
79-
"@storybook/addon-interactions": "^8.4.2",
80-
"@storybook/addon-links": "^8.4.2",
81-
"@storybook/addon-viewport": "^8.4.2",
82-
"@storybook/addon-webpack5-compiler-babel": "^3.0.3",
76+
"@storybook/addon-a11y": "^10.0.4",
77+
"@storybook/addon-docs": "^10.0.4",
78+
"@storybook/addon-links": "^10.0.4",
79+
"@storybook/addon-webpack5-compiler-babel": "^3.0.6",
8380
"@storybook/preset-scss": "^1.0.3",
84-
"@storybook/react": "^8.4.2",
85-
"@storybook/react-webpack5": "^8.4.2",
86-
"@storybook/test": "^8.4.2",
81+
"@storybook/react-webpack5": "^10.0.4",
8782
"@storybook/test-runner": "^0.24.1",
83+
"@testing-library/dom": "^10.4.1",
8884
"@testing-library/jest-dom": "^6.6.3",
8985
"@testing-library/react": "^16.0.1",
9086
"@testing-library/user-event": "^14.5.2",
@@ -97,6 +93,7 @@
9793
"@typescript-eslint/eslint-plugin": "^8.14.0",
9894
"@typescript-eslint/parser": "^8.14.0",
9995
"axe-playwright": "^2.0.3",
96+
"babel-jest": "^30.2.0",
10097
"babel-loader": "^9.2.1",
10198
"cross-env": "^7.0.3",
10299
"crypto-browserify": "^3.12.1",
@@ -116,8 +113,7 @@
116113
"jest": "^29.7.0",
117114
"jest-axe": "^9.0.0",
118115
"jest-fetch-mock": "^3.0.3",
119-
"msw": "^1.1.0",
120-
"msw-storybook-addon": "1.8.0",
116+
"msw-storybook-addon": "^2.0.6",
121117
"postcss": "^8.4.49",
122118
"postcss-scss": "^4.0.9",
123119
"prettier": "3.3.3",
@@ -134,7 +130,7 @@
134130
"rollup-plugin-typescript2": "^0.36.0",
135131
"sass": "^1.66.0",
136132
"sass-loader": "^13.3.2",
137-
"storybook": "^8.4.2",
133+
"storybook": "^10.0.4",
138134
"style-loader": "^4.0.0",
139135
"tslib": "^2.8.1",
140136
"typescript": "^5.6.3",
@@ -148,7 +144,9 @@
148144
"html-react-parser": "^4.2.9",
149145
"isomorphic-dompurify": "^2.31.0",
150146
"jest-environment-jsdom": "^30.2.0",
151-
"lodash-es": "^4.17.21"
147+
"jest-fixed-jsdom": "^0.0.10",
148+
"lodash-es": "^4.17.21",
149+
"msw": "^2.11.6"
152150
},
153151
"msw": {
154152
"workerDirectory": "public"

public/mockServiceWorker.js

Lines changed: 29 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,9 @@
22
/* tslint:disable */
33

44
/**
5-
* Mock Service Worker (1.3.5).
5+
* Mock Service Worker.
66
* @see https://github.com/mswjs/msw
77
* - Please do NOT modify this file.
8-
* - Please do NOT serve this file on production.
98
*/
109

1110
const PACKAGE_VERSION = '2.11.6';
@@ -72,11 +71,6 @@ addEventListener('message', async function (event) {
7271
break;
7372
}
7473

75-
case 'MOCK_DEACTIVATE': {
76-
activeClientIds.delete(clientId)
77-
break
78-
}
79-
8074
case 'CLIENT_CLOSED': {
8175
activeClientIds.delete(clientId);
8276

@@ -97,11 +91,6 @@ addEventListener('message', async function (event) {
9791
addEventListener('fetch', function (event) {
9892
const requestInterceptedAt = Date.now();
9993

100-
// Bypass server-sent events.
101-
if (accept.includes('text/event-stream')) {
102-
return
103-
}
104-
10594
// Bypass navigation requests.
10695
if (event.request.mode === 'navigate') {
10796
return;
@@ -118,7 +107,7 @@ addEventListener('fetch', function (event) {
118107

119108
// Bypass all requests when there are no active clients.
120109
// Prevents the self-unregistered worked from handling requests
121-
// after it's been deleted (still remains active until the next reload).
110+
// after it's been terminated (still remains active until the next reload).
122111
if (activeClientIds.size === 0) {
123112
return;
124113
}
@@ -156,15 +145,18 @@ async function handleRequest(event, requestId, requestInterceptedAt) {
156145
{
157146
type: 'RESPONSE',
158147
payload: {
159-
requestId,
160-
type: clonedResponse.type,
161-
ok: clonedResponse.ok,
162-
status: clonedResponse.status,
163-
statusText: clonedResponse.statusText,
164-
body:
165-
clonedResponse.body === null ? null : await clonedResponse.text(),
166-
headers: Object.fromEntries(clonedResponse.headers.entries()),
167-
redirected: clonedResponse.redirected,
148+
isMockedResponse: IS_MOCKED_RESPONSE in response,
149+
request: {
150+
id: requestId,
151+
...serializedRequest,
152+
},
153+
response: {
154+
type: responseClone.type,
155+
status: responseClone.status,
156+
statusText: responseClone.statusText,
157+
headers: Object.fromEntries(responseClone.headers.entries()),
158+
body: responseClone.body,
159+
},
168160
},
169161
},
170162
responseClone.body ? [serializedRequest.body, responseClone.body] : [],
@@ -174,10 +166,14 @@ async function handleRequest(event, requestId, requestInterceptedAt) {
174166
return response;
175167
}
176168

177-
// Resolve the main client for the given event.
178-
// Client that issues a request doesn't necessarily equal the client
179-
// that registered the worker. It's with the latter the worker should
180-
// communicate with during the response resolving phase.
169+
/**
170+
* Resolve the main client for the given event.
171+
* Client that issues a request doesn't necessarily equal the client
172+
* that registered the worker. It's with the latter the worker should
173+
* communicate with during the response resolving phase.
174+
* @param {FetchEvent} event
175+
* @returns {Promise<Client | undefined>}
176+
*/
181177
async function resolveMainClient(event) {
182178
const client = await self.clients.get(event.clientId);
183179

@@ -255,12 +251,6 @@ async function getResponse(event, client, requestId, requestInterceptedAt) {
255251
return passthrough();
256252
}
257253

258-
// Bypass requests with the explicit bypass header.
259-
// Such requests can be issued by "ctx.fetch()".
260-
if (request.headers.get('x-msw-bypass') === 'true') {
261-
return passthrough()
262-
}
263-
264254
// Notify the client that a request has been intercepted.
265255
const serializedRequest = await serializeRequest(event.request);
266256
const clientMessage = await sendToClient(
@@ -284,21 +274,18 @@ async function getResponse(event, client, requestId, requestInterceptedAt) {
284274
case 'PASSTHROUGH': {
285275
return passthrough();
286276
}
287-
288-
case 'NETWORK_ERROR': {
289-
const { name, message } = clientMessage.data
290-
const networkError = new Error(message)
291-
networkError.name = name
292-
293-
// Rejecting a "respondWith" promise emulates a network error.
294-
throw networkError
295-
}
296277
}
297278

298279
return passthrough();
299280
}
300281

301-
function sendToClient(client, message) {
282+
/**
283+
* @param {Client} client
284+
* @param {any} message
285+
* @param {Array<Transferable>} transferrables
286+
* @returns {Promise<any>}
287+
*/
288+
function sendToClient(client, message, transferrables = []) {
302289
return new Promise((resolve, reject) => {
303290
const channel = new MessageChannel();
304291

src/apollo/apollo-custom-template.stories.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/* eslint-disable react/function-component-definition */
22

33
import React from 'react';
4-
import type { StoryFn, Meta } from '@storybook/react';
4+
import type { StoryFn, Meta } from '@storybook/react-webpack5';
55
import { HelmetProvider } from 'react-helmet-async';
66

77
import { ConfigProvider } from '../core/configProvider/ConfigProvider';

0 commit comments

Comments
 (0)