Skip to content

Commit

Permalink
Merge pull request #23852 from storybookjs/shilman/fix-story-indexer
Browse files Browse the repository at this point in the history
Index: Fix `*.story.*` CSF indexing
(cherry picked from commit 377f7f9)
  • Loading branch information
shilman authored and storybook-bot committed Aug 16, 2023
1 parent 3d5a816 commit be4ea71
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 1 deletion.
2 changes: 1 addition & 1 deletion code/lib/core-server/src/presets/common-preset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};

Expand Down
30 changes: 30 additions & 0 deletions code/lib/core-server/src/utils/StoryIndexGenerator.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
7 changes: 7 additions & 0 deletions code/lib/core-server/src/utils/__mockdata__/src/F.story.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
const component = {};
export default {
component,
tags: ['autodocs'],
};

export const StoryOne = {};

0 comments on commit be4ea71

Please sign in to comment.