Skip to content

Commit 6e13a94

Browse files
authored
fix(action): use correct glob patterns for screenshots (#704)
Co-authored-by: danadajian <danadajian@users.noreply.github.com>
1 parent c841a41 commit 6e13a94

File tree

8 files changed

+41
-37
lines changed

8 files changed

+41
-37
lines changed

action/dist/main.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61523,7 +61523,7 @@ async function downloadS3Directory(bucketName, s3Prefix, localDir) {
6152361523
info(`Downloaded ${objects.length} file(s) to ${localDir}`);
6152461524
}
6152561525
async function uploadLocalDirectory(localDir, bucketName, s3Prefix) {
61526-
const files = await glob("**/*", {
61526+
const files = await glob("**/*.png", {
6152761527
cwd: localDir,
6152861528
nodir: true,
6152961529
absolute: false
@@ -65565,7 +65565,6 @@ var run = async () => {
6556565565
return;
6556665566
}
6556765567
const hash = commitHash || diffId;
65568-
const screenshotsDirectory = getInput("screenshots-directory");
6556965568
const useBaseImages = getBooleanInput("use-base-images") ?? true;
6557065569
if (useBaseImages) {
6557165570
await downloadBaseImages();
@@ -65576,8 +65575,11 @@ var run = async () => {
6557665575
const numVisualTestFailures = visualTestExitCode.filter(
6557765576
(code) => code !== 0
6557865577
).length;
65578+
const screenshotsDirectory = getInput("screenshots-directory");
6557965579
const screenshotsPath = path6.join(process.cwd(), screenshotsDirectory);
65580-
const filesInScreenshotDirectory = sync(`${screenshotsPath}/**`, { absolute: false }) || [];
65580+
const filesInScreenshotDirectory = await glob(`${screenshotsPath}/**/*.png`, {
65581+
absolute: false
65582+
});
6558165583
const diffFilePaths = filesInScreenshotDirectory.filter(
6558265584
(file) => file.endsWith("diff.png")
6558365585
);

action/dist/main.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

action/dist/post.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30784,7 +30784,7 @@ var post = async () => {
3078430784
info("Cleaning up PNG files in screenshots directory...");
3078530785
const screenshotsDirectory = getInput("screenshots-directory");
3078630786
try {
30787-
const pngFiles = sync(`${screenshotsDirectory}/**/*.png`);
30787+
const pngFiles = await glob(`${screenshotsDirectory}/**/*.png`);
3078830788
await (0, import_bluebird.map)(pngFiles, (file) => (0, import_promises2.rm)(file, { force: true }));
3078930789
info(`Removed ${pngFiles.length} PNG file(s) from ${screenshotsDirectory}`);
3079030790
} catch (error) {

action/dist/post.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

action/src/post.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { info, getInput } from '@actions/core';
22
import { rm } from 'fs/promises';
3-
import { sync as globSync } from 'glob';
3+
import { glob } from 'glob';
44
import { map } from 'bluebird';
55

66
const post = async () => {
@@ -9,7 +9,7 @@ const post = async () => {
99
const screenshotsDirectory = getInput('screenshots-directory');
1010

1111
try {
12-
const pngFiles = globSync(`${screenshotsDirectory}/**/*.png`);
12+
const pngFiles = await glob(`${screenshotsDirectory}/**/*.png`);
1313
await map(pngFiles, file => rm(file, { force: true }));
1414

1515
info(`Removed ${pngFiles.length} PNG file(s) from ${screenshotsDirectory}`);

action/src/run.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import { exec } from '@actions/exec';
1515
import { octokit } from './octokit';
1616
import { context } from '@actions/github';
1717
import * as path from 'path';
18-
import { sync } from 'glob';
18+
import { glob } from 'glob';
1919
import { unlinkSync } from 'fs';
2020
import { createGithubComment } from './comment';
2121
import { getLatestVisualRegressionStatus } from './get-latest-visual-regression-status';
@@ -40,8 +40,6 @@ export const run = async () => {
4040

4141
const hash = commitHash || diffId;
4242

43-
const screenshotsDirectory = getInput('screenshots-directory');
44-
4543
const useBaseImages = getBooleanInput('use-base-images') ?? true;
4644
if (useBaseImages) {
4745
await downloadBaseImages();
@@ -54,9 +52,11 @@ export const run = async () => {
5452
code => code !== 0
5553
).length;
5654

55+
const screenshotsDirectory = getInput('screenshots-directory');
5756
const screenshotsPath = path.join(process.cwd(), screenshotsDirectory);
58-
const filesInScreenshotDirectory =
59-
sync(`${screenshotsPath}/**`, { absolute: false }) || [];
57+
const filesInScreenshotDirectory = await glob(`${screenshotsPath}/**/*.png`, {
58+
absolute: false
59+
});
6060
const diffFilePaths = filesInScreenshotDirectory.filter(file =>
6161
file.endsWith('diff.png')
6262
);

action/src/s3-operations.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ async function uploadLocalDirectory(
8484
bucketName: string,
8585
s3Prefix: string
8686
): Promise<void> {
87-
const files = await glob('**/*', {
87+
const files = await glob('**/*.png', {
8888
cwd: localDir,
8989
nodir: true,
9090
absolute: false

action/test/run.test.ts

Lines changed: 25 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ mock.module('../src/disable-auto-merge', () => ({
99
disableAutoMerge: disableAutoMergeMock
1010
}));
1111

12-
const globSyncMock = mock();
12+
const globMock = mock();
1313
mock.module('glob', () => ({
14-
sync: globSyncMock
14+
glob: globMock
1515
}));
1616

1717
const getInputMock = mock();
@@ -159,6 +159,8 @@ describe('main', () => {
159159
unlinkSyncMock.mockReturnValue(undefined);
160160
rmMock.mockResolvedValue(undefined);
161161

162+
globMock.mockResolvedValue([]);
163+
162164
s3OperationCalls = [];
163165
});
164166

@@ -211,7 +213,7 @@ describe('main', () => {
211213
};
212214
getInputMock.mockImplementation(name => extendedInputMap[name]);
213215
execMock.mockResolvedValue(0);
214-
globSyncMock.mockReturnValue(['path/to/screenshots/base.png']);
216+
globMock.mockResolvedValue(['path/to/screenshots/base.png']);
215217
await runAction();
216218
expect(setFailedMock).not.toHaveBeenCalled();
217219
expect(createCommitStatusMock).toHaveBeenCalledWith({
@@ -233,7 +235,7 @@ describe('main', () => {
233235

234236
it('should pass if visual tests pass and no diffs or new images', async () => {
235237
execMock.mockResolvedValue(0);
236-
globSyncMock.mockReturnValue(['path/to/screenshots/base.png']);
238+
globMock.mockResolvedValue(['path/to/screenshots/base.png']);
237239
await runAction();
238240
expect(setFailedMock).not.toHaveBeenCalled();
239241
expect(createCommitStatusMock).toHaveBeenCalledWith({
@@ -249,15 +251,15 @@ describe('main', () => {
249251
it('should pass if visual tests pass and no diffs or new images with diff-id input', async () => {
250252
getInputMock.mockImplementation(name => diffIdInputMap[name]);
251253
execMock.mockResolvedValue(0);
252-
globSyncMock.mockReturnValue(['path/to/screenshots/base.png']);
254+
globMock.mockResolvedValue(['path/to/screenshots/base.png']);
253255
await runAction();
254256
expect(setFailedMock).not.toHaveBeenCalled();
255257
assertNoOctokitCalls();
256258
});
257259

258260
it('should fail if visual tests pass and some diff images were created', async () => {
259261
execMock.mockResolvedValue(1);
260-
globSyncMock.mockReturnValue([
262+
globMock.mockResolvedValue([
261263
'path/to/screenshots/base.png',
262264
'path/to/screenshots/diff.png',
263265
'path/to/screenshots/new.png',
@@ -287,7 +289,7 @@ describe('main', () => {
287289
it('should fail if visual tests pass and some diff images were created', async () => {
288290
getInputMock.mockImplementation(name => diffIdInputMap[name]);
289291
execMock.mockResolvedValue(1);
290-
globSyncMock.mockReturnValue([
292+
globMock.mockResolvedValue([
291293
'path/to/screenshots/base.png',
292294
'path/to/screenshots/diff.png',
293295
'path/to/screenshots/new.png',
@@ -312,7 +314,7 @@ describe('main', () => {
312314
name => multiLineInputMapMultipleCommands[name]
313315
);
314316
execMock.mockResolvedValue(1);
315-
globSyncMock.mockReturnValue([
317+
globMock.mockResolvedValue([
316318
'path/to/screenshots/base.png',
317319
'path/to/screenshots/diff.png',
318320
'path/to/screenshots/new.png'
@@ -338,7 +340,7 @@ describe('main', () => {
338340
name => multiLineInputMapMultipleCommands[name]
339341
);
340342
execMock.mockResolvedValue(1);
341-
globSyncMock.mockReturnValue([
343+
globMock.mockResolvedValue([
342344
'path/to/screenshots/base.png',
343345
'path/to/screenshots/diff.png',
344346
'path/to/screenshots/new.png'
@@ -350,7 +352,7 @@ describe('main', () => {
350352

351353
it('should pass if visual tests initially fail but pass on retry', async () => {
352354
execMock.mockResolvedValue(0);
353-
globSyncMock.mockReturnValue(['path/to/screenshots/diff.png']);
355+
globMock.mockResolvedValue(['path/to/screenshots/diff.png']);
354356
await runAction();
355357
expect(setFailedMock).not.toHaveBeenCalled();
356358
expect(unlinkSyncMock).toHaveBeenCalledWith('path/to/screenshots/diff.png');
@@ -367,7 +369,7 @@ describe('main', () => {
367369
it('should pass if visual tests initially fail but pass on retry with diff-id input', async () => {
368370
getInputMock.mockImplementation(name => diffIdInputMap[name]);
369371
execMock.mockResolvedValue(0);
370-
globSyncMock.mockReturnValue(['path/to/screenshots/diff.png']);
372+
globMock.mockResolvedValue(['path/to/screenshots/diff.png']);
371373
await runAction();
372374
expect(setFailedMock).not.toHaveBeenCalled();
373375
expect(unlinkSyncMock).toHaveBeenCalledWith('path/to/screenshots/diff.png');
@@ -376,7 +378,7 @@ describe('main', () => {
376378

377379
it('should pass and upload base images if visual tests pass and only new images were created', async () => {
378380
execMock.mockResolvedValue(0);
379-
globSyncMock.mockReturnValue([
381+
globMock.mockResolvedValue([
380382
'path/to/screenshots/existingTest/base.png',
381383
'path/to/screenshots/newTest1/new.png',
382384
'path/to/screenshots/newTest2/new.png'
@@ -401,7 +403,7 @@ describe('main', () => {
401403
it('should pass and upload base images if visual tests pass and only new images were created with diff-id input', async () => {
402404
getInputMock.mockImplementation(name => diffIdInputMap[name]);
403405
execMock.mockResolvedValue(0);
404-
globSyncMock.mockReturnValue([
406+
globMock.mockResolvedValue([
405407
'path/to/screenshots/existingTest/base.png',
406408
'path/to/screenshots/newTest1/new.png',
407409
'path/to/screenshots/newTest2/new.png'
@@ -422,7 +424,7 @@ describe('main', () => {
422424
'package-paths': 'path/1,path/2'
423425
};
424426
getInputMock.mockImplementation(name => extendedInputMap[name]);
425-
globSyncMock.mockReturnValue([
427+
globMock.mockResolvedValue([
426428
'path/to/screenshots/base.png',
427429
'path/to/screenshots/diff.png',
428430
'path/to/screenshots/new.png'
@@ -439,7 +441,7 @@ describe('main', () => {
439441
'package-paths': 'path/1,path/2'
440442
};
441443
getInputMock.mockImplementation(name => extendedInputMap[name]);
442-
globSyncMock.mockReturnValue([
444+
globMock.mockResolvedValue([
443445
'path/to/screenshots/base.png',
444446
'path/to/screenshots/diff.png',
445447
'path/to/screenshots/new.png'
@@ -455,7 +457,7 @@ describe('main', () => {
455457
execMock.mockResolvedValue(0);
456458
getInputMock.mockImplementation(name => inputMap[name]);
457459
getBooleanInputMock.mockImplementation(() => downloadBaseImages);
458-
globSyncMock.mockReturnValue([
460+
globMock.mockResolvedValue([
459461
'path/to/screenshots/base.png',
460462
'path/to/screenshots/diff.png',
461463
'path/to/screenshots/new.png'
@@ -469,7 +471,7 @@ describe('main', () => {
469471
execMock.mockResolvedValue(0);
470472
getInputMock.mockImplementation(name => inputMap[name]);
471473
getBooleanInputMock.mockImplementation(() => downloadBaseImages);
472-
globSyncMock.mockReturnValue([
474+
globMock.mockResolvedValue([
473475
'path/to/screenshots/base.png',
474476
'path/to/screenshots/diff.png',
475477
'path/to/screenshots/new.png'
@@ -496,7 +498,7 @@ describe('main', () => {
496498
'package-paths': 'path/1,path/2'
497499
};
498500
getInputMock.mockImplementation(name => extendedInputMap[name]);
499-
globSyncMock.mockReturnValue([
501+
globMock.mockResolvedValue([
500502
'path/to/screenshots/base.png',
501503
'path/to/screenshots/diff.png',
502504
'path/to/screenshots/new.png'
@@ -508,7 +510,7 @@ describe('main', () => {
508510

509511
it('should not set successful commit status or create comment if the latest Visual Regression status is failure', async () => {
510512
execMock.mockResolvedValue(0);
511-
globSyncMock.mockReturnValue(['path/to/screenshots/base.png']);
513+
globMock.mockResolvedValue(['path/to/screenshots/base.png']);
512514
listCommitStatusesForRefMock.mockImplementationOnce(() => ({
513515
data: [
514516
{
@@ -536,7 +538,7 @@ describe('main', () => {
536538

537539
it('should not set successful commit status if the latest Visual Regression status has been set', async () => {
538540
execMock.mockResolvedValue(0);
539-
globSyncMock.mockReturnValue(['path/to/screenshots/base.png']);
541+
globMock.mockResolvedValue(['path/to/screenshots/base.png']);
540542
listCommitStatusesForRefMock.mockImplementationOnce(() => ({
541543
data: [
542544
{
@@ -562,7 +564,7 @@ describe('main', () => {
562564

563565
it('should not set commit status or create comment if the latest Visual Regression status is failure because tests failed to execute successfully', async () => {
564566
execMock.mockResolvedValue(1);
565-
globSyncMock.mockReturnValue([
567+
globMock.mockResolvedValue([
566568
'path/to/screenshots/base.png',
567569
'path/to/screenshots/diff.png',
568570
'path/to/screenshots/new.png'
@@ -596,7 +598,7 @@ describe('main', () => {
596598
it('should set successful commit status (and disable auto merge) if a visual test failed to execute but this is a re-run', async () => {
597599
githubContext.runAttempt = 2;
598600
execMock.mockResolvedValue(0);
599-
globSyncMock.mockReturnValue(['path/to/screenshots/base.png']);
601+
globMock.mockResolvedValue(['path/to/screenshots/base.png']);
600602
listCommitStatusesForRefMock.mockImplementationOnce(() => ({
601603
data: [
602604
{
@@ -625,7 +627,7 @@ describe('main', () => {
625627
it('should set failure commit status (and not disable auto merge) if a visual test failed to execute but this is a re-run', async () => {
626628
githubContext.runAttempt = 2;
627629
execMock.mockResolvedValue(1);
628-
globSyncMock.mockReturnValue([
630+
globMock.mockResolvedValue([
629631
'path/to/screenshots/base.png',
630632
'path/to/screenshots/diff.png',
631633
'path/to/screenshots/new.png'

0 commit comments

Comments
 (0)