From 89e30ffef1f43e809b37b4226666cba9cd5a0658 Mon Sep 17 00:00:00 2001 From: Michael Shilman Date: Tue, 8 Mar 2022 19:08:21 +0800 Subject: [PATCH] Core: Error when namedExportsOrder causes story to disappear --- examples/react-ts/src/button.stories.tsx | 10 ---------- lib/csf-tools/src/CsfFile.ts | 10 ++++++++++ 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/examples/react-ts/src/button.stories.tsx b/examples/react-ts/src/button.stories.tsx index db360ee35e0..2c9d8151b20 100644 --- a/examples/react-ts/src/button.stories.tsx +++ b/examples/react-ts/src/button.stories.tsx @@ -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', -]; diff --git a/lib/csf-tools/src/CsfFile.ts b/lib/csf-tools/src/CsfFile.ts index 014bde430e2..25af480e83f 100644 --- a/lib/csf-tools/src/CsfFile.ts +++ b/lib/csf-tools/src/CsfFile.ts @@ -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;