Skip to content

Commit 4ea1f69

Browse files
committed
test: update
1 parent 2fcd379 commit 4ea1f69

File tree

5 files changed

+103
-72
lines changed

5 files changed

+103
-72
lines changed

src/compiler/post-transform/appendix/create-export-order.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import { print } from 'esrap';
22
import { describe, it } from 'vitest';
33

4-
import { createExportOrderVariable } from './create-export-order.js';
4+
import { createExportOrderVariableDeclaration } from './create-export-order.js';
55

6-
describe(createExportOrderVariable.name, () => {
6+
describe(createExportOrderVariableDeclaration.name, () => {
77
it('correctly creates a variable with named exports order', ({ expect }) => {
88
const stringified = print(
9-
createExportOrderVariable({
10-
storyIdentifiers: [
9+
createExportOrderVariableDeclaration({
10+
storiesIdentifiers: [
1111
{ exportName: 'Default', name: 'Default' },
1212
{ exportName: 'SomeComponent', name: 'Some Component' },
1313
{ exportName: 'ThisNameIsWeird', name: 'This-Name-Is-Weird' },
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import { print } from 'esrap';
2+
import { describe, it } from 'vitest';
3+
4+
import { createNamedExportStories } from './create-named-export-stories.js';
5+
6+
describe(createNamedExportStories, () => {
7+
it('works', ({ expect }) => {
8+
const namedExportDeclaration = createNamedExportStories({
9+
storiesIdentifiers: [
10+
{
11+
exportName: 'Default',
12+
name: undefined,
13+
},
14+
{
15+
exportName: 'Primary',
16+
name: 'Primary',
17+
},
18+
{
19+
exportName: 'Secondary',
20+
name: 'Secondary',
21+
},
22+
{
23+
exportName: 'Disabled',
24+
name: 'Disabled',
25+
},
26+
],
27+
});
28+
29+
expect(print(namedExportDeclaration).code).toMatchInlineSnapshot(`
30+
"export {
31+
$__Default as Default,
32+
$__Primary as Primary,
33+
$__Secondary as Secondary,
34+
$__Disabled as Disabled
35+
};"
36+
`);
37+
});
38+
});

src/compiler/post-transform/appendix/create-named-export-story.test.ts renamed to src/compiler/post-transform/appendix/create-runtime-story-variable-declaration.test.ts

Lines changed: 41 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,22 @@
11
import { print } from 'esrap';
22
import { describe, it } from 'vitest';
33

4-
import { createNamedExportStory } from './create-named-export-story.js';
5-
import { createVariableFromRuntimeStoriesCall } from './create-variable-from-runtime-stories-call.js';
4+
import { createASTArrayExpression, createASTIdentifier } from '$lib/parser/ast.js';
5+
import { SVELTE_CSF_V4_TAG } from '$lib/constants.js';
66

7-
import type { ESTreeAST } from '$lib/parser/ast.js';
8-
import { SVELTE_CSF_V4_TAG } from '../../../constants.js';
7+
import { createRuntimeStoryVariableDeclaration } from './create-runtime-story-variable-declaration.js';
8+
import { createVariableFromRuntimeStoriesCall } from './create-variable-from-runtime-stories-call.js';
99

10-
describe(createNamedExportStory.name, () => {
11-
it('correctly creates a variable with named exports order', ({ expect }) => {
10+
describe(createRuntimeStoryVariableDeclaration, () => {
11+
it('correctly creates a runtime story variable', ({ expect }) => {
1212
const stringified = print(
13-
createNamedExportStory({
13+
createRuntimeStoryVariableDeclaration({
1414
exportName: 'Default',
1515
nodes: {
1616
variable: createVariableFromRuntimeStoriesCall({
1717
storiesFunctionDeclaration: {
1818
type: 'FunctionDeclaration',
19-
id: {
20-
type: 'Identifier',
21-
name: 'Example_stories',
22-
},
19+
id: createASTIdentifier('Example_stories'),
2320
body: {
2421
type: 'BlockStatement',
2522
body: [],
@@ -28,13 +25,13 @@ describe(createNamedExportStory.name, () => {
2825
},
2926
}),
3027
},
31-
}) as unknown as ESTreeAST.Program
28+
})
3229
).code;
3330

3431
expect(stringified).toMatchInlineSnapshot(
3532
`
36-
"export const Default = {
37-
...__stories["Default"],
33+
"const $__Default = {
34+
...$__stories["Default"],
3835
tags: ["svelte-csf-v5"]
3936
};"
4037
`
@@ -43,44 +40,38 @@ describe(createNamedExportStory.name, () => {
4340

4441
it('allows passing Story-level tags', ({ expect }) => {
4542
const stringified = print(
46-
createNamedExportStory({
43+
createRuntimeStoryVariableDeclaration({
4744
exportName: 'Default',
4845
nodes: {
4946
variable: createVariableFromRuntimeStoriesCall({
5047
storiesFunctionDeclaration: {
5148
type: 'FunctionDeclaration',
52-
id: {
53-
type: 'Identifier',
54-
name: 'Example_stories',
55-
},
49+
id: createASTIdentifier('Example_stories'),
5650
body: {
5751
type: 'BlockStatement',
5852
body: [],
5953
},
6054
params: [],
6155
},
6256
}),
63-
tags: {
64-
type: 'ArrayExpression',
65-
elements: [
66-
{
67-
type: 'Literal',
68-
value: 'autodocs',
69-
},
70-
{
71-
type: 'Literal',
72-
value: '!test',
73-
},
74-
],
75-
},
57+
tags: createASTArrayExpression([
58+
{
59+
type: 'Literal',
60+
value: 'autodocs',
61+
},
62+
{
63+
type: 'Literal',
64+
value: '!test',
65+
},
66+
]),
7667
},
77-
}) as unknown as ESTreeAST.Program
68+
})
7869
).code;
7970

8071
expect(stringified).toMatchInlineSnapshot(
8172
`
82-
"export const Default = {
83-
...__stories["Default"],
73+
"const $__Default = {
74+
...$__stories["Default"],
8475
tags: ["autodocs", "!test", "svelte-csf-v5"]
8576
};"
8677
`
@@ -89,44 +80,38 @@ describe(createNamedExportStory.name, () => {
8980

9081
it('keeps Svelte CSF v4 tag if present, and does not add Svelte CSF v5 tag', ({ expect }) => {
9182
const stringified = print(
92-
createNamedExportStory({
83+
createRuntimeStoryVariableDeclaration({
9384
exportName: 'Default',
9485
nodes: {
9586
variable: createVariableFromRuntimeStoriesCall({
9687
storiesFunctionDeclaration: {
9788
type: 'FunctionDeclaration',
98-
id: {
99-
type: 'Identifier',
100-
name: 'Example_stories',
101-
},
89+
id: createASTIdentifier('Example_stories'),
10290
body: {
10391
type: 'BlockStatement',
10492
body: [],
10593
},
10694
params: [],
10795
},
10896
}),
109-
tags: {
110-
type: 'ArrayExpression',
111-
elements: [
112-
{
113-
type: 'Literal',
114-
value: 'autodocs',
115-
},
116-
{
117-
type: 'Literal',
118-
value: SVELTE_CSF_V4_TAG,
119-
},
120-
],
121-
},
97+
tags: createASTArrayExpression([
98+
{
99+
type: 'Literal',
100+
value: 'autodocs',
101+
},
102+
{
103+
type: 'Literal',
104+
value: SVELTE_CSF_V4_TAG,
105+
},
106+
]),
122107
},
123-
}) as unknown as ESTreeAST.Program
108+
})
124109
).code;
125110

126111
expect(stringified).toMatchInlineSnapshot(
127112
`
128-
"export const Default = {
129-
...__stories["Default"],
113+
"const $__Default = {
114+
...$__stories["Default"],
130115
tags: ["autodocs", "svelte-csf-v4"]
131116
};"
132117
`

src/compiler/post-transform/appendix/create-variable-from-runtime-stories-call.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ describe(createVariableFromRuntimeStoriesCall.name, () => {
2323
).code;
2424

2525
expect(stringified).toMatchInlineSnapshot(
26-
`"const __stories = createRuntimeStories(Example_stories, $__meta);"`
26+
`"const $__stories = createRuntimeStories(Example_stories, $__meta);"`
2727
);
2828
});
2929
});

src/compiler/post-transform/index.test.ts

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ describe(transformStoriesCode.name, () => {
254254
255255
import { createRuntimeStories } from "@storybook/addon-svelte-csf/internal/create-runtime-stories";
256256
257-
const __stories = createRuntimeStories(Example_stories, $__meta);
257+
const $__stories = createRuntimeStories(Example_stories, $__meta);
258258
259259
export default $__meta;
260260
@@ -266,29 +266,37 @@ describe(transformStoriesCode.name, () => {
266266
"ChildrenForwared"
267267
];
268268
269-
export const Default = {
270-
...__stories["Default"],
269+
const $__Default = {
270+
...$__stories["Default"],
271271
tags: ["svelte-csf-v5"]
272272
};
273273
274-
export const Rounded = {
275-
...__stories["Rounded"],
274+
const $__Rounded = {
275+
...$__stories["Rounded"],
276276
tags: ["svelte-csf-v5"]
277277
};
278278
279-
export const Square = {
280-
...__stories["Square"],
279+
const $__Square = {
280+
...$__stories["Square"],
281281
tags: ["svelte-csf-v5"]
282282
};
283283
284-
export const AsChild = {
285-
...__stories["AsChild"],
284+
const $__AsChild = {
285+
...$__stories["AsChild"],
286286
tags: ["svelte-csf-v5"]
287287
};
288288
289-
export const ChildrenForwared = {
290-
...__stories["ChildrenForwared"],
289+
const $__ChildrenForwared = {
290+
...$__stories["ChildrenForwared"],
291291
tags: ["svelte-csf-v5"]
292+
};
293+
294+
export {
295+
$__Default as Default,
296+
$__Rounded as Rounded,
297+
$__Square as Square,
298+
$__AsChild as AsChild,
299+
$__ChildrenForwared as ChildrenForwared
292300
};"
293301
`
294302
);

0 commit comments

Comments
 (0)