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

CLI: Warn the user when stories glob does not match any file #21392

Merged
merged 1 commit into from Mar 8, 2023
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
18 changes: 17 additions & 1 deletion code/lib/core-server/src/utils/StoryIndexGenerator.test.ts
Expand Up @@ -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';

Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -925,6 +926,21 @@ 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);
const logMessage = jest.mocked(once.warn).mock.calls[0][0];
expect(logMessage).toContain(`No story files found for the specified pattern`);
});
});

describe('duplicates', () => {
it('warns when two MDX entries reference the same CSF file without a name', async () => {
const docsErrorSpecifier: NormalizedStoriesSpecifier = normalizeStoriesEntry(
Expand Down
11 changes: 10 additions & 1 deletion code/lib/core-server/src/utils/StoryIndexGenerator.ts
Expand Up @@ -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';
Expand Down Expand Up @@ -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') {
Expand Down