Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't generate docs page entries for CSF files with no stories #19529

Merged
merged 1 commit into from
Oct 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,
};