diff --git a/code/lib/core-server/src/utils/StoryIndexGenerator.test.ts b/code/lib/core-server/src/utils/StoryIndexGenerator.test.ts index 6468c33358a..b1f8065431c 100644 --- a/code/lib/core-server/src/utils/StoryIndexGenerator.test.ts +++ b/code/lib/core-server/src/utils/StoryIndexGenerator.test.ts @@ -11,7 +11,7 @@ import { normalizeStoriesEntry } from '@storybook/core-common'; import type { NormalizedStoriesSpecifier, StoryIndexer, StoryIndexEntry } from '@storybook/types'; import { loadCsf, getStorySortParameter } from '@storybook/csf-tools'; import { toId } from '@storybook/csf'; -import { logger } from '@storybook/node-logger'; +import { logger, once } from '@storybook/node-logger'; import { StoryIndexGenerator } from './StoryIndexGenerator'; @@ -61,6 +61,7 @@ describe('StoryIndexGenerator', () => { const actual = jest.requireActual('@storybook/csf-tools'); loadCsfMock.mockImplementation(actual.loadCsf); jest.mocked(logger.warn).mockClear(); + jest.mocked(once.warn).mockClear(); }); describe('extraction', () => { const storiesSpecifier: NormalizedStoriesSpecifier = normalizeStoriesEntry( @@ -925,6 +926,22 @@ describe('StoryIndexGenerator', () => { }); }); + describe('warnings', () => { + it('when entries do not match any files', async () => { + const generator = new StoryIndexGenerator( + [normalizeStoriesEntry('./src/docs2/wrong.js', options)], + options + ); + await generator.initialize(); + await generator.getIndex(); + + expect(once.warn).toHaveBeenCalledTimes(1); + expect(jest.mocked(once.warn).mock.calls[0][0]).toMatchInlineSnapshot( + `"No story files found for the specified pattern: src/docs2/wrong.js"` + ); + }); + }); + describe('duplicates', () => { it('warns when two MDX entries reference the same CSF file without a name', async () => { const docsErrorSpecifier: NormalizedStoriesSpecifier = normalizeStoriesEntry( diff --git a/code/lib/core-server/src/utils/StoryIndexGenerator.ts b/code/lib/core-server/src/utils/StoryIndexGenerator.ts index 1b966920017..e8062a93914 100644 --- a/code/lib/core-server/src/utils/StoryIndexGenerator.ts +++ b/code/lib/core-server/src/utils/StoryIndexGenerator.ts @@ -21,7 +21,7 @@ import type { } from '@storybook/types'; import { userOrAutoTitleFromSpecifier, sortStoriesV7 } from '@storybook/preview-api'; import { normalizeStoryPath } from '@storybook/core-common'; -import { logger } from '@storybook/node-logger'; +import { logger, once } from '@storybook/node-logger'; import { getStorySortParameter } from '@storybook/csf-tools'; import { toId } from '@storybook/csf'; import { analyze } from '@storybook/docs-mdx'; @@ -122,6 +122,15 @@ export class StoryIndexGenerator { path.join(this.options.workingDir, specifier.directory, specifier.files) ); const files = await glob(fullGlob); + + if (files.length === 0) { + once.warn( + `No story files found for the specified pattern: ${chalk.blue( + path.join(specifier.directory, specifier.files) + )}` + ); + } + files.sort().forEach((absolutePath: Path) => { const ext = path.extname(absolutePath); if (ext === '.storyshot') {