From 256c73815db15de1e255cb0856db49c64461c7ff Mon Sep 17 00:00:00 2001 From: Tom Coleman Date: Wed, 6 Jul 2022 12:07:10 +1000 Subject: [PATCH] Don't append title prefix to Meta of= docs entries --- .../src/utils/StoryIndexGenerator.test.ts | 27 +++++++++++++++++++ .../src/utils/StoryIndexGenerator.ts | 2 +- 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/lib/core-server/src/utils/StoryIndexGenerator.test.ts b/lib/core-server/src/utils/StoryIndexGenerator.test.ts index eb7f7dbf3267..8de17d6a6679 100644 --- a/lib/core-server/src/utils/StoryIndexGenerator.test.ts +++ b/lib/core-server/src/utils/StoryIndexGenerator.test.ts @@ -525,6 +525,33 @@ describe('StoryIndexGenerator', () => { `); }); + it('does not append title prefix if meta references a CSF file', async () => { + const generator = new StoryIndexGenerator( + [ + storiesSpecifier, + normalizeStoriesEntry( + { directory: './src/docs2', files: '**/*.mdx', titlePrefix: 'titlePrefix' }, + options + ), + ], + options + ); + await generator.initialize(); + + // NOTE: `toMatchInlineSnapshot` on objects sorts the keys, but in actuality, they are + // not sorted by default. + expect(Object.values((await generator.getIndex()).entries).map((e) => e.title)) + .toMatchInlineSnapshot(` + Array [ + "A", + "A", + "titlePrefix/NoTitle", + "A", + "titlePrefix/docs2/Yabbadabbadooo", + ] + `); + }); + it('generates no docs entries when docs are disabled', async () => { const generator = new StoryIndexGenerator([storiesSpecifier, docsSpecifier], { ...options, diff --git a/lib/core-server/src/utils/StoryIndexGenerator.ts b/lib/core-server/src/utils/StoryIndexGenerator.ts index a8eaaa893c2c..d094808b77aa 100644 --- a/lib/core-server/src/utils/StoryIndexGenerator.ts +++ b/lib/core-server/src/utils/StoryIndexGenerator.ts @@ -307,7 +307,7 @@ export class StoryIndexGenerator { dep.dependents.push(absolutePath); }); - const title = userOrAutoTitleFromSpecifier(importPath, specifier, result.title || ofTitle); + const title = ofTitle || userOrAutoTitleFromSpecifier(importPath, specifier, result.title); const name = result.name || this.options.docs.defaultName; const id = toId(title, name);