Skip to content

Commit

Permalink
Merge pull request #19529 from storybookjs/tom/sb-736-docs2-sb19142-c…
Browse files Browse the repository at this point in the history
…sf-file-with-no-stories

Don't generate docs page entries for CSF files with no stories
  • Loading branch information
tmeasday authored Oct 19, 2022
2 parents b346bfc + 17c08a8 commit bd0c79d
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 bd0c79d

Please sign in to comment.