Skip to content

Commit

Permalink
Merge pull request #30561 from storybookjs/shilman/fix-csf-example-fe…
Browse files Browse the repository at this point in the history
…ature-usage

Telemetry: Don't count example stories towards CSF feature stats
(cherry picked from commit 0673b6f)
  • Loading branch information
shilman committed Feb 18, 2025
1 parent 022225a commit 0d7f000
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 5 deletions.
39 changes: 35 additions & 4 deletions code/core/src/core-server/utils/StoryIndexGenerator.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,19 @@ describe('StoryIndexGenerator', () => {
"title": "D",
"type": "story",
},
"example-button--story-one": {
"componentPath": undefined,
"id": "example-button--story-one",
"importPath": "./src/Button.stories.ts",
"name": "Story One",
"tags": [
"dev",
"test",
"foobar",
],
"title": "Example/Button",
"type": "story",
},
"first-nested-deeply-f--story-one": {
"componentPath": undefined,
"id": "first-nested-deeply-f--story-one",
Expand Down Expand Up @@ -597,6 +610,19 @@ describe('StoryIndexGenerator', () => {
"title": "D",
"type": "story",
},
"example-button--story-one": {
"componentPath": undefined,
"id": "example-button--story-one",
"importPath": "./src/Button.stories.ts",
"name": "Story One",
"tags": [
"dev",
"test",
"foobar",
],
"title": "Example/Button",
"type": "story",
},
"first-nested-deeply-f--story-one": {
"componentPath": undefined,
"id": "first-nested-deeply-f--story-one",
Expand Down Expand Up @@ -764,6 +790,8 @@ describe('StoryIndexGenerator', () => {
"a--story-one",
"b--docs",
"b--story-one",
"example-button--docs",
"example-button--story-one",
"d--docs",
"d--story-one",
"h--docs",
Expand Down Expand Up @@ -806,6 +834,8 @@ describe('StoryIndexGenerator', () => {
"a--story-one",
"b--docs",
"b--story-one",
"example-button--docs",
"example-button--story-one",
"d--docs",
"d--story-one",
"h--docs",
Expand Down Expand Up @@ -1794,6 +1824,7 @@ describe('StoryIndexGenerator', () => {
"second-nested-g--story-one",
"componentreference--docs",
"notitle--docs",
"example-button--story-one",
"h--story-one",
"componentpath-extension--story-one",
"componentpath-noextension--story-one",
Expand Down Expand Up @@ -1822,7 +1853,7 @@ describe('StoryIndexGenerator', () => {
const generator = new StoryIndexGenerator([specifier], options);
await generator.initialize();
await generator.getIndex();
expect(readCsfMock).toHaveBeenCalledTimes(11);
expect(readCsfMock).toHaveBeenCalledTimes(12);

readCsfMock.mockClear();
await generator.getIndex();
Expand Down Expand Up @@ -1880,7 +1911,7 @@ describe('StoryIndexGenerator', () => {
const generator = new StoryIndexGenerator([specifier], options);
await generator.initialize();
await generator.getIndex();
expect(readCsfMock).toHaveBeenCalledTimes(11);
expect(readCsfMock).toHaveBeenCalledTimes(12);

generator.invalidate(specifier, './src/B.stories.ts', false);

Expand Down Expand Up @@ -1965,7 +1996,7 @@ describe('StoryIndexGenerator', () => {
const generator = new StoryIndexGenerator([specifier], options);
await generator.initialize();
await generator.getIndex();
expect(readCsfMock).toHaveBeenCalledTimes(11);
expect(readCsfMock).toHaveBeenCalledTimes(12);

generator.invalidate(specifier, './src/B.stories.ts', true);

Expand Down Expand Up @@ -2004,7 +2035,7 @@ describe('StoryIndexGenerator', () => {
const generator = new StoryIndexGenerator([specifier], options);
await generator.initialize();
await generator.getIndex();
expect(readCsfMock).toHaveBeenCalledTimes(11);
expect(readCsfMock).toHaveBeenCalledTimes(12);

generator.invalidate(specifier, './src/B.stories.ts', true);

Expand Down
6 changes: 5 additions & 1 deletion code/core/src/core-server/utils/StoryIndexGenerator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { readFile } from 'node:fs/promises';
import { dirname, extname, join, normalize, relative, resolve, sep } from 'node:path';

import { commonGlobOptions, normalizeStoryPath } from '@storybook/core/common';
import { isExampleStoryId } from '@storybook/core/telemetry';
import type {
DocsIndexEntry,
DocsOptions,
Expand Down Expand Up @@ -269,7 +270,10 @@ export class StoryIndexGenerator {
return item;
}

addStats(item.extra.stats, statsSummary);
// don't count example stories towards feature usage stats
if (!isExampleStoryId(item.id)) {
addStats(item.extra.stats, statsSummary);
}

// Drop extra data used for internal bookkeeping
const { extra, ...existing } = item;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
const component = {};
export default {
title: 'Example/Button',
component,
tags: ['foobar'],
};

export const StoryOne = {};
12 changes: 12 additions & 0 deletions code/core/src/core-server/utils/stories-json.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,18 @@ describe('useStoriesJson', () => {
"title": "docs2/Yabbadabbadooo",
"type": "docs",
},
"example-button--story-one": {
"id": "example-button--story-one",
"importPath": "./src/Button.stories.ts",
"name": "Story One",
"tags": [
"dev",
"test",
"foobar",
],
"title": "Example/Button",
"type": "story",
},
"first-nested-deeply-f--story-one": {
"id": "first-nested-deeply-f--story-one",
"importPath": "./src/first-nested/deeply/F.stories.js",
Expand Down

0 comments on commit 0d7f000

Please sign in to comment.