Skip to content

Commit 3e88a6e

Browse files
authored
fix(action): fail job correctly if visualTestsIsolated is false (#728)
Co-authored-by: danadajian <danadajian@users.noreply.github.com>
1 parent f00ddff commit 3e88a6e

File tree

4 files changed

+57
-39
lines changed

4 files changed

+57
-39
lines changed

action/dist/main.js

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -163870,23 +163870,22 @@ var run = async () => {
163870163870
}, 0);
163871163871
const newFileCount = newFilePaths.length;
163872163872
const visualTestsIsolated = getBooleanInput("visual-tests-isolated");
163873-
const visualTestsFailedForReasonOtherThanDiff = numVisualTestFailures > diffFileCount;
163874-
if (visualTestsFailedForReasonOtherThanDiff) {
163875-
if (visualTestsIsolated) {
163876-
setFailed(
163877-
"Visual tests failed to execute successfully. Perhaps one failed to take a screenshot?"
163878-
);
163879-
if (!commitHash) return;
163880-
return octokit.rest.repos.createCommitStatus({
163881-
sha: commitHash,
163882-
context: VISUAL_REGRESSION_CONTEXT,
163883-
state: "failure",
163884-
description: VISUAL_TESTS_FAILED_TO_EXECUTE,
163885-
...context2.repo
163886-
});
163887-
} else {
163888-
warning("The job failed, but this might not be due to visual tests.");
163889-
}
163873+
if (visualTestsIsolated && numVisualTestFailures > diffFileCount) {
163874+
setFailed(
163875+
"Visual tests failed to execute successfully. Perhaps one failed to take a screenshot?"
163876+
);
163877+
if (!commitHash) return;
163878+
return octokit.rest.repos.createCommitStatus({
163879+
sha: commitHash,
163880+
context: VISUAL_REGRESSION_CONTEXT,
163881+
state: "failure",
163882+
description: VISUAL_TESTS_FAILED_TO_EXECUTE,
163883+
...context2.repo
163884+
});
163885+
}
163886+
if (!visualTestsIsolated && numVisualTestFailures > 0) {
163887+
setFailed("The job failed, but this might not be due to visual tests.");
163888+
return;
163890163889
}
163891163890
const latestVisualRegressionStatus = commitHash ? await getLatestVisualRegressionStatus(commitHash) : null;
163892163891
const isRetry = context2.runAttempt > 1;

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: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -86,24 +86,23 @@ export const run = async () => {
8686

8787
const visualTestsIsolated = getBooleanInput('visual-tests-isolated');
8888

89-
const visualTestsFailedForReasonOtherThanDiff =
90-
numVisualTestFailures > diffFileCount;
91-
if (visualTestsFailedForReasonOtherThanDiff) {
92-
if (visualTestsIsolated) {
93-
setFailed(
94-
'Visual tests failed to execute successfully. Perhaps one failed to take a screenshot?'
95-
);
96-
if (!commitHash) return;
97-
return octokit.rest.repos.createCommitStatus({
98-
sha: commitHash,
99-
context: VISUAL_REGRESSION_CONTEXT,
100-
state: 'failure',
101-
description: VISUAL_TESTS_FAILED_TO_EXECUTE,
102-
...context.repo
103-
});
104-
} else {
105-
warning('The job failed, but this might not be due to visual tests.');
106-
}
89+
if (visualTestsIsolated && numVisualTestFailures > diffFileCount) {
90+
setFailed(
91+
'Visual tests failed to execute successfully. Perhaps one failed to take a screenshot?'
92+
);
93+
if (!commitHash) return;
94+
return octokit.rest.repos.createCommitStatus({
95+
sha: commitHash,
96+
context: VISUAL_REGRESSION_CONTEXT,
97+
state: 'failure',
98+
description: VISUAL_TESTS_FAILED_TO_EXECUTE,
99+
...context.repo
100+
});
101+
}
102+
103+
if (!visualTestsIsolated && numVisualTestFailures > 0) {
104+
setFailed('The job failed, but this might not be due to visual tests.');
105+
return;
107106
}
108107

109108
const latestVisualRegressionStatus = commitHash

action/test/run.test.ts

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -768,17 +768,37 @@ describe('main', () => {
768768
);
769769
});
770770

771-
it('should call warning instead of setFailed when visual tests fail for non-diff reason and visual-tests-isolated is false', async () => {
771+
it('should call setFailed without setting commit status when visual tests fail for non-diff reason and visual-tests-isolated is false', async () => {
772772
execMock.mockResolvedValue(1);
773773
getBooleanInputMock.mockImplementation(name =>
774774
name === 'visual-tests-isolated' ? false : undefined
775775
);
776776
globMock.mockResolvedValue([]);
777777
await runAction();
778-
expect(setFailedMock).not.toHaveBeenCalled();
779-
expect(warningMock).toHaveBeenCalledWith(
778+
expect(setFailedMock).toHaveBeenCalledWith(
780779
'The job failed, but this might not be due to visual tests.'
781780
);
781+
expect(createCommitStatusMock).not.toHaveBeenCalled();
782+
});
783+
784+
it('should call setFailed without setting commit status when visual-tests-isolated is false and 1 failure with multiple diffs', async () => {
785+
execMock.mockResolvedValue(1);
786+
getBooleanInputMock.mockImplementation(name =>
787+
name === 'visual-tests-isolated' ? false : undefined
788+
);
789+
globMock.mockResolvedValue([
790+
'path/to/screenshots/diff1.png',
791+
'path/to/screenshots/new1.png',
792+
'path/to/screenshots/diff2.png',
793+
'path/to/screenshots/new2.png',
794+
'path/to/screenshots/diff3.png',
795+
'path/to/screenshots/new3.png'
796+
]);
797+
await runAction();
798+
expect(setFailedMock).toHaveBeenCalledWith(
799+
'The job failed, but this might not be due to visual tests.'
800+
);
801+
expect(createCommitStatusMock).not.toHaveBeenCalled();
782802
});
783803
});
784804

0 commit comments

Comments
 (0)