Warn when storyName usage is detected in CSF3 stories

This commit is contained in:
joshwooding 2022-06-12 00:40:32 +01:00
parent b2f4390c05
commit 084043e46f
No known key found for this signature in database
GPG Key ID: B496BB89A7E00330
2 changed files with 23 additions and 0 deletions

View File

@ -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();
});
});
});

View File

@ -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;
}