Skip to content

Commit

Permalink
Merge pull request #20539 from storybookjs/shilman/add-page-story-counts
Browse files Browse the repository at this point in the history
Telemetry: Add pageStoryCount
  • Loading branch information
shilman authored Jan 10, 2023
2 parents 7ec50cb + 769b351 commit 65f82ad
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
34 changes: 34 additions & 0 deletions code/lib/core-server/src/utils/summarizeIndex.test.ts
Original file line number Diff line number Diff line change
@@ -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);
});
});
});
9 changes: 9 additions & 0 deletions code/lib/core-server/src/utils/summarizeIndex.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -22,6 +30,7 @@ export function summarizeIndex(storyIndex: StoryIndex) {
});
return {
storyCount,
pageStoryCount,
autodocsCount,
storiesMdxCount,
mdxCount,
Expand Down

0 comments on commit 65f82ad

Please sign in to comment.