Skip to content

Commit bd17e3b

Browse files
authored
fix(action): do not set status if it's already set for new image case (#723)
Co-authored-by: danadajian <danadajian@users.noreply.github.com>
1 parent 13a6d89 commit bd17e3b

File tree

4 files changed

+26
-3
lines changed

4 files changed

+26
-3
lines changed

action/dist/main.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163926,7 +163926,8 @@ var run = async () => {
163926163926
`New visual tests found! ${newFileCount} images will be uploaded as new base images.`
163927163927
);
163928163928
await uploadBaseImages(newFilePaths);
163929-
if (!commitHash) return;
163929+
if (!commitHash || latestVisualRegressionStatus?.state === "failure")
163930+
return;
163930163931
return octokit.rest.repos.createCommitStatus({
163931163932
sha: commitHash,
163932163933
context: VISUAL_REGRESSION_CONTEXT,

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/src/run.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,8 @@ export const run = async () => {
159159
`New visual tests found! ${newFileCount} images will be uploaded as new base images.`
160160
);
161161
await uploadBaseImages(newFilePaths);
162-
if (!commitHash) return;
162+
if (!commitHash || latestVisualRegressionStatus?.state === 'failure')
163+
return;
163164
return octokit.rest.repos.createCommitStatus({
164165
sha: commitHash,
165166
context: VISUAL_REGRESSION_CONTEXT,

action/test/run.test.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -430,6 +430,27 @@ describe('main', () => {
430430
expect(createCommentMock).not.toHaveBeenCalled();
431431
});
432432

433+
it('should not set successful commit status if latest Visual Regression status is failure and only new images were created', async () => {
434+
execMock.mockResolvedValue(0);
435+
globMock.mockResolvedValue([
436+
'path/to/screenshots/newTest1/new.png',
437+
'path/to/screenshots/newTest2/new.png'
438+
]);
439+
listCommitStatusesForRefMock.mockImplementationOnce(() => ({
440+
data: [
441+
{
442+
context: VISUAL_REGRESSION_CONTEXT,
443+
created_at: '2023-05-21T16:51:29Z',
444+
state: 'failure',
445+
description: 'A visual regression was detected!'
446+
}
447+
]
448+
}));
449+
await runAction();
450+
expect(putObjectMock).toHaveBeenCalled();
451+
expect(createCommitStatusMock).not.toHaveBeenCalled();
452+
});
453+
433454
it('should pass and upload base images if visual tests pass and only new images were created with diff-id input', async () => {
434455
getInputMock.mockImplementation(name => diffIdInputMap[name]);
435456
execMock.mockResolvedValue(0);

0 commit comments

Comments
 (0)