diff --git a/code/lib/core-server/src/utils/summarizeIndex.test.ts b/code/lib/core-server/src/utils/summarizeIndex.test.ts new file mode 100644 index 000000000000..9c65c928ce7f --- /dev/null +++ b/code/lib/core-server/src/utils/summarizeIndex.test.ts @@ -0,0 +1,34 @@ +import { isPageStory } from './summarizeIndex'; + +describe('isPageStory', () => { + describe('true positives', () => { + it.each(['pages/login', 'screens/login', 'components/LoginPage', 'components/LoginScreen'])( + '%s', + (title) => { + expect(isPageStory(title)).toBe(true); + } + ); + }); + + describe('false positives', () => { + it.each([ + 'components/PagerStatus', + 'components/DefectScreener', + 'addons/docs/docspage/autoplay', + ])('%s', (title) => { + expect(isPageStory(title)).toBe(true); + }); + }); + + describe('true negatives', () => { + it.each(['atoms/Button', 'components/Slider'])('%s', (title) => { + expect(isPageStory(title)).toBe(false); + }); + }); + + describe('false negatives', () => { + it.each(['flows/login', 'login-flow/forgot password'])('%s', (title) => { + expect(isPageStory(title)).toBe(false); + }); + }); +}); diff --git a/code/lib/core-server/src/utils/summarizeIndex.ts b/code/lib/core-server/src/utils/summarizeIndex.ts index afe09812fe7a..8cbed54f59b8 100644 --- a/code/lib/core-server/src/utils/summarizeIndex.ts +++ b/code/lib/core-server/src/utils/summarizeIndex.ts @@ -2,14 +2,22 @@ import type { StoryIndex } from '@storybook/types'; import { STORIES_MDX_TAG, isMdxEntry, AUTODOCS_TAG } from './StoryIndexGenerator'; +const PAGE_REGEX = /(page|screen)/i; + +export const isPageStory = (storyId: string) => PAGE_REGEX.test(storyId); + export function summarizeIndex(storyIndex: StoryIndex) { let storyCount = 0; + let pageStoryCount = 0; let autodocsCount = 0; let storiesMdxCount = 0; let mdxCount = 0; Object.values(storyIndex.entries).forEach((entry) => { if (entry.type === 'story') { storyCount += 1; + if (isPageStory(entry.title)) { + pageStoryCount += 1; + } } else if (entry.type === 'docs') { if (isMdxEntry(entry)) { mdxCount += 1; @@ -22,6 +30,7 @@ export function summarizeIndex(storyIndex: StoryIndex) { }); return { storyCount, + pageStoryCount, autodocsCount, storiesMdxCount, mdxCount,