@storybook/codemod 7.3.2 → 7.4.0-alpha.1
Sign up to get free protection for your applications and to get access to all the features.
- package/package.json +11 -4
- package/project.json +0 -6
- package/src/index.ts +0 -103
- package/src/lib/utils.test.js +0 -9
- package/src/lib/utils.ts +0 -29
- package/src/transforms/__testfixtures__/add-component-parameters/add-component-parameters.input.js +0 -44
- package/src/transforms/__testfixtures__/add-component-parameters/add-component-parameters.output.snapshot +0 -68
- package/src/transforms/__testfixtures__/csf-hoist-story-annotations/basic.input.js +0 -25
- package/src/transforms/__testfixtures__/csf-hoist-story-annotations/basic.output.snapshot +0 -27
- package/src/transforms/__testfixtures__/csf-hoist-story-annotations/overrides.input.js +0 -25
- package/src/transforms/__testfixtures__/csf-hoist-story-annotations/overrides.output.snapshot +0 -28
- package/src/transforms/__testfixtures__/csf-hoist-story-annotations/variable.input.js +0 -13
- package/src/transforms/__testfixtures__/csf-hoist-story-annotations/variable.output.snapshot +0 -17
- package/src/transforms/__testfixtures__/mdx-to-csf/basic.input.mdx +0 -18
- package/src/transforms/__testfixtures__/mdx-to-csf/basic.output.snapshot +0 -40
- package/src/transforms/__testfixtures__/mdx-to-csf/component-id.input.mdx +0 -6
- package/src/transforms/__testfixtures__/mdx-to-csf/component-id.output.snapshot +0 -17
- package/src/transforms/__testfixtures__/mdx-to-csf/decorators.input.mdx +0 -8
- package/src/transforms/__testfixtures__/mdx-to-csf/decorators.output.snapshot +0 -18
- package/src/transforms/__testfixtures__/mdx-to-csf/exclude-stories.input.mdx +0 -19
- package/src/transforms/__testfixtures__/mdx-to-csf/exclude-stories.output.snapshot +0 -39
- package/src/transforms/__testfixtures__/mdx-to-csf/parameters.input.mdx +0 -14
- package/src/transforms/__testfixtures__/mdx-to-csf/parameters.output.snapshot +0 -23
- package/src/transforms/__testfixtures__/mdx-to-csf/plaintext.input.mdx +0 -3
- package/src/transforms/__testfixtures__/mdx-to-csf/plaintext.output.snapshot +0 -11
- package/src/transforms/__testfixtures__/mdx-to-csf/story-function.input.mdx +0 -10
- package/src/transforms/__testfixtures__/mdx-to-csf/story-function.output.snapshot +0 -18
- package/src/transforms/__testfixtures__/mdx-to-csf/story-parameters.input.mdx +0 -18
- package/src/transforms/__testfixtures__/mdx-to-csf/story-parameters.output.snapshot +0 -32
- package/src/transforms/__testfixtures__/mdx-to-csf/story-refs.input.mdx +0 -22
- package/src/transforms/__testfixtures__/mdx-to-csf/story-refs.output.snapshot +0 -34
- package/src/transforms/__testfixtures__/move-builtin-addons/default.input.js +0 -2
- package/src/transforms/__testfixtures__/move-builtin-addons/default.output.snapshot +0 -8
- package/src/transforms/__testfixtures__/move-builtin-addons/with-no-change.input.js +0 -3
- package/src/transforms/__testfixtures__/move-builtin-addons/with-no-change.output.snapshot +0 -7
- package/src/transforms/__testfixtures__/storiesof-to-csf/basic.input.js +0 -18
- package/src/transforms/__testfixtures__/storiesof-to-csf/basic.output.snapshot +0 -45
- package/src/transforms/__testfixtures__/storiesof-to-csf/collision.input.js +0 -11
- package/src/transforms/__testfixtures__/storiesof-to-csf/collision.output.snapshot +0 -38
- package/src/transforms/__testfixtures__/storiesof-to-csf/const.input.js +0 -1
- package/src/transforms/__testfixtures__/storiesof-to-csf/const.output.snapshot +0 -13
- package/src/transforms/__testfixtures__/storiesof-to-csf/decorators.input.js +0 -9
- package/src/transforms/__testfixtures__/storiesof-to-csf/decorators.output.snapshot +0 -18
- package/src/transforms/__testfixtures__/storiesof-to-csf/default.input.js +0 -7
- package/src/transforms/__testfixtures__/storiesof-to-csf/default.output.snapshot +0 -17
- package/src/transforms/__testfixtures__/storiesof-to-csf/digit.input.js +0 -1
- package/src/transforms/__testfixtures__/storiesof-to-csf/digit.output.js +0 -5
- package/src/transforms/__testfixtures__/storiesof-to-csf/digit.output.snapshot +0 -9
- package/src/transforms/__testfixtures__/storiesof-to-csf/export-destructuring.input.js +0 -11
- package/src/transforms/__testfixtures__/storiesof-to-csf/export-destructuring.output.snapshot +0 -23
- package/src/transforms/__testfixtures__/storiesof-to-csf/export-function.input.js +0 -12
- package/src/transforms/__testfixtures__/storiesof-to-csf/export-function.output.snapshot +0 -23
- package/src/transforms/__testfixtures__/storiesof-to-csf/export-names.input.js +0 -14
- package/src/transforms/__testfixtures__/storiesof-to-csf/export-names.output.snapshot +0 -26
- package/src/transforms/__testfixtures__/storiesof-to-csf/exports.input.js +0 -2
- package/src/transforms/__testfixtures__/storiesof-to-csf/exports.output.snapshot +0 -16
- package/src/transforms/__testfixtures__/storiesof-to-csf/module.input.js +0 -12
- package/src/transforms/__testfixtures__/storiesof-to-csf/module.output.snapshot +0 -16
- package/src/transforms/__testfixtures__/storiesof-to-csf/multi.input.js +0 -14
- package/src/transforms/__testfixtures__/storiesof-to-csf/multi.output.snapshot +0 -39
- package/src/transforms/__testfixtures__/storiesof-to-csf/parameters-as-var.input.js +0 -8
- package/src/transforms/__testfixtures__/storiesof-to-csf/parameters-as-var.output.snapshot +0 -20
- package/src/transforms/__testfixtures__/storiesof-to-csf/parameters.input.js +0 -10
- package/src/transforms/__testfixtures__/storiesof-to-csf/parameters.output.snapshot +0 -23
- package/src/transforms/__testfixtures__/storiesof-to-csf/storiesof-var.input.js +0 -11
- package/src/transforms/__testfixtures__/storiesof-to-csf/storiesof-var.output.snapshot +0 -23
- package/src/transforms/__testfixtures__/storiesof-to-csf/story-decorators.input.js +0 -11
- package/src/transforms/__testfixtures__/storiesof-to-csf/story-decorators.output.snapshot +0 -29
- package/src/transforms/__testfixtures__/storiesof-to-csf/story-parameters.input.js +0 -14
- package/src/transforms/__testfixtures__/storiesof-to-csf/story-parameters.output.snapshot +0 -32
- package/src/transforms/__testfixtures__/update-addon-info/update-addon-info.input.js +0 -184
- package/src/transforms/__testfixtures__/update-addon-info/update-addon-info.output.snapshot +0 -184
- package/src/transforms/__testfixtures__/update-organisation-name/update-organisation-name.input.js +0 -19
- package/src/transforms/__testfixtures__/update-organisation-name/update-organisation-name.output.snapshot +0 -23
- package/src/transforms/__testfixtures__/upgrade-hierarchy-separators/csf.input.js +0 -3
- package/src/transforms/__testfixtures__/upgrade-hierarchy-separators/csf.output.snapshot +0 -7
- package/src/transforms/__testfixtures__/upgrade-hierarchy-separators/dynamic-storiesof.input.js +0 -5
- package/src/transforms/__testfixtures__/upgrade-hierarchy-separators/dynamic-storiesof.output.snapshot +0 -9
- package/src/transforms/__testfixtures__/upgrade-hierarchy-separators/storiesof.input.js +0 -8
- package/src/transforms/__testfixtures__/upgrade-hierarchy-separators/storiesof.output.snapshot +0 -12
- package/src/transforms/__tests__/csf-2-to-3.test.ts +0 -439
- package/src/transforms/__tests__/mdx-to-csf.test.ts +0 -628
- package/src/transforms/__tests__/transforms.tests.js +0 -32
- package/src/transforms/__tests__/upgrade-deprecated-types.test.ts +0 -170
- package/src/transforms/add-component-parameters.js +0 -62
- package/src/transforms/csf-2-to-3.ts +0 -335
- package/src/transforms/csf-hoist-story-annotations.js +0 -97
- package/src/transforms/mdx-to-csf.ts +0 -340
- package/src/transforms/move-builtin-addons.js +0 -32
- package/src/transforms/storiesof-to-csf.js +0 -277
- package/src/transforms/update-addon-info.js +0 -114
- package/src/transforms/update-organisation-name.js +0 -71
- package/src/transforms/upgrade-deprecated-types.ts +0 -142
- package/src/transforms/upgrade-hierarchy-separators.js +0 -39
- package/tsconfig.json +0 -10
@@ -1,628 +0,0 @@
|
|
1
|
-
import * as fs_ from 'node:fs';
|
2
|
-
import { expect, test } from '@jest/globals';
|
3
|
-
import dedent from 'ts-dedent';
|
4
|
-
import jscodeshift, { nameToValidExport } from '../mdx-to-csf';
|
5
|
-
|
6
|
-
expect.addSnapshotSerializer({
|
7
|
-
print: (val: any) => (typeof val === 'string' ? val : JSON.stringify(val, null, 2) ?? ''),
|
8
|
-
test: () => true,
|
9
|
-
});
|
10
|
-
|
11
|
-
jest.mock('node:fs');
|
12
|
-
const fs = fs_ as jest.Mocked<typeof import('node:fs')>;
|
13
|
-
|
14
|
-
beforeEach(() => {
|
15
|
-
fs.existsSync.mockImplementation(() => false);
|
16
|
-
});
|
17
|
-
|
18
|
-
test('update import even when no stories can be extracted', () => {
|
19
|
-
const input = dedent`
|
20
|
-
import { Heading } from '@storybook/addon-docs';
|
21
|
-
|
22
|
-
<Heading />
|
23
|
-
`;
|
24
|
-
|
25
|
-
const mdx = jscodeshift({ source: input, path: 'Foobar.stories.mdx' });
|
26
|
-
|
27
|
-
expect(mdx).toMatchInlineSnapshot(`
|
28
|
-
import { Heading } from '@storybook/blocks';
|
29
|
-
|
30
|
-
<Heading />
|
31
|
-
|
32
|
-
`);
|
33
|
-
});
|
34
|
-
|
35
|
-
test('drop invalid story nodes', () => {
|
36
|
-
const input = dedent`
|
37
|
-
import { Meta, Story } from '@storybook/addon-docs';
|
38
|
-
|
39
|
-
<Meta title="Foobar" />
|
40
|
-
|
41
|
-
<Story>No name!</Story>
|
42
|
-
|
43
|
-
<Story name="Primary">Story</Story>
|
44
|
-
`;
|
45
|
-
|
46
|
-
const mdx = jscodeshift({ source: input, path: 'Foobar.stories.mdx' });
|
47
|
-
|
48
|
-
expect(mdx).toMatchInlineSnapshot(`
|
49
|
-
import { Meta, Story } from '@storybook/blocks';
|
50
|
-
import * as FoobarStories from './Foobar.stories';
|
51
|
-
|
52
|
-
<Meta of={FoobarStories} />
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
<Story of={FoobarStories.Primary} />
|
57
|
-
|
58
|
-
`);
|
59
|
-
});
|
60
|
-
|
61
|
-
test('convert story re-definition', () => {
|
62
|
-
const input = dedent`
|
63
|
-
import { Meta, Story } from '@storybook/addon-docs';
|
64
|
-
import { Primary } from './Foobar.stories';
|
65
|
-
|
66
|
-
<Meta title="Foobar" />
|
67
|
-
|
68
|
-
<Story story={Primary} />
|
69
|
-
`;
|
70
|
-
|
71
|
-
fs.existsSync.mockImplementation((path) => path === 'Foobar.stories.js');
|
72
|
-
|
73
|
-
const mdx = jscodeshift({ source: input, path: 'Foobar.stories.mdx' });
|
74
|
-
|
75
|
-
expect(mdx).toMatchInlineSnapshot(`
|
76
|
-
import { Meta, Story } from '@storybook/blocks';
|
77
|
-
import { Primary } from './Foobar.stories';
|
78
|
-
import * as FoobarStories from './Foobar_.stories';
|
79
|
-
|
80
|
-
<Meta of={FoobarStories} />
|
81
|
-
|
82
|
-
<Story of={FoobarStories.Primary} />
|
83
|
-
|
84
|
-
`);
|
85
|
-
const [csfFileName, csf] = fs.writeFileSync.mock.calls[0];
|
86
|
-
expect(csfFileName).toMatchInlineSnapshot(`Foobar_.stories.js`);
|
87
|
-
expect(csf).toMatchInlineSnapshot(`
|
88
|
-
import { Primary } from './Foobar.stories';
|
89
|
-
|
90
|
-
export default {
|
91
|
-
title: 'Foobar',
|
92
|
-
};
|
93
|
-
|
94
|
-
export { Primary };
|
95
|
-
|
96
|
-
`);
|
97
|
-
});
|
98
|
-
|
99
|
-
test('Comment out story nodes with id', () => {
|
100
|
-
const input = dedent`
|
101
|
-
import { Meta, Story } from '@storybook/addon-docs';
|
102
|
-
|
103
|
-
<Meta title="Foobar" />
|
104
|
-
|
105
|
-
<Story id="button--primary" />
|
106
|
-
`;
|
107
|
-
|
108
|
-
const mdx = jscodeshift({ source: input, path: 'Foobar.stories.mdx' });
|
109
|
-
|
110
|
-
expect(mdx).toMatchInlineSnapshot(`
|
111
|
-
import { Meta, Story } from '@storybook/blocks';
|
112
|
-
import * as FoobarStories from './Foobar.stories';
|
113
|
-
|
114
|
-
<Meta of={FoobarStories} />
|
115
|
-
|
116
|
-
{/* <Story id="button--primary" /> is deprecated, please migrate it to <Story of={referenceToStory} /> see: https://storybook.js.org/migration-guides/7.0 */}
|
117
|
-
|
118
|
-
<Story id="button--primary" />
|
119
|
-
|
120
|
-
`);
|
121
|
-
});
|
122
|
-
|
123
|
-
test('convert correct story nodes', () => {
|
124
|
-
const input = dedent`
|
125
|
-
import { Meta, Story } from '@storybook/addon-docs';
|
126
|
-
|
127
|
-
<Meta title="Foobar" />
|
128
|
-
|
129
|
-
<Story name="Primary">Story</Story>
|
130
|
-
`;
|
131
|
-
|
132
|
-
const mdx = jscodeshift({ source: input, path: 'Foobar.stories.mdx' });
|
133
|
-
|
134
|
-
expect(mdx).toMatchInlineSnapshot(`
|
135
|
-
import { Meta, Story } from '@storybook/blocks';
|
136
|
-
import * as FoobarStories from './Foobar.stories';
|
137
|
-
|
138
|
-
<Meta of={FoobarStories} />
|
139
|
-
|
140
|
-
<Story of={FoobarStories.Primary} />
|
141
|
-
|
142
|
-
`);
|
143
|
-
|
144
|
-
const [, csf] = fs.writeFileSync.mock.calls[0];
|
145
|
-
expect(csf).toMatchInlineSnapshot(`
|
146
|
-
export default {
|
147
|
-
title: 'Foobar',
|
148
|
-
};
|
149
|
-
|
150
|
-
export const Primary = {
|
151
|
-
render: () => 'Story',
|
152
|
-
name: 'Primary',
|
153
|
-
};
|
154
|
-
|
155
|
-
`);
|
156
|
-
});
|
157
|
-
|
158
|
-
test('convert addon-docs imports', () => {
|
159
|
-
const input = dedent`
|
160
|
-
import { Meta } from '@storybook/addon-docs';
|
161
|
-
import { Story } from '@storybook/addon-docs/blocks';
|
162
|
-
|
163
|
-
<Meta title="Foobar" />
|
164
|
-
|
165
|
-
<Story name="Primary">Story</Story>
|
166
|
-
`;
|
167
|
-
|
168
|
-
const mdx = jscodeshift({ source: input, path: 'Foobar.stories.mdx' });
|
169
|
-
|
170
|
-
expect(mdx).toMatchInlineSnapshot(`
|
171
|
-
import { Meta } from '@storybook/blocks';
|
172
|
-
import { Story } from '@storybook/blocks';
|
173
|
-
import * as FoobarStories from './Foobar.stories';
|
174
|
-
|
175
|
-
<Meta of={FoobarStories} />
|
176
|
-
|
177
|
-
<Story of={FoobarStories.Primary} />
|
178
|
-
|
179
|
-
`);
|
180
|
-
});
|
181
|
-
|
182
|
-
test('convert story nodes with spaces', () => {
|
183
|
-
const input = dedent`
|
184
|
-
import { Meta, Story } from '@storybook/addon-docs';
|
185
|
-
|
186
|
-
<Meta title="Foobar" />
|
187
|
-
|
188
|
-
<Story name="Primary Space">Story</Story>
|
189
|
-
`;
|
190
|
-
|
191
|
-
const mdx = jscodeshift({ source: input, path: 'Foobar.stories.mdx' });
|
192
|
-
|
193
|
-
expect(mdx).toMatchInlineSnapshot(`
|
194
|
-
import { Meta, Story } from '@storybook/blocks';
|
195
|
-
import * as FoobarStories from './Foobar.stories';
|
196
|
-
|
197
|
-
<Meta of={FoobarStories} />
|
198
|
-
|
199
|
-
<Story of={FoobarStories.PrimarySpace} />
|
200
|
-
|
201
|
-
`);
|
202
|
-
|
203
|
-
const [, csf] = fs.writeFileSync.mock.calls[0];
|
204
|
-
expect(csf).toMatchInlineSnapshot(`
|
205
|
-
export default {
|
206
|
-
title: 'Foobar',
|
207
|
-
};
|
208
|
-
|
209
|
-
export const PrimarySpace = {
|
210
|
-
render: () => 'Story',
|
211
|
-
name: 'Primary Space',
|
212
|
-
};
|
213
|
-
|
214
|
-
`);
|
215
|
-
});
|
216
|
-
|
217
|
-
test('extract esm into csf head code', () => {
|
218
|
-
const input = dedent`
|
219
|
-
import { Meta, Story } from '@storybook/addon-docs';
|
220
|
-
import { Button } from './Button';
|
221
|
-
|
222
|
-
# hello
|
223
|
-
|
224
|
-
export const args = { bla: 1 };
|
225
|
-
export const Template = (args) => <Button {...args} />;
|
226
|
-
|
227
|
-
<Meta title="foobar" />
|
228
|
-
|
229
|
-
world {2 + 1}
|
230
|
-
|
231
|
-
<Story name="foo">bar</Story>
|
232
|
-
|
233
|
-
<Story
|
234
|
-
name="Unchecked"
|
235
|
-
args={{
|
236
|
-
...args,
|
237
|
-
label: 'Unchecked',
|
238
|
-
}}>
|
239
|
-
{Template.bind({})}
|
240
|
-
</Story>
|
241
|
-
`;
|
242
|
-
|
243
|
-
const mdx = jscodeshift({ source: input, path: 'Foobar.stories.mdx' });
|
244
|
-
|
245
|
-
expect(mdx).toMatchInlineSnapshot(`
|
246
|
-
import { Meta, Story } from '@storybook/blocks';
|
247
|
-
import { Button } from './Button';
|
248
|
-
import * as FoobarStories from './Foobar.stories';
|
249
|
-
|
250
|
-
# hello
|
251
|
-
|
252
|
-
export const args = { bla: 1 };
|
253
|
-
export const Template = (args) => <Button {...args} />;
|
254
|
-
|
255
|
-
<Meta of={FoobarStories} />
|
256
|
-
|
257
|
-
world {2 + 1}
|
258
|
-
|
259
|
-
<Story of={FoobarStories.Foo} />
|
260
|
-
|
261
|
-
<Story of={FoobarStories.Unchecked} />
|
262
|
-
|
263
|
-
`);
|
264
|
-
|
265
|
-
const [csfFileName, csf] = fs.writeFileSync.mock.calls[0];
|
266
|
-
expect(csfFileName).toMatchInlineSnapshot(`Foobar.stories.js`);
|
267
|
-
expect(csf).toMatchInlineSnapshot(`
|
268
|
-
import { Button } from './Button';
|
269
|
-
|
270
|
-
const args = { bla: 1 };
|
271
|
-
const Template = (args) => <Button {...args} />;
|
272
|
-
|
273
|
-
export default {
|
274
|
-
title: 'foobar',
|
275
|
-
};
|
276
|
-
|
277
|
-
export const Foo = {
|
278
|
-
render: () => 'bar',
|
279
|
-
name: 'foo',
|
280
|
-
};
|
281
|
-
|
282
|
-
export const Unchecked = {
|
283
|
-
render: Template.bind({}),
|
284
|
-
name: 'Unchecked',
|
285
|
-
|
286
|
-
args: {
|
287
|
-
...args,
|
288
|
-
label: 'Unchecked',
|
289
|
-
},
|
290
|
-
};
|
291
|
-
|
292
|
-
`);
|
293
|
-
});
|
294
|
-
|
295
|
-
test('extract all meta parameters', () => {
|
296
|
-
const input = dedent`
|
297
|
-
import { Meta, Story } from '@storybook/addon-docs';
|
298
|
-
|
299
|
-
export const args = { bla: 1 };
|
300
|
-
|
301
|
-
<Meta title="foobar" args={{...args}} parameters={{a: '1'}} />
|
302
|
-
|
303
|
-
<Story name="foo">bar</Story>
|
304
|
-
`;
|
305
|
-
|
306
|
-
jscodeshift({ source: input, path: 'Foobar.stories.mdx' });
|
307
|
-
|
308
|
-
const [, csf] = fs.writeFileSync.mock.calls[0];
|
309
|
-
|
310
|
-
expect(csf).toMatchInlineSnapshot(`
|
311
|
-
const args = { bla: 1 };
|
312
|
-
|
313
|
-
export default {
|
314
|
-
title: 'foobar',
|
315
|
-
|
316
|
-
args: {
|
317
|
-
...args,
|
318
|
-
},
|
319
|
-
|
320
|
-
parameters: {
|
321
|
-
a: '1',
|
322
|
-
},
|
323
|
-
};
|
324
|
-
|
325
|
-
export const Foo = {
|
326
|
-
render: () => 'bar',
|
327
|
-
name: 'foo',
|
328
|
-
};
|
329
|
-
|
330
|
-
`);
|
331
|
-
});
|
332
|
-
|
333
|
-
test('extract all story attributes', () => {
|
334
|
-
const input = dedent`
|
335
|
-
import { Meta, Story } from '@storybook/addon-docs';
|
336
|
-
import { Button } from './Button';
|
337
|
-
|
338
|
-
export const args = { bla: 1 };
|
339
|
-
export const Template = (args) => <Button {...args} />;
|
340
|
-
|
341
|
-
<Meta title="foobar" />
|
342
|
-
|
343
|
-
<Story name="foo">bar</Story>
|
344
|
-
|
345
|
-
<Story
|
346
|
-
name="Unchecked"
|
347
|
-
args={{
|
348
|
-
...args,
|
349
|
-
label: 'Unchecked',
|
350
|
-
}}>
|
351
|
-
{Template.bind({})}
|
352
|
-
</Story>
|
353
|
-
|
354
|
-
<Story name="Second">{Template.bind({})}</Story>
|
355
|
-
|
356
|
-
`;
|
357
|
-
|
358
|
-
jscodeshift({ source: input, path: 'Foobar.stories.mdx' });
|
359
|
-
|
360
|
-
const [, csf] = fs.writeFileSync.mock.calls[0];
|
361
|
-
|
362
|
-
expect(csf).toMatchInlineSnapshot(`
|
363
|
-
import { Button } from './Button';
|
364
|
-
|
365
|
-
const args = { bla: 1 };
|
366
|
-
const Template = (args) => <Button {...args} />;
|
367
|
-
|
368
|
-
export default {
|
369
|
-
title: 'foobar',
|
370
|
-
};
|
371
|
-
|
372
|
-
export const Foo = {
|
373
|
-
render: () => 'bar',
|
374
|
-
name: 'foo',
|
375
|
-
};
|
376
|
-
|
377
|
-
export const Unchecked = {
|
378
|
-
render: Template.bind({}),
|
379
|
-
name: 'Unchecked',
|
380
|
-
|
381
|
-
args: {
|
382
|
-
...args,
|
383
|
-
label: 'Unchecked',
|
384
|
-
},
|
385
|
-
};
|
386
|
-
|
387
|
-
export const Second = {
|
388
|
-
render: Template.bind({}),
|
389
|
-
name: 'Second',
|
390
|
-
};
|
391
|
-
|
392
|
-
`);
|
393
|
-
});
|
394
|
-
|
395
|
-
test('duplicate story name', () => {
|
396
|
-
const input = dedent`
|
397
|
-
import { Meta, Story } from '@storybook/addon-docs';
|
398
|
-
import { Button } from './Button';
|
399
|
-
|
400
|
-
export const Default = (args) => <Button {...args} />;
|
401
|
-
|
402
|
-
<Meta title="Button" />
|
403
|
-
|
404
|
-
<Story name="Default">
|
405
|
-
{Default.bind({})}
|
406
|
-
</Story>
|
407
|
-
|
408
|
-
<Story name="Second">{Default.bind({})}</Story>
|
409
|
-
|
410
|
-
`;
|
411
|
-
|
412
|
-
const mdx = jscodeshift({ source: input, path: 'Foobar.stories.mdx' });
|
413
|
-
const [, csf] = fs.writeFileSync.mock.calls[0];
|
414
|
-
|
415
|
-
expect(mdx).toMatchInlineSnapshot(`
|
416
|
-
import { Meta, Story } from '@storybook/blocks';
|
417
|
-
import { Button } from './Button';
|
418
|
-
import * as FoobarStories from './Foobar.stories';
|
419
|
-
|
420
|
-
export const Default = (args) => <Button {...args} />;
|
421
|
-
|
422
|
-
<Meta of={FoobarStories} />
|
423
|
-
|
424
|
-
<Story of={FoobarStories.Default_} />
|
425
|
-
|
426
|
-
<Story of={FoobarStories.Second} />
|
427
|
-
|
428
|
-
`);
|
429
|
-
expect(csf).toMatchInlineSnapshot(`
|
430
|
-
import { Button } from './Button';
|
431
|
-
|
432
|
-
const Default = (args) => <Button {...args} />;
|
433
|
-
|
434
|
-
export default {
|
435
|
-
title: 'Button',
|
436
|
-
};
|
437
|
-
|
438
|
-
export const Default_ = {
|
439
|
-
render: Default.bind({}),
|
440
|
-
name: 'Default',
|
441
|
-
};
|
442
|
-
|
443
|
-
export const Second = {
|
444
|
-
render: Default.bind({}),
|
445
|
-
name: 'Second',
|
446
|
-
};
|
447
|
-
|
448
|
-
`);
|
449
|
-
});
|
450
|
-
|
451
|
-
test('kebab case file name', () => {
|
452
|
-
const input = dedent`
|
453
|
-
import { Meta, Story } from '@storybook/addon-docs';
|
454
|
-
import { Kebab } from './my-component/some-kebab-case';
|
455
|
-
|
456
|
-
export const Template = (args) => <Kebab {...args} />;
|
457
|
-
|
458
|
-
<Meta title="Kebab" />
|
459
|
-
|
460
|
-
<Story name="Much-Kebab">
|
461
|
-
{Template.bind({})}
|
462
|
-
</Story>
|
463
|
-
|
464
|
-
<Story name="Really-Much-Kebab">{Template.bind({})}</Story>
|
465
|
-
|
466
|
-
`;
|
467
|
-
|
468
|
-
const mdx = jscodeshift({ source: input, path: 'some-kebab-case.stories.mdx' });
|
469
|
-
|
470
|
-
expect(mdx).toMatchInlineSnapshot(`
|
471
|
-
import { Meta, Story } from '@storybook/blocks';
|
472
|
-
import { Kebab } from './my-component/some-kebab-case';
|
473
|
-
import * as SomeKebabCaseStories from './some-kebab-case.stories';
|
474
|
-
|
475
|
-
export const Template = (args) => <Kebab {...args} />;
|
476
|
-
|
477
|
-
<Meta of={SomeKebabCaseStories} />
|
478
|
-
|
479
|
-
<Story of={SomeKebabCaseStories.MuchKebab} />
|
480
|
-
|
481
|
-
<Story of={SomeKebabCaseStories.ReallyMuchKebab} />
|
482
|
-
|
483
|
-
`);
|
484
|
-
|
485
|
-
const [, csf] = fs.writeFileSync.mock.calls[0];
|
486
|
-
|
487
|
-
expect(csf).toMatchInlineSnapshot(`
|
488
|
-
import { Kebab } from './my-component/some-kebab-case';
|
489
|
-
|
490
|
-
const Template = (args) => <Kebab {...args} />;
|
491
|
-
|
492
|
-
export default {
|
493
|
-
title: 'Kebab',
|
494
|
-
};
|
495
|
-
|
496
|
-
export const MuchKebab = {
|
497
|
-
render: Template.bind({}),
|
498
|
-
name: 'Much-Kebab',
|
499
|
-
};
|
500
|
-
|
501
|
-
export const ReallyMuchKebab = {
|
502
|
-
render: Template.bind({}),
|
503
|
-
name: 'Really-Much-Kebab',
|
504
|
-
};
|
505
|
-
|
506
|
-
`);
|
507
|
-
});
|
508
|
-
|
509
|
-
test('story child is jsx', () => {
|
510
|
-
const input = dedent`
|
511
|
-
import { Canvas, Meta, Story } from '@storybook/addon-docs';
|
512
|
-
import { Button } from './button';
|
513
|
-
|
514
|
-
<Story name="Primary">
|
515
|
-
<Button>
|
516
|
-
<div>Hello!</div>
|
517
|
-
</Button>
|
518
|
-
</Story>
|
519
|
-
`;
|
520
|
-
|
521
|
-
jscodeshift({ source: input, path: 'Foobar.stories.mdx' });
|
522
|
-
|
523
|
-
const [, csf] = fs.writeFileSync.mock.calls[0];
|
524
|
-
|
525
|
-
expect(csf).toMatchInlineSnapshot(`
|
526
|
-
import { Button } from './button';
|
527
|
-
export default {};
|
528
|
-
|
529
|
-
export const Primary = {
|
530
|
-
render: () => (
|
531
|
-
<Button>
|
532
|
-
<div>Hello!</div>
|
533
|
-
</Button>
|
534
|
-
),
|
535
|
-
|
536
|
-
name: 'Primary',
|
537
|
-
};
|
538
|
-
|
539
|
-
`);
|
540
|
-
});
|
541
|
-
|
542
|
-
test('story child is CSF3', () => {
|
543
|
-
const input = dedent`
|
544
|
-
import { Story } from '@storybook/addon-docs';
|
545
|
-
import { Button } from './button';
|
546
|
-
|
547
|
-
<Story name="Primary" render={(args) => <Button {...args}></Button> } args={{label: 'Hello' }} />
|
548
|
-
`;
|
549
|
-
|
550
|
-
jscodeshift({ source: input, path: 'Foobar.stories.mdx' });
|
551
|
-
|
552
|
-
const [, csf] = fs.writeFileSync.mock.calls[0];
|
553
|
-
|
554
|
-
expect(csf).toMatchInlineSnapshot(`
|
555
|
-
import { Button } from './button';
|
556
|
-
export default {};
|
557
|
-
|
558
|
-
export const Primary = {
|
559
|
-
name: 'Primary',
|
560
|
-
render: (args) => <Button {...args}></Button>,
|
561
|
-
|
562
|
-
args: {
|
563
|
-
label: 'Hello',
|
564
|
-
},
|
565
|
-
};
|
566
|
-
|
567
|
-
`);
|
568
|
-
});
|
569
|
-
|
570
|
-
test('story child is arrow function', () => {
|
571
|
-
const input = dedent`
|
572
|
-
import { Canvas, Meta, Story } from '@storybook/addon-docs';
|
573
|
-
import { Button } from './button';
|
574
|
-
|
575
|
-
<Story name="Primary">
|
576
|
-
{(args) => <Button />}
|
577
|
-
</Story>
|
578
|
-
`;
|
579
|
-
|
580
|
-
jscodeshift({ source: input, path: 'Foobar.stories.mdx' });
|
581
|
-
|
582
|
-
const [, csf] = fs.writeFileSync.mock.calls[0];
|
583
|
-
|
584
|
-
expect(csf).toMatchInlineSnapshot(`
|
585
|
-
import { Button } from './button';
|
586
|
-
export default {};
|
587
|
-
|
588
|
-
export const Primary = {
|
589
|
-
render: (args) => <Button />,
|
590
|
-
name: 'Primary',
|
591
|
-
};
|
592
|
-
|
593
|
-
`);
|
594
|
-
});
|
595
|
-
|
596
|
-
test('story child is identifier', () => {
|
597
|
-
const input = dedent`
|
598
|
-
import { Canvas, Meta, Story } from '@storybook/addon-docs';
|
599
|
-
import { Button } from './button';
|
600
|
-
|
601
|
-
<Story name="Primary">
|
602
|
-
{Button}
|
603
|
-
</Story>
|
604
|
-
`;
|
605
|
-
|
606
|
-
jscodeshift({ source: input, path: 'Foobar.stories.mdx' });
|
607
|
-
|
608
|
-
const [, csf] = fs.writeFileSync.mock.calls[0];
|
609
|
-
|
610
|
-
expect(csf).toMatchInlineSnapshot(`
|
611
|
-
import { Button } from './button';
|
612
|
-
export default {};
|
613
|
-
|
614
|
-
export const Primary = {
|
615
|
-
render: Button,
|
616
|
-
name: 'Primary',
|
617
|
-
};
|
618
|
-
|
619
|
-
`);
|
620
|
-
});
|
621
|
-
|
622
|
-
test('nameToValidExport', () => {
|
623
|
-
expect(nameToValidExport('1 starts with digit')).toMatchInlineSnapshot(`$1StartsWithDigit`);
|
624
|
-
expect(nameToValidExport('name')).toMatchInlineSnapshot(`Name`);
|
625
|
-
expect(nameToValidExport('Multi words')).toMatchInlineSnapshot(`MultiWords`);
|
626
|
-
// Unicode is valid in JS variable names
|
627
|
-
expect(nameToValidExport('Keep unicode 😅')).toMatchInlineSnapshot(`KeepUnicode😅`);
|
628
|
-
});
|
@@ -1,32 +0,0 @@
|
|
1
|
-
import path from 'path';
|
2
|
-
import fs from 'fs';
|
3
|
-
import 'jest-specific-snapshot';
|
4
|
-
import { applyTransform } from 'jscodeshift/dist/testUtils';
|
5
|
-
|
6
|
-
jest.mock('@storybook/node-logger');
|
7
|
-
|
8
|
-
const inputRegExp = /\.input\.js$/;
|
9
|
-
|
10
|
-
const fixturesDir = path.resolve(__dirname, '../__testfixtures__');
|
11
|
-
fs.readdirSync(fixturesDir).forEach((transformName) => {
|
12
|
-
// FIXME: delete after https://github.com/storybookjs/storybook/issues/19497
|
13
|
-
if (transformName === 'mdx-to-csf') return;
|
14
|
-
|
15
|
-
const transformFixturesDir = path.join(fixturesDir, transformName);
|
16
|
-
describe(`${transformName}`, () => {
|
17
|
-
fs.readdirSync(transformFixturesDir)
|
18
|
-
.filter((fileName) => inputRegExp.test(fileName))
|
19
|
-
.forEach((fileName) => {
|
20
|
-
const inputPath = path.join(transformFixturesDir, fileName);
|
21
|
-
it(`transforms correctly using "${fileName}" data`, () =>
|
22
|
-
expect(
|
23
|
-
applyTransform(
|
24
|
-
// eslint-disable-next-line global-require,import/no-dynamic-require
|
25
|
-
require(path.join(__dirname, '..', transformName)),
|
26
|
-
null,
|
27
|
-
{ path: inputPath, source: fs.readFileSync(inputPath, 'utf8') }
|
28
|
-
)
|
29
|
-
).toMatchSpecificSnapshot(inputPath.replace(inputRegExp, '.output.snapshot')));
|
30
|
-
});
|
31
|
-
});
|
32
|
-
});
|