@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.
- package/dist/compiler/post-transform/appendix/create-export-order.test.d.ts +1 -0
- package/dist/compiler/post-transform/appendix/create-export-order.test.js +21 -0
- package/dist/compiler/post-transform/appendix/create-import.test.d.ts +1 -0
- package/dist/compiler/post-transform/appendix/create-import.test.js +9 -0
- package/dist/compiler/post-transform/appendix/create-named-export-stories.test.d.ts +1 -0
- package/dist/compiler/post-transform/appendix/create-named-export-stories.test.js +35 -0
- package/dist/compiler/post-transform/appendix/create-runtime-story-variable-declaration.test.d.ts +1 -0
- package/dist/compiler/post-transform/appendix/create-runtime-story-variable-declaration.test.js +100 -0
- package/dist/compiler/post-transform/appendix/create-variable-from-runtime-stories-call.test.d.ts +1 -0
- package/dist/compiler/post-transform/appendix/create-variable-from-runtime-stories-call.test.js +22 -0
- package/dist/compiler/post-transform/define-meta/index.test.d.ts +1 -0
- package/dist/compiler/post-transform/define-meta/index.test.js +96 -0
- package/dist/compiler/post-transform/index.test.d.ts +1 -0
- package/dist/compiler/post-transform/index.test.js +279 -0
- package/dist/compiler/post-transform/remove-export-default.test.d.ts +1 -0
- package/dist/compiler/post-transform/remove-export-default.test.js +33 -0
- package/dist/compiler/post-transform/story/index.test.d.ts +1 -0
- package/dist/compiler/post-transform/story/index.test.js +147 -0
- package/dist/compiler/pre-transform/codemods/component-meta-to-define-meta.test.d.ts +1 -0
- package/dist/compiler/pre-transform/codemods/component-meta-to-define-meta.test.js +121 -0
- package/dist/compiler/pre-transform/codemods/export-const-to-define-meta.test.d.ts +1 -0
- package/dist/compiler/pre-transform/codemods/export-const-to-define-meta.test.js +68 -0
- package/dist/compiler/pre-transform/codemods/import-declaration.test.d.ts +1 -0
- package/dist/compiler/pre-transform/codemods/import-declaration.test.js +24 -0
- package/dist/compiler/pre-transform/codemods/legacy-story.test.d.ts +1 -0
- package/dist/compiler/pre-transform/codemods/legacy-story.test.js +287 -0
- package/dist/compiler/pre-transform/codemods/template-to-snippet.test.d.ts +1 -0
- package/dist/compiler/pre-transform/codemods/template-to-snippet.test.js +75 -0
- package/dist/compiler/pre-transform/index.test.d.ts +1 -0
- package/dist/compiler/pre-transform/index.test.js +256 -0
- package/dist/parser/analyse/story/attributes/identifiers.test.d.ts +1 -0
- package/dist/parser/analyse/story/attributes/identifiers.test.js +294 -0
- package/dist/parser/analyse/story/attributes.test.d.ts +1 -0
- package/dist/parser/analyse/story/attributes.test.js +151 -0
- package/dist/parser/analyse/story/content.test.d.ts +1 -0
- package/dist/parser/analyse/story/content.test.js +263 -0
- package/dist/parser/extract/svelte/define-meta.test.d.ts +1 -0
- package/dist/parser/extract/svelte/define-meta.test.js +32 -0
- package/dist/parser/extract/svelte/fragment-nodes.test.d.ts +1 -0
- package/dist/parser/extract/svelte/fragment-nodes.test.js +101 -0
- package/dist/parser/extract/svelte/module-nodes.test.d.ts +1 -0
- package/dist/parser/extract/svelte/module-nodes.test.js +143 -0
- package/dist/parser/extract/svelte/nodes.test.d.ts +1 -0
- package/dist/parser/extract/svelte/nodes.test.js +29 -0
- package/dist/parser/extract/svelte/story/attributes.test.d.ts +1 -0
- package/dist/parser/extract/svelte/story/attributes.test.js +50 -0
- package/dist/parser/extract/svelte/story/template.test.d.ts +1 -0
- package/dist/parser/extract/svelte/story/template.test.js +51 -0
- package/dist/runtime/emit-code.test.d.ts +1 -0
- package/dist/runtime/emit-code.test.js +149 -0
- package/dist/utils/identifier-utils.test.d.ts +1 -0
- package/dist/utils/identifier-utils.test.js +22 -0
- package/package.json +24 -28
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
import { describe, it } from 'vitest';
|
|
2
|
+
import { extractModuleNodes } from './module-nodes.js';
|
|
3
|
+
import { getSvelteAST } from '../../ast.js';
|
|
4
|
+
import { StorybookSvelteCSFError } from '../../../utils/error.js';
|
|
5
|
+
describe(extractModuleNodes.name, () => {
|
|
6
|
+
it('fails when module tag not found', async ({ expect }) => {
|
|
7
|
+
const { module } = getSvelteAST({
|
|
8
|
+
code: `<script></script>`,
|
|
9
|
+
});
|
|
10
|
+
await expect(extractModuleNodes({ module })).rejects.toThrowErrorMatchingInlineSnapshot(`
|
|
11
|
+
[SB_SVELTE_CSF_PARSER_EXTRACT_SVELTE_0001 (MissingModuleTagError): The file '<path not specified>'
|
|
12
|
+
does not have a module context (<script module> ... </script>).
|
|
13
|
+
|
|
14
|
+
defineMeta(...) should be called inside a module script tag, like so:
|
|
15
|
+
|
|
16
|
+
<script module>
|
|
17
|
+
import { defineMeta } from "@storybook/addon-svelte-csf";
|
|
18
|
+
|
|
19
|
+
const { Story } = defineMeta({});
|
|
20
|
+
</script>
|
|
21
|
+
|
|
22
|
+
More info: https://github.com/storybookjs/addon-svelte-csf/blob/v${StorybookSvelteCSFError.packageVersion}/ERRORS.md#SB_SVELTE_CSF_PARSER_EXTRACT_SVELTE_0001
|
|
23
|
+
]
|
|
24
|
+
`);
|
|
25
|
+
});
|
|
26
|
+
it("fails when 'defineMeta' not imported", async ({ expect }) => {
|
|
27
|
+
const { module } = getSvelteAST({
|
|
28
|
+
code: `<script module></script>`,
|
|
29
|
+
});
|
|
30
|
+
await expect(extractModuleNodes({ module })).rejects.toThrowErrorMatchingInlineSnapshot(`
|
|
31
|
+
[SB_SVELTE_CSF_PARSER_EXTRACT_SVELTE_0003 (MissingDefineMetaImportError): The file '<path not specified>'
|
|
32
|
+
does not import defineMeta from "@storybook/addon-svelte-csf" inside the module context.
|
|
33
|
+
|
|
34
|
+
Make sure to import defineMeta from the package and use it inside the module context like so:
|
|
35
|
+
|
|
36
|
+
<script module>
|
|
37
|
+
import { defineMeta } from "@storybook/addon-svelte-csf";
|
|
38
|
+
|
|
39
|
+
const { Story } = defineMeta({});
|
|
40
|
+
</script>
|
|
41
|
+
|
|
42
|
+
More info: https://github.com/storybookjs/addon-svelte-csf/blob/v${StorybookSvelteCSFError.packageVersion}/ERRORS.md#SB_SVELTE_CSF_PARSER_EXTRACT_SVELTE_0003
|
|
43
|
+
]
|
|
44
|
+
`);
|
|
45
|
+
});
|
|
46
|
+
it("fails when 'defineMeta' not used", async ({ expect }) => {
|
|
47
|
+
const { module } = getSvelteAST({
|
|
48
|
+
code: `
|
|
49
|
+
<script module>
|
|
50
|
+
import { defineMeta } from "@storybook/addon-svelte-csf";
|
|
51
|
+
</script>
|
|
52
|
+
`,
|
|
53
|
+
});
|
|
54
|
+
await expect(extractModuleNodes({ module })).rejects.toThrowErrorMatchingInlineSnapshot(`
|
|
55
|
+
[SB_SVELTE_CSF_PARSER_EXTRACT_SVELTE_0004 (MissingDefineMetaVariableDeclarationError): The file '<path not specified>'
|
|
56
|
+
does not store the result of calling defineMeta(). While defineMeta() might have been called,
|
|
57
|
+
it's return value needs to be stored and destructured for the parsing to succeed, eg.:
|
|
58
|
+
|
|
59
|
+
<script module>
|
|
60
|
+
import { defineMeta } from "@storybook/addon-svelte-csf";
|
|
61
|
+
|
|
62
|
+
const { Story } = defineMeta({});
|
|
63
|
+
</script>
|
|
64
|
+
|
|
65
|
+
More info: https://github.com/storybookjs/addon-svelte-csf/blob/v${StorybookSvelteCSFError.packageVersion}/ERRORS.md#SB_SVELTE_CSF_PARSER_EXTRACT_SVELTE_0004
|
|
66
|
+
]
|
|
67
|
+
`);
|
|
68
|
+
});
|
|
69
|
+
it("fails when 'Story' is not destructured", async ({ expect }) => {
|
|
70
|
+
const { module } = getSvelteAST({
|
|
71
|
+
code: `
|
|
72
|
+
<script module>
|
|
73
|
+
import { defineMeta } from "@storybook/addon-svelte-csf"
|
|
74
|
+
defineMeta();
|
|
75
|
+
</script>`,
|
|
76
|
+
});
|
|
77
|
+
await expect(extractModuleNodes({ module })).rejects.toThrowErrorMatchingInlineSnapshot(`
|
|
78
|
+
[SB_SVELTE_CSF_PARSER_EXTRACT_SVELTE_0004 (MissingDefineMetaVariableDeclarationError): The file '<path not specified>'
|
|
79
|
+
does not store the result of calling defineMeta(). While defineMeta() might have been called,
|
|
80
|
+
it's return value needs to be stored and destructured for the parsing to succeed, eg.:
|
|
81
|
+
|
|
82
|
+
<script module>
|
|
83
|
+
import { defineMeta } from "@storybook/addon-svelte-csf";
|
|
84
|
+
|
|
85
|
+
const { Story } = defineMeta({});
|
|
86
|
+
</script>
|
|
87
|
+
|
|
88
|
+
More info: https://github.com/storybookjs/addon-svelte-csf/blob/v${StorybookSvelteCSFError.packageVersion}/ERRORS.md#SB_SVELTE_CSF_PARSER_EXTRACT_SVELTE_0004
|
|
89
|
+
]
|
|
90
|
+
`);
|
|
91
|
+
});
|
|
92
|
+
it('works when it has valid required entry snippet', async ({ expect }) => {
|
|
93
|
+
const { module } = getSvelteAST({
|
|
94
|
+
code: `
|
|
95
|
+
<script module>
|
|
96
|
+
import { defineMeta } from "@storybook/addon-svelte-csf"
|
|
97
|
+
const { Story } = defineMeta();
|
|
98
|
+
</script>`,
|
|
99
|
+
});
|
|
100
|
+
await expect(extractModuleNodes({ module })).resolves.not.toThrow();
|
|
101
|
+
});
|
|
102
|
+
it('works when meta was destructured too', async ({ expect }) => {
|
|
103
|
+
const { module } = getSvelteAST({
|
|
104
|
+
code: `
|
|
105
|
+
<script module>
|
|
106
|
+
import { defineMeta } from "@storybook/addon-svelte-csf"
|
|
107
|
+
const { Story, meta } = defineMeta();
|
|
108
|
+
</script>
|
|
109
|
+
`,
|
|
110
|
+
});
|
|
111
|
+
await expect(extractModuleNodes({ module })).resolves.not.toThrow();
|
|
112
|
+
});
|
|
113
|
+
it('extracts module nodes', async ({ expect }) => {
|
|
114
|
+
const { module } = getSvelteAST({
|
|
115
|
+
code: `
|
|
116
|
+
<script module>
|
|
117
|
+
import { defineMeta } from "@storybook/addon-svelte-csf"
|
|
118
|
+
const { Story } = defineMeta();
|
|
119
|
+
</script>
|
|
120
|
+
`,
|
|
121
|
+
});
|
|
122
|
+
const nodes = await extractModuleNodes({ module });
|
|
123
|
+
expect(nodes.defineMetaImport).toBeDefined();
|
|
124
|
+
expect(nodes.defineMetaImport.imported.name).toBe('defineMeta');
|
|
125
|
+
expect(nodes.defineMetaVariableDeclaration).toBeDefined();
|
|
126
|
+
expect(nodes.storyIdentifier).toBeDefined();
|
|
127
|
+
expect(nodes.storyIdentifier.name).toBe('Story');
|
|
128
|
+
});
|
|
129
|
+
it('extracts module nodes with renamed identifiers', async ({ expect }) => {
|
|
130
|
+
const { module } = getSvelteAST({
|
|
131
|
+
code: `
|
|
132
|
+
<script module>
|
|
133
|
+
import { defineMeta as dm } from "@storybook/addon-svelte-csf"
|
|
134
|
+
const { Story: S, meta: m } = dm();
|
|
135
|
+
</script>
|
|
136
|
+
`,
|
|
137
|
+
});
|
|
138
|
+
const nodes = await extractModuleNodes({ module });
|
|
139
|
+
expect(nodes.defineMetaImport.local.name).toBe('dm');
|
|
140
|
+
expect(nodes.defineMetaVariableDeclaration).toBeDefined();
|
|
141
|
+
expect(nodes.storyIdentifier.name).toBe('S');
|
|
142
|
+
});
|
|
143
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { describe, it } from 'vitest';
|
|
2
|
+
import { extractSvelteASTNodes } from './nodes.js';
|
|
3
|
+
import { getSvelteAST } from '../../ast.js';
|
|
4
|
+
describe(extractSvelteASTNodes.name, () => {
|
|
5
|
+
it('works with a simple example', async ({ expect }) => {
|
|
6
|
+
const ast = getSvelteAST({
|
|
7
|
+
code: `
|
|
8
|
+
<script module>
|
|
9
|
+
import { defineMeta } from "@storybook/addon-svelte-csf"
|
|
10
|
+
|
|
11
|
+
import Button from "./Button.svelte";
|
|
12
|
+
|
|
13
|
+
const { Story, meta } = defineMeta({
|
|
14
|
+
component: Button,
|
|
15
|
+
});
|
|
16
|
+
</script>
|
|
17
|
+
|
|
18
|
+
<Story name="Default" />
|
|
19
|
+
|
|
20
|
+
<Story name="Playground">
|
|
21
|
+
{#snippet template(args)}
|
|
22
|
+
<Button {...args} />
|
|
23
|
+
{/snippet}
|
|
24
|
+
</Story>
|
|
25
|
+
`,
|
|
26
|
+
});
|
|
27
|
+
await expect(extractSvelteASTNodes({ ast })).resolves.not.toThrow();
|
|
28
|
+
});
|
|
29
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest';
|
|
2
|
+
import { extractStoryAttributesNodes } from './attributes.js';
|
|
3
|
+
import { getSvelteAST } from '../../../ast.js';
|
|
4
|
+
import { extractSvelteASTNodes } from '../nodes.js';
|
|
5
|
+
describe(extractStoryAttributesNodes.name, () => {
|
|
6
|
+
it("extracts '<Story />' attributes 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="Default" />
|
|
14
|
+
`,
|
|
15
|
+
});
|
|
16
|
+
const nodes = await extractSvelteASTNodes({ ast });
|
|
17
|
+
const { component } = nodes.storyComponents[0];
|
|
18
|
+
const attributes = extractStoryAttributesNodes({
|
|
19
|
+
component,
|
|
20
|
+
attributes: ['name', 'args'],
|
|
21
|
+
});
|
|
22
|
+
expect(attributes.name).not.toBeUndefined();
|
|
23
|
+
expect(attributes.name?.name).toBe('name');
|
|
24
|
+
expect(attributes.name?.value[0].data).toBe('Default');
|
|
25
|
+
expect(attributes.args).toBeUndefined();
|
|
26
|
+
});
|
|
27
|
+
it('it ignores the attributes of <Story> children components', async () => {
|
|
28
|
+
const ast = getSvelteAST({
|
|
29
|
+
code: `
|
|
30
|
+
<script module>
|
|
31
|
+
import { defineMeta } from "@storybook/addon-svelte-csf"
|
|
32
|
+
const { Story } = defineMeta();
|
|
33
|
+
</script>
|
|
34
|
+
<Story name="Default">
|
|
35
|
+
<Icon name="close" />
|
|
36
|
+
</Story>
|
|
37
|
+
`,
|
|
38
|
+
});
|
|
39
|
+
const nodes = await extractSvelteASTNodes({ ast });
|
|
40
|
+
const { component } = nodes.storyComponents[0];
|
|
41
|
+
const attributes = extractStoryAttributesNodes({
|
|
42
|
+
component,
|
|
43
|
+
attributes: ['name', 'args'],
|
|
44
|
+
});
|
|
45
|
+
expect(attributes.name).not.toBeUndefined();
|
|
46
|
+
expect(attributes.name?.name).toBe('name');
|
|
47
|
+
expect(attributes.name?.value[0].data).toBe('Default');
|
|
48
|
+
expect(attributes.args).toBeUndefined();
|
|
49
|
+
});
|
|
50
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { describe, it } from 'vitest';
|
|
2
|
+
import { extractStoryTemplateSnippetBlock } from './template.js';
|
|
3
|
+
import { getSvelteAST } from '../../../ast.js';
|
|
4
|
+
import { extractSvelteASTNodes } from '../nodes.js';
|
|
5
|
+
describe(extractStoryTemplateSnippetBlock.name, () => {
|
|
6
|
+
it('returns correctly AST node, when a `<Story>` compponent has a snippet block `template` inside', async ({ expect, }) => {
|
|
7
|
+
const code = `
|
|
8
|
+
<script module>
|
|
9
|
+
import { defineMeta } from "@storybook/addon-svelte-csf";
|
|
10
|
+
|
|
11
|
+
import SampleComponent from "./SampleComponent.svelte";
|
|
12
|
+
|
|
13
|
+
const { Story } = defineMeta({
|
|
14
|
+
component: SampleComponent,
|
|
15
|
+
});
|
|
16
|
+
</script>
|
|
17
|
+
|
|
18
|
+
<Story name="With template">
|
|
19
|
+
{#snippet template(args)}
|
|
20
|
+
<SomeComponent {...args} />
|
|
21
|
+
{/snippet}
|
|
22
|
+
</Story>
|
|
23
|
+
`;
|
|
24
|
+
const ast = getSvelteAST({ code });
|
|
25
|
+
const svelteASTNodes = await extractSvelteASTNodes({ ast });
|
|
26
|
+
const { storyComponents } = svelteASTNodes;
|
|
27
|
+
const component = storyComponents[0].component;
|
|
28
|
+
expect(extractStoryTemplateSnippetBlock(component)).toBeDefined();
|
|
29
|
+
expect(extractStoryTemplateSnippetBlock(component)?.expression.name).toBe('template');
|
|
30
|
+
});
|
|
31
|
+
it('returns undefined, when a `<Story>` compponent is a self-closing tag', async ({ expect }) => {
|
|
32
|
+
const code = `
|
|
33
|
+
<script module>
|
|
34
|
+
import { defineMeta } from "@storybook/addon-svelte-csf";
|
|
35
|
+
|
|
36
|
+
import SampleComponent from "./SampleComponent.svelte";
|
|
37
|
+
|
|
38
|
+
const { Story } = defineMeta({
|
|
39
|
+
component: SampleComponent,
|
|
40
|
+
});
|
|
41
|
+
</script>
|
|
42
|
+
|
|
43
|
+
<Story name="Self closing" />
|
|
44
|
+
`;
|
|
45
|
+
const ast = getSvelteAST({ code });
|
|
46
|
+
const svelteASTNodes = await extractSvelteASTNodes({ ast });
|
|
47
|
+
const { storyComponents } = svelteASTNodes;
|
|
48
|
+
const component = storyComponents[0].component;
|
|
49
|
+
expect(extractStoryTemplateSnippetBlock(component)).not.toBeDefined();
|
|
50
|
+
});
|
|
51
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
import { describe, expect, it, vi } from 'vitest';
|
|
2
|
+
import dedent from 'dedent';
|
|
3
|
+
import { generateCodeToEmit } from './emit-code.js';
|
|
4
|
+
describe('Emit Code', () => {
|
|
5
|
+
it('should replace short spread args with single-line props', () => {
|
|
6
|
+
expect(generateCodeToEmit({
|
|
7
|
+
code: '<MyComponent {...args} />',
|
|
8
|
+
args: { someBool: true, someString: 'this is a string' },
|
|
9
|
+
})).toMatchInlineSnapshot(`"<MyComponent someBool someString="this is a string" />"`);
|
|
10
|
+
});
|
|
11
|
+
it('should replace long spread args with multi-line props', () => {
|
|
12
|
+
expect(generateCodeToEmit({
|
|
13
|
+
code: '<MyComponent {...args} />',
|
|
14
|
+
args: {
|
|
15
|
+
someBool: true,
|
|
16
|
+
someString: 'this is a string',
|
|
17
|
+
someNumber: 42,
|
|
18
|
+
someObject: { nested: 'yes', multiple: 'also yes' },
|
|
19
|
+
},
|
|
20
|
+
})).toMatchInlineSnapshot(`
|
|
21
|
+
"<MyComponent
|
|
22
|
+
someBool
|
|
23
|
+
someString="this is a string"
|
|
24
|
+
someNumber={42}
|
|
25
|
+
someObject={{ "nested": "yes", "multiple": "also yes" }}
|
|
26
|
+
/>"
|
|
27
|
+
`);
|
|
28
|
+
});
|
|
29
|
+
it('should replace all types of values', () => {
|
|
30
|
+
expect(generateCodeToEmit({
|
|
31
|
+
code: '<MyComponent {...args} />',
|
|
32
|
+
args: {
|
|
33
|
+
someTrue: true,
|
|
34
|
+
someFalse: false,
|
|
35
|
+
someNull: null,
|
|
36
|
+
someUndefined: undefined,
|
|
37
|
+
someString: 'this is a string',
|
|
38
|
+
someNumber: 42,
|
|
39
|
+
someObject: { nested: 'yes', deep: { nestedDeep: true } },
|
|
40
|
+
someArray: [11, 'some string', { someObj: { nested: 'yes' } }],
|
|
41
|
+
},
|
|
42
|
+
})).toMatchInlineSnapshot(`
|
|
43
|
+
"<MyComponent
|
|
44
|
+
someTrue
|
|
45
|
+
someFalse={false}
|
|
46
|
+
someString="this is a string"
|
|
47
|
+
someNumber={42}
|
|
48
|
+
someObject={{ "nested": "yes", "deep": { "nestedDeep": true } }}
|
|
49
|
+
someArray={[ 11, "some string", { "someObj": { "nested": "yes" } } ]}
|
|
50
|
+
/>"
|
|
51
|
+
`);
|
|
52
|
+
});
|
|
53
|
+
it('should replace args in nested components', () => {
|
|
54
|
+
expect(generateCodeToEmit({
|
|
55
|
+
code: dedent `
|
|
56
|
+
<Top topProp={args.single}>
|
|
57
|
+
<Child {...args}>
|
|
58
|
+
<GrandChild nestedProp={args.other} />
|
|
59
|
+
</Child>
|
|
60
|
+
</Top>`,
|
|
61
|
+
args: {
|
|
62
|
+
single: 'some string',
|
|
63
|
+
aNumber: 42,
|
|
64
|
+
other: { someBool: true, nested: 'yes' },
|
|
65
|
+
},
|
|
66
|
+
})).toMatchInlineSnapshot(`
|
|
67
|
+
"<Top topProp={"some string"}>
|
|
68
|
+
<Child
|
|
69
|
+
single="some string"
|
|
70
|
+
aNumber={42}
|
|
71
|
+
other={{ "someBool": true, "nested": "yes" }}
|
|
72
|
+
>
|
|
73
|
+
<GrandChild nestedProp={{ "someBool": true, "nested": "yes" }} />
|
|
74
|
+
</Child>
|
|
75
|
+
</Top>"
|
|
76
|
+
`);
|
|
77
|
+
});
|
|
78
|
+
it('should replace individually referenced args', () => {
|
|
79
|
+
expect(generateCodeToEmit({
|
|
80
|
+
code: dedent `<MyComponent
|
|
81
|
+
firstProp={args.someString}
|
|
82
|
+
num={args.someNumber}
|
|
83
|
+
nestedBool={args.someObject.someBool}
|
|
84
|
+
nestedOptional={args.someObject?.nested}
|
|
85
|
+
optionalNotExist={args.doesNotExist?.someKey}
|
|
86
|
+
ternaryProp={args.someObject.someBool ? args.yes : args.no}
|
|
87
|
+
>
|
|
88
|
+
{args}
|
|
89
|
+
{args.text}
|
|
90
|
+
{args?.optional?.text}
|
|
91
|
+
{args.someObject["someStringKey"]}
|
|
92
|
+
{args.someObject['someStringKey']}
|
|
93
|
+
{args.someObject['someStringKey'].nested}
|
|
94
|
+
{args.someArray[1]}
|
|
95
|
+
{args.someUnnamedFn}
|
|
96
|
+
{args.someNamedFn}
|
|
97
|
+
{args.someUnnamedMockFn}
|
|
98
|
+
{args.someNamedMockFn}
|
|
99
|
+
{someFunction(args.yes)}
|
|
100
|
+
{someFunction(!args.someObject.someBool ? "literal yes" : args.no)}
|
|
101
|
+
args.shouldNotBeReplacedButIs
|
|
102
|
+
</MyComponent>`,
|
|
103
|
+
args: {
|
|
104
|
+
someIgnoredArg: 'should not show up anywhere',
|
|
105
|
+
someString: 'this is a string',
|
|
106
|
+
someNumber: 42,
|
|
107
|
+
someObject: {
|
|
108
|
+
someBool: true,
|
|
109
|
+
nested: 'yes',
|
|
110
|
+
deep: { shouldAlsoBeIgnored: true },
|
|
111
|
+
someStringKey: { nested: 'deep' },
|
|
112
|
+
},
|
|
113
|
+
someArray: ['first', 'second'],
|
|
114
|
+
someUnnamedFn: () => { },
|
|
115
|
+
someNamedFn: function namedFunc() { },
|
|
116
|
+
someUnnamedMockFn: vi.fn(),
|
|
117
|
+
someNamedMockFn: vi.fn().mockName('namedMockFn'),
|
|
118
|
+
yes: 'yup',
|
|
119
|
+
no: 'nope',
|
|
120
|
+
text: 'some text',
|
|
121
|
+
optional: { text: 'optional text' },
|
|
122
|
+
},
|
|
123
|
+
})).toMatchInlineSnapshot(`
|
|
124
|
+
"<MyComponent
|
|
125
|
+
firstProp={"this is a string"}
|
|
126
|
+
num={42}
|
|
127
|
+
nestedBool={true}
|
|
128
|
+
nestedOptional={"yes"}
|
|
129
|
+
optionalNotExist={undefined}
|
|
130
|
+
ternaryProp={true ? "yup" : "nope"}
|
|
131
|
+
>
|
|
132
|
+
{args}
|
|
133
|
+
{"some text"}
|
|
134
|
+
{"optional text"}
|
|
135
|
+
{{ "nested": "deep" }}
|
|
136
|
+
{{ "nested": "deep" }}
|
|
137
|
+
{"deep"}
|
|
138
|
+
{"second"}
|
|
139
|
+
{someUnnamedFn}
|
|
140
|
+
{namedFunc}
|
|
141
|
+
{vi.fn()}
|
|
142
|
+
{namedMockFn}
|
|
143
|
+
{someFunction("yup")}
|
|
144
|
+
{someFunction(!true ? "literal yes" : "nope")}
|
|
145
|
+
undefined
|
|
146
|
+
</MyComponent>"
|
|
147
|
+
`);
|
|
148
|
+
});
|
|
149
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { it, expect } from 'vitest';
|
|
2
|
+
import { storyIdToExportName, exportNameToStoryId, storyNameToId, storyNameToExportName, } from './identifier-utils.js';
|
|
3
|
+
it('storyIdToExportName', () => {
|
|
4
|
+
expect(storyIdToExportName('single')).toBe('Single');
|
|
5
|
+
expect(storyIdToExportName('multiple-parts')).toBe('MultipleParts');
|
|
6
|
+
});
|
|
7
|
+
it('exportNameToStoryId', () => {
|
|
8
|
+
expect(exportNameToStoryId('Single')).toBe('single');
|
|
9
|
+
expect(exportNameToStoryId('MultipleParts')).toBe('multiple-parts');
|
|
10
|
+
});
|
|
11
|
+
it('storyNameToId', () => {
|
|
12
|
+
expect(storyNameToId('simple')).toBe('simple');
|
|
13
|
+
expect(storyNameToId('PascalCase')).toBe('pascal-case');
|
|
14
|
+
expect(storyNameToId('Start Case')).toBe('start-case');
|
|
15
|
+
expect(storyNameToId('With 2 illegal !! characters, a PascalCase and an ?')).toBe('with-2-illegal-characters-a-pascal-case-and-an');
|
|
16
|
+
});
|
|
17
|
+
it('storyNameToExportName', () => {
|
|
18
|
+
expect(storyNameToExportName('simple')).toBe('Simple');
|
|
19
|
+
expect(storyNameToExportName('PascalCase')).toBe('PascalCase');
|
|
20
|
+
expect(storyNameToExportName('Start Case')).toBe('StartCase');
|
|
21
|
+
expect(storyNameToExportName('With 2 illegal !! characters, a PascalCase and an ?')).toBe('With2IllegalCharactersAPascalCaseAndAn');
|
|
22
|
+
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@storybook/addon-svelte-csf",
|
|
3
|
-
"version": "5.1.
|
|
3
|
+
"version": "5.1.2",
|
|
4
4
|
"description": "Allows to write stories in Svelte syntax",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"storybook-addons",
|
|
@@ -35,22 +35,6 @@
|
|
|
35
35
|
"preset.js",
|
|
36
36
|
"README.md"
|
|
37
37
|
],
|
|
38
|
-
"scripts": {
|
|
39
|
-
"build": "svelte-package --types",
|
|
40
|
-
"build-storybook": "storybook build",
|
|
41
|
-
"check": "svelte-check",
|
|
42
|
-
"chromatic": "chromatic --exit-zero-on-changes",
|
|
43
|
-
"clean": "rimraf ./dist ./node_modules/.cache ./storybook-static ./svelte-kit ./.vite-inspect",
|
|
44
|
-
"coverage": "vitest run --coverage",
|
|
45
|
-
"format": "prettier --write .",
|
|
46
|
-
"format:check": "prettier --check .",
|
|
47
|
-
"lint": "eslint . --cache --cache-location=\"./node_modules/.cache\"",
|
|
48
|
-
"prepublish": "pnpm run clean && pnpm run build",
|
|
49
|
-
"release": "pnpm run build && auto shipit",
|
|
50
|
-
"start": "pnpm run build && concurrently \"pnpm run build --watch\" \"pnpm run storybook --quiet\"",
|
|
51
|
-
"storybook": "storybook dev --port 6006 --no-open",
|
|
52
|
-
"test": "vitest"
|
|
53
|
-
},
|
|
54
38
|
"dependencies": {
|
|
55
39
|
"@storybook/csf": "^0.1.13",
|
|
56
40
|
"dedent": "^1.5.3",
|
|
@@ -61,7 +45,8 @@
|
|
|
61
45
|
"zimmerframe": "^1.1.2"
|
|
62
46
|
},
|
|
63
47
|
"devDependencies": {
|
|
64
|
-
"@
|
|
48
|
+
"@changesets/changelog-github": "^0.5.1",
|
|
49
|
+
"@changesets/cli": "^2.29.6",
|
|
65
50
|
"@chromatic-com/storybook": "^5.0.2",
|
|
66
51
|
"@eslint/compat": "^1.2.8",
|
|
67
52
|
"@eslint/js": "^9.25.0",
|
|
@@ -77,13 +62,13 @@
|
|
|
77
62
|
"@vitest/browser-playwright": "^4.1.0",
|
|
78
63
|
"@vitest/coverage-v8": "^4.1.0",
|
|
79
64
|
"@vitest/ui": "^4.1.0",
|
|
80
|
-
"auto": "^11.3.6",
|
|
81
65
|
"chromatic": "^15.1.0",
|
|
82
66
|
"concurrently": "^9.2.1",
|
|
83
67
|
"eslint": "^9.25.0",
|
|
84
68
|
"eslint-plugin-storybook": "^10.3.0",
|
|
85
69
|
"eslint-plugin-svelte": "^3.15.0",
|
|
86
70
|
"happy-dom": "^20.6.1",
|
|
71
|
+
"pkg-pr-new": "^0.0.57",
|
|
87
72
|
"playwright": "^1.58.2",
|
|
88
73
|
"prettier": "^3.8.1",
|
|
89
74
|
"prettier-plugin-svelte": "^3.4.1",
|
|
@@ -108,15 +93,9 @@
|
|
|
108
93
|
"svelte": "^5.0.0",
|
|
109
94
|
"vite": "^5.0.0 || ^6.0.0 || ^7.0.0 || ^8.0.0"
|
|
110
95
|
},
|
|
111
|
-
"packageManager": "pnpm@10.18.0+sha512.e804f889f1cecc40d572db084eec3e4881739f8dec69c0ff10d2d1beff9a4e309383ba27b5b750059d7f4c149535b6cd0d2cb1ed3aeb739239a4284a68f40cfa",
|
|
112
96
|
"publishConfig": {
|
|
113
|
-
"access": "public"
|
|
114
|
-
|
|
115
|
-
"auto": {
|
|
116
|
-
"plugins": [
|
|
117
|
-
"npm",
|
|
118
|
-
"released"
|
|
119
|
-
]
|
|
97
|
+
"access": "public",
|
|
98
|
+
"provenance": true
|
|
120
99
|
},
|
|
121
100
|
"storybook": {
|
|
122
101
|
"displayName": "Svelte CSF",
|
|
@@ -124,5 +103,22 @@
|
|
|
124
103
|
"svelte"
|
|
125
104
|
],
|
|
126
105
|
"icon": "https://user-images.githubusercontent.com/321738/63501763-88dbf600-c4cc-11e9-96cd-94adadc2fd72.png"
|
|
106
|
+
},
|
|
107
|
+
"scripts": {
|
|
108
|
+
"build": "svelte-package --types",
|
|
109
|
+
"build-storybook": "storybook build",
|
|
110
|
+
"check": "svelte-check",
|
|
111
|
+
"chromatic": "chromatic --exit-zero-on-changes",
|
|
112
|
+
"clean": "rimraf ./dist ./node_modules/.cache ./storybook-static ./svelte-kit ./.vite-inspect",
|
|
113
|
+
"coverage": "vitest run --coverage",
|
|
114
|
+
"format": "prettier --write .",
|
|
115
|
+
"format:check": "prettier --check .",
|
|
116
|
+
"lint": "eslint . --cache --cache-location=\"./node_modules/.cache\"",
|
|
117
|
+
"prepublish": "pnpm run clean && pnpm run build",
|
|
118
|
+
"release": "pnpm changeset publish",
|
|
119
|
+
"start": "pnpm run build && concurrently \"pnpm run build --watch\" \"pnpm run storybook --quiet\"",
|
|
120
|
+
"storybook": "storybook dev --port 6006 --no-open",
|
|
121
|
+
"test": "vitest",
|
|
122
|
+
"changeset": "changeset"
|
|
127
123
|
}
|
|
128
|
-
}
|
|
124
|
+
}
|