Skip to content

Commit

Permalink
throw an error with unexpected node value
Browse files Browse the repository at this point in the history
  • Loading branch information
yannbf committed Jan 19, 2023
1 parent b59bee6 commit 9c541c8
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
8 changes: 5 additions & 3 deletions code/lib/csf-tools/src/ConfigFile.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -768,15 +768,15 @@ describe('ConfigFile', () => {
import type { StorybookConfig } from '@storybook/react-webpack5';
const config: StorybookConfig = {
framework: { name: 'foo', options: {} },
framework: { name: 'foo', options: { bar: require('baz') } },
}
export default config;
`;
const config = loadConfig(source).parse();
expect(config.getNameFromPath(['framework'])).toEqual('foo');
});

it(`returns undefined with unexpected node value`, () => {
it(`throws an error with unexpected node value`, () => {
const source = dedent`
import type { StorybookConfig } from '@storybook/react-webpack5';
Expand All @@ -786,7 +786,9 @@ describe('ConfigFile', () => {
export default config;
`;
const config = loadConfig(source).parse();
expect(config.getNameFromPath(['framework'])).toBeUndefined();
expect(() => config.getNameFromPath(['framework'])).toThrowError(
`The given node must be a string literal or an object expression with a "name" property that is a string literal.`
);
});
});

Expand Down
6 changes: 6 additions & 0 deletions code/lib/csf-tools/src/ConfigFile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,12 @@ export class ConfigFile {
});
}

if (!value) {
throw new Error(
`The given node must be a string literal or an object expression with a "${fallbackProperty}" property that is a string literal.`
);
}

return value;
}

Expand Down

0 comments on commit 9c541c8

Please sign in to comment.