Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Story index: Warn on storyName in CSF3 exports #18464

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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