Skip to content

Commit

Permalink
Merge pull request Expensify#38363 from software-mansion-labs/ts-migr…
Browse files Browse the repository at this point in the history
…ation/32051-23055-tests

[No QA][TS migration] Migrate workflow_tests, adjust utils migration
  • Loading branch information
roryabraham authored Mar 23, 2024
2 parents 191d932 + 448af1f commit 2003844
Show file tree
Hide file tree
Showing 9 changed files with 107 additions and 82 deletions.
14 changes: 14 additions & 0 deletions src/types/modules/act.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import type {StepIdentifier as ActStepIdentifier} from '@kie/act-js';

declare module '@kie/act-js' {
// eslint-disable-next-line rulesdir/no-inline-named-export
export declare type StepIdentifier = {
id?: string;
name: string;
run?: string;
mockWith?: string;
with?: string;
envs?: string[];
inputs?: string[];
} & Omit<ActStepIdentifier, 'name' | 'id' | 'run' | 'mockWith'>;
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
const path = require('path');
const kieMockGithub = require('@kie/mock-github');
const utils = require('./utils/utils');
const assertions = require('./assertions/createNewVersionAssertions');
const mocks = require('./mocks/createNewVersionMocks');
const ExtendedAct = require('./utils/ExtendedAct').default;
import {MockGithub} from '@kie/mock-github';
import path from 'path';
import assertions from './assertions/createNewVersionAssertions';
import mocks from './mocks/createNewVersionMocks';

Check failure on line 4 in workflow_tests/createNewVersion.test.ts

View workflow job for this annotation

GitHub Actions / typecheck / typecheck

Module '"/home/runner/work/Expensify/Expensify/workflow_tests/mocks/createNewVersionMocks"' has no default export.
import ExtendedAct from './utils/ExtendedAct';
import * as utils from './utils/utils';

jest.setTimeout(90 * 1000); // 90 sec
let mockGithub;
let mockGithub: MockGithub;

const FILES_TO_COPY_INTO_TEST_REPO = [
...utils.deepCopy(utils.FILES_TO_COPY_INTO_TEST_REPO),
{
Expand All @@ -16,15 +17,15 @@ const FILES_TO_COPY_INTO_TEST_REPO = [
];

describe('test workflow createNewVersion', () => {
beforeAll(async () => {
beforeAll(() => {
// in case of the tests being interrupted without cleanup the mock repo directory may be left behind
// which breaks the next test run, this removes any possible leftovers
utils.removeMockRepoDir();
});

beforeEach(async () => {
// create a local repository and copy required files
mockGithub = new kieMockGithub.MockGithub({
mockGithub = new MockGithub({
repo: {
testCreateNewVersionWorkflowRepo: {
files: FILES_TO_COPY_INTO_TEST_REPO,
Expand Down Expand Up @@ -56,7 +57,7 @@ describe('test workflow createNewVersion', () => {
describe('actor is admin', () => {
const validateActorMockSteps = mocks.CREATENEWVERSION__VALIDATEACTOR__ADMIN__STEP_MOCKS;
it('executes full workflow', async () => {
const repoPath = mockGithub.repo.getPath('testCreateNewVersionWorkflowRepo') || '';
const repoPath = mockGithub.repo.getPath('testCreateNewVersionWorkflowRepo') ?? '';
const workflowPath = path.join(repoPath, '.github', 'workflows', 'createNewVersion.yml');
let act = new ExtendedAct(repoPath, workflowPath);
act = utils.setUpActParams(act, event, {}, secrets, githubToken, {}, inputs);
Expand All @@ -79,7 +80,7 @@ describe('test workflow createNewVersion', () => {
describe('actor is writer', () => {
const validateActorMockSteps = mocks.CREATENEWVERSION__VALIDATEACTOR__WRITER__STEP_MOCKS;
it('executes full workflow', async () => {
const repoPath = mockGithub.repo.getPath('testCreateNewVersionWorkflowRepo') || '';
const repoPath = mockGithub.repo.getPath('testCreateNewVersionWorkflowRepo') ?? '';
const workflowPath = path.join(repoPath, '.github', 'workflows', 'createNewVersion.yml');
let act = new ExtendedAct(repoPath, workflowPath);
act = utils.setUpActParams(act, event, {}, secrets, githubToken, {}, inputs);
Expand All @@ -102,7 +103,7 @@ describe('test workflow createNewVersion', () => {
describe('actor is reader', () => {
const validateActorMockSteps = mocks.CREATENEWVERSION__VALIDATEACTOR__NO_PERMISSION__STEP_MOCKS;
it('stops after validation', async () => {
const repoPath = mockGithub.repo.getPath('testCreateNewVersionWorkflowRepo') || '';
const repoPath = mockGithub.repo.getPath('testCreateNewVersionWorkflowRepo') ?? '';
const workflowPath = path.join(repoPath, '.github', 'workflows', 'createNewVersion.yml');
let act = new ExtendedAct(repoPath, workflowPath);
act = utils.setUpActParams(act, event, {}, secrets, githubToken, {}, inputs);
Expand All @@ -124,7 +125,7 @@ describe('test workflow createNewVersion', () => {

describe('one step fails', () => {
it('announces failure on Slack', async () => {
const repoPath = mockGithub.repo.getPath('testCreateNewVersionWorkflowRepo') || '';
const repoPath = mockGithub.repo.getPath('testCreateNewVersionWorkflowRepo') ?? '';
const workflowPath = path.join(repoPath, '.github', 'workflows', 'createNewVersion.yml');
let act = new ExtendedAct(repoPath, workflowPath);
act = utils.setUpActParams(act, event, {}, secrets, githubToken, {}, inputs);
Expand All @@ -133,7 +134,7 @@ describe('test workflow createNewVersion', () => {
validateActor: mocks.CREATENEWVERSION__VALIDATEACTOR__ADMIN__STEP_MOCKS,
createNewVersion: utils.deepCopy(mocks.CREATENEWVERSION__CREATENEWVERSION__STEP_MOCKS),
};
testMockSteps.createNewVersion[5] = utils.createMockStep('Commit new version', 'Commit new version', 'CREATENEWVERSION', [], [], [], [], false);
testMockSteps.createNewVersion[5] = utils.createMockStep('Commit new version', 'Commit new version', 'CREATENEWVERSION', [], [], {}, {}, false);
const result = await act.runEvent(event, {
workflowFile: path.join(repoPath, '.github', 'workflows', 'createNewVersion.yml'),
mockSteps: testMockSteps,
Expand All @@ -146,7 +147,7 @@ describe('test workflow createNewVersion', () => {
});

it('chooses source branch depending on the SEMVER_LEVEL', async () => {
const repoPath = mockGithub.repo.getPath('testCreateNewVersionWorkflowRepo') || '';
const repoPath = mockGithub.repo.getPath('testCreateNewVersionWorkflowRepo') ?? '';
const workflowPath = path.join(repoPath, '.github', 'workflows', 'createNewVersion.yml');
let act = new ExtendedAct(repoPath, workflowPath);
act = utils.setUpActParams(act, event, {}, secrets, githubToken, {}, {SEMVER_LEVEL: 'MAJOR'});
Expand Down
27 changes: 14 additions & 13 deletions workflow_tests/deploy.test.js → workflow_tests/deploy.test.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
const path = require('path');
const kieMockGithub = require('@kie/mock-github');
const utils = require('./utils/utils');
const assertions = require('./assertions/deployAssertions');
const mocks = require('./mocks/deployMocks');
const ExtendedAct = require('./utils/ExtendedAct').default;
import {MockGithub} from '@kie/mock-github';
import path from 'path';
import assertions from './assertions/deployAssertions';
import mocks from './mocks/deployMocks';

Check failure on line 4 in workflow_tests/deploy.test.ts

View workflow job for this annotation

GitHub Actions / typecheck / typecheck

Module '"/home/runner/work/Expensify/Expensify/workflow_tests/mocks/deployMocks"' has no default export.
import ExtendedAct from './utils/ExtendedAct';
import * as utils from './utils/utils';

jest.setTimeout(90 * 1000);
let mockGithub;
let mockGithub: MockGithub;

const FILES_TO_COPY_INTO_TEST_REPO = [
...utils.deepCopy(utils.FILES_TO_COPY_INTO_TEST_REPO),
{
Expand All @@ -16,15 +17,15 @@ const FILES_TO_COPY_INTO_TEST_REPO = [
];

describe('test workflow deploy', () => {
beforeAll(async () => {
beforeAll(() => {
// in case of the tests being interrupted without cleanup the mock repo directory may be left behind
// which breaks the next test run, this removes any possible leftovers
utils.removeMockRepoDir();
});

beforeEach(async () => {
// create a local repository and copy required files
mockGithub = new kieMockGithub.MockGithub({
mockGithub = new MockGithub({
repo: {
testDeployWorkflowRepo: {
files: FILES_TO_COPY_INTO_TEST_REPO,
Expand All @@ -48,7 +49,7 @@ describe('test workflow deploy', () => {
};
describe('push', () => {
it('to main - nothing triggered', async () => {
const repoPath = mockGithub.repo.getPath('testDeployWorkflowRepo') || '';
const repoPath = mockGithub.repo.getPath('testDeployWorkflowRepo') ?? '';
const workflowPath = path.join(repoPath, '.github', 'workflows', 'deploy.yml');
let act = new ExtendedAct(repoPath, workflowPath);
act = utils.setUpActParams(
Expand All @@ -75,7 +76,7 @@ describe('test workflow deploy', () => {
});

it('to staging - deployStaging triggered', async () => {
const repoPath = mockGithub.repo.getPath('testDeployWorkflowRepo') || '';
const repoPath = mockGithub.repo.getPath('testDeployWorkflowRepo') ?? '';
const workflowPath = path.join(repoPath, '.github', 'workflows', 'deploy.yml');
let act = new ExtendedAct(repoPath, workflowPath);
act = utils.setUpActParams(
Expand All @@ -102,7 +103,7 @@ describe('test workflow deploy', () => {
});

it('to production - deployProduction triggered', async () => {
const repoPath = mockGithub.repo.getPath('testDeployWorkflowRepo') || '';
const repoPath = mockGithub.repo.getPath('testDeployWorkflowRepo') ?? '';
const workflowPath = path.join(repoPath, '.github', 'workflows', 'deploy.yml');
let act = new ExtendedAct(repoPath, workflowPath);
act = utils.setUpActParams(
Expand Down Expand Up @@ -130,7 +131,7 @@ describe('test workflow deploy', () => {
});

it('different event than push - workflow does not execute', async () => {
const repoPath = mockGithub.repo.getPath('testDeployWorkflowRepo') || '';
const repoPath = mockGithub.repo.getPath('testDeployWorkflowRepo') ?? '';
const workflowPath = path.join(repoPath, '.github', 'workflows', 'deploy.yml');
let act = new ExtendedAct(repoPath, workflowPath);
const testMockSteps = {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
const path = require('path');
const kieMockGithub = require('@kie/mock-github');
const utils = require('./utils/utils');
const assertions = require('./assertions/deployBlockerAssertions');
const mocks = require('./mocks/deployBlockerMocks');
const ExtendedAct = require('./utils/ExtendedAct').default;
import {MockGithub} from '@kie/mock-github';
import path from 'path';
import assertions from './assertions/deployBlockerAssertions';
import mocks from './mocks/deployBlockerMocks';

Check failure on line 4 in workflow_tests/deployBlocker.test.ts

View workflow job for this annotation

GitHub Actions / typecheck / typecheck

Module '"/home/runner/work/Expensify/Expensify/workflow_tests/mocks/deployBlockerMocks"' has no default export.
import ExtendedAct from './utils/ExtendedAct';
import * as utils from './utils/utils';

jest.setTimeout(90 * 1000);
let mockGithub;
let mockGithub: MockGithub;

const FILES_TO_COPY_INTO_TEST_REPO = [
...utils.deepCopy(utils.FILES_TO_COPY_INTO_TEST_REPO),
{
Expand All @@ -23,15 +24,15 @@ describe('test workflow deployBlocker', () => {
SLACK_WEBHOOK: 'dummy_slack_webhook',
};

beforeAll(async () => {
beforeAll(() => {
// in case of the tests being interrupted without cleanup the mock repo directory may be left behind
// which breaks the next test run, this removes any possible leftovers
utils.removeMockRepoDir();
});

beforeEach(async () => {
// create a local repository and copy required files
mockGithub = new kieMockGithub.MockGithub({
mockGithub = new MockGithub({
repo: {
testDeployBlockerWorkflowRepo: {
files: FILES_TO_COPY_INTO_TEST_REPO,
Expand All @@ -57,14 +58,15 @@ describe('test workflow deployBlocker', () => {
issue: {
title: 'Labeled issue title',
number: '1234',
// eslint-disable-next-line @typescript-eslint/naming-convention
html_url: 'http://issue.html.url',
},
};
describe('label is DeployBlockerCash', () => {
const testEventOptions = utils.deepCopy(eventOptions);
testEventOptions.label = {name: 'DeployBlockerCash'};
it('runs the workflow and announces success on Slack', async () => {
const repoPath = mockGithub.repo.getPath('testDeployBlockerWorkflowRepo') || '';
const repoPath = mockGithub.repo.getPath('testDeployBlockerWorkflowRepo') ?? '';
const workflowPath = path.join(repoPath, '.github', 'workflows', 'deployBlocker.yml');
let act = new ExtendedAct(repoPath, workflowPath);
act = utils.setUpActParams(act, event, testEventOptions, secrets, githubToken, {}, {});
Expand All @@ -90,7 +92,7 @@ describe('test workflow deployBlocker', () => {
});
describe('one step fails', () => {
it('announces failure on Slack', async () => {
const repoPath = mockGithub.repo.getPath('testDeployBlockerWorkflowRepo') || '';
const repoPath = mockGithub.repo.getPath('testDeployBlockerWorkflowRepo') ?? '';
const workflowPath = path.join(repoPath, '.github', 'workflows', 'deployBlocker.yml');
let act = new ExtendedAct(repoPath, workflowPath);
act = utils.setUpActParams(act, event, testEventOptions, secrets, githubToken, {}, {});
Expand Down Expand Up @@ -130,7 +132,7 @@ describe('test workflow deployBlocker', () => {
const testEventOptions = utils.deepCopy(eventOptions);
testEventOptions.label = {name: 'Different Label'};
it('does not run workflow', async () => {
const repoPath = mockGithub.repo.getPath('testDeployBlockerWorkflowRepo') || '';
const repoPath = mockGithub.repo.getPath('testDeployBlockerWorkflowRepo') ?? '';
const workflowPath = path.join(repoPath, '.github', 'workflows', 'deployBlocker.yml');
let act = new ExtendedAct(repoPath, workflowPath);
act = utils.setUpActParams(act, event, testEventOptions, secrets, githubToken, {}, {});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
const path = require('path');
const kieMockGithub = require('@kie/mock-github');
const utils = require('./utils/utils');
const assertions = require('./assertions/finishReleaseCycleAssertions');
const mocks = require('./mocks/finishReleaseCycleMocks');
const ExtendedAct = require('./utils/ExtendedAct').default;
import {MockGithub} from '@kie/mock-github';
import path from 'path';
import assertions from './assertions/finishReleaseCycleAssertions';
import mocks from './mocks/finishReleaseCycleMocks';

Check failure on line 4 in workflow_tests/finishReleaseCycle.test.ts

View workflow job for this annotation

GitHub Actions / typecheck / typecheck

Module '"/home/runner/work/Expensify/Expensify/workflow_tests/mocks/finishReleaseCycleMocks"' has no default export.
import ExtendedAct from './utils/ExtendedAct';
import type {MockJobs} from './utils/JobMocker';
import * as utils from './utils/utils';

jest.setTimeout(90 * 1000);
let mockGithub;
let mockGithub: MockGithub;
const FILES_TO_COPY_INTO_TEST_REPO = [
...utils.deepCopy(utils.FILES_TO_COPY_INTO_TEST_REPO),
{
Expand All @@ -16,15 +17,15 @@ const FILES_TO_COPY_INTO_TEST_REPO = [
];

describe('test workflow finishReleaseCycle', () => {
beforeAll(async () => {
beforeAll(() => {
// in case of the tests being interrupted without cleanup the mock repo directory may be left behind
// which breaks the next test run, this removes any possible leftovers
utils.removeMockRepoDir();
});

beforeEach(async () => {
// create a local repository and copy required files
mockGithub = new kieMockGithub.MockGithub({
mockGithub = new MockGithub({
repo: {
testFinishReleaseCycleWorkflowRepo: {
files: FILES_TO_COPY_INTO_TEST_REPO,
Expand All @@ -50,7 +51,7 @@ describe('test workflow finishReleaseCycle', () => {
describe('actor is a team member', () => {
describe('no deploy blockers', () => {
it('production updated, new version created', async () => {
const repoPath = mockGithub.repo.getPath('testFinishReleaseCycleWorkflowRepo') || '';
const repoPath = mockGithub.repo.getPath('testFinishReleaseCycleWorkflowRepo') ?? '';
const workflowPath = path.join(repoPath, '.github', 'workflows', 'finishReleaseCycle.yml');
let act = new ExtendedAct(repoPath, workflowPath);
act = utils.setUpActParams(
Expand All @@ -71,7 +72,7 @@ describe('test workflow finishReleaseCycle', () => {
updateProduction: mocks.FINISHRELEASECYCLE__UPDATEPRODUCTION__STEP_MOCKS,
updateStaging: mocks.FINISHRELEASECYCLE__UPDATESTAGING__STEP_MOCKS,
};
const testMockJobs = {
const testMockJobs: MockJobs = {
createNewPatchVersion: {
steps: mocks.FINISHRELEASECYCLE__CREATENEWPATCHVERSION__STEP_MOCKS,
outputs: {
Expand All @@ -96,7 +97,7 @@ describe('test workflow finishReleaseCycle', () => {
});
describe('deploy blockers', () => {
it('production not updated, new version not created, issue reopened', async () => {
const repoPath = mockGithub.repo.getPath('testFinishReleaseCycleWorkflowRepo') || '';
const repoPath = mockGithub.repo.getPath('testFinishReleaseCycleWorkflowRepo') ?? '';
const workflowPath = path.join(repoPath, '.github', 'workflows', 'finishReleaseCycle.yml');
let act = new ExtendedAct(repoPath, workflowPath);
act = utils.setUpActParams(
Expand Down Expand Up @@ -143,7 +144,7 @@ describe('test workflow finishReleaseCycle', () => {
});
describe('actor is not a team member', () => {
it('production not updated, new version not created, issue reopened', async () => {
const repoPath = mockGithub.repo.getPath('testFinishReleaseCycleWorkflowRepo') || '';
const repoPath = mockGithub.repo.getPath('testFinishReleaseCycleWorkflowRepo') ?? '';
const workflowPath = path.join(repoPath, '.github', 'workflows', 'finishReleaseCycle.yml');
let act = new ExtendedAct(repoPath, workflowPath);
act = utils.setUpActParams(
Expand Down Expand Up @@ -190,7 +191,7 @@ describe('test workflow finishReleaseCycle', () => {
});
describe('issue does not have StagingDeployCash', () => {
it('validate job not run', async () => {
const repoPath = mockGithub.repo.getPath('testFinishReleaseCycleWorkflowRepo') || '';
const repoPath = mockGithub.repo.getPath('testFinishReleaseCycleWorkflowRepo') ?? '';
const workflowPath = path.join(repoPath, '.github', 'workflows', 'finishReleaseCycle.yml');
let act = new ExtendedAct(repoPath, workflowPath);
act = utils.setUpActParams(
Expand Down
Loading

0 comments on commit 2003844

Please sign in to comment.