@storybook/addon-svelte-csf 5.1.0 → 5.1.2

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.
Files changed (53) hide show
  1. package/dist/compiler/post-transform/appendix/create-export-order.test.d.ts +1 -0
  2. package/dist/compiler/post-transform/appendix/create-export-order.test.js +21 -0
  3. package/dist/compiler/post-transform/appendix/create-import.test.d.ts +1 -0
  4. package/dist/compiler/post-transform/appendix/create-import.test.js +9 -0
  5. package/dist/compiler/post-transform/appendix/create-named-export-stories.test.d.ts +1 -0
  6. package/dist/compiler/post-transform/appendix/create-named-export-stories.test.js +35 -0
  7. package/dist/compiler/post-transform/appendix/create-runtime-story-variable-declaration.test.d.ts +1 -0
  8. package/dist/compiler/post-transform/appendix/create-runtime-story-variable-declaration.test.js +100 -0
  9. package/dist/compiler/post-transform/appendix/create-variable-from-runtime-stories-call.test.d.ts +1 -0
  10. package/dist/compiler/post-transform/appendix/create-variable-from-runtime-stories-call.test.js +22 -0
  11. package/dist/compiler/post-transform/define-meta/index.test.d.ts +1 -0
  12. package/dist/compiler/post-transform/define-meta/index.test.js +96 -0
  13. package/dist/compiler/post-transform/index.test.d.ts +1 -0
  14. package/dist/compiler/post-transform/index.test.js +279 -0
  15. package/dist/compiler/post-transform/remove-export-default.test.d.ts +1 -0
  16. package/dist/compiler/post-transform/remove-export-default.test.js +33 -0
  17. package/dist/compiler/post-transform/story/index.test.d.ts +1 -0
  18. package/dist/compiler/post-transform/story/index.test.js +147 -0
  19. package/dist/compiler/pre-transform/codemods/component-meta-to-define-meta.test.d.ts +1 -0
  20. package/dist/compiler/pre-transform/codemods/component-meta-to-define-meta.test.js +121 -0
  21. package/dist/compiler/pre-transform/codemods/export-const-to-define-meta.test.d.ts +1 -0
  22. package/dist/compiler/pre-transform/codemods/export-const-to-define-meta.test.js +68 -0
  23. package/dist/compiler/pre-transform/codemods/import-declaration.test.d.ts +1 -0
  24. package/dist/compiler/pre-transform/codemods/import-declaration.test.js +24 -0
  25. package/dist/compiler/pre-transform/codemods/legacy-story.test.d.ts +1 -0
  26. package/dist/compiler/pre-transform/codemods/legacy-story.test.js +287 -0
  27. package/dist/compiler/pre-transform/codemods/template-to-snippet.test.d.ts +1 -0
  28. package/dist/compiler/pre-transform/codemods/template-to-snippet.test.js +75 -0
  29. package/dist/compiler/pre-transform/index.test.d.ts +1 -0
  30. package/dist/compiler/pre-transform/index.test.js +256 -0
  31. package/dist/parser/analyse/story/attributes/identifiers.test.d.ts +1 -0
  32. package/dist/parser/analyse/story/attributes/identifiers.test.js +294 -0
  33. package/dist/parser/analyse/story/attributes.test.d.ts +1 -0
  34. package/dist/parser/analyse/story/attributes.test.js +151 -0
  35. package/dist/parser/analyse/story/content.test.d.ts +1 -0
  36. package/dist/parser/analyse/story/content.test.js +263 -0
  37. package/dist/parser/extract/svelte/define-meta.test.d.ts +1 -0
  38. package/dist/parser/extract/svelte/define-meta.test.js +32 -0
  39. package/dist/parser/extract/svelte/fragment-nodes.test.d.ts +1 -0
  40. package/dist/parser/extract/svelte/fragment-nodes.test.js +101 -0
  41. package/dist/parser/extract/svelte/module-nodes.test.d.ts +1 -0
  42. package/dist/parser/extract/svelte/module-nodes.test.js +143 -0
  43. package/dist/parser/extract/svelte/nodes.test.d.ts +1 -0
  44. package/dist/parser/extract/svelte/nodes.test.js +29 -0
  45. package/dist/parser/extract/svelte/story/attributes.test.d.ts +1 -0
  46. package/dist/parser/extract/svelte/story/attributes.test.js +50 -0
  47. package/dist/parser/extract/svelte/story/template.test.d.ts +1 -0
  48. package/dist/parser/extract/svelte/story/template.test.js +51 -0
  49. package/dist/runtime/emit-code.test.d.ts +1 -0
  50. package/dist/runtime/emit-code.test.js +149 -0
  51. package/dist/utils/identifier-utils.test.d.ts +1 -0
  52. package/dist/utils/identifier-utils.test.js +22 -0
  53. package/package.json +24 -28
@@ -0,0 +1,151 @@
1
+ import { describe, it } from 'vitest';
2
+ import { getArrayOfStringsValueFromAttribute, getStringValueFromAttribute } from './attributes.js';
3
+ import { getSvelteAST } from '../../ast.js';
4
+ import { extractSvelteASTNodes } from '../../extract/svelte/nodes.js';
5
+ import { extractStoryAttributesNodes } from '../../extract/svelte/story/attributes.js';
6
+ import { StorybookSvelteCSFError } from '../../../utils/error.js';
7
+ describe(getStringValueFromAttribute.name, () => {
8
+ it("throws error when a `<Story />` 'name' attribute value is not a string", async ({ expect, }) => {
9
+ const code = `
10
+ <script module>
11
+ import { defineMeta } from "@storybook/addon-svelte-csf";
12
+
13
+ import SampleComponent from "./SampleComponent.svelte";
14
+
15
+ const { Story } = defineMeta({
16
+ component: SampleComponent,
17
+ });
18
+ </script>
19
+
20
+ <Story name />
21
+ `;
22
+ const ast = getSvelteAST({ code });
23
+ const svelteASTNodes = await extractSvelteASTNodes({ ast });
24
+ const { storyComponents } = svelteASTNodes;
25
+ const component = storyComponents[0].component;
26
+ const { name } = extractStoryAttributesNodes({
27
+ attributes: ['name'],
28
+ component,
29
+ });
30
+ expect(() => getStringValueFromAttribute({ component, node: name }))
31
+ .toThrowErrorMatchingInlineSnapshot(`
32
+ [SB_SVELTE_CSF_PARSER_ANALYSE_STORY_0001 (AttributeNotStringError): In the stories file: <path not specified>
33
+
34
+ A '<Story name="undefined" />' has a prop 'name' whose value must be a static literal string.
35
+
36
+ More info: https://github.com/storybookjs/addon-svelte-csf/blob/v${StorybookSvelteCSFError.packageVersion}/ERRORS.md#SB_SVELTE_CSF_PARSER_ANALYSE_STORY_0001
37
+ ]
38
+ `);
39
+ });
40
+ });
41
+ describe(getArrayOfStringsValueFromAttribute.name, () => {
42
+ it("throws error when a `<Story />` 'tags' attribute value is not an array expression", async ({ expect, }) => {
43
+ const code = `
44
+ <script module>
45
+ import { defineMeta } from "@storybook/addon-svelte-csf";
46
+
47
+ import SampleComponent from "./SampleComponent.svelte";
48
+
49
+ const { Story } = defineMeta({
50
+ component: SampleComponent,
51
+ });
52
+ </script>
53
+
54
+ <Story name="Default" tags={0} />
55
+ `;
56
+ const ast = getSvelteAST({ code });
57
+ const svelteASTNodes = await extractSvelteASTNodes({ ast });
58
+ const { storyComponents } = svelteASTNodes;
59
+ const component = storyComponents[0].component;
60
+ const { tags } = extractStoryAttributesNodes({
61
+ attributes: ['tags'],
62
+ component,
63
+ });
64
+ expect(() => getArrayOfStringsValueFromAttribute({ component, node: tags })).toThrowErrorMatchingInlineSnapshot(`
65
+ [SB_SVELTE_CSF_PARSER_ANALYSE_STORY_0002 (AttributeNotArrayError): In the stories file: <path not specified>
66
+
67
+ A '<Story name="Default" />' has a prop'tags' whose value was expected to be a static array.
68
+ Instead the value type is '0'.
69
+
70
+ More info: https://github.com/storybookjs/addon-svelte-csf/blob/v${StorybookSvelteCSFError.packageVersion}/ERRORS.md#SB_SVELTE_CSF_PARSER_ANALYSE_STORY_0002
71
+ ]
72
+ `);
73
+ });
74
+ it("throws error when a `<Story />` 'tags' attribute value is not an array of strings only", async ({ expect, }) => {
75
+ const code = `
76
+ <script module>
77
+ import { defineMeta } from "@storybook/addon-svelte-csf";
78
+
79
+ import SampleComponent from "./SampleComponent.svelte";
80
+
81
+ const { Story } = defineMeta({
82
+ component: SampleComponent,
83
+ });
84
+ </script>
85
+
86
+ <Story name="Default" tags={[null, "autodocs"]} />
87
+ `;
88
+ const ast = getSvelteAST({ code });
89
+ const svelteASTNodes = await extractSvelteASTNodes({ ast });
90
+ const { storyComponents } = svelteASTNodes;
91
+ const component = storyComponents[0].component;
92
+ const { tags } = extractStoryAttributesNodes({
93
+ attributes: ['tags'],
94
+ component,
95
+ });
96
+ expect(() => getArrayOfStringsValueFromAttribute({ component, node: tags })).toThrowErrorMatchingInlineSnapshot(`
97
+ [SB_SVELTE_CSF_PARSER_ANALYSE_STORY_0003 (AttributeNotArrayOfStringsError): In the stories file: <path not specified>
98
+
99
+ A '<Story name="Default" />' has attribute 'tags' whose value was expected to be an array expression.
100
+ All elements in the array must be static literal strings only, but one of the elements is of type 'undefined'.
101
+
102
+ More info: https://github.com/storybookjs/addon-svelte-csf/blob/v${StorybookSvelteCSFError.packageVersion}/ERRORS.md#SB_SVELTE_CSF_PARSER_ANALYSE_STORY_0003
103
+ ]
104
+ `);
105
+ });
106
+ it("extracts 'tags' attribute when is a correct type - array of strings", async ({ expect }) => {
107
+ const ast = getSvelteAST({
108
+ code: `
109
+ <script module>
110
+ import { defineMeta } from "@storybook/addon-svelte-csf"
111
+ const { Story } = defineMeta();
112
+ </script>
113
+ <Story name="Default" tags={["autodocs", "!dev"]} />
114
+ `,
115
+ });
116
+ const nodes = await extractSvelteASTNodes({ ast });
117
+ const { component } = nodes.storyComponents[0];
118
+ const { tags } = extractStoryAttributesNodes({
119
+ component,
120
+ attributes: ['tags'],
121
+ });
122
+ const tagsValue = getArrayOfStringsValueFromAttribute({
123
+ node: tags,
124
+ component,
125
+ });
126
+ expect(tagsValue).toBeInstanceOf(Array);
127
+ expect(tagsValue).toEqual(['autodocs', '!dev']);
128
+ });
129
+ it("returns empty array when 'tags' attribute is not provided", async ({ expect }) => {
130
+ const ast = getSvelteAST({
131
+ code: `
132
+ <script module>
133
+ import { defineMeta } from "@storybook/addon-svelte-csf"
134
+ const { Story } = defineMeta();
135
+ </script>
136
+ <Story name="Default" />
137
+ `,
138
+ });
139
+ const nodes = await extractSvelteASTNodes({ ast });
140
+ const { component } = nodes.storyComponents[0];
141
+ const { tags } = extractStoryAttributesNodes({
142
+ component,
143
+ attributes: ['tags'],
144
+ });
145
+ const tagsValue = getArrayOfStringsValueFromAttribute({
146
+ node: tags,
147
+ component,
148
+ });
149
+ expect(tagsValue).toEqual([]);
150
+ });
151
+ });
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,263 @@
1
+ import { describe, it } from 'vitest';
2
+ import { getStoryContentRawCode } from './content.js';
3
+ import { getSvelteAST } from '../../ast.js';
4
+ import { extractSvelteASTNodes } from '../../extract/svelte/nodes.js';
5
+ import dedent from 'dedent';
6
+ describe(getStoryContentRawCode.name, () => {
7
+ describe('When a `<Story />` is a self-closing tag...', () => {
8
+ it('works when `template` attribute was provided with a reference to snippet at the root of fragment', async ({ expect, }) => {
9
+ const code = `
10
+ <script module>
11
+ import { defineMeta } from "@storybook/addon-svelte-csf";
12
+
13
+ import SampleComponent from "./SampleComponent.svelte";
14
+
15
+ const { Story } = defineMeta({
16
+ component: SampleComponent,
17
+ });
18
+ </script>
19
+
20
+ {#snippet template(args)}
21
+ <SomeComponent {...args} />
22
+ {/snippet}
23
+
24
+ <Story name="Default" {template} />
25
+ `;
26
+ const ast = getSvelteAST({ code });
27
+ const svelteASTNodes = await extractSvelteASTNodes({ ast });
28
+ const { storyComponents } = svelteASTNodes;
29
+ const component = storyComponents[0].component;
30
+ const rawSource = getStoryContentRawCode({
31
+ nodes: {
32
+ component,
33
+ svelte: svelteASTNodes,
34
+ },
35
+ originalCode: code,
36
+ });
37
+ expect(rawSource).toBe('<SomeComponent {...args} />');
38
+ });
39
+ it('works when `render` is set in `defineMeta`', async ({ expect }) => {
40
+ const code = `
41
+ <script module>
42
+ import { defineMeta } from "@storybook/addon-svelte-csf";
43
+
44
+ import SampleComponent from "./SampleComponent.svelte";
45
+
46
+ const { Story } = defineMeta({
47
+ component: SampleComponent,
48
+ render: template,
49
+ });
50
+ </script>
51
+
52
+ {#snippet template(args)}
53
+ <SomeComponent {...args} />
54
+ {/snippet}
55
+
56
+ <Story name="Default" />
57
+ `;
58
+ const ast = getSvelteAST({ code });
59
+ const svelteASTNodes = await extractSvelteASTNodes({ ast });
60
+ const { storyComponents } = svelteASTNodes;
61
+ const component = storyComponents[0].component;
62
+ const rawSource = getStoryContentRawCode({
63
+ nodes: {
64
+ component,
65
+ svelte: svelteASTNodes,
66
+ },
67
+ originalCode: code,
68
+ });
69
+ expect(rawSource).toBe('<SomeComponent {...args} />');
70
+ });
71
+ it('works implicit `template` attribute takes precedence over `render` in `defineMeta`', async ({ expect, }) => {
72
+ const code = `
73
+ <script module>
74
+ import { defineMeta } from "@storybook/addon-svelte-csf";
75
+
76
+ import SampleComponent from "./SampleComponent.svelte";
77
+
78
+ const { Story } = defineMeta({
79
+ component: SampleComponent,
80
+ render: templateForRender,
81
+ });
82
+ </script>
83
+
84
+ {#snippet templateForRender(args)}
85
+ <SomeComponent wins="render" {...args} />
86
+ {/snippet}
87
+
88
+ {#snippet templateForTemplateAttribute(args)}
89
+ <SomeComponent wins="templateAttribute" {...args} />
90
+ {/snippet}
91
+
92
+ <Story name="Default" template={templateForTemplateAttribute} />
93
+ `;
94
+ const ast = getSvelteAST({ code });
95
+ const svelteASTNodes = await extractSvelteASTNodes({ ast });
96
+ const { storyComponents } = svelteASTNodes;
97
+ const component = storyComponents[0].component;
98
+ const rawSource = getStoryContentRawCode({
99
+ nodes: {
100
+ component,
101
+ svelte: svelteASTNodes,
102
+ },
103
+ originalCode: code,
104
+ });
105
+ expect(rawSource).toBe(`<SomeComponent wins="templateAttribute" {...args} />`);
106
+ });
107
+ it('works when no `render` in `defineMeta`, no `template` attribute, just a story', async ({ expect, }) => {
108
+ const code = `
109
+ <script module>
110
+ import { defineMeta } from "@storybook/addon-svelte-csf";
111
+
112
+ import SampleComponent from "./SampleComponent.svelte";
113
+
114
+ const { Story } = defineMeta({
115
+ component: SampleComponent,
116
+ });
117
+ </script>
118
+
119
+ <Story name="Default" />
120
+ `;
121
+ const ast = getSvelteAST({ code });
122
+ const svelteASTNodes = await extractSvelteASTNodes({ ast });
123
+ const { storyComponents } = svelteASTNodes;
124
+ const component = storyComponents[0].component;
125
+ const rawSource = getStoryContentRawCode({
126
+ nodes: {
127
+ component,
128
+ svelte: svelteASTNodes,
129
+ },
130
+ originalCode: code,
131
+ });
132
+ expect(rawSource).toBe(`<SampleComponent {...args} />`);
133
+ });
134
+ });
135
+ describe('When a `<Story />` is NOT a self-closing tag...', () => {
136
+ it('works when a static children content provided with asChild', async ({ expect }) => {
137
+ const code = `
138
+ <script module>
139
+ import { defineMeta } from "@storybook/addon-svelte-csf";
140
+
141
+ import SampleComponent from "./SampleComponent.svelte";
142
+
143
+ const { Story } = defineMeta({
144
+ component: SampleComponent,
145
+ });
146
+ </script>
147
+
148
+ <Story name="Default" asChild>
149
+ <h1>Static content</h1>
150
+ </Story>
151
+ `;
152
+ const ast = getSvelteAST({ code });
153
+ const svelteASTNodes = await extractSvelteASTNodes({ ast });
154
+ const { storyComponents } = svelteASTNodes;
155
+ const component = storyComponents[0].component;
156
+ const rawSource = getStoryContentRawCode({
157
+ nodes: {
158
+ component,
159
+ svelte: svelteASTNodes,
160
+ },
161
+ originalCode: code,
162
+ });
163
+ expect(rawSource).toBe(`<h1>Static content</h1>`);
164
+ });
165
+ it('works when a static children content provided as a child to the component', async ({ expect, }) => {
166
+ const code = `
167
+ <script module>
168
+ import { defineMeta } from "@storybook/addon-svelte-csf";
169
+
170
+ import SampleComponent from "./SampleComponent.svelte";
171
+
172
+ const { Story } = defineMeta({
173
+ component: SampleComponent,
174
+ });
175
+ </script>
176
+
177
+ <Story name="Default">
178
+ <h1>Static children content</h1>
179
+ </Story>
180
+ `;
181
+ const ast = getSvelteAST({ code });
182
+ const svelteASTNodes = await extractSvelteASTNodes({ ast });
183
+ const { storyComponents } = svelteASTNodes;
184
+ const component = storyComponents[0].component;
185
+ const rawSource = getStoryContentRawCode({
186
+ nodes: {
187
+ component,
188
+ svelte: svelteASTNodes,
189
+ },
190
+ originalCode: code,
191
+ });
192
+ expect(rawSource).toBe(dedent `<SampleComponent {...args}>
193
+ <h1>Static children content</h1>
194
+ </SampleComponent>`);
195
+ });
196
+ it("works when a `template` svelte's snippet block used inside", async ({ expect }) => {
197
+ const code = `
198
+ <script module>
199
+ import { defineMeta } from "@storybook/addon-svelte-csf";
200
+
201
+ import SampleComponent from "./SampleComponent.svelte";
202
+
203
+ const { Story } = defineMeta({
204
+ component: SampleComponent,
205
+ });
206
+ </script>
207
+
208
+ <Story name="Default">
209
+ {#snippet template(args)}
210
+ <SomeComponent {...args} />
211
+ {/snippet}
212
+ </Story>
213
+ `;
214
+ const ast = getSvelteAST({ code });
215
+ const svelteASTNodes = await extractSvelteASTNodes({ ast });
216
+ const { storyComponents } = svelteASTNodes;
217
+ const component = storyComponents[0].component;
218
+ const rawSource = getStoryContentRawCode({
219
+ nodes: {
220
+ component,
221
+ svelte: svelteASTNodes,
222
+ },
223
+ originalCode: code,
224
+ });
225
+ expect(rawSource).toBe(`<SomeComponent {...args} />`);
226
+ });
227
+ it("inner `<Story>`'s template content takes precedence over `render` in `defineMeta`", async ({ expect, }) => {
228
+ const code = `
229
+ <script module>
230
+ import { defineMeta } from "@storybook/addon-svelte-csf";
231
+
232
+ import SampleComponent from "./SampleComponent.svelte";
233
+
234
+ const { Story } = defineMeta({
235
+ component: SampleComponent,
236
+ });
237
+ </script>
238
+
239
+ {#snippet templateForRender(args)}
240
+ <SomeComponent wins="render" {...args} />
241
+ {/snippet}
242
+
243
+ <Story name="Default">
244
+ {#snippet template(args)}
245
+ <SomeComponent wins="inner-template" {...args} />
246
+ {/snippet}
247
+ </Story>
248
+ `;
249
+ const ast = getSvelteAST({ code });
250
+ const svelteASTNodes = await extractSvelteASTNodes({ ast });
251
+ const { storyComponents } = svelteASTNodes;
252
+ const component = storyComponents[0].component;
253
+ const rawSource = getStoryContentRawCode({
254
+ nodes: {
255
+ component,
256
+ svelte: svelteASTNodes,
257
+ },
258
+ originalCode: code,
259
+ });
260
+ expect(rawSource).toBe(`<SomeComponent wins="inner-template" {...args} />`);
261
+ });
262
+ });
263
+ });
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,32 @@
1
+ import { describe, it } from 'vitest';
2
+ import { extractDefineMetaPropertiesNodes } from './define-meta.js';
3
+ import { getSvelteAST } from '../../ast.js';
4
+ import { extractSvelteASTNodes } from './nodes.js';
5
+ describe(extractDefineMetaPropertiesNodes.name, () => {
6
+ it('extracts correctly selected properties', async ({ expect }) => {
7
+ const ast = getSvelteAST({
8
+ code: `
9
+ <script module>
10
+ import { defineMeta } from "@storybook/addon-svelte-csf"
11
+
12
+ const { Story } = defineMeta({
13
+ title: "My Story",
14
+ id: "custom-id",
15
+ tags: ["autodocs", "!dev"],
16
+ });
17
+ </script>
18
+ `,
19
+ });
20
+ const nodes = await extractSvelteASTNodes({ ast });
21
+ const properties = extractDefineMetaPropertiesNodes({
22
+ nodes,
23
+ properties: ['title', 'id', 'tags', 'args', 'parameters'],
24
+ });
25
+ expect((properties.title?.value).value).toBe('My Story');
26
+ expect((properties.id?.value).value).toBe('custom-id');
27
+ expect((properties.tags?.value).elements[0].value).toBe('autodocs');
28
+ expect((properties.tags?.value).elements[1].value).toBe('!dev');
29
+ expect(properties.args).toBeUndefined();
30
+ expect(properties.parameters).toBeUndefined();
31
+ });
32
+ });
@@ -0,0 +1,101 @@
1
+ import { describe, expect, it } from 'vitest';
2
+ import { extractFragmentNodes } from './fragment-nodes.js';
3
+ import { extractModuleNodes } from './module-nodes.js';
4
+ import { getSvelteAST } from '../../ast.js';
5
+ describe(extractFragmentNodes.name, () => {
6
+ it("extracts '<Story />' AST nodes correctly", async () => {
7
+ const ast = getSvelteAST({
8
+ code: `
9
+ <script module>
10
+ import { defineMeta } from "@storybook/addon-svelte-csf"
11
+ const { Story } = defineMeta();
12
+ </script>
13
+ <Story name="1" />
14
+ <Story name="2" />
15
+ <Story name="3" />
16
+ <Story name="4" />
17
+ <Story name="5" />
18
+ `,
19
+ });
20
+ const moduleNodes = await extractModuleNodes({ module: ast.module });
21
+ const fragmentNodes = await extractFragmentNodes({
22
+ fragment: ast.fragment,
23
+ moduleNodes,
24
+ });
25
+ expect(fragmentNodes.storyComponents).toHaveLength(5);
26
+ for (const story of fragmentNodes.storyComponents) {
27
+ expect(story.comment).toBeUndefined();
28
+ }
29
+ expect(fragmentNodes.snippetBlocks).toHaveLength(0);
30
+ });
31
+ it("extracts '<Story />' leading HTML comments correctly", async () => {
32
+ const ast = getSvelteAST({
33
+ code: `
34
+ <script module>
35
+ import { defineMeta } from "@storybook/addon-svelte-csf"
36
+ const { Story } = defineMeta();
37
+ </script>
38
+ <!-- Comment 1 -->
39
+ <Story name="1" />
40
+ <!-- Comment 2 -->
41
+ <Story name="2" />
42
+ <!-- Comment 3 -->
43
+ <Story name="3" />
44
+ <!-- Comment 4 -->
45
+ <Story name="4" />
46
+ <!-- Comment 5 -->
47
+ <Story name="5" />
48
+ `,
49
+ });
50
+ const moduleNodes = await extractModuleNodes({ module: ast.module });
51
+ const fragmentNodes = await extractFragmentNodes({
52
+ fragment: ast.fragment,
53
+ moduleNodes,
54
+ });
55
+ expect(fragmentNodes.storyComponents).toHaveLength(5);
56
+ for (const [index, story] of Object.entries(fragmentNodes.storyComponents)) {
57
+ expect(story.comment?.data).toBe(` Comment ${Number(index) + 1} `);
58
+ }
59
+ });
60
+ it('extracts first level snippet blocks (at the root of fragment) correctly', async () => {
61
+ const ast = getSvelteAST({
62
+ code: `
63
+ <script module>
64
+ import { defineMeta } from "@storybook/addon-svelte-csf"
65
+ const { Story } = defineMeta({
66
+ render,
67
+ });
68
+ </script>
69
+
70
+ {#snippet render(args)}
71
+ <SampleComponent {...args} />
72
+ {/snippet}
73
+
74
+ {#snippet template1(args)}
75
+ <SampleComponent {...args} />
76
+ {/snippet}
77
+
78
+ {#snippet template2(args)}
79
+ <SampleComponent {...args} />
80
+ {/snippet}
81
+
82
+ <Story name="Example1" />
83
+
84
+ <Story name="Example2">
85
+ {#snippet template(args)}
86
+ <SampleComponent {...args} />
87
+ {/snippet}
88
+ </Story>
89
+ `,
90
+ });
91
+ const moduleNodes = await extractModuleNodes({ module: ast.module });
92
+ const fragmentNodes = await extractFragmentNodes({
93
+ fragment: ast.fragment,
94
+ moduleNodes,
95
+ });
96
+ expect(fragmentNodes.snippetBlocks).toHaveLength(3);
97
+ expect(fragmentNodes.snippetBlocks[0].expression.name).toBe('render');
98
+ expect(fragmentNodes.snippetBlocks[1].expression.name).toBe('template1');
99
+ expect(fragmentNodes.snippetBlocks[2].expression.name).toBe('template2');
100
+ });
101
+ });
@@ -0,0 +1 @@
1
+ export {};