diff --git a/code/core/src/core-server/utils/StoryIndexGenerator.test.ts b/code/core/src/core-server/utils/StoryIndexGenerator.test.ts index 4c3bb0817bd6..82f12b110064 100644 --- a/code/core/src/core-server/utils/StoryIndexGenerator.test.ts +++ b/code/core/src/core-server/utils/StoryIndexGenerator.test.ts @@ -1,3 +1,4 @@ +import { existsSync } from 'node:fs'; import { join } from 'node:path'; import { beforeEach, describe, expect, it, vi } from 'vitest'; @@ -1997,6 +1998,28 @@ describe('StoryIndexGenerator', () => { }); describe('warnings', () => { + it('does not match directories that have story-like names', async () => { + const specifier: NormalizedStoriesSpecifier = normalizeStoriesEntry( + './src/**/*.stories.tsx', + options + ); + + const files = await StoryIndexGenerator.findMatchingFiles( + specifier, + options.workingDir, + true + ); + const storyLikeDirectory = join( + options.workingDir, + './src/__screenshots__/Button.stories.tsx' + ); + const storyLikeDirectoryFile = join(storyLikeDirectory, 'Primary.png'); + + expect(existsSync(storyLikeDirectoryFile)).toBe(true); + expect(Object.keys(files)).not.toContain(storyLikeDirectory); + expect(Object.keys(files)).not.toContain(storyLikeDirectoryFile); + }); + it('when entries do not match any files', async () => { const generator = new StoryIndexGenerator( [normalizeStoriesEntry('./src/docs2/wrong.js', options)], diff --git a/code/core/src/core-server/utils/StoryIndexGenerator.ts b/code/core/src/core-server/utils/StoryIndexGenerator.ts index 3848861d4fa5..2cab59229dc5 100644 --- a/code/core/src/core-server/utils/StoryIndexGenerator.ts +++ b/code/core/src/core-server/utils/StoryIndexGenerator.ts @@ -167,11 +167,11 @@ export class StoryIndexGenerator { // eslint-disable-next-line depend/ban-dependencies const { globby } = await import('globby'); - // Execute globby within the new CWD to ensure `ignore` patterns work correctly. const files = await globby(globPattern, { absolute: true, cwd: globCwd, ...commonGlobOptions(globPattern), + onlyFiles: true, }); if (files.length === 0 && !ignoreWarnings) { diff --git a/code/core/src/core-server/utils/__mockdata__/src/__screenshots__/Button.stories.tsx/Primary.png b/code/core/src/core-server/utils/__mockdata__/src/__screenshots__/Button.stories.tsx/Primary.png new file mode 100644 index 000000000000..b97e4a75e2ca --- /dev/null +++ b/code/core/src/core-server/utils/__mockdata__/src/__screenshots__/Button.stories.tsx/Primary.png @@ -0,0 +1 @@ +mock screenshot fixture