CsfFile: Improve meta error handling and fix failing test

This commit is contained in:
Michael Shilman 2025-01-07 01:41:37 +08:00
parent 84f2ae609c
commit 3753cde16c
2 changed files with 14 additions and 6 deletions

View File

@ -2408,7 +2408,7 @@ describe('CsfFile', () => {
`);
});
it.only('local defineConfig', () => {
it('local defineConfig', () => {
expect(() =>
parse(
dedent`

View File

@ -521,11 +521,19 @@ export class CsfFile {
self._options.fileName
);
} else if (!self._metaIsFactory && storyIsFactory) {
throw new BadMetaError(
'meta() factory must be imported from .storybook/preview configuration',
storyNode as t.Node,
self._options.fileName
);
if (self._metaNode) {
throw new MixedFactoryError(
'expected non-factory story',
storyNode as t.Node,
self._options.fileName
);
} else {
throw new BadMetaError(
'meta() factory must be imported from .storybook/preview configuration',
storyNode as t.Node,
self._options.fileName
);
}
}
const parameters: { [key: string]: any } = {};
if (t.isObjectExpression(storyNode)) {