Core: Error when namedExportsOrder causes story to disappear

This commit is contained in:
Michael Shilman 2022-03-08 19:08:21 +08:00
parent 7c87145792
commit 89e30ffef1
2 changed files with 10 additions and 10 deletions

View File

@ -47,13 +47,3 @@ CSF2StoryWithPlay.play = () => {
console.log('play!!');
userEvent.click(screen.getByRole('button'));
};
// eslint-disable-next-line no-underscore-dangle
export const __namedExportsOrder = [
'Basic',
'WithArgs',
'StoryObject',
'StoryNoRender',
'StoryWithPlay',
'CSF2StoryWithPlay',
];

View File

@ -388,8 +388,18 @@ export class CsfFile {
});
if (self._namedExportsOrder) {
const unsortedExports = Object.keys(self._storyExports);
self._storyExports = sortExports(self._storyExports, self._namedExportsOrder);
self._stories = sortExports(self._stories, self._namedExportsOrder);
const sortedExports = Object.keys(self._storyExports);
if (unsortedExports.length !== sortedExports.length) {
throw new Error(
`Missing exports after sort: ${unsortedExports.filter(
(key) => !sortedExports.includes(key)
)}`
);
}
}
return self;