Skip to content

Commit

Permalink
fix(action): stop skipping status update for job re-runs
Browse files Browse the repository at this point in the history
  • Loading branch information
danadajian committed Jul 31, 2023
1 parent 89db2ce commit fc92228
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 7 deletions.
7 changes: 5 additions & 2 deletions action/dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12003,7 +12003,8 @@ const run = async () => {
if (diffFileCount === 0 && newFileCount === 0) {
(0, core_1.info)('All visual tests passed, and no diffs found!');
const latestVisualRegressionStatus = await (0, get_latest_visual_regression_status_1.getLatestVisualRegressionStatus)(commitHash);
if (latestVisualRegressionStatus?.state === 'failure') {
if (latestVisualRegressionStatus?.state === 'failure' &&
github_1.context.runNumber === 1) {
(0, core_1.info)('Visual Regression status has already been set to failed, so skipping status update.');
return;
}
Expand All @@ -12017,7 +12018,9 @@ const run = async () => {
}
const latestVisualRegressionStatus = await (0, get_latest_visual_regression_status_1.getLatestVisualRegressionStatus)(commitHash);
if (latestVisualRegressionStatus?.state === 'failure' &&
latestVisualRegressionStatus?.description === shared_1.VISUAL_TESTS_FAILED_TO_EXECUTE) {
latestVisualRegressionStatus?.description ===
shared_1.VISUAL_TESTS_FAILED_TO_EXECUTE &&
github_1.context.runNumber === 1) {
(0, core_1.warning)('Some other Visual Regression tests failed to execute successfully, so skipping status update and comment.');
return;
}
Expand Down
2 changes: 1 addition & 1 deletion action/dist/index.js.map

Large diffs are not rendered by default.

9 changes: 7 additions & 2 deletions action/src/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,10 @@ export const run = async () => {
const latestVisualRegressionStatus = await getLatestVisualRegressionStatus(
commitHash
);
if (latestVisualRegressionStatus?.state === 'failure') {
if (
latestVisualRegressionStatus?.state === 'failure' &&
context.runNumber === 1
) {
info(
'Visual Regression status has already been set to failed, so skipping status update.'
);
Expand All @@ -79,7 +82,9 @@ export const run = async () => {
);
if (
latestVisualRegressionStatus?.state === 'failure' &&
latestVisualRegressionStatus?.description === VISUAL_TESTS_FAILED_TO_EXECUTE
latestVisualRegressionStatus?.description ===
VISUAL_TESTS_FAILED_TO_EXECUTE &&
context.runNumber === 1
) {
warning(
'Some other Visual Regression tests failed to execute successfully, so skipping status update and comment.'
Expand Down
75 changes: 73 additions & 2 deletions action/test/run.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { run } from '../src/run';
import { exec } from '@actions/exec';
import { context } from '@actions/github';
import { getInput, getMultilineInput, setFailed } from '@actions/core';
import { octokit } from '../src/octokit';
import { sync } from 'glob';
Expand All @@ -13,7 +14,7 @@ jest.mock('glob');
jest.mock('@actions/core');
jest.mock('@actions/exec');
jest.mock('@actions/github', () => ({
context: { repo: { repo: 'repo', owner: 'owner' } },
context: { repo: { repo: 'repo', owner: 'owner' }, runNumber: 1 },
getOctokit: jest.fn(() => ({
rest: {
repos: {
Expand Down Expand Up @@ -224,7 +225,7 @@ describe('main', () => {
expect(octokit.rest.repos.createCommitStatus).toHaveBeenCalled();
});

it('should not set failure commit status or create comment if the latest Visual Regression status is failure because tests failed to execute successfully', async () => {
it('should not set commit status or create comment if the latest Visual Regression status is failure because tests failed to execute successfully', async () => {
(exec as jest.Mock).mockResolvedValue(0);
(sync as unknown as jest.Mock).mockReturnValue([
'path/to/screenshots/base.png',
Expand Down Expand Up @@ -259,3 +260,73 @@ describe('main', () => {
expect(octokit.rest.issues.createComment).not.toHaveBeenCalled();
});
});

describe('main with rerun', () => {
beforeEach(() => {
context.runNumber = 2;
});

it('should set successful commit status if a visual test failed to execute but this is a re-run', async () => {
(exec as jest.Mock).mockResolvedValue(0);
(sync as unknown as jest.Mock).mockReturnValue([
'path/to/screenshots/base.png'
]);
(
octokit.rest.repos.listCommitStatusesForRef as unknown as jest.Mock
).mockResolvedValue({
data: [
{
context: 'some context',
created_at: '2023-05-21T16:51:29Z',
state: 'success'
},
{
context: VISUAL_REGRESSION_CONTEXT,
created_at: '2023-05-21T16:51:29Z',
state: 'failure',
description: VISUAL_TESTS_FAILED_TO_EXECUTE
},
{
context: VISUAL_REGRESSION_CONTEXT,
created_at: '2023-05-21T15:51:29Z',
state: 'success'
}
]
});
await run();
expect(octokit.rest.repos.createCommitStatus).toHaveBeenCalled();
});

it('should set failure commit status if a visual test failed to execute but this is a re-run', async () => {
(exec as jest.Mock).mockResolvedValue(0);
(sync as unknown as jest.Mock).mockReturnValue([
'path/to/screenshots/base.png',
'path/to/screenshots/diff.png',
'path/to/screenshots/new.png'
]);
(
octokit.rest.repos.listCommitStatusesForRef as unknown as jest.Mock
).mockResolvedValue({
data: [
{
context: 'some context',
created_at: '2023-05-21T16:51:29Z',
state: 'success'
},
{
context: VISUAL_REGRESSION_CONTEXT,
created_at: '2023-05-21T16:51:29Z',
state: 'failure',
description: VISUAL_TESTS_FAILED_TO_EXECUTE
},
{
context: VISUAL_REGRESSION_CONTEXT,
created_at: '2023-05-21T15:51:29Z',
state: 'success'
}
]
});
await run();
expect(octokit.rest.repos.createCommitStatus).toHaveBeenCalled();
});
});

0 comments on commit fc92228

Please sign in to comment.