Skip to content
This repository was archived by the owner on Jan 31, 2024. It is now read-only.

Commit b0d25ad

Browse files
authored
Merge pull request #120 from storybookjs/default-decorate-story
Support Storybook 7.0
2 parents 3774b12 + dce8fc8 commit b0d25ad

16 files changed

+10529
-16679
lines changed

.vscode/settings.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,6 @@
77
"prettier.printWidth": 100,
88
"editor.formatOnSave": true,
99
"editor.tabSize": 2,
10-
"deepscan.enable": true
10+
"deepscan.enable": true,
11+
"typescript.tsdk": "node_modules/typescript/lib"
1112
}

CONTRIBUTING.md

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
## Branch structure
2+
3+
- **next** - the `next` version on npm, and the development branch where most work occurs
4+
- **prerelease** - the `prerelease` version on npm, where eventual changes to `main` get tested
5+
- **main** - the `latest` version on npm and the stable version that most users use
6+
7+
## Release process
8+
9+
1. All PRs should target the `next` branch, which depends on the `next` version of Storybook.
10+
2. When merged, a new version of this package will be released on the `next` NPM tag.
11+
3. If the change contains a bugfix that needs to be patched back to the stable version, please note that in PR description.
12+
4. PRs labeled `pick` will get cherry-picked back to the `prerelease` branch and will generate a release on the `prerelease` npm tag.
13+
5. Once validated, `prerelease` PRs will get merged back to the `main` branch, which will generate a release on the `latest` npm tag.

README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,10 @@ If you have global decorators/parameters/etc and want them applied to your stori
5959

6060
```tsx
6161
// setupFile.js <-- this will run before the tests in jest.
62-
import { setGlobalConfig } from '@storybook/testing-react';
62+
import { setProjectAnnotations } from '@storybook/testing-react';
6363
import * as globalStorybookConfig from './.storybook/preview'; // path of your preview.js file
6464

65-
setGlobalConfig(globalStorybookConfig);
65+
setProjectAnnotations(globalStorybookConfig);
6666
```
6767

6868
For the setup file to be picked up, you need to pass it as an option to jest in your test command:

example/.storybook/main.ts

+14-3
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,22 @@
1-
import type { StorybookConfig } from '@storybook/react/types';
1+
import type { StorybookConfig } from '@storybook/react-webpack5';
22

33
const config: StorybookConfig = {
44
stories: ['../src/**/*.stories.tsx'],
55
logLevel: 'debug',
6-
addons: ['@storybook/preset-create-react-app', '@storybook/addon-essentials'],
6+
addons: [
7+
'@storybook/preset-create-react-app',
8+
'@storybook/addon-essentials',
9+
'@storybook/addon-interactions',
10+
],
11+
docs: {
12+
docsPage: 'automatic',
13+
},
14+
framework: {
15+
name: '@storybook/react-webpack5',
16+
options: {},
17+
},
718
features: {
8-
previewCsfV3: true,
19+
interactionsDebugger: true,
920
},
1021
};
1122

example/.storybook/preview.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import React from 'react';
2-
import type { DecoratorFn } from '@storybook/react';
2+
import type { Decorator } from '@storybook/react';
33
import { ThemeProvider, convert, themes } from '@storybook/theming';
44

55
export const parameters = {
66
actions: { argTypesRegex: '^on[A-Z].*' }
77
}
88

9-
export const decorators: DecoratorFn[] = [
9+
export const decorators: Decorator[] = [
1010
(StoryFn, { globals: { locale } }) => (
1111
<>
1212
<div>Locale: {locale}</div>

example/package.json

+22-17
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
44
"private": true,
55
"scripts": {
66
"build": "react-scripts build",
7-
"build-storybook": "build-storybook -s public",
7+
"build-storybook": "storybook build -s public",
88
"eject": "react-scripts eject",
99
"start": "react-scripts start",
10-
"storybook": "start-storybook -p 9009 -s public",
10+
"storybook": "storybook dev -p 9009 -s public",
1111
"test": "SKIP_PREFLIGHT_CHECK=true react-scripts test --setupFiles ./setup.ts"
1212
},
1313
"browserslist": {
@@ -23,24 +23,29 @@
2323
]
2424
},
2525
"dependencies": {
26-
"@types/jest": "25.2.3",
26+
"@types/jest": "^27.0.0",
2727
"@types/node": "14.14.20",
28-
"@types/react": "^16.14.2",
29-
"@types/react-dom": "16.9.10",
28+
"@types/react": "^17.0.2",
29+
"@types/react-dom": "^17.0.2",
3030
"formik": "^2.2.9",
3131
"global": "^4.4.0",
32-
"react": "16.14.0",
33-
"react-dom": "16.14.0",
34-
"react-scripts": "3.4.4",
35-
"typescript": "^3.9.7"
32+
"react": "^17.0.2",
33+
"react-dom": "^17.0.2",
34+
"react-scripts": "5.0.1",
35+
"typescript": "^4.9.3"
3636
},
3737
"devDependencies": {
38-
"@storybook/addon-essentials": "^6.4.0-rc.2",
39-
"@storybook/react": "^6.4.0-rc.2",
40-
"@storybook/components": "^6.4.0-rc.2",
41-
"@storybook/theming": "^6.4.0-rc.2",
42-
"@storybook/preset-create-react-app": "^3.1.5",
43-
"@testing-library/react": "^11.2.5",
44-
"@testing-library/user-event": "^13.1.9"
38+
"@storybook/addon-essentials": "7.0.0-alpha.62",
39+
"@storybook/addon-interactions": "7.0.0-alpha.62",
40+
"@storybook/components": "7.0.0-alpha.62",
41+
"@storybook/preset-create-react-app": "^4.1.2",
42+
"@storybook/react": "7.0.0-alpha.62",
43+
"@storybook/react-webpack5": "7.0.0-alpha.62",
44+
"@storybook/testing-library": "^0.0.14-next.0",
45+
"@storybook/theming": "7.0.0-alpha.62",
46+
"@testing-library/react": "^12.0.0",
47+
"@testing-library/user-event": "^13.1.9",
48+
"storybook": "7.0.0-alpha.62",
49+
"type-fest": "^3.3.0"
4550
}
46-
}
51+
}

example/setup.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { setGlobalConfig } from '../dist/index';
1+
import { setProjectAnnotations } from '../dist/index';
22
import * as globalStorybookConfig from './.storybook/preview';
33

4-
setGlobalConfig(globalStorybookConfig);
4+
setProjectAnnotations(globalStorybookConfig);

example/src/components/AccountForm.stories.tsx

+37-22
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
import React from 'react';
2-
import type { ComponentMeta, ComponentStoryObj } from '@storybook/react';
3-
import { screen } from '@testing-library/dom';
4-
import userEvent from '@testing-library/user-event';
2+
import type { Meta, StoryObj } from '@storybook/react';
3+
import { within, userEvent} from '@storybook/testing-library';
54

65
import { AccountForm, AccountFormProps } from './AccountForm';
76

8-
export default {
7+
const meta = {
98
title: 'CSF3/AccountForm',
109
component: AccountForm,
1110
parameters: {
@@ -15,43 +14,53 @@ export default {
1514
<p>This uses a custom render from meta</p>
1615
<AccountForm {...args} />
1716
</div>)
18-
} as ComponentMeta<typeof AccountForm>;
17+
} as Meta<typeof AccountForm>;
1918

20-
type Story = ComponentStoryObj<typeof AccountForm>
19+
export default meta;
20+
21+
type Story = StoryObj<typeof meta>;
2122

2223
export const Standard: Story = {
2324
args: { passwordVerification: false },
2425
};
2526

2627
export const StandardEmailFilled: Story = {
2728
...Standard,
28-
play: () => userEvent.type(screen.getByTestId('email'), '[email protected]'),
29+
play: async ({canvasElement}) => {
30+
const canvas = within(canvasElement);
31+
await userEvent.type(canvas.getByTestId('email'), '[email protected]');
32+
}
2933
};
3034

3135
export const StandardEmailFailed: Story = {
3236
...Standard,
33-
play: async () => {
34-
await userEvent.type(screen.getByTestId('email'), '[email protected]@com');
35-
await userEvent.type(screen.getByTestId('password1'), 'testpasswordthatwontfail');
36-
await userEvent.click(screen.getByTestId('submit'));
37+
play: async ({canvasElement}) => {
38+
const canvas = within(canvasElement);
39+
await userEvent.type(canvas.getByTestId('email'), '[email protected]@com');
40+
await userEvent.type(canvas.getByTestId('password1'), 'testpasswordthatwontfail');
41+
await userEvent.click(canvas.getByTestId('submit'));
3742
},
3843
};
3944

4045
export const StandardPasswordFailed: Story = {
4146
...Standard,
4247
play: async (context) => {
48+
const {canvasElement} = context;
49+
const canvas = within(canvasElement);
4350
await StandardEmailFilled.play!(context);
44-
await userEvent.type(screen.getByTestId('password1'), 'asdf');
45-
await userEvent.click(screen.getByTestId('submit'));
51+
await userEvent.type(canvas.getByTestId('password1'), 'asdf');
52+
await userEvent.click(canvas.getByTestId('submit'));
4653
},
4754
};
4855

4956
export const StandardFailHover: Story = {
5057
...StandardPasswordFailed,
5158
play: async (context) => {
59+
const {canvasElement} = context;
60+
const canvas = within(canvasElement);
5261
await StandardPasswordFailed.play!(context);
5362
await sleep(100);
54-
await userEvent.hover(screen.getByTestId('password-error-info'));
63+
await userEvent.hover(canvas.getByTestId('password-error-info'));
5564
},
5665
};
5766

@@ -62,19 +71,23 @@ export const Verification: Story = {
6271
export const VerificationPasssword1: Story = {
6372
...Verification,
6473
play: async (context) => {
74+
const {canvasElement} = context;
75+
const canvas = within(canvasElement);
6576
await StandardEmailFilled.play!(context);
66-
await userEvent.type(screen.getByTestId('password1'), 'asdfasdf');
67-
await userEvent.click(screen.getByTestId('submit'));
77+
await userEvent.type(canvas.getByTestId('password1'), 'asdfasdf');
78+
await userEvent.click(canvas.getByTestId('submit'));
6879
},
6980
};
7081

7182
export const VerificationPasswordMismatch: Story = {
7283
...Verification,
7384
play: async (context) => {
85+
const {canvasElement} = context;
86+
const canvas = within(canvasElement);
7487
await StandardEmailFilled.play!(context);
75-
await userEvent.type(screen.getByTestId('password1'), 'asdfasdf');
76-
await userEvent.type(screen.getByTestId('password2'), 'asdf1234');
77-
await userEvent.click(screen.getByTestId('submit'));
88+
await userEvent.type(canvas.getByTestId('password1'), 'asdfasdf');
89+
await userEvent.type(canvas.getByTestId('password2'), 'asdf1234');
90+
await userEvent.click(canvas.getByTestId('submit'));
7891
},
7992
};
8093

@@ -83,13 +96,15 @@ const sleep = (ms: number) => new Promise((r) => setTimeout(r, ms));
8396
export const VerificationSuccess: Story = {
8497
...Verification,
8598
play: async (context) => {
99+
const {canvasElement} = context;
100+
const canvas = within(canvasElement);
86101
await StandardEmailFilled.play!(context);
87102
await sleep(1000);
88-
await userEvent.type(screen.getByTestId('password1'), 'asdfasdf', { delay: 50 });
103+
await userEvent.type(canvas.getByTestId('password1'), 'asdfasdf', { delay: 50 });
89104
await sleep(1000);
90-
await userEvent.type(screen.getByTestId('password2'), 'asdfasdf', { delay: 50 });
105+
await userEvent.type(canvas.getByTestId('password2'), 'asdfasdf', { delay: 50 });
91106
await sleep(1000);
92-
await userEvent.click(screen.getByTestId('submit'));
107+
await userEvent.click(canvas.getByTestId('submit'));
93108
},
94109
};
95110

example/src/components/Button.stories.tsx

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
import React from 'react';
2-
import { StoryFn as CSF2Story, StoryObj as CSF3Story, Meta, ComponentStoryObj } from '@storybook/react';
2+
import { StoryFn as CSF2Story, StoryObj as CSF3Story, Meta } from '@storybook/react';
33
import { useArgs } from '@storybook/addons';
4-
import { screen } from '@testing-library/react';
5-
import userEvent from '@testing-library/user-event';
4+
import { within, userEvent} from '@storybook/testing-library';
65

76
import { Button, ButtonProps } from './Button';
87

@@ -81,8 +80,9 @@ export const InputFieldFilled: CSF3Story = {
8180
render: () => {
8281
return <input />;
8382
},
84-
play: async (context) => {
85-
await userEvent.type(screen.getByRole('textbox'), 'Hello world!');
83+
play: async ({canvasElement}) => {
84+
const canvas = within(canvasElement);
85+
await userEvent.type(canvas.getByRole('textbox'), 'Hello world!');
8686
},
8787
};
8888

example/tsconfig.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,6 @@
3030
"noEmit": true
3131
},
3232
"include": [
33-
"src"
33+
"src", "../../dist"
3434
]
3535
}

0 commit comments

Comments
 (0)