Skip to content

Commit

Permalink
Don't generate docs page entries for CSF files with no stories
Browse files Browse the repository at this point in the history
  • Loading branch information
tmeasday committed Oct 19, 2022
1 parent 7d70d7c commit 17c08a8
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 1 deletion.
20 changes: 20 additions & 0 deletions code/lib/core-server/src/utils/StoryIndexGenerator.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/// <reference types="@types/jest" />;

import path from 'path';
import fs from 'fs-extra';
import { normalizeStoriesEntry } from '@storybook/core-common';
Expand Down Expand Up @@ -462,6 +464,24 @@ describe('StoryIndexGenerator', () => {
}
`);
});

// https://github.com/storybookjs/storybook/issues/19142
it('does not generate a docs page entry if there are no stories in the CSF file', async () => {
const csfSpecifier: NormalizedStoriesSpecifier = normalizeStoriesEntry(
'./errors/NoStories.stories.ts',
options
);

const generator = new StoryIndexGenerator([csfSpecifier], docsPageOptions);
await generator.initialize();

expect(await generator.getIndex()).toMatchInlineSnapshot(`
Object {
"entries": Object {},
"v": 4,
}
`);
});
});

describe('docs specifier', () => {
Expand Down
2 changes: 1 addition & 1 deletion code/lib/core-server/src/utils/StoryIndexGenerator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ export class StoryIndexGenerator {
}
});

if (this.options.docs.enabled) {
if (this.options.docs.enabled && csf.stories.length) {
// We always add a template for *.stories.mdx, but only if docs page is enabled for
// regular CSF files
if (storyIndexer.addDocsTemplate || this.options.docs.docsPage) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/* eslint-disable storybook/story-exports */
const component = {};
export default {
component,
};

0 comments on commit 17c08a8

Please sign in to comment.