diff --git a/lib/csf-tools/src/CsfFile.test.ts b/lib/csf-tools/src/CsfFile.test.ts index 6bfa3245610..80d2bc2ca05 100644 --- a/lib/csf-tools/src/CsfFile.test.ts +++ b/lib/csf-tools/src/CsfFile.test.ts @@ -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(); + }); }); }); diff --git a/lib/csf-tools/src/CsfFile.ts b/lib/csf-tools/src/CsfFile.ts index 3d38d6a2f93..88a8fbd5eec 100644 --- a/lib/csf-tools/src/CsfFile.ts +++ b/lib/csf-tools/src/CsfFile.ts @@ -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; }