Skip to content

Commit

Permalink
Merge pull request #23974 from storybookjs/shilman/23923-fix-story-in…
Browse files Browse the repository at this point in the history
…dexing

Core: Fix indexing for non-prefixed `stories.*` stories
  • Loading branch information
shilman committed Aug 28, 2023
2 parents a20c2d8 + 86c5b83 commit aecfa17
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 @@ -196,7 +196,7 @@ export const features = async (
});

export const csfIndexer: Indexer = {
test: /\.(stories|story)\.(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 @@ -129,6 +129,36 @@ describe('StoryIndexGenerator', () => {
`);
});
});
describe('no prefix stories specifier', () => {
it('extracts stories from the right files', async () => {
const specifier: NormalizedStoriesSpecifier = normalizeStoriesEntry(
'./src/stories.ts',
options
);

const generator = new StoryIndexGenerator([specifier], options);
await generator.initialize();

expect(await generator.getIndex()).toMatchInlineSnapshot(`
Object {
"entries": Object {
"stories--story-one": Object {
"id": "stories--story-one",
"importPath": "./src/stories.ts",
"name": "Story One",
"tags": Array [
"autodocs",
"story",
],
"title": "stories",
"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/stories.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 aecfa17

Please sign in to comment.