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

Index: Fix *.story.* CSF indexing #23852

Merged
merged 1 commit into from
Aug 16, 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
2 changes: 1 addition & 1 deletion code/lib/core-server/src/presets/common-preset.ts
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
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
@@ -0,0 +1,7 @@
const component = {};
export default {
component,
tags: ['autodocs'],
};

export const StoryOne = {};