@storybook/codemod 7.0.0-beta.5 → 7.0.0-beta.51
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/chunk-HBPKIMKE.mjs +1 -0
- package/dist/chunk-YH46OF24.mjs +2 -0
- package/dist/index.js +1 -1
- package/dist/index.mjs +1 -1
- package/dist/transforms/add-component-parameters.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/csf-2-to-3.mjs +2 -1
- package/dist/transforms/csf-hoist-story-annotations.js +1 -1
- package/dist/transforms/move-builtin-addons.js +1 -1
- package/dist/transforms/storiesof-to-csf.js +1 -1
- package/dist/transforms/storiesof-to-csf.mjs +1 -1
- package/dist/transforms/update-addon-info.js +1 -1
- package/dist/transforms/update-organisation-name.js +1 -1
- package/dist/transforms/upgrade-deprecated-types.d.ts +10 -0
- package/dist/transforms/upgrade-deprecated-types.js +2 -0
- package/dist/transforms/upgrade-deprecated-types.mjs +1 -0
- package/dist/transforms/upgrade-hierarchy-separators.js +1 -1
- package/jest.config.js +1 -0
- package/package.json +15 -10
- package/project.json +6 -0
- package/src/index.js +11 -1
- 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 +175 -57
- package/src/transforms/__tests__/upgrade-deprecated-types.test.ts +170 -0
- package/src/transforms/csf-2-to-3.ts +161 -33
- package/src/transforms/upgrade-deprecated-types.ts +142 -0
- package/dist/chunk-CO6EPEMB.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/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
@@ -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,162 @@ 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
|
+
> 1 | import * as SB from '@storybook/react';
|
239
|
+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
240
|
+
2 | import { CatProps } from './Cat';
|
241
|
+
3 |
|
242
|
+
4 | const meta = { title: 'Cat', component: Cat } as Meta<CatProps>
|
243
|
+
`);
|
244
|
+
});
|
245
|
+
it('should keep local names', () => {
|
246
|
+
expect(
|
247
|
+
tsTransform(dedent`
|
248
|
+
import { Meta, StoryObj as CSF3, StoryFn as CSF2 } from '@storybook/react';
|
249
|
+
import { CatProps } from './Cat';
|
250
|
+
|
251
|
+
const meta = { title: 'Cat', component: Cat } satisfies Meta<CatProps>
|
252
|
+
export default meta;
|
253
|
+
|
254
|
+
export const A: CSF2<CatProps> = () => <Cat />;
|
255
|
+
|
256
|
+
export const B: CSF3<CatProps> = {
|
257
|
+
args: { name: "already csf3" }
|
258
|
+
};
|
259
|
+
|
260
|
+
export const C: CSF2<CatProps> = (args) => <Cat {...args} />;
|
261
|
+
C.args = {
|
262
|
+
name: "Fluffy"
|
263
|
+
};
|
264
|
+
`)
|
265
|
+
).toMatchInlineSnapshot(`
|
266
|
+
import { Meta, StoryObj as CSF3, StoryFn as CSF2 } from '@storybook/react';
|
267
|
+
import { CatProps } from './Cat';
|
268
|
+
|
269
|
+
const meta = { title: 'Cat', component: Cat } satisfies Meta<CatProps>;
|
270
|
+
export default meta;
|
271
|
+
|
272
|
+
export const A: CSF2<CatProps> = () => <Cat />;
|
273
|
+
|
274
|
+
export const B: CSF3<CatProps> = {
|
275
|
+
args: { name: 'already csf3' },
|
276
|
+
};
|
277
|
+
|
278
|
+
export const C: CSF3<CatProps> = {
|
279
|
+
args: {
|
280
|
+
name: 'Fluffy',
|
281
|
+
},
|
282
|
+
};
|
283
|
+
`);
|
284
|
+
});
|
285
|
+
|
286
|
+
it('should replace function exports with objects and update type', () => {
|
229
287
|
expect(
|
230
288
|
tsTransform(dedent`
|
231
|
-
|
289
|
+
import { Story, StoryFn, ComponentStory, ComponentStoryObj } from '@storybook/react';
|
290
|
+
|
291
|
+
// some extra whitespace to test
|
292
|
+
|
293
|
+
export default {
|
294
|
+
title: 'Cat',
|
295
|
+
component: Cat,
|
296
|
+
} as Meta<CatProps>;
|
297
|
+
|
232
298
|
export const A: Story<CatProps> = (args) => <Cat {...args} />;
|
299
|
+
A.args = { name: "Fluffy" };
|
300
|
+
|
233
301
|
export const B: any = (args) => <Button {...args} />;
|
302
|
+
|
234
303
|
export const C: Story<CatProps> = () => <Cat />;
|
304
|
+
|
305
|
+
export const D: StoryFn<CatProps> = (args) => <Cat {...args} />;
|
306
|
+
D.args = {
|
307
|
+
name: "Fluffy"
|
308
|
+
};
|
309
|
+
|
310
|
+
export const E: ComponentStory<Cat> = (args) => <Cat {...args} />;
|
311
|
+
E.args = { name: "Fluffy" };
|
312
|
+
|
313
|
+
export const F: Story = (args) => <Cat {...args} />;
|
314
|
+
F.args = {
|
315
|
+
name: "Fluffy"
|
316
|
+
};
|
317
|
+
|
318
|
+
export const G: ComponentStoryObj<typeof Cat> = {
|
319
|
+
args: {
|
320
|
+
name: 'Fluffy',
|
321
|
+
},
|
322
|
+
};
|
235
323
|
`)
|
236
324
|
).toMatchInlineSnapshot(`
|
325
|
+
import { StoryObj, StoryFn } from '@storybook/react';
|
326
|
+
|
327
|
+
// some extra whitespace to test
|
328
|
+
|
237
329
|
export default {
|
238
330
|
title: 'Cat',
|
331
|
+
component: Cat,
|
239
332
|
} as Meta<CatProps>;
|
240
|
-
|
241
|
-
|
333
|
+
|
334
|
+
export const A: StoryObj<CatProps> = {
|
335
|
+
args: { name: 'Fluffy' },
|
242
336
|
};
|
337
|
+
|
243
338
|
export const B: any = {
|
244
339
|
render: (args) => <Button {...args} />,
|
245
340
|
};
|
246
|
-
|
341
|
+
|
342
|
+
export const C: StoryFn<CatProps> = () => <Cat />;
|
343
|
+
|
344
|
+
export const D: StoryObj<CatProps> = {
|
345
|
+
args: {
|
346
|
+
name: 'Fluffy',
|
347
|
+
},
|
348
|
+
};
|
349
|
+
|
350
|
+
export const E: StoryObj<Cat> = {
|
351
|
+
args: { name: 'Fluffy' },
|
352
|
+
};
|
353
|
+
|
354
|
+
export const F: StoryObj = {
|
355
|
+
args: {
|
356
|
+
name: 'Fluffy',
|
357
|
+
},
|
358
|
+
};
|
359
|
+
|
360
|
+
export const G: StoryObj<typeof Cat> = {
|
361
|
+
args: {
|
362
|
+
name: 'Fluffy',
|
363
|
+
},
|
364
|
+
};
|
247
365
|
`);
|
248
366
|
});
|
249
367
|
});
|
@@ -0,0 +1,170 @@
|
|
1
|
+
import { describe, expect, it } from '@jest/globals';
|
2
|
+
import { dedent } from 'ts-dedent';
|
3
|
+
import type { API } from 'jscodeshift';
|
4
|
+
import ansiRegex from 'ansi-regex';
|
5
|
+
import _transform from '../upgrade-deprecated-types';
|
6
|
+
|
7
|
+
expect.addSnapshotSerializer({
|
8
|
+
print: (val: any) => val,
|
9
|
+
test: () => true,
|
10
|
+
});
|
11
|
+
|
12
|
+
const tsTransform = (source: string) =>
|
13
|
+
_transform({ source, path: 'Component.stories.ts' }, {} as API, { parser: 'tsx' }).trim();
|
14
|
+
|
15
|
+
describe('upgrade-deprecated-types', () => {
|
16
|
+
describe('typescript', () => {
|
17
|
+
it('upgrade regular imports', () => {
|
18
|
+
expect(
|
19
|
+
tsTransform(dedent`
|
20
|
+
import { Story, ComponentMeta, Meta, ComponentStory, ComponentStoryObj, ComponentStoryFn } from '@storybook/react';
|
21
|
+
import { Cat, CatProps } from './Cat';
|
22
|
+
|
23
|
+
const meta = { title: 'Cat', component: Cat } satisfies ComponentMeta<typeof Cat>
|
24
|
+
const meta2: Meta<CatProps> = { title: 'Cat', component: Cat };
|
25
|
+
export default meta;
|
26
|
+
|
27
|
+
export const A: ComponentStory<typeof Cat> = (args) => <Cat {...args} />;
|
28
|
+
export const B: any = (args) => <Button {...args} />;
|
29
|
+
export const C: ComponentStoryFn<typeof Cat> = (args) => <Cat {...args} />;
|
30
|
+
export const D: ComponentStoryObj<typeof Cat> = {
|
31
|
+
args: {
|
32
|
+
name: 'Fluffy',
|
33
|
+
},
|
34
|
+
};
|
35
|
+
export const E: Story<CatProps> = (args) => <Cat {...args} />;
|
36
|
+
`)
|
37
|
+
).toMatchInlineSnapshot(`
|
38
|
+
import { StoryFn, Meta, StoryObj } from '@storybook/react';
|
39
|
+
import { Cat, CatProps } from './Cat';
|
40
|
+
|
41
|
+
const meta = { title: 'Cat', component: Cat } satisfies Meta<typeof Cat>;
|
42
|
+
const meta2: Meta<CatProps> = { title: 'Cat', component: Cat };
|
43
|
+
export default meta;
|
44
|
+
|
45
|
+
export const A: StoryFn<typeof Cat> = (args) => <Cat {...args} />;
|
46
|
+
export const B: any = (args) => <Button {...args} />;
|
47
|
+
export const C: StoryFn<typeof Cat> = (args) => <Cat {...args} />;
|
48
|
+
export const D: StoryObj<typeof Cat> = {
|
49
|
+
args: {
|
50
|
+
name: 'Fluffy',
|
51
|
+
},
|
52
|
+
};
|
53
|
+
export const E: StoryFn<CatProps> = (args) => <Cat {...args} />;
|
54
|
+
`);
|
55
|
+
});
|
56
|
+
|
57
|
+
it('upgrade imports with local names', () => {
|
58
|
+
expect(
|
59
|
+
tsTransform(dedent`
|
60
|
+
import { Story as Story_, ComponentMeta as ComponentMeta_, ComponentStory as Story__, ComponentStoryObj as ComponentStoryObj_, ComponentStoryFn as StoryFn_ } from '@storybook/react';
|
61
|
+
import { Cat } from './Cat';
|
62
|
+
|
63
|
+
const meta = { title: 'Cat', component: Cat } satisfies ComponentMeta_<typeof Cat>
|
64
|
+
const meta2: ComponentMeta_<typeof Cat> = { title: 'Cat', component: Cat };
|
65
|
+
export default meta;
|
66
|
+
|
67
|
+
export const A: Story__<typeof Cat> = (args) => <Cat {...args} />;
|
68
|
+
export const B: any = (args) => <Button {...args} />;
|
69
|
+
export const C: StoryFn_<typeof Cat> = (args) => <Cat {...args} />;
|
70
|
+
export const D: ComponentStoryObj_<typeof Cat> = {
|
71
|
+
args: {
|
72
|
+
name: 'Fluffy',
|
73
|
+
},
|
74
|
+
};
|
75
|
+
export const E: Story_<CatProps> = (args) => <Cat {...args} />;
|
76
|
+
`)
|
77
|
+
).toMatchInlineSnapshot(`
|
78
|
+
import {
|
79
|
+
StoryFn as Story_,
|
80
|
+
Meta as ComponentMeta_,
|
81
|
+
StoryObj as ComponentStoryObj_,
|
82
|
+
} from '@storybook/react';
|
83
|
+
import { Cat } from './Cat';
|
84
|
+
|
85
|
+
const meta = { title: 'Cat', component: Cat } satisfies ComponentMeta_<typeof Cat>;
|
86
|
+
const meta2: ComponentMeta_<typeof Cat> = { title: 'Cat', component: Cat };
|
87
|
+
export default meta;
|
88
|
+
|
89
|
+
export const A: Story__<typeof Cat> = (args) => <Cat {...args} />;
|
90
|
+
export const B: any = (args) => <Button {...args} />;
|
91
|
+
export const C: StoryFn_<typeof Cat> = (args) => <Cat {...args} />;
|
92
|
+
export const D: ComponentStoryObj_<typeof Cat> = {
|
93
|
+
args: {
|
94
|
+
name: 'Fluffy',
|
95
|
+
},
|
96
|
+
};
|
97
|
+
export const E: Story_<CatProps> = (args) => <Cat {...args} />;
|
98
|
+
`);
|
99
|
+
});
|
100
|
+
|
101
|
+
it('upgrade imports with conflicting local names', () => {
|
102
|
+
expect.addSnapshotSerializer({
|
103
|
+
serialize: (value) => value.replace(ansiRegex(), ''),
|
104
|
+
test: () => true,
|
105
|
+
});
|
106
|
+
|
107
|
+
expect(() =>
|
108
|
+
tsTransform(dedent`
|
109
|
+
import { ComponentMeta as Meta, ComponentStory as StoryFn } from '@storybook/react';
|
110
|
+
import { Cat } from './Cat';
|
111
|
+
|
112
|
+
const meta = { title: 'Cat', component: Cat } satisfies Meta<typeof Cat>
|
113
|
+
export default meta;
|
114
|
+
|
115
|
+
export const A: StoryFn<typeof Cat> = (args) => <Cat {...args} />;
|
116
|
+
|
117
|
+
`)
|
118
|
+
).toThrowErrorMatchingInlineSnapshot(`
|
119
|
+
This codemod does not support local imports that are called the same as a storybook import.
|
120
|
+
Rename this local import and try again.
|
121
|
+
> 1 | import { ComponentMeta as Meta, ComponentStory as StoryFn } from '@storybook/react';
|
122
|
+
| ^^^^^^^^^^^^^^^^^^^^^
|
123
|
+
2 | import { Cat } from './Cat';
|
124
|
+
3 |
|
125
|
+
4 | const meta = { title: 'Cat', component: Cat } satisfies Meta<typeof Cat>
|
126
|
+
`);
|
127
|
+
});
|
128
|
+
|
129
|
+
it('upgrade namespaces', () => {
|
130
|
+
expect(
|
131
|
+
tsTransform(dedent`
|
132
|
+
import * as SB from '@storybook/react';
|
133
|
+
import { Cat, CatProps } from './Cat';
|
134
|
+
|
135
|
+
const meta = { title: 'Cat', component: Cat } satisfies SB.ComponentMeta<typeof Cat>;
|
136
|
+
const meta2: SB.ComponentMeta<typeof Cat> = { title: 'Cat', component: Cat };
|
137
|
+
export default meta;
|
138
|
+
|
139
|
+
export const A: SB.ComponentStory<typeof Cat> = (args) => <Cat {...args} />;
|
140
|
+
export const B: any = (args) => <Button {...args} />;
|
141
|
+
export const C: SB.ComponentStoryFn<typeof Cat> = (args) => <Cat {...args} />;
|
142
|
+
export const D: SB.ComponentStoryObj<typeof Cat> = {
|
143
|
+
args: {
|
144
|
+
name: 'Fluffy',
|
145
|
+
},
|
146
|
+
};
|
147
|
+
export const E: SB.Story<CatProps> = (args) => <Cat {...args} />;
|
148
|
+
|
149
|
+
`)
|
150
|
+
).toMatchInlineSnapshot(`
|
151
|
+
import * as SB from '@storybook/react';
|
152
|
+
import { Cat, CatProps } from './Cat';
|
153
|
+
|
154
|
+
const meta = { title: 'Cat', component: Cat } satisfies SB.Meta<typeof Cat>;
|
155
|
+
const meta2: SB.Meta<typeof Cat> = { title: 'Cat', component: Cat };
|
156
|
+
export default meta;
|
157
|
+
|
158
|
+
export const A: SB.StoryFn<typeof Cat> = (args) => <Cat {...args} />;
|
159
|
+
export const B: any = (args) => <Button {...args} />;
|
160
|
+
export const C: SB.StoryFn<typeof Cat> = (args) => <Cat {...args} />;
|
161
|
+
export const D: SB.StoryObj<typeof Cat> = {
|
162
|
+
args: {
|
163
|
+
name: 'Fluffy',
|
164
|
+
},
|
165
|
+
};
|
166
|
+
export const E: SB.StoryFn<CatProps> = (args) => <Cat {...args} />;
|
167
|
+
`);
|
168
|
+
});
|
169
|
+
});
|
170
|
+
});
|