From 7e3178d843d930ffed3b116d49a3969548c1d130 Mon Sep 17 00:00:00 2001 From: Aron Griffis Date: Thu, 30 Mar 2023 15:08:19 -0400 Subject: [PATCH] feat: handle stories.js as meaningless for auto-titling --- .../src/modules/store/autoTitle.test.ts | 20 +++++++++++++++++++ .../src/modules/store/autoTitle.ts | 4 +++- 2 files changed, 23 insertions(+), 1 deletion(-) 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..7e7329ea38e1 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,26 @@ 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; }; /**