Skip to content

Commit

Permalink
feat: handle stories.js as meaningless for auto-titling
Browse files Browse the repository at this point in the history
  • Loading branch information
agriffis committed Sep 20, 2023
1 parent 42a35ae commit 8ce45d5
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
23 changes: 23 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 @@ -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(
Expand Down
4 changes: 3 additions & 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,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;
};

/**
Expand Down

0 comments on commit 8ce45d5

Please sign in to comment.