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 Mar 30, 2023
1 parent 2c7fa46 commit 846954a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
10 changes: 10 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,16 @@ 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 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|stories)$/i.test(last))
? parts.slice(0, -1)
: parts;
};

/**
Expand Down

0 comments on commit 846954a

Please sign in to comment.