Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[No QA][TS migration] migrate workflow tests #38491

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion workflow_tests/assertions/testBuildAssertions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,7 @@ function assertPostGithubCommentJobExecuted(
});
}

export {
export default {
assertValidateActorJobExecuted,
assertGetBranchRefJobExecuted,
assertAndroidJobExecuted,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,4 @@ function assertVerifyJobExecuted(workflowResult: Step[], didExecute = true) {
});
}

// eslint-disable-next-line import/prefer-default-export
export {assertVerifyJobExecuted};
export default {assertVerifyJobExecuted};
3 changes: 1 addition & 2 deletions workflow_tests/assertions/verifyPodfileAssertions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,4 @@ function assertVerifyJobExecuted(workflowResult: Step[], didExecute = true) {
});
}

// eslint-disable-next-line import/prefer-default-export
export {assertVerifyJobExecuted};
export default {assertVerifyJobExecuted};
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ function assertVerifySignedCommitsJobExecuted(workflowResult: Step[], didExecute
}

// eslint-disable-next-line import/prefer-default-export
export {assertVerifySignedCommitsJobExecuted};
export default {assertVerifySignedCommitsJobExecuted};
9 changes: 0 additions & 9 deletions workflow_tests/jest.config.js

This file was deleted.

13 changes: 13 additions & 0 deletions workflow_tests/jest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/* eslint-disable @typescript-eslint/naming-convention */
import type {Config} from 'jest';

const config: Config = {
verbose: true,
transform: {
'^.+\\.(js|jsx|ts|tsx)$': 'ts-jest',
},
clearMocks: true,
resetMocks: true,
};

export default config;
2 changes: 1 addition & 1 deletion workflow_tests/mocks/testBuildMocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ const TESTBUILD__POSTGITHUBCOMMENT__STEP_MOCKS = [
TESTBUILD__POSTGITHUBCOMMENT__PUBLISH_LINKS_TO_APPS_FOR_DOWNLOAD__STEP_MOCK,
];

export {
export default {
TESTBUILD__VALIDATEACTOR__TEAM_MEMBER_HAS_FLAG__STEP_MOCKS,
TESTBUILD__VALIDATEACTOR__TEAM_MEMBER_NO_FLAG__STEP_MOCKS,
TESTBUILD__VALIDATEACTOR__NO_TEAM_MEMBER_HAS_FLAG__STEP_MOCKS,
Expand Down
2 changes: 1 addition & 1 deletion workflow_tests/scripts/runWorkflowTests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,4 @@ info 'ACT_BINARY environment variable set to an Act executable'
success 'Environment setup properly - running tests'

# Run tests
npm test -- --config=workflow_tests/jest.config.js --runInBand "$@"
npm test -- --config=workflow_tests/jest.config.ts --runInBand "$@"
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/testBuildAssertions');
const mocks = require('./mocks/testBuildMocks');
const ExtendedAct = require('./utils/ExtendedAct').default;
/* eslint-disable @typescript-eslint/naming-convention */
import {MockGithub} from '@kie/mock-github';
import path from 'path';
import assertions from './assertions/testBuildAssertions';
import mocks from './mocks/testBuildMocks';
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 @@ -32,15 +33,15 @@ describe('test workflow testBuild', () => {
MYAPP_UPLOAD_KEY_PASSWORD: 'dummy_myapp_upload_key_password',
};

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: {
testTestBuildWorkflowRepo: {
files: FILES_TO_COPY_INTO_TEST_REPO,
Expand All @@ -60,7 +61,7 @@ describe('test workflow testBuild', () => {
PULL_REQUEST_NUMBER: '1234',
};
it('executes workflow', async () => {
const repoPath = mockGithub.repo.getPath('testTestBuildWorkflowRepo') || '';
const repoPath = mockGithub.repo.getPath('testTestBuildWorkflowRepo') ?? '';
const workflowPath = path.join(repoPath, '.github', 'workflows', 'testBuild.yml');
let act = new ExtendedAct(repoPath, workflowPath);
act = utils.setUpActParams(act, event, {}, secrets, githubToken, {}, inputs);
Expand Down Expand Up @@ -91,7 +92,7 @@ describe('test workflow testBuild', () => {
});
describe('actor is not a team member', () => {
it('stops the workflow after validation', async () => {
const repoPath = mockGithub.repo.getPath('testTestBuildWorkflowRepo') || '';
const repoPath = mockGithub.repo.getPath('testTestBuildWorkflowRepo') ?? '';
const workflowPath = path.join(repoPath, '.github', 'workflows', 'testBuild.yml');
let act = new ExtendedAct(repoPath, workflowPath);
act = utils.setUpActParams(act, event, {}, secrets, githubToken, {}, inputs);
Expand Down Expand Up @@ -123,7 +124,7 @@ describe('test workflow testBuild', () => {
});
describe('PR does not have READY_TO_BUILD label', () => {
it('stops the workflow after validation', async () => {
const repoPath = mockGithub.repo.getPath('testTestBuildWorkflowRepo') || '';
const repoPath = mockGithub.repo.getPath('testTestBuildWorkflowRepo') ?? '';
const workflowPath = path.join(repoPath, '.github', 'workflows', 'testBuild.yml');
let act = new ExtendedAct(repoPath, workflowPath);
act = utils.setUpActParams(act, event, {}, secrets, githubToken, {}, inputs);
Expand Down Expand Up @@ -155,7 +156,7 @@ describe('test workflow testBuild', () => {
});
describe('actor is not a team member and PR does not have READY_TO_BUILD label', () => {
it('stops the workflow after validation', async () => {
const repoPath = mockGithub.repo.getPath('testTestBuildWorkflowRepo') || '';
const repoPath = mockGithub.repo.getPath('testTestBuildWorkflowRepo') ?? '';
const workflowPath = path.join(repoPath, '.github', 'workflows', 'testBuild.yml');
let act = new ExtendedAct(repoPath, workflowPath);
act = utils.setUpActParams(act, event, {}, secrets, githubToken, {}, inputs);
Expand Down Expand Up @@ -187,7 +188,7 @@ describe('test workflow testBuild', () => {
});
describe('android fails', () => {
it('executes workflow, failure reflected', async () => {
const repoPath = mockGithub.repo.getPath('testTestBuildWorkflowRepo') || '';
const repoPath = mockGithub.repo.getPath('testTestBuildWorkflowRepo') ?? '';
const workflowPath = path.join(repoPath, '.github', 'workflows', 'testBuild.yml');
let act = new ExtendedAct(repoPath, workflowPath);
act = utils.setUpActParams(act, event, {}, secrets, githubToken, {}, inputs);
Expand Down Expand Up @@ -220,7 +221,7 @@ describe('test workflow testBuild', () => {
});
describe('iOS fails', () => {
it('executes workflow, failure reflected', async () => {
const repoPath = mockGithub.repo.getPath('testTestBuildWorkflowRepo') || '';
const repoPath = mockGithub.repo.getPath('testTestBuildWorkflowRepo') ?? '';
const workflowPath = path.join(repoPath, '.github', 'workflows', 'testBuild.yml');
let act = new ExtendedAct(repoPath, workflowPath);
act = utils.setUpActParams(act, event, {}, secrets, githubToken, {}, inputs);
Expand Down Expand Up @@ -253,7 +254,7 @@ describe('test workflow testBuild', () => {
});
describe('desktop fails', () => {
it('executes workflow, failure reflected', async () => {
const repoPath = mockGithub.repo.getPath('testTestBuildWorkflowRepo') || '';
const repoPath = mockGithub.repo.getPath('testTestBuildWorkflowRepo') ?? '';
const workflowPath = path.join(repoPath, '.github', 'workflows', 'testBuild.yml');
let act = new ExtendedAct(repoPath, workflowPath);
act = utils.setUpActParams(act, event, {}, secrets, githubToken, {}, inputs);
Expand Down Expand Up @@ -295,7 +296,7 @@ describe('test workflow testBuild', () => {
});
describe('web fails', () => {
it('executes workflow, failure reflected', async () => {
const repoPath = mockGithub.repo.getPath('testTestBuildWorkflowRepo') || '';
const repoPath = mockGithub.repo.getPath('testTestBuildWorkflowRepo') ?? '';
const workflowPath = path.join(repoPath, '.github', 'workflows', 'testBuild.yml');
let act = new ExtendedAct(repoPath, workflowPath);
act = utils.setUpActParams(act, event, {}, secrets, githubToken, {}, inputs);
Expand Down Expand Up @@ -348,7 +349,7 @@ describe('test workflow testBuild', () => {
},
};
it('executes workflow, without getBranchRef', async () => {
const repoPath = mockGithub.repo.getPath('testTestBuildWorkflowRepo') || '';
const repoPath = mockGithub.repo.getPath('testTestBuildWorkflowRepo') ?? '';
const workflowPath = path.join(repoPath, '.github', 'workflows', 'testBuild.yml');
let act = new ExtendedAct(repoPath, workflowPath);
act = utils.setUpActParams(act, event, eventOptions, secrets, githubToken, {});
Expand Down Expand Up @@ -379,7 +380,7 @@ describe('test workflow testBuild', () => {
});
describe('actor is not a team member', () => {
it('stops the workflow after validation', async () => {
const repoPath = mockGithub.repo.getPath('testTestBuildWorkflowRepo') || '';
const repoPath = mockGithub.repo.getPath('testTestBuildWorkflowRepo') ?? '';
const workflowPath = path.join(repoPath, '.github', 'workflows', 'testBuild.yml');
let act = new ExtendedAct(repoPath, workflowPath);
act = utils.setUpActParams(act, event, eventOptions, secrets, githubToken, {});
Expand Down Expand Up @@ -411,7 +412,7 @@ describe('test workflow testBuild', () => {
});
describe('PR does not have READY_TO_BUILD label', () => {
it('stops the workflow after validation', async () => {
const repoPath = mockGithub.repo.getPath('testTestBuildWorkflowRepo') || '';
const repoPath = mockGithub.repo.getPath('testTestBuildWorkflowRepo') ?? '';
const workflowPath = path.join(repoPath, '.github', 'workflows', 'testBuild.yml');
let act = new ExtendedAct(repoPath, workflowPath);
act = utils.setUpActParams(act, event, eventOptions, secrets, githubToken, {});
Expand Down Expand Up @@ -443,7 +444,7 @@ describe('test workflow testBuild', () => {
});
describe('actor is not a team member and PR does not have READY_TO_BUILD label', () => {
it('stops the workflow after validation', async () => {
const repoPath = mockGithub.repo.getPath('testTestBuildWorkflowRepo') || '';
const repoPath = mockGithub.repo.getPath('testTestBuildWorkflowRepo') ?? '';
const workflowPath = path.join(repoPath, '.github', 'workflows', 'testBuild.yml');
let act = new ExtendedAct(repoPath, workflowPath);
act = utils.setUpActParams(act, event, eventOptions, secrets, githubToken, {});
Expand Down Expand Up @@ -486,7 +487,7 @@ describe('test workflow testBuild', () => {
},
};
it('executes workflow, without getBranchRef', async () => {
const repoPath = mockGithub.repo.getPath('testTestBuildWorkflowRepo') || '';
const repoPath = mockGithub.repo.getPath('testTestBuildWorkflowRepo') ?? '';
const workflowPath = path.join(repoPath, '.github', 'workflows', 'testBuild.yml');
let act = new ExtendedAct(repoPath, workflowPath);
act = utils.setUpActParams(act, event, eventOptions, secrets, githubToken, {});
Expand Down Expand Up @@ -517,7 +518,7 @@ describe('test workflow testBuild', () => {
});
describe('actor is not a team member', () => {
it('stops the workflow after validation', async () => {
const repoPath = mockGithub.repo.getPath('testTestBuildWorkflowRepo') || '';
const repoPath = mockGithub.repo.getPath('testTestBuildWorkflowRepo') ?? '';
const workflowPath = path.join(repoPath, '.github', 'workflows', 'testBuild.yml');
let act = new ExtendedAct(repoPath, workflowPath);
act = utils.setUpActParams(act, event, eventOptions, secrets, githubToken, {});
Expand Down Expand Up @@ -549,7 +550,7 @@ describe('test workflow testBuild', () => {
});
describe('PR does not have READY_TO_BUILD label', () => {
it('stops the workflow after validation', async () => {
const repoPath = mockGithub.repo.getPath('testTestBuildWorkflowRepo') || '';
const repoPath = mockGithub.repo.getPath('testTestBuildWorkflowRepo') ?? '';
const workflowPath = path.join(repoPath, '.github', 'workflows', 'testBuild.yml');
let act = new ExtendedAct(repoPath, workflowPath);
act = utils.setUpActParams(act, event, eventOptions, secrets, githubToken, {});
Expand Down Expand Up @@ -581,7 +582,7 @@ describe('test workflow testBuild', () => {
});
describe('actor is not a team member and PR does not have READY_TO_BUILD label', () => {
it('stops the workflow after validation', async () => {
const repoPath = mockGithub.repo.getPath('testTestBuildWorkflowRepo') || '';
const repoPath = mockGithub.repo.getPath('testTestBuildWorkflowRepo') ?? '';
const workflowPath = path.join(repoPath, '.github', 'workflows', 'testBuild.yml');
let act = new ExtendedAct(repoPath, workflowPath);
act = utils.setUpActParams(act, event, eventOptions, secrets, githubToken, {});
Expand Down Expand Up @@ -624,7 +625,7 @@ describe('test workflow testBuild', () => {
},
};
it('executes workflow, withuout getBranchRef', async () => {
const repoPath = mockGithub.repo.getPath('testTestBuildWorkflowRepo') || '';
const repoPath = mockGithub.repo.getPath('testTestBuildWorkflowRepo') ?? '';
const workflowPath = path.join(repoPath, '.github', 'workflows', 'testBuild.yml');
let act = new ExtendedAct(repoPath, workflowPath);
act = utils.setUpActParams(act, event, eventOptions, secrets, githubToken, {});
Expand Down Expand Up @@ -655,7 +656,7 @@ describe('test workflow testBuild', () => {
});
describe('actor is not a team member', () => {
it('stops the workflow after validation', async () => {
const repoPath = mockGithub.repo.getPath('testTestBuildWorkflowRepo') || '';
const repoPath = mockGithub.repo.getPath('testTestBuildWorkflowRepo') ?? '';
const workflowPath = path.join(repoPath, '.github', 'workflows', 'testBuild.yml');
let act = new ExtendedAct(repoPath, workflowPath);
act = utils.setUpActParams(act, event, eventOptions, secrets, githubToken, {});
Expand Down Expand Up @@ -687,7 +688,7 @@ describe('test workflow testBuild', () => {
});
describe('PR does not have READY_TO_BUILD label', () => {
it('stops the workflow after validation', async () => {
const repoPath = mockGithub.repo.getPath('testTestBuildWorkflowRepo') || '';
const repoPath = mockGithub.repo.getPath('testTestBuildWorkflowRepo') ?? '';
const workflowPath = path.join(repoPath, '.github', 'workflows', 'testBuild.yml');
let act = new ExtendedAct(repoPath, workflowPath);
act = utils.setUpActParams(act, event, eventOptions, secrets, githubToken, {});
Expand Down Expand Up @@ -719,7 +720,7 @@ describe('test workflow testBuild', () => {
});
describe('actor is not a team member and PR does not have READY_TO_BUILD label', () => {
it('stops the workflow after validation', async () => {
const repoPath = mockGithub.repo.getPath('testTestBuildWorkflowRepo') || '';
const repoPath = mockGithub.repo.getPath('testTestBuildWorkflowRepo') ?? '';
const workflowPath = path.join(repoPath, '.github', 'workflows', 'testBuild.yml');
let act = new ExtendedAct(repoPath, workflowPath);
act = utils.setUpActParams(act, event, eventOptions, secrets, githubToken, {});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
const path = require('path');
const kieMockGithub = require('@kie/mock-github');
const utils = require('./utils/utils');
const assertions = require('./assertions/validateGithubActionsAssertions');
const mocks = require('./mocks/validateGithubActionsMocks').default;
const ExtendedAct = require('./utils/ExtendedAct').default;
import {MockGithub} from '@kie/mock-github';
import path from 'path';
import assertions from './assertions/validateGithubActionsAssertions';
import mocks from './mocks/validateGithubActionsMocks';
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 @@ -19,15 +19,15 @@ describe('test workflow validateGithubActions', () => {
const githubToken = 'dummy_github_token';
const actor = 'Dummy Actor';

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: {
testValidateGithubActionsWorkflowRepo: {
files: FILES_TO_COPY_INTO_TEST_REPO,
Expand All @@ -47,7 +47,7 @@ describe('test workflow validateGithubActions', () => {
action: 'opened',
};
it('executes verification', async () => {
const repoPath = mockGithub.repo.getPath('testValidateGithubActionsWorkflowRepo') || '';
const repoPath = mockGithub.repo.getPath('testValidateGithubActionsWorkflowRepo') ?? '';
const workflowPath = path.join(repoPath, '.github', 'workflows', 'validateGithubActions.yml');
let act = new ExtendedAct(repoPath, workflowPath);
act = utils.setUpActParams(act, event, eventOptions, {}, githubToken);
Expand All @@ -70,7 +70,7 @@ describe('test workflow validateGithubActions', () => {
action: 'synchronize',
};
it('executes verification', async () => {
const repoPath = mockGithub.repo.getPath('testValidateGithubActionsWorkflowRepo') || '';
const repoPath = mockGithub.repo.getPath('testValidateGithubActionsWorkflowRepo') ?? '';
const workflowPath = path.join(repoPath, '.github', 'workflows', 'validateGithubActions.yml');
let act = new ExtendedAct(repoPath, workflowPath);
act = utils.setUpActParams(act, event, eventOptions, {}, githubToken);
Expand Down
Loading
Loading