@storybook/codemod 7.0.0-beta.9 → 7.0.0-rc.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +0 -39
- package/dist/index.js +1 -1
- package/dist/transforms/csf-2-to-3.d.ts +5 -4
- package/dist/transforms/csf-2-to-3.js +3 -1
- package/dist/transforms/mdx-to-csf.d.ts +7 -0
- package/dist/transforms/mdx-to-csf.js +55 -0
- package/dist/transforms/storiesof-to-csf.js +1 -1
- package/dist/transforms/upgrade-deprecated-types.d.ts +10 -0
- package/dist/transforms/upgrade-deprecated-types.js +2 -0
- package/jest.config.js +2 -0
- package/package.json +31 -16
- package/project.json +6 -0
- package/src/index.js +30 -4
- package/src/lib/utils.ts +2 -2
- package/src/transforms/__testfixtures__/storiesof-to-csf/decorators.input.js +1 -1
- package/src/transforms/__testfixtures__/storiesof-to-csf/export-function.input.js +1 -1
- package/src/transforms/__testfixtures__/storiesof-to-csf/story-decorators.input.js +1 -1
- package/src/transforms/__testfixtures__/update-addon-info/update-addon-info.input.js +34 -48
- package/src/transforms/__testfixtures__/update-addon-info/update-addon-info.output.snapshot +33 -47
- package/src/transforms/__tests__/csf-2-to-3.test.ts +170 -57
- package/src/transforms/__tests__/mdx-to-csf.test.ts +611 -0
- package/src/transforms/__tests__/upgrade-deprecated-types.test.ts +170 -0
- package/src/transforms/csf-2-to-3.ts +173 -37
- package/src/transforms/mdx-to-csf.ts +342 -0
- package/src/transforms/upgrade-deprecated-types.ts +142 -0
- package/dist/chunk-3OPQTROG.mjs +0 -1
- package/dist/chunk-B5FMQ3BX.mjs +0 -1
- package/dist/chunk-CO6EPEMB.mjs +0 -1
- package/dist/index.mjs +0 -1
- package/dist/transforms/add-component-parameters.mjs +0 -1
- package/dist/transforms/csf-2-to-3.mjs +0 -1
- package/dist/transforms/csf-hoist-story-annotations.mjs +0 -1
- package/dist/transforms/csf-to-mdx.d.ts +0 -29
- package/dist/transforms/csf-to-mdx.js +0 -3
- package/dist/transforms/csf-to-mdx.mjs +0 -3
- package/dist/transforms/move-builtin-addons.mjs +0 -1
- package/dist/transforms/storiesof-to-csf.mjs +0 -1
- package/dist/transforms/update-addon-info.mjs +0 -1
- package/dist/transforms/update-organisation-name.mjs +0 -1
- package/dist/transforms/upgrade-hierarchy-separators.mjs +0 -1
- package/src/transforms/__testfixtures__/csf-to-mdx/basic.input.js +0 -20
- package/src/transforms/__testfixtures__/csf-to-mdx/basic.output.snapshot +0 -18
- package/src/transforms/__testfixtures__/csf-to-mdx/component-id.input.js +0 -9
- package/src/transforms/__testfixtures__/csf-to-mdx/component-id.output.snapshot +0 -10
- package/src/transforms/__testfixtures__/csf-to-mdx/decorators.input.js +0 -13
- package/src/transforms/__testfixtures__/csf-to-mdx/decorators.output.snapshot +0 -12
- package/src/transforms/__testfixtures__/csf-to-mdx/exclude-stories.input.js +0 -23
- package/src/transforms/__testfixtures__/csf-to-mdx/exclude-stories.output.snapshot +0 -22
- package/src/transforms/__testfixtures__/csf-to-mdx/parameters.input.js +0 -16
- package/src/transforms/__testfixtures__/csf-to-mdx/parameters.output.snapshot +0 -17
- package/src/transforms/__testfixtures__/csf-to-mdx/story-function.input.js +0 -19
- package/src/transforms/__testfixtures__/csf-to-mdx/story-function.output.snapshot +0 -18
- package/src/transforms/__testfixtures__/csf-to-mdx/story-parameters.input.js +0 -24
- package/src/transforms/__testfixtures__/csf-to-mdx/story-parameters.output.snapshot +0 -22
- package/src/transforms/csf-to-mdx.js +0 -190
@@ -2,27 +2,23 @@
|
|
2
2
|
|
3
3
|
exports[`update-addon-info transforms correctly using "update-addon-info.input.js" data 1`] = `
|
4
4
|
"/* eslint-disable */
|
5
|
-
import React from 'react'
|
6
|
-
import Button from './Button'
|
5
|
+
import React from 'react';
|
6
|
+
import Button from './Button';
|
7
7
|
|
8
|
-
import { storiesOf } from '@storybook/react'
|
9
|
-
import { action } from '@storybook/addon-actions'
|
8
|
+
import { storiesOf } from '@storybook/react';
|
9
|
+
import { action } from '@storybook/addon-actions';
|
10
10
|
|
11
11
|
import { withInfo } from \\"@storybook/addon-info\\";
|
12
12
|
|
13
|
-
storiesOf(
|
14
|
-
'Button'
|
15
|
-
).add('simple usage', withInfo(
|
13
|
+
storiesOf('Button').add('simple usage', withInfo(
|
16
14
|
'This is the basic usage with the button with providing a label to show the text.'
|
17
15
|
)(() => (
|
18
16
|
<div>
|
19
17
|
<Button label=\\"The Button\\" onClick={action('onClick')} />
|
20
18
|
<br />
|
21
|
-
<p>
|
22
|
-
Click the \\"?\\" mark at top-right to view the info.
|
23
|
-
</p>
|
19
|
+
<p>Click the \\"?\\" mark at top-right to view the info.</p>
|
24
20
|
</div>
|
25
|
-
)))
|
21
|
+
)));
|
26
22
|
|
27
23
|
storiesOf('Button').add('simple usage (inline info)', withInfo({
|
28
24
|
text: \`
|
@@ -30,7 +26,7 @@ storiesOf('Button').add('simple usage (inline info)', withInfo({
|
|
30
26
|
\`,
|
31
27
|
|
32
28
|
inline: true
|
33
|
-
})(() => <Button label=\\"The Button\\" onClick={action('onClick')} />))
|
29
|
+
})(() => <Button label=\\"The Button\\" onClick={action('onClick')} />));
|
34
30
|
|
35
31
|
storiesOf('Button').add('simple usage (disable source)', withInfo({
|
36
32
|
text: \`
|
@@ -39,7 +35,7 @@ storiesOf('Button').add('simple usage (disable source)', withInfo({
|
|
39
35
|
|
40
36
|
source: false,
|
41
37
|
inline: true
|
42
|
-
})(() => <Button label=\\"The Button\\" onClick={action('onClick')} />))
|
38
|
+
})(() => <Button label=\\"The Button\\" onClick={action('onClick')} />));
|
43
39
|
|
44
40
|
storiesOf('Button').add('simple usage (no header)', withInfo({
|
45
41
|
text: \`
|
@@ -48,7 +44,7 @@ storiesOf('Button').add('simple usage (no header)', withInfo({
|
|
48
44
|
|
49
45
|
header: false,
|
50
46
|
inline: true
|
51
|
-
})(() => <Button label=\\"The Button\\" onClick={action('onClick')} />))
|
47
|
+
})(() => <Button label=\\"The Button\\" onClick={action('onClick')} />));
|
52
48
|
|
53
49
|
storiesOf('Button').add('simple usage (no prop tables)', withInfo({
|
54
50
|
text: \`
|
@@ -57,7 +53,7 @@ storiesOf('Button').add('simple usage (no prop tables)', withInfo({
|
|
57
53
|
|
58
54
|
propTables: false,
|
59
55
|
inline: true
|
60
|
-
})(() => <Button label=\\"The Button\\" onClick={action('onClick')} />))
|
56
|
+
})(() => <Button label=\\"The Button\\" onClick={action('onClick')} />));
|
61
57
|
|
62
58
|
storiesOf('Button').add('simple usage (custom propTables)', withInfo({
|
63
59
|
text: \`
|
@@ -82,20 +78,17 @@ storiesOf('Button').add('simple usage (custom propTables)', withInfo({
|
|
82
78
|
<Button label=\\"The Button\\" onClick={action('onClick')} />
|
83
79
|
<br />
|
84
80
|
</div>
|
85
|
-
)))
|
81
|
+
)));
|
86
82
|
|
87
83
|
storiesOf('Button').add('simple usage (JSX description)', withInfo(<div>
|
88
84
|
<h2>This is a JSX info section</h2>
|
89
85
|
<p>
|
90
|
-
Lorem ipsum dolor sit amet, consectetur adipiscing elit.
|
91
|
-
|
92
|
-
|
93
|
-
nulla.
|
86
|
+
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed ornare massa rutrum metus
|
87
|
+
commodo, a mattis velit dignissim. Fusce vestibulum turpis sed massa egestas pharetra. Sed at
|
88
|
+
libero nulla.
|
94
89
|
</p>
|
95
90
|
<p>
|
96
|
-
<a href=\\"https://github.com/storybookjs/react-storybook-addon-info\\">
|
97
|
-
This is a link
|
98
|
-
</a>
|
91
|
+
<a href=\\"https://github.com/storybookjs/react-storybook-addon-info\\">This is a link</a>
|
99
92
|
</p>
|
100
93
|
<p>
|
101
94
|
<img src=\\"https://storybook.js.org/images/placeholders/350x150.png\\" />
|
@@ -104,25 +97,20 @@ storiesOf('Button').add('simple usage (JSX description)', withInfo(<div>
|
|
104
97
|
<div>
|
105
98
|
<Button label=\\"The Button\\" onClick={action('onClick')} />
|
106
99
|
<br />
|
107
|
-
<p>
|
108
|
-
Click the \\"?\\" mark at top-right to view the info.
|
109
|
-
</p>
|
100
|
+
<p>Click the \\"?\\" mark at top-right to view the info.</p>
|
110
101
|
</div>
|
111
|
-
)))
|
102
|
+
)));
|
112
103
|
|
113
104
|
storiesOf('Button').add('simple usage (inline JSX description)', withInfo({
|
114
105
|
text: <div>
|
115
106
|
<h2>This is a JSX info section</h2>
|
116
107
|
<p>
|
117
|
-
Lorem ipsum dolor sit amet, consectetur adipiscing elit.
|
118
|
-
|
119
|
-
|
120
|
-
nulla.
|
108
|
+
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed ornare massa rutrum metus
|
109
|
+
commodo, a mattis velit dignissim. Fusce vestibulum turpis sed massa egestas pharetra. Sed at
|
110
|
+
libero nulla.
|
121
111
|
</p>
|
122
112
|
<p>
|
123
|
-
<a href=\\"https://github.com/storybookjs/react-storybook-addon-info\\">
|
124
|
-
This is a link
|
125
|
-
</a>
|
113
|
+
<a href=\\"https://github.com/storybookjs/react-storybook-addon-info\\">This is a link</a>
|
126
114
|
</p>
|
127
115
|
<p>
|
128
116
|
<img src=\\"https://storybook.js.org/images/placeholders/350x150.png\\" />
|
@@ -130,7 +118,7 @@ storiesOf('Button').add('simple usage (inline JSX description)', withInfo({
|
|
130
118
|
</div>,
|
131
119
|
|
132
120
|
inline: true
|
133
|
-
})(() => <Button label=\\"The Button\\" onClick={action('onClick')} />))
|
121
|
+
})(() => <Button label=\\"The Button\\" onClick={action('onClick')} />));
|
134
122
|
|
135
123
|
storiesOf('Button').add('simple usage (maxPropsInLine === 1)', withInfo({
|
136
124
|
text: \`
|
@@ -139,7 +127,7 @@ storiesOf('Button').add('simple usage (maxPropsInLine === 1)', withInfo({
|
|
139
127
|
|
140
128
|
inline: true,
|
141
129
|
maxPropsIntoLine: 1
|
142
|
-
})(() => <Button label=\\"The Button\\" onClick={action('onClick')} />))
|
130
|
+
})(() => <Button label=\\"The Button\\" onClick={action('onClick')} />));
|
143
131
|
|
144
132
|
storiesOf('Button').add('simple usage (maxPropObjectKeys === 5)', withInfo({
|
145
133
|
text: \`
|
@@ -150,7 +138,7 @@ storiesOf('Button').add('simple usage (maxPropObjectKeys === 5)', withInfo({
|
|
150
138
|
maxPropObjectKeys: 5
|
151
139
|
})(
|
152
140
|
() => <Button label=\\"The Button\\" object={{ a: 1, b: 2, c: 3, d: 4, e: 5, f: 6 }} />
|
153
|
-
))
|
141
|
+
));
|
154
142
|
|
155
143
|
storiesOf('Button').add('simple usage (maxPropArrayLength === 8)', withInfo({
|
156
144
|
text: \`
|
@@ -161,7 +149,7 @@ storiesOf('Button').add('simple usage (maxPropArrayLength === 8)', withInfo({
|
|
161
149
|
maxPropArrayLength: 8
|
162
150
|
})(
|
163
151
|
() => <Button label=\\"The Button\\" array={[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]} />
|
164
|
-
))
|
152
|
+
));
|
165
153
|
|
166
154
|
storiesOf('Button').add('simple usage (maxPropStringLength === 10)', withInfo({
|
167
155
|
text: \`
|
@@ -170,7 +158,7 @@ storiesOf('Button').add('simple usage (maxPropStringLength === 10)', withInfo({
|
|
170
158
|
|
171
159
|
inline: true,
|
172
160
|
maxPropStringLength: 5
|
173
|
-
})(() => <Button label=\\"The Button\\" string=\\"1 2 3 4 5 6 7 8\\" />))
|
161
|
+
})(() => <Button label=\\"The Button\\" string=\\"1 2 3 4 5 6 7 8\\" />));
|
174
162
|
|
175
163
|
storiesOf('Button').add('with custom styles', withInfo({
|
176
164
|
text: \`
|
@@ -180,19 +168,17 @@ storiesOf('Button').add('with custom styles', withInfo({
|
|
180
168
|
|
181
169
|
inline: true,
|
182
170
|
|
183
|
-
styles: stylesheet => {
|
171
|
+
styles: (stylesheet) => {
|
184
172
|
stylesheet.infoPage = {
|
185
|
-
backgroundColor: '#ccc'
|
186
|
-
}
|
187
|
-
return stylesheet
|
173
|
+
backgroundColor: '#ccc',
|
174
|
+
};
|
175
|
+
return stylesheet;
|
188
176
|
}
|
189
|
-
})(() => <Button label=\\"The Button\\" onClick={action('onClick')} />))
|
177
|
+
})(() => <Button label=\\"The Button\\" onClick={action('onClick')} />));
|
190
178
|
|
191
179
|
storiesOf('shared/ProgressBar', module)
|
192
180
|
.addDecorator(withKnobs)
|
193
181
|
.add('default style', withInfo('default style')(() => (
|
194
|
-
<ProgressBar progress={number('progress', 25)}
|
195
|
-
delay={number('delay', 500)}
|
196
|
-
/>
|
182
|
+
<ProgressBar progress={number('progress', 25)} delay={number('delay', 500)} />
|
197
183
|
)));"
|
198
184
|
`;
|
@@ -1,5 +1,7 @@
|
|
1
1
|
import { describe, it, expect } from '@jest/globals';
|
2
2
|
import { dedent } from 'ts-dedent';
|
3
|
+
import type { API } from 'jscodeshift';
|
4
|
+
import ansiRegex from 'ansi-regex';
|
3
5
|
import _transform from '../csf-2-to-3';
|
4
6
|
|
5
7
|
expect.addSnapshotSerializer({
|
@@ -7,8 +9,10 @@ expect.addSnapshotSerializer({
|
|
7
9
|
test: () => true,
|
8
10
|
});
|
9
11
|
|
10
|
-
const jsTransform = (source: string) =>
|
11
|
-
|
12
|
+
const jsTransform = (source: string) =>
|
13
|
+
_transform({ source, path: 'Component.stories.js' }, {} as API, {}).trim();
|
14
|
+
const tsTransform = (source: string) =>
|
15
|
+
_transform({ source, path: 'Component.stories.ts' }, {} as API, { parser: 'tsx' }).trim();
|
12
16
|
|
13
17
|
describe('csf-2-to-3', () => {
|
14
18
|
describe('javascript', () => {
|
@@ -20,9 +24,7 @@ describe('csf-2-to-3', () => {
|
|
20
24
|
export const B = (args) => <Button {...args} />;
|
21
25
|
`)
|
22
26
|
).toMatchInlineSnapshot(`
|
23
|
-
export default {
|
24
|
-
title: 'Cat',
|
25
|
-
};
|
27
|
+
export default { title: 'Cat' };
|
26
28
|
export const A = () => <Cat />;
|
27
29
|
export const B = {
|
28
30
|
render: (args) => <Button {...args} />,
|
@@ -34,21 +36,19 @@ describe('csf-2-to-3', () => {
|
|
34
36
|
expect(
|
35
37
|
jsTransform(dedent`
|
36
38
|
export default { title: 'Cat' };
|
39
|
+
|
37
40
|
export const A = () => <Cat />;
|
38
41
|
A.storyName = 'foo';
|
39
42
|
A.parameters = { bar: 2 };
|
40
43
|
A.play = () => {};
|
41
44
|
`)
|
42
45
|
).toMatchInlineSnapshot(`
|
43
|
-
export default {
|
44
|
-
|
45
|
-
};
|
46
|
+
export default { title: 'Cat' };
|
47
|
+
|
46
48
|
export const A = {
|
47
49
|
render: () => <Cat />,
|
48
50
|
name: 'foo',
|
49
|
-
parameters: {
|
50
|
-
bar: 2,
|
51
|
-
},
|
51
|
+
parameters: { bar: 2 },
|
52
52
|
play: () => {},
|
53
53
|
};
|
54
54
|
`);
|
@@ -58,19 +58,22 @@ describe('csf-2-to-3', () => {
|
|
58
58
|
expect(
|
59
59
|
jsTransform(dedent`
|
60
60
|
export default { title: 'components/Fruit', includeStories: ['A'] };
|
61
|
+
|
61
62
|
export const A = (args) => <Apple {...args} />;
|
63
|
+
|
62
64
|
export const B = (args) => <Banana {...args} />;
|
65
|
+
|
63
66
|
const C = (args) => <Cherry {...args} />;
|
64
67
|
`)
|
65
68
|
).toMatchInlineSnapshot(`
|
66
|
-
export default {
|
67
|
-
|
68
|
-
includeStories: ['A'],
|
69
|
-
};
|
69
|
+
export default { title: 'components/Fruit', includeStories: ['A'] };
|
70
|
+
|
70
71
|
export const A = {
|
71
72
|
render: (args) => <Apple {...args} />,
|
72
73
|
};
|
74
|
+
|
73
75
|
export const B = (args) => <Banana {...args} />;
|
76
|
+
|
74
77
|
const C = (args) => <Cherry {...args} />;
|
75
78
|
`);
|
76
79
|
});
|
@@ -79,10 +82,12 @@ describe('csf-2-to-3', () => {
|
|
79
82
|
expect(
|
80
83
|
jsTransform(dedent`
|
81
84
|
export const A = () => <Apple />;
|
85
|
+
|
82
86
|
export const B = (args) => <Banana {...args} />;
|
83
87
|
`)
|
84
88
|
).toMatchInlineSnapshot(`
|
85
89
|
export const A = () => <Apple />;
|
90
|
+
|
86
91
|
export const B = (args) => <Banana {...args} />;
|
87
92
|
`);
|
88
93
|
});
|
@@ -95,10 +100,7 @@ describe('csf-2-to-3', () => {
|
|
95
100
|
export const B = (args) => <Banana {...args} />;
|
96
101
|
`)
|
97
102
|
).toMatchInlineSnapshot(`
|
98
|
-
export default {
|
99
|
-
title: 'Cat',
|
100
|
-
component: Cat,
|
101
|
-
};
|
103
|
+
export default { title: 'Cat', component: Cat };
|
102
104
|
export const A = {};
|
103
105
|
export const B = {
|
104
106
|
render: (args) => <Banana {...args} />,
|
@@ -110,15 +112,14 @@ describe('csf-2-to-3', () => {
|
|
110
112
|
expect(
|
111
113
|
jsTransform(dedent`
|
112
114
|
export default { title: 'Cat', component: Cat };
|
115
|
+
|
113
116
|
export const A = {
|
114
117
|
render: (args) => <Cat {...args} />
|
115
118
|
};
|
116
119
|
`)
|
117
120
|
).toMatchInlineSnapshot(`
|
118
|
-
export default {
|
119
|
-
|
120
|
-
component: Cat,
|
121
|
-
};
|
121
|
+
export default { title: 'Cat', component: Cat };
|
122
|
+
|
122
123
|
export const A = {
|
123
124
|
render: (args) => <Cat {...args} />,
|
124
125
|
};
|
@@ -134,14 +135,11 @@ describe('csf-2-to-3', () => {
|
|
134
135
|
A.args = { isPrimary: false };
|
135
136
|
`)
|
136
137
|
).toMatchInlineSnapshot(`
|
137
|
-
export default {
|
138
|
-
|
139
|
-
};
|
138
|
+
export default { title: 'Cat' };
|
139
|
+
|
140
140
|
export const A = {
|
141
141
|
render: (args) => <Cat {...args} />,
|
142
|
-
args: {
|
143
|
-
isPrimary: false,
|
144
|
-
},
|
142
|
+
args: { isPrimary: false },
|
145
143
|
};
|
146
144
|
`);
|
147
145
|
});
|
@@ -150,28 +148,27 @@ describe('csf-2-to-3', () => {
|
|
150
148
|
expect(
|
151
149
|
jsTransform(dedent`
|
152
150
|
export default { title: 'Cat', component: Cat };
|
151
|
+
|
153
152
|
const Template = (args) => <Cat {...args} />;
|
153
|
+
|
154
154
|
export const A = Template.bind({});
|
155
155
|
A.args = { isPrimary: false };
|
156
|
+
|
156
157
|
const Template2 = (args) => <Banana {...args} />;
|
158
|
+
|
157
159
|
export const B = Template2.bind({});
|
158
160
|
B.args = { isPrimary: true };
|
159
161
|
`)
|
160
162
|
).toMatchInlineSnapshot(`
|
161
|
-
export default {
|
162
|
-
|
163
|
-
component: Cat,
|
164
|
-
};
|
163
|
+
export default { title: 'Cat', component: Cat };
|
164
|
+
|
165
165
|
export const A = {
|
166
|
-
args: {
|
167
|
-
isPrimary: false,
|
168
|
-
},
|
166
|
+
args: { isPrimary: false },
|
169
167
|
};
|
168
|
+
|
170
169
|
export const B = {
|
171
170
|
render: (args) => <Banana {...args} />,
|
172
|
-
args: {
|
173
|
-
isPrimary: true,
|
174
|
-
},
|
171
|
+
args: { isPrimary: true },
|
175
172
|
};
|
176
173
|
`);
|
177
174
|
});
|
@@ -180,23 +177,21 @@ describe('csf-2-to-3', () => {
|
|
180
177
|
expect(
|
181
178
|
jsTransform(dedent`
|
182
179
|
export default { title: 'Cat', component: Cat };
|
180
|
+
|
183
181
|
export const A = (args) => <Cat {...args} />;
|
184
182
|
export const B = () => <Cat name="frisky" />;
|
185
183
|
export const C = () => <Cat name="fluffy" />;
|
186
184
|
C.parameters = { foo: 2 };
|
187
185
|
`)
|
188
186
|
).toMatchInlineSnapshot(`
|
189
|
-
export default {
|
190
|
-
|
191
|
-
component: Cat,
|
192
|
-
};
|
187
|
+
export default { title: 'Cat', component: Cat };
|
188
|
+
|
193
189
|
export const A = {};
|
194
190
|
export const B = () => <Cat name="frisky" />;
|
191
|
+
|
195
192
|
export const C = {
|
196
193
|
render: () => <Cat name="fluffy" />,
|
197
|
-
parameters: {
|
198
|
-
foo: 2,
|
199
|
-
},
|
194
|
+
parameters: { foo: 2 },
|
200
195
|
};
|
201
196
|
`);
|
202
197
|
});
|
@@ -211,39 +206,157 @@ describe('csf-2-to-3', () => {
|
|
211
206
|
};
|
212
207
|
`)
|
213
208
|
).toMatchInlineSnapshot(`
|
214
|
-
export default {
|
215
|
-
|
216
|
-
};
|
209
|
+
export default { title: 'Cat' };
|
210
|
+
|
217
211
|
export const A = {
|
218
212
|
render: (args) => <Cat {...args} />,
|
219
|
-
parameters: {
|
220
|
-
foo: 2,
|
221
|
-
},
|
213
|
+
parameters: { foo: 2 },
|
222
214
|
};
|
223
215
|
`);
|
224
216
|
});
|
225
217
|
});
|
226
218
|
|
227
219
|
describe('typescript', () => {
|
228
|
-
it('should
|
220
|
+
it('should error with namespace imports', () => {
|
221
|
+
expect.addSnapshotSerializer({
|
222
|
+
serialize: (value) => value.replace(ansiRegex(), ''),
|
223
|
+
test: () => true,
|
224
|
+
});
|
225
|
+
expect(() =>
|
226
|
+
tsTransform(dedent`
|
227
|
+
import * as SB from '@storybook/react';
|
228
|
+
import { CatProps } from './Cat';
|
229
|
+
|
230
|
+
const meta = { title: 'Cat', component: Cat } as Meta<CatProps>
|
231
|
+
export default meta;
|
232
|
+
|
233
|
+
export const A: SB.StoryFn<CatProps> = () => <Cat />;
|
234
|
+
`)
|
235
|
+
).toThrowErrorMatchingInlineSnapshot(`
|
236
|
+
This codemod does not support namespace imports for a @storybook/react package.
|
237
|
+
Replace the namespace import with named imports and try again.
|
238
|
+
`);
|
239
|
+
});
|
240
|
+
it('should keep local names', () => {
|
241
|
+
expect(
|
242
|
+
tsTransform(dedent`
|
243
|
+
import { Meta, StoryObj as CSF3, StoryFn as CSF2 } from '@storybook/react';
|
244
|
+
import { CatProps } from './Cat';
|
245
|
+
|
246
|
+
const meta = { title: 'Cat', component: Cat } satisfies Meta<CatProps>
|
247
|
+
export default meta;
|
248
|
+
|
249
|
+
export const A: CSF2<CatProps> = () => <Cat />;
|
250
|
+
|
251
|
+
export const B: CSF3<CatProps> = {
|
252
|
+
args: { name: "already csf3" }
|
253
|
+
};
|
254
|
+
|
255
|
+
export const C: CSF2<CatProps> = (args) => <Cat {...args} />;
|
256
|
+
C.args = {
|
257
|
+
name: "Fluffy"
|
258
|
+
};
|
259
|
+
`)
|
260
|
+
).toMatchInlineSnapshot(`
|
261
|
+
import { Meta, StoryObj as CSF3, StoryFn as CSF2 } from '@storybook/react';
|
262
|
+
import { CatProps } from './Cat';
|
263
|
+
|
264
|
+
const meta = { title: 'Cat', component: Cat } satisfies Meta<CatProps>;
|
265
|
+
export default meta;
|
266
|
+
|
267
|
+
export const A: CSF2<CatProps> = () => <Cat />;
|
268
|
+
|
269
|
+
export const B: CSF3<CatProps> = {
|
270
|
+
args: { name: 'already csf3' },
|
271
|
+
};
|
272
|
+
|
273
|
+
export const C: CSF3<CatProps> = {
|
274
|
+
args: {
|
275
|
+
name: 'Fluffy',
|
276
|
+
},
|
277
|
+
};
|
278
|
+
`);
|
279
|
+
});
|
280
|
+
|
281
|
+
it('should replace function exports with objects and update type', () => {
|
229
282
|
expect(
|
230
283
|
tsTransform(dedent`
|
231
|
-
|
284
|
+
import { Story, StoryFn, ComponentStory, ComponentStoryObj } from '@storybook/react';
|
285
|
+
|
286
|
+
// some extra whitespace to test
|
287
|
+
|
288
|
+
export default {
|
289
|
+
title: 'Cat',
|
290
|
+
component: Cat,
|
291
|
+
} as Meta<CatProps>;
|
292
|
+
|
232
293
|
export const A: Story<CatProps> = (args) => <Cat {...args} />;
|
294
|
+
A.args = { name: "Fluffy" };
|
295
|
+
|
233
296
|
export const B: any = (args) => <Button {...args} />;
|
297
|
+
|
234
298
|
export const C: Story<CatProps> = () => <Cat />;
|
299
|
+
|
300
|
+
export const D: StoryFn<CatProps> = (args) => <Cat {...args} />;
|
301
|
+
D.args = {
|
302
|
+
name: "Fluffy"
|
303
|
+
};
|
304
|
+
|
305
|
+
export const E: ComponentStory<Cat> = (args) => <Cat {...args} />;
|
306
|
+
E.args = { name: "Fluffy" };
|
307
|
+
|
308
|
+
export const F: Story = (args) => <Cat {...args} />;
|
309
|
+
F.args = {
|
310
|
+
name: "Fluffy"
|
311
|
+
};
|
312
|
+
|
313
|
+
export const G: ComponentStoryObj<typeof Cat> = {
|
314
|
+
args: {
|
315
|
+
name: 'Fluffy',
|
316
|
+
},
|
317
|
+
};
|
235
318
|
`)
|
236
319
|
).toMatchInlineSnapshot(`
|
320
|
+
import { StoryObj, StoryFn } from '@storybook/react';
|
321
|
+
|
322
|
+
// some extra whitespace to test
|
323
|
+
|
237
324
|
export default {
|
238
325
|
title: 'Cat',
|
326
|
+
component: Cat,
|
239
327
|
} as Meta<CatProps>;
|
240
|
-
|
241
|
-
|
328
|
+
|
329
|
+
export const A: StoryObj<CatProps> = {
|
330
|
+
args: { name: 'Fluffy' },
|
242
331
|
};
|
332
|
+
|
243
333
|
export const B: any = {
|
244
334
|
render: (args) => <Button {...args} />,
|
245
335
|
};
|
246
|
-
|
336
|
+
|
337
|
+
export const C: StoryFn<CatProps> = () => <Cat />;
|
338
|
+
|
339
|
+
export const D: StoryObj<CatProps> = {
|
340
|
+
args: {
|
341
|
+
name: 'Fluffy',
|
342
|
+
},
|
343
|
+
};
|
344
|
+
|
345
|
+
export const E: StoryObj<Cat> = {
|
346
|
+
args: { name: 'Fluffy' },
|
347
|
+
};
|
348
|
+
|
349
|
+
export const F: StoryObj = {
|
350
|
+
args: {
|
351
|
+
name: 'Fluffy',
|
352
|
+
},
|
353
|
+
};
|
354
|
+
|
355
|
+
export const G: StoryObj<typeof Cat> = {
|
356
|
+
args: {
|
357
|
+
name: 'Fluffy',
|
358
|
+
},
|
359
|
+
};
|
247
360
|
`);
|
248
361
|
});
|
249
362
|
});
|