Skip to content

Commit

Permalink
update error message test snapshots
Browse files Browse the repository at this point in the history
  • Loading branch information
JReinhold committed Jul 11, 2024
1 parent c0e0ff7 commit 51b6318
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 23 deletions.
3 changes: 2 additions & 1 deletion src/compiler/transform/remove-export-default.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { describe, it } from 'vitest';
import { removeExportDefault } from './remove-export-default';

import { extractCompiledASTNodes } from '#parser/extract/compiled/nodes';
import { StorybookSvelteCSFError } from '#utils/error';

const __dirname = path.dirname(url.fileURLToPath(import.meta.url));

Expand Down Expand Up @@ -36,7 +37,7 @@ describe(removeExportDefault.name, () => {
`
[SB_SVELTE_CSF_PARSER_EXTRACT_COMPILED_0003 (NoExportDefaultError): Could not find 'export default' in the compiled output of the stories file: <path not specified>
More info: https://github.com/storybookjs/addon-svelte-csf/blob/v4.1.2/ERRORS.md#SB_SVELTE_CSF_PARSER_EXTRACT_COMPILED_0003
More info: https://github.com/storybookjs/addon-svelte-csf/blob/v${StorybookSvelteCSFError.packageVersion}/ERRORS.md#SB_SVELTE_CSF_PARSER_EXTRACT_COMPILED_0003
]
`
);
Expand Down
34 changes: 20 additions & 14 deletions src/parser/analyse/story/attributes.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { getArrayOfStringsValueFromAttribute, getStringValueFromAttribute } from
import { getSvelteAST } from '#parser/ast';
import { extractSvelteASTNodes } from '#parser/extract/svelte/nodes';
import { extractStoryAttributesNodes } from '#parser/extract/svelte/story/attributes';
import { StorybookSvelteCSFError } from '#utils/error';

describe(getStringValueFromAttribute.name, () => {
it("throws error when a `<Story />` 'name' attribute value is not a string", async ({
Expand Down Expand Up @@ -34,10 +35,12 @@ describe(getStringValueFromAttribute.name, () => {

expect(() => getStringValueFromAttribute({ component, node: name }))
.toThrowErrorMatchingInlineSnapshot(`
[SB_SVELTE_CSF_PARSER_ANALYSE_STORY_0001 (AttributeNotStringError): Invalid schema.
In the stories file: <path not specified>
[SB_SVELTE_CSF_PARSER_ANALYSE_STORY_0001 (AttributeNotStringError): In the stories file: <path not specified>
A '<Story name="<unspecified Story name>" />' has an attribute 'name' whose value was expected to be a static literal string.]
A '<Story name="<unspecified Story name>" />' has a prop 'name' whose value must be a static literal string.
More info: https://github.com/storybookjs/addon-svelte-csf/blob/v${StorybookSvelteCSFError.packageVersion}/ERRORS.md#SB_SVELTE_CSF_PARSER_ANALYSE_STORY_0001
]
`);
});
});
Expand Down Expand Up @@ -72,12 +75,14 @@ describe(getArrayOfStringsValueFromAttribute.name, () => {
getArrayOfStringsValueFromAttribute({ component, node: tags })
).toThrowErrorMatchingInlineSnapshot(
`
[SB_SVELTE_CSF_PARSER_ANALYSE_STORY_0002 (AttributeNotArrayError): Invalid schema.
In the stories file: <path not specified>
[SB_SVELTE_CSF_PARSER_ANALYSE_STORY_0002 (AttributeNotArrayError): In the stories file: <path not specified>
A '<Story name="Default" />' has a prop'tags' whose value was expected to be a static array.
Instead the value type is '0'.
A '<Story name="Default" />' has attribute 'tags' whose value was expected to be an array expression.
Instead the value type is '0'.]
`
More info: https://github.com/storybookjs/addon-svelte-csf/blob/v${StorybookSvelteCSFError.packageVersion}/ERRORS.md#SB_SVELTE_CSF_PARSER_ANALYSE_STORY_0002
]
`
);
});

Expand Down Expand Up @@ -110,13 +115,14 @@ describe(getArrayOfStringsValueFromAttribute.name, () => {
getArrayOfStringsValueFromAttribute({ component, node: tags })
).toThrowErrorMatchingInlineSnapshot(
`
[SB_SVELTE_CSF_PARSER_ANALYSE_STORY_0003 (AttributeNotArrayOfStringsError): Invalid schema.
In the stories file: <path not specified>
[SB_SVELTE_CSF_PARSER_ANALYSE_STORY_0003 (AttributeNotArrayOfStringsError): In the stories file: <path not specified>
A '<Story name="Default" />' has attribute 'tags' whose value was expected to be an array expression.
All elements in the array must be static literal strings only, but one of the elements is of type 'undefined'.
A '<Story name="Default" />' has attribute 'tags' whose value was expected to be an array expression.
And this array elements are supposed to be static literal strings only.
One of the elements has a type 'undefined']
`
More info: https://github.com/storybookjs/addon-svelte-csf/blob/v${StorybookSvelteCSFError.packageVersion}/ERRORS.md#SB_SVELTE_CSF_PARSER_ANALYSE_STORY_0003
]
`
);
});

Expand Down
21 changes: 17 additions & 4 deletions src/parser/analyse/story/attributes/identifiers.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { getStoryIdentifiers, getStoriesIdentifiers } from './identifiers';
import { getSvelteAST } from '#parser/ast';
import { extractSvelteASTNodes } from '#parser/extract/svelte/nodes';
import { extractStoryAttributesNodes } from '#parser/extract/svelte/story/attributes';
import { StorybookSvelteCSFError } from '#utils/error';

describe(getStoryIdentifiers.name, () => {
it("extracts 'exportName' attribute when is a Text string", async () => {
Expand Down Expand Up @@ -92,7 +93,10 @@ describe(getStoryIdentifiers.name, () => {
).toThrowErrorMatchingInlineSnapshot(
`
[SB_SVELTE_CSF_PARSER_ANALYSE_STORY_0004 (NoStoryIdentifierError): Missing 'name' or 'exportName' attribute (prop) in a '<Story />' definition in the stories file: 'file://${process.cwd()}/invalid.stories.svelte'.
All stories must either have a 'name' or an 'exportName' prop.]
All stories must either have a 'name' or an 'exportName' prop, or both.
More info: https://github.com/storybookjs/addon-svelte-csf/blob/v${StorybookSvelteCSFError.packageVersion}/ERRORS.md#SB_SVELTE_CSF_PARSER_ANALYSE_STORY_0004
]
`
);
});
Expand Down Expand Up @@ -216,7 +220,10 @@ describe(getStoryIdentifiers.name, () => {
'exportName' value must be a valid JavaScript variable name.
It must start with a letter, $ or _, followed by letters, numbers, $ or _.
Reserved words like 'default' are also not allowed (see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Lexical_grammar#reserved_words)]
Reserved words like 'default' are also not allowed (see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Lexical_grammar#reserved_words)
More info: https://github.com/storybookjs/addon-svelte-csf/blob/v${StorybookSvelteCSFError.packageVersion}/ERRORS.md#SB_SVELTE_CSF_PARSER_ANALYSE_STORY_0005
]
`
);
});
Expand Down Expand Up @@ -289,7 +296,10 @@ describe(getStoriesIdentifiers.name, () => {
This can happen when 'exportName' is implicitly derived by 'name'.
Complex names will be simplified to a PascalCased, valid JavaScript variable name,
eg. 'Some story name!!' will be converted to 'SomeStoryName'.
You can fix this collision by providing a unique 'exportName' prop with <Story exportName="SomeUniqueExportName" ... />.]
You can fix this collision by providing a unique 'exportName' prop with <Story exportName="SomeUniqueExportName" ... />.
More info: https://github.com/storybookjs/addon-svelte-csf/blob/v${StorybookSvelteCSFError.packageVersion}/ERRORS.md#SB_SVELTE_CSF_PARSER_ANALYSE_STORY_0006
]
`
);
});
Expand Down Expand Up @@ -322,7 +332,10 @@ describe(getStoriesIdentifiers.name, () => {
This can happen when 'exportName' is implicitly derived by 'name'.
Complex names will be simplified to a PascalCased, valid JavaScript variable name,
eg. 'Some story name!!' will be converted to 'SomeStoryName'.
You can fix this collision by providing a unique 'exportName' prop with <Story exportName="SomeUniqueExportName" ... />.]
You can fix this collision by providing a unique 'exportName' prop with <Story exportName="SomeUniqueExportName" ... />.
More info: https://github.com/storybookjs/addon-svelte-csf/blob/v${StorybookSvelteCSFError.packageVersion}/ERRORS.md#SB_SVELTE_CSF_PARSER_ANALYSE_STORY_0006
]
`
);
});
Expand Down
9 changes: 5 additions & 4 deletions src/parser/extract/svelte/module-nodes.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { describe, it } from 'vitest';
import { extractModuleNodes } from './module-nodes';

import { getSvelteAST } from '#parser/ast';
import { StorybookSvelteCSFError } from '#utils/error';

describe(extractModuleNodes.name, () => {
it('fails when module tag not found', ({ expect }) => {
Expand All @@ -22,7 +23,7 @@ describe(extractModuleNodes.name, () => {
const { Story } = defineMeta({});
</script>
More info: https://github.com/storybookjs/addon-svelte-csf/blob/v4.1.2/ERRORS.md#SB_SVELTE_CSF_PARSER_EXTRACT_SVELTE_0001
More info: https://github.com/storybookjs/addon-svelte-csf/blob/v${StorybookSvelteCSFError.packageVersion}/ERRORS.md#SB_SVELTE_CSF_PARSER_EXTRACT_SVELTE_0001
]
`);
});
Expand All @@ -44,7 +45,7 @@ describe(extractModuleNodes.name, () => {
const { Story } = defineMeta({});
</script>
More info: https://github.com/storybookjs/addon-svelte-csf/blob/v4.1.2/ERRORS.md#SB_SVELTE_CSF_PARSER_EXTRACT_SVELTE_0003
More info: https://github.com/storybookjs/addon-svelte-csf/blob/v${StorybookSvelteCSFError.packageVersion}/ERRORS.md#SB_SVELTE_CSF_PARSER_EXTRACT_SVELTE_0003
]
`);
});
Expand All @@ -69,7 +70,7 @@ describe(extractModuleNodes.name, () => {
const { Story } = defineMeta({});
</script>
More info: https://github.com/storybookjs/addon-svelte-csf/blob/v4.1.2/ERRORS.md#SB_SVELTE_CSF_PARSER_EXTRACT_SVELTE_0004
More info: https://github.com/storybookjs/addon-svelte-csf/blob/v${StorybookSvelteCSFError.packageVersion}/ERRORS.md#SB_SVELTE_CSF_PARSER_EXTRACT_SVELTE_0004
]
`);
});
Expand All @@ -94,7 +95,7 @@ describe(extractModuleNodes.name, () => {
const { Story } = defineMeta({});
</script>
More info: https://github.com/storybookjs/addon-svelte-csf/blob/v4.1.2/ERRORS.md#SB_SVELTE_CSF_PARSER_EXTRACT_SVELTE_0004
More info: https://github.com/storybookjs/addon-svelte-csf/blob/v${StorybookSvelteCSFError.packageVersion}/ERRORS.md#SB_SVELTE_CSF_PARSER_EXTRACT_SVELTE_0004
]
`);
});
Expand Down

0 comments on commit 51b6318

Please sign in to comment.