diff --git a/code/lib/core-server/src/presets/common-preset.ts b/code/lib/core-server/src/presets/common-preset.ts index fcb4b5681571..7e13ade9ddf0 100644 --- a/code/lib/core-server/src/presets/common-preset.ts +++ b/code/lib/core-server/src/presets/common-preset.ts @@ -195,7 +195,7 @@ export const features = async ( }); export const csfIndexer: Indexer = { - test: /\.stories\.(m?js|ts)x?$/, + test: /\.(stories|story)\.(m?js|ts)x?$/, index: async (fileName, options) => (await readCsf(fileName, options)).parse().indexInputs, }; diff --git a/code/lib/core-server/src/utils/StoryIndexGenerator.test.ts b/code/lib/core-server/src/utils/StoryIndexGenerator.test.ts index 7110743b7003..b1097c168a86 100644 --- a/code/lib/core-server/src/utils/StoryIndexGenerator.test.ts +++ b/code/lib/core-server/src/utils/StoryIndexGenerator.test.ts @@ -99,6 +99,36 @@ describe('StoryIndexGenerator', () => { `); }); }); + describe('single file .story specifier', () => { + it('extracts stories from the right files', async () => { + const specifier: NormalizedStoriesSpecifier = normalizeStoriesEntry( + './src/F.story.ts', + options + ); + + const generator = new StoryIndexGenerator([specifier], options); + await generator.initialize(); + + expect(await generator.getIndex()).toMatchInlineSnapshot(` + Object { + "entries": Object { + "f--story-one": Object { + "id": "f--story-one", + "importPath": "./src/F.story.ts", + "name": "Story One", + "tags": Array [ + "autodocs", + "story", + ], + "title": "F", + "type": "story", + }, + }, + "v": 4, + } + `); + }); + }); describe('non-recursive specifier', () => { it('extracts stories from the right files', async () => { const specifier: NormalizedStoriesSpecifier = normalizeStoriesEntry( diff --git a/code/lib/core-server/src/utils/__mockdata__/src/F.story.ts b/code/lib/core-server/src/utils/__mockdata__/src/F.story.ts new file mode 100644 index 000000000000..bb14d42c7112 --- /dev/null +++ b/code/lib/core-server/src/utils/__mockdata__/src/F.story.ts @@ -0,0 +1,7 @@ +const component = {}; +export default { + component, + tags: ['autodocs'], +}; + +export const StoryOne = {};