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 Aug 19, 2023
1 parent ef2c3b8 commit 7e3178d
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
20 changes: 20 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,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(
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 7e3178d

Please sign in to comment.