diff --git a/code/lib/preview-api/src/modules/store/autoTitle.test.ts b/code/lib/preview-api/src/modules/store/autoTitle.test.ts index c117b44a05a9..013ccac6690f 100644 --- a/code/lib/preview-api/src/modules/store/autoTitle.test.ts +++ b/code/lib/preview-api/src/modules/store/autoTitle.test.ts @@ -187,6 +187,29 @@ describe('userOrAutoTitleFromSpecifier', () => { ).toMatchInlineSnapshot(`to/button`); }); + it('match with trailing stories', () => { + expect( + userOrAuto( + './path/to/button/stories.js', + normalizeStoriesEntry({ directory: './path', files: '**/?(*.)stories.*' }, options), + undefined + ) + ).toMatchInlineSnapshot(`to/button`); + }); + + it('match with trailing stories (windows path)', () => { + expect( + userOrAuto( + './path/to/button/stories.js', + normalizeStoriesEntry( + { directory: '.\\path\\', files: '**/?(*.)stories.*' }, + winOptions + ), + undefined + ) + ).toMatchInlineSnapshot(`to/button`); + }); + it('match with dotted component', () => { expect( userOrAuto( diff --git a/code/lib/preview-api/src/modules/store/autoTitle.ts b/code/lib/preview-api/src/modules/store/autoTitle.ts index c28125f65ff4..85fff681ddf2 100644 --- a/code/lib/preview-api/src/modules/store/autoTitle.ts +++ b/code/lib/preview-api/src/modules/store/autoTitle.ts @@ -15,7 +15,9 @@ const stripExtension = (parts: string[]) => { const removeRedundantFilename = (parts: string[]) => { const last = parts[parts.length - 1]; const nextToLast = parts[parts.length - 2]; - return last && (last === nextToLast || /^index$/i.test(last)) ? parts.slice(0, -1) : parts; + return last && (last === nextToLast || /^(?:index|story|stories)$/i.test(last)) + ? parts.slice(0, -1) + : parts; }; /**