Skip to content

Commit

Permalink
Merge pull request #18464 from joshwooding/fix-csf3-storyName-storySt…
Browse files Browse the repository at this point in the history
…oreV7

Story index: Warn on `storyName` in CSF3 exports
  • Loading branch information
shilman committed Jun 12, 2022
1 parent ab44e4c commit 85280ea
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
19 changes: 19 additions & 0 deletions lib/csf-tools/src/CsfFile.test.ts
Expand Up @@ -613,5 +613,24 @@ describe('CsfFile', () => {
__id: foo-bar--a
`);
});

it('Object export with storyName', () => {
const consoleWarnMock = jest.spyOn(console, 'warn').mockImplementation();

parse(
dedent`
export default { title: 'foo/bar' };
export const A = {
storyName: 'Apple'
}
`,
true
);

expect(consoleWarnMock).toHaveBeenCalledWith(
'Unexpected usage of "storyName" in "A". Please use "name" instead.'
);
consoleWarnMock.mockRestore();
});
});
});
4 changes: 4 additions & 0 deletions lib/csf-tools/src/CsfFile.ts
Expand Up @@ -268,6 +268,10 @@ export class CsfFile {
__isArgsStory = isArgsStory(p.value as t.Expression, parent, self);
} else if (p.key.name === 'name' && t.isStringLiteral(p.value)) {
name = p.value.value;
} else if (p.key.name === 'storyName' && t.isStringLiteral(p.value)) {
logger.warn(
`Unexpected usage of "storyName" in "${exportName}". Please use "name" instead.`
);
}
self._storyAnnotations[exportName][p.key.name] = p.value;
}
Expand Down

0 comments on commit 85280ea

Please sign in to comment.