Skip to content

Commit

Permalink
fix: don't remove redundant filename part if there won't be anything …
Browse files Browse the repository at this point in the history
…left
  • Loading branch information
agriffis committed Sep 20, 2023
1 parent 8ce45d5 commit 59fc329
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
12 changes: 12 additions & 0 deletions code/lib/preview-api/src/modules/store/autoTitle.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,18 @@ describe('userOrAutoTitleFromSpecifier', () => {
).toMatchInlineSnapshot(`to_my/file`);
});

it('match with short path', () => {
// Make sure "stories" isn't trimmed as redundant when there won't be
// anything left.
expect(
userOrAuto(
'./path/stories.js',
normalizeStoriesEntry({ directory: './path', files: '**/?(*.)stories.*' }, options),
undefined
)
).toMatchInlineSnapshot(`stories`);
});

it('match with windows path', () => {
expect(
userOrAuto(
Expand Down
2 changes: 1 addition & 1 deletion code/lib/preview-api/src/modules/store/autoTitle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ 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|story|stories)$/i.test(last))
return last && nextToLast && (last === nextToLast || /^(?:index|story|stories)$/i.test(last))
? parts.slice(0, -1)
: parts;
};
Expand Down

0 comments on commit 59fc329

Please sign in to comment.