From 084043e46ff3c782d55d89ea0983e2e36fd64e89 Mon Sep 17 00:00:00 2001 From: joshwooding <12938082+joshwooding@users.noreply.github.com> Date: Sun, 12 Jun 2022 00:40:32 +0100 Subject: [PATCH] Warn when storyName usage is detected in CSF3 stories --- lib/csf-tools/src/CsfFile.test.ts | 19 +++++++++++++++++++ lib/csf-tools/src/CsfFile.ts | 4 ++++ 2 files changed, 23 insertions(+) diff --git a/lib/csf-tools/src/CsfFile.test.ts b/lib/csf-tools/src/CsfFile.test.ts index 6bfa32456104..80d2bc2ca052 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 3d38d6a2f93d..88a8fbd5eec3 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; }