Skip to content

Commit

Permalink
Merge pull request #1004 from chromaui/reuben/ap-4683-chromatic-is-no…
Browse files Browse the repository at this point in the history
…t-detecting-changed-files-when-turbosnap

Chore: Update the RegEx filter to pull out empty strings
  • Loading branch information
ethriel3695 committed Jun 6, 2024
2 parents 7728406 + fedd8ea commit d4b171b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
10 changes: 8 additions & 2 deletions node-src/tasks/upload.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,10 @@ describe('traceChangedFiles', () => {
});

it('escapes special characters on context', async () => {
const deps = { './example-(new).stories.js': ['./example-(new).stories.js'] };
const deps = {
'./example-(new).stories.js': ['./example-(new).stories.js'],
'./example[[lang=language]].stories.js': ['./example[[lang=language]].stories.js'],
};
findChangedDependencies.mockResolvedValue([]);
findChangedPackageFiles.mockResolvedValue([]);
getDependentStoryFiles.mockResolvedValue(deps);
Expand All @@ -182,7 +185,10 @@ describe('traceChangedFiles', () => {
} as any;
await traceChangedFiles(ctx, {} as any);

expect(ctx.onlyStoryFiles).toStrictEqual(["./example-\\(\\new\\)\\.stories.js"]);
expect(ctx.onlyStoryFiles).toStrictEqual([
'./example-\\(\\new\\)\\.stories.js',
'./example\\[\\[\\lang=language\\]\\]\\.stories.js',
]);
});

it('does not run package dependency analysis if there are no metadata changes', async () => {
Expand Down
7 changes: 4 additions & 3 deletions node-src/tasks/upload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,9 +162,10 @@ export const traceChangedFiles = async (ctx: Context, task: Task) => {
);
if (onlyStoryFiles) {
// Escape special characters in the filename so it does not conflict with picomatch
ctx.onlyStoryFiles = Object.keys(onlyStoryFiles).map((key) =>
key.split(SPECIAL_CHARS_REGEXP).join('\\')
);
ctx.onlyStoryFiles = Object.keys(onlyStoryFiles).map((key) => {
const filteredArray = key.split(SPECIAL_CHARS_REGEXP).filter((item) => item !== '');
return filteredArray.join('\\');
});

if (!ctx.options.interactive) {
if (!ctx.options.traceChanged) {
Expand Down

0 comments on commit d4b171b

Please sign in to comment.