Skip to content

Commit 0cecd36

Browse files
Strip ' + N modules' when matching against untraced files
1 parent 1548300 commit 0cecd36

File tree

2 files changed

+37
-31
lines changed

2 files changed

+37
-31
lines changed

node-src/lib/turbosnap/getDependentStoryFiles.test.ts

Lines changed: 35 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -708,37 +708,41 @@ describe('getDependentStoryFiles', () => {
708708
expect(result).toEqual({});
709709
});
710710

711-
it('ignores untraced files', async () => {
712-
const changedFiles = ['src/utils.js'];
713-
const modules = [
714-
{
715-
id: 1,
716-
name: './src/utils.js', // changed
717-
reasons: [{ moduleName: './src/foo.js' }],
718-
},
719-
{
720-
id: 2,
721-
name: './src/foo.js', // untraced
722-
reasons: [{ moduleName: './src/foo.stories.js' }],
723-
},
724-
{
725-
id: 3,
726-
name: './src/foo.stories.js',
727-
reasons: [{ moduleName: CSF_GLOB }],
728-
},
729-
{
730-
id: 999,
731-
name: CSF_GLOB,
732-
reasons: [{ moduleName: './.storybook/generated-stories-entry.js' }],
733-
},
734-
];
735-
const ctx = getContext({
736-
staticDir: ['path/to/statics'],
737-
untraced: ['**/foo.js'],
738-
});
739-
const result = await getDependentStoryFiles(ctx, { modules }, statsPath, changedFiles);
740-
expect(result).toEqual({});
741-
});
711+
it.each(['./src/foo.js', './src/foo.js + 1 module', './src/foo.js + 2 modules'])(
712+
`ignores untraced files for module name %s`,
713+
async (moduleName) => {
714+
const changedFiles = ['src/utils.js'];
715+
const modules = [
716+
{
717+
id: 1,
718+
name: './src/utils.js', // changed
719+
reasons: [{ moduleName: moduleName }],
720+
},
721+
{
722+
id: 2,
723+
name: moduleName, // untraced
724+
reasons: [{ moduleName: './src/foo.stories.js' }],
725+
},
726+
{
727+
id: 3,
728+
name: './src/foo.stories.js',
729+
reasons: [{ moduleName: CSF_GLOB }],
730+
},
731+
{
732+
id: 999,
733+
name: CSF_GLOB,
734+
reasons: [{ moduleName: './.storybook/generated-stories-entry.js' }],
735+
},
736+
];
737+
const ctx = getContext({
738+
staticDir: ['path/to/statics'],
739+
untraced: ['**/foo.js'],
740+
});
741+
const result = await getDependentStoryFiles(ctx, { modules }, statsPath, changedFiles);
742+
expect(ctx.turboSnap.bailReason).toBeUndefined();
743+
expect(result).toEqual({});
744+
}
745+
);
742746

743747
it('does not bail on untraced global files', async () => {
744748
const changedFiles = [

node-src/lib/turbosnap/getDependentStoryFiles.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,9 @@ export async function getDependentStoryFiles(
207207
staticDirectories.some((directory) => name && name.startsWith(`${directory}/`));
208208

209209
ctx.untracedFiles = [];
210+
210211
function untrace(filepath: string) {
212+
filepath = filepath.replace(/\s\+\s\d+\smodules?$/, ''); // strip ' + N modules' from the string before matching against `untraced`
211213
if (untraced.some((glob) => matchesFile(glob, filepath))) {
212214
ctx.untracedFiles?.push(filepath);
213215
return false;

0 commit comments

Comments
 (0)