From 5d56fb096ca6cf1d7c346b5581fcd5939c05ad18 Mon Sep 17 00:00:00 2001 From: Jakub Szymczak Date: Mon, 18 Mar 2024 17:36:07 +0100 Subject: [PATCH 01/54] migrate jest.config --- workflow_tests/jest.config.js | 9 --------- workflow_tests/jest.config.ts | 13 +++++++++++++ 2 files changed, 13 insertions(+), 9 deletions(-) delete mode 100644 workflow_tests/jest.config.js create mode 100644 workflow_tests/jest.config.ts diff --git a/workflow_tests/jest.config.js b/workflow_tests/jest.config.js deleted file mode 100644 index cecdf8589d7f..000000000000 --- a/workflow_tests/jest.config.js +++ /dev/null @@ -1,9 +0,0 @@ -module.exports = { - verbose: true, - transform: { - '^.+\\.jsx?$': 'babel-jest', - '^.+\\.tsx?$': 'ts-jest', - }, - clearMocks: true, - resetMocks: true, -}; diff --git a/workflow_tests/jest.config.ts b/workflow_tests/jest.config.ts new file mode 100644 index 000000000000..da9dd2e15794 --- /dev/null +++ b/workflow_tests/jest.config.ts @@ -0,0 +1,13 @@ +/* eslint-disable @typescript-eslint/naming-convention */ +import type {Config} from 'jest'; + +const config: Config = { + verbose: true, + transform: { + '^.+\\.jsx?$': 'babel-jest', + }, + clearMocks: true, + resetMocks: true, +}; + +export default config; From 94702fbd9564b31afd94e78d37e54d374edd9cf2 Mon Sep 17 00:00:00 2001 From: Jakub Szymczak Date: Mon, 18 Mar 2024 17:36:27 +0100 Subject: [PATCH 02/54] migrate testBuild --- .../{testBuild.test.js => testBuild.test.ts} | 58 ++++++++++--------- 1 file changed, 31 insertions(+), 27 deletions(-) rename workflow_tests/{testBuild.test.js => testBuild.test.ts} (97%) diff --git a/workflow_tests/testBuild.test.js b/workflow_tests/testBuild.test.ts similarity index 97% rename from workflow_tests/testBuild.test.js rename to workflow_tests/testBuild.test.ts index 371759607ed5..2c676a63adfe 100644 --- a/workflow_tests/testBuild.test.js +++ b/workflow_tests/testBuild.test.ts @@ -1,12 +1,16 @@ -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 eAct = require('./utils/ExtendedAct'); +/* eslint-disable @typescript-eslint/naming-convention */ + +/* eslint-disable @typescript-eslint/require-await */ +import type {MockGithub} from '@kie/mock-github'; +import kieMockGithub from '@kie/mock-github'; +import path from 'path'; +import assertions from './assertions/testBuildAssertions'; +import mocks from './mocks/testBuildMocks'; +import * as eAct 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), { @@ -60,7 +64,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 eAct.ExtendedAct(repoPath, workflowPath); act = utils.setUpActParams(act, event, {}, secrets, githubToken, {}, inputs); @@ -91,7 +95,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 eAct.ExtendedAct(repoPath, workflowPath); act = utils.setUpActParams(act, event, {}, secrets, githubToken, {}, inputs); @@ -123,7 +127,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 eAct.ExtendedAct(repoPath, workflowPath); act = utils.setUpActParams(act, event, {}, secrets, githubToken, {}, inputs); @@ -155,7 +159,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 eAct.ExtendedAct(repoPath, workflowPath); act = utils.setUpActParams(act, event, {}, secrets, githubToken, {}, inputs); @@ -187,7 +191,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 eAct.ExtendedAct(repoPath, workflowPath); act = utils.setUpActParams(act, event, {}, secrets, githubToken, {}, inputs); @@ -220,7 +224,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 eAct.ExtendedAct(repoPath, workflowPath); act = utils.setUpActParams(act, event, {}, secrets, githubToken, {}, inputs); @@ -253,7 +257,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 eAct.ExtendedAct(repoPath, workflowPath); act = utils.setUpActParams(act, event, {}, secrets, githubToken, {}, inputs); @@ -295,7 +299,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 eAct.ExtendedAct(repoPath, workflowPath); act = utils.setUpActParams(act, event, {}, secrets, githubToken, {}, inputs); @@ -348,7 +352,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 eAct.ExtendedAct(repoPath, workflowPath); act = utils.setUpActParams(act, event, eventOptions, secrets, githubToken, {}); @@ -379,7 +383,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 eAct.ExtendedAct(repoPath, workflowPath); act = utils.setUpActParams(act, event, eventOptions, secrets, githubToken, {}); @@ -411,7 +415,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 eAct.ExtendedAct(repoPath, workflowPath); act = utils.setUpActParams(act, event, eventOptions, secrets, githubToken, {}); @@ -443,7 +447,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 eAct.ExtendedAct(repoPath, workflowPath); act = utils.setUpActParams(act, event, eventOptions, secrets, githubToken, {}); @@ -486,7 +490,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 eAct.ExtendedAct(repoPath, workflowPath); act = utils.setUpActParams(act, event, eventOptions, secrets, githubToken, {}); @@ -517,7 +521,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 eAct.ExtendedAct(repoPath, workflowPath); act = utils.setUpActParams(act, event, eventOptions, secrets, githubToken, {}); @@ -549,7 +553,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 eAct.ExtendedAct(repoPath, workflowPath); act = utils.setUpActParams(act, event, eventOptions, secrets, githubToken, {}); @@ -581,7 +585,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 eAct.ExtendedAct(repoPath, workflowPath); act = utils.setUpActParams(act, event, eventOptions, secrets, githubToken, {}); @@ -624,7 +628,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 eAct.ExtendedAct(repoPath, workflowPath); act = utils.setUpActParams(act, event, eventOptions, secrets, githubToken, {}); @@ -655,7 +659,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 eAct.ExtendedAct(repoPath, workflowPath); act = utils.setUpActParams(act, event, eventOptions, secrets, githubToken, {}); @@ -687,7 +691,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 eAct.ExtendedAct(repoPath, workflowPath); act = utils.setUpActParams(act, event, eventOptions, secrets, githubToken, {}); @@ -719,7 +723,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 eAct.ExtendedAct(repoPath, workflowPath); act = utils.setUpActParams(act, event, eventOptions, secrets, githubToken, {}); From d6aefab946dd40cd7576b7d23be9c939bf477792 Mon Sep 17 00:00:00 2001 From: Jakub Szymczak Date: Mon, 18 Mar 2024 17:36:45 +0100 Subject: [PATCH 03/54] migrate validateGithubActions --- ....test.js => validateGithubActions.test.ts} | 20 ++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) rename workflow_tests/{validateGithubActions.test.js => validateGithubActions.test.ts} (87%) diff --git a/workflow_tests/validateGithubActions.test.js b/workflow_tests/validateGithubActions.test.ts similarity index 87% rename from workflow_tests/validateGithubActions.test.js rename to workflow_tests/validateGithubActions.test.ts index dfa5e9362ce7..850f21a54163 100644 --- a/workflow_tests/validateGithubActions.test.js +++ b/workflow_tests/validateGithubActions.test.ts @@ -1,12 +1,14 @@ -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'); -const eAct = require('./utils/ExtendedAct'); +/* eslint-disable @typescript-eslint/require-await */ +import type {MockGithub} from '@kie/mock-github'; +import kieMockGithub from '@kie/mock-github'; +import path from 'path'; +import assertions from './assertions/validateGithubActionsAssertions'; +import mocks from './mocks/validateGithubActionsMocks'; +import * as eAct 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), { @@ -47,7 +49,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 eAct.ExtendedAct(repoPath, workflowPath); act = utils.setUpActParams(act, event, eventOptions, {}, githubToken); @@ -70,7 +72,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 eAct.ExtendedAct(repoPath, workflowPath); act = utils.setUpActParams(act, event, eventOptions, {}, githubToken); From 9c18645db6ba2b9602d459bdf21cd44880cbabde Mon Sep 17 00:00:00 2001 From: Jakub Szymczak Date: Mon, 18 Mar 2024 17:37:05 +0100 Subject: [PATCH 04/54] migrate verifyPodfile --- ...yPodfile.test.js => verifyPodfile.test.ts} | 25 +++++++++++-------- 1 file changed, 14 insertions(+), 11 deletions(-) rename workflow_tests/{verifyPodfile.test.js => verifyPodfile.test.ts} (91%) diff --git a/workflow_tests/verifyPodfile.test.js b/workflow_tests/verifyPodfile.test.ts similarity index 91% rename from workflow_tests/verifyPodfile.test.js rename to workflow_tests/verifyPodfile.test.ts index de062af2a2c2..b5ccfc46c336 100644 --- a/workflow_tests/verifyPodfile.test.js +++ b/workflow_tests/verifyPodfile.test.ts @@ -1,12 +1,15 @@ -const path = require('path'); -const kieMockGithub = require('@kie/mock-github'); -const utils = require('./utils/utils'); -const assertions = require('./assertions/verifyPodfileAssertions'); -const mocks = require('./mocks/verifyPodfileMocks'); -const eAct = require('./utils/ExtendedAct'); +/* eslint-disable @typescript-eslint/require-await */ +import kieMockGithub from '@kie/mock-github'; +import type {MockGithub} from '@kie/mock-github'; +import path from 'path'; +import assertions from './assertions/verifyPodfileAssertions'; +import mocks from './mocks/verifyPodfileMocks'; +import * as eAct 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), { @@ -48,7 +51,7 @@ describe('test workflow verifyPodfile', () => { action: 'opened', }; it('executes workflow', async () => { - const repoPath = mockGithub.repo.getPath('testVerifyPodfileWorkflowRepo') || ''; + const repoPath = mockGithub.repo.getPath('testVerifyPodfileWorkflowRepo') ?? ''; const workflowPath = path.join(repoPath, '.github', 'workflows', 'verifyPodfile.yml'); let act = new eAct.ExtendedAct(repoPath, workflowPath); act = utils.setUpActParams(act, event, eventOptions, {}, githubToken); @@ -67,7 +70,7 @@ describe('test workflow verifyPodfile', () => { }); describe('actor is OSBotify', () => { it('does not execute workflow', async () => { - const repoPath = mockGithub.repo.getPath('testVerifyPodfileWorkflowRepo') || ''; + const repoPath = mockGithub.repo.getPath('testVerifyPodfileWorkflowRepo') ?? ''; const workflowPath = path.join(repoPath, '.github', 'workflows', 'verifyPodfile.yml'); let act = new eAct.ExtendedAct(repoPath, workflowPath); act = utils.setUpActParams(act, event, eventOptions, {}, githubToken); @@ -92,7 +95,7 @@ describe('test workflow verifyPodfile', () => { action: 'synchronize', }; it('executes workflow', async () => { - const repoPath = mockGithub.repo.getPath('testVerifyPodfileWorkflowRepo') || ''; + const repoPath = mockGithub.repo.getPath('testVerifyPodfileWorkflowRepo') ?? ''; const workflowPath = path.join(repoPath, '.github', 'workflows', 'verifyPodfile.yml'); let act = new eAct.ExtendedAct(repoPath, workflowPath); act = utils.setUpActParams(act, event, eventOptions, {}, githubToken); @@ -111,7 +114,7 @@ describe('test workflow verifyPodfile', () => { }); describe('actor is OSBotify', () => { it('does not execute workflow', async () => { - const repoPath = mockGithub.repo.getPath('testVerifyPodfileWorkflowRepo') || ''; + const repoPath = mockGithub.repo.getPath('testVerifyPodfileWorkflowRepo') ?? ''; const workflowPath = path.join(repoPath, '.github', 'workflows', 'verifyPodfile.yml'); let act = new eAct.ExtendedAct(repoPath, workflowPath); act = utils.setUpActParams(act, event, eventOptions, {}, githubToken); From fe4547d7ea539a7460539a9fc869375281ebcb08 Mon Sep 17 00:00:00 2001 From: Jakub Szymczak Date: Mon, 18 Mar 2024 17:37:31 +0100 Subject: [PATCH 05/54] migrate verifySignedCommits --- workflow_tests/scripts/runWorkflowTests.sh | 2 +- ...ts.test.js => verifySignedCommits.test.ts} | 21 +++++++++++-------- 2 files changed, 13 insertions(+), 10 deletions(-) rename workflow_tests/{verifySignedCommits.test.js => verifySignedCommits.test.ts} (87%) diff --git a/workflow_tests/scripts/runWorkflowTests.sh b/workflow_tests/scripts/runWorkflowTests.sh index 71ddcdceffb5..c8ee88e33e99 100755 --- a/workflow_tests/scripts/runWorkflowTests.sh +++ b/workflow_tests/scripts/runWorkflowTests.sh @@ -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 "$@" diff --git a/workflow_tests/verifySignedCommits.test.js b/workflow_tests/verifySignedCommits.test.ts similarity index 87% rename from workflow_tests/verifySignedCommits.test.js rename to workflow_tests/verifySignedCommits.test.ts index 911208e91f4a..9319829118e6 100644 --- a/workflow_tests/verifySignedCommits.test.js +++ b/workflow_tests/verifySignedCommits.test.ts @@ -1,12 +1,15 @@ -const path = require('path'); -const kieMockGithub = require('@kie/mock-github'); -const utils = require('./utils/utils'); -const assertions = require('./assertions/verifySignedCommitsAssertions'); -const mocks = require('./mocks/verifySignedCommitsMocks'); -const eAct = require('./utils/ExtendedAct'); +/* eslint-disable @typescript-eslint/require-await */ +import type {MockGithub} from '@kie/mock-github'; +import kieMockGithub from '@kie/mock-github'; +import path from 'path'; +import assertions from './assertions/verifySignedCommitsAssertions'; +import mocks from './mocks/verifySignedCommitsMocks'; +import * as eAct 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), { @@ -47,7 +50,7 @@ describe('test workflow verifySignedCommits', () => { action: 'opened', }; it('test stub', async () => { - const repoPath = mockGithub.repo.getPath('testVerifySignedCommitsWorkflowRepo') || ''; + const repoPath = mockGithub.repo.getPath('testVerifySignedCommitsWorkflowRepo') ?? ''; const workflowPath = path.join(repoPath, '.github', 'workflows', 'verifySignedCommits.yml'); let act = new eAct.ExtendedAct(repoPath, workflowPath); act = utils.setUpActParams(act, event, eventOptions, {}, githubToken); @@ -70,7 +73,7 @@ describe('test workflow verifySignedCommits', () => { action: 'synchronize', }; it('test stub', async () => { - const repoPath = mockGithub.repo.getPath('testVerifySignedCommitsWorkflowRepo') || ''; + const repoPath = mockGithub.repo.getPath('testVerifySignedCommitsWorkflowRepo') ?? ''; const workflowPath = path.join(repoPath, '.github', 'workflows', 'verifySignedCommits.yml'); let act = new eAct.ExtendedAct(repoPath, workflowPath); act = utils.setUpActParams(act, event, eventOptions, {}, githubToken); From c6f9af1d8e456f73e80cd1a2d109f8710820f361 Mon Sep 17 00:00:00 2001 From: Jakub Szymczak Date: Tue, 19 Mar 2024 17:05:47 +0100 Subject: [PATCH 06/54] fix babel not formatting test files --- workflow_tests/jest.config.ts | 2 +- workflow_tests/testBuild.test.ts | 5 ++--- workflow_tests/validateGithubActions.test.ts | 11 +++++------ workflow_tests/verifyPodfile.test.ts | 5 ++--- workflow_tests/verifySignedCommits.test.ts | 5 ++--- 5 files changed, 12 insertions(+), 16 deletions(-) diff --git a/workflow_tests/jest.config.ts b/workflow_tests/jest.config.ts index da9dd2e15794..8156e449039f 100644 --- a/workflow_tests/jest.config.ts +++ b/workflow_tests/jest.config.ts @@ -4,7 +4,7 @@ import type {Config} from 'jest'; const config: Config = { verbose: true, transform: { - '^.+\\.jsx?$': 'babel-jest', + '^.+\\.(js|jsx|ts|tsx)$': 'ts-jest', }, clearMocks: true, resetMocks: true, diff --git a/workflow_tests/testBuild.test.ts b/workflow_tests/testBuild.test.ts index 2c676a63adfe..5f09b851a5b5 100644 --- a/workflow_tests/testBuild.test.ts +++ b/workflow_tests/testBuild.test.ts @@ -1,8 +1,7 @@ /* eslint-disable @typescript-eslint/naming-convention */ /* eslint-disable @typescript-eslint/require-await */ -import type {MockGithub} from '@kie/mock-github'; -import kieMockGithub from '@kie/mock-github'; +import {MockGithub} from '@kie/mock-github'; import path from 'path'; import assertions from './assertions/testBuildAssertions'; import mocks from './mocks/testBuildMocks'; @@ -44,7 +43,7 @@ describe('test workflow testBuild', () => { 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, diff --git a/workflow_tests/validateGithubActions.test.ts b/workflow_tests/validateGithubActions.test.ts index 850f21a54163..1fcfd95834b6 100644 --- a/workflow_tests/validateGithubActions.test.ts +++ b/workflow_tests/validateGithubActions.test.ts @@ -1,10 +1,9 @@ /* eslint-disable @typescript-eslint/require-await */ -import type {MockGithub} from '@kie/mock-github'; -import kieMockGithub from '@kie/mock-github'; +import {MockGithub} from '@kie/mock-github'; import path from 'path'; import assertions from './assertions/validateGithubActionsAssertions'; import mocks from './mocks/validateGithubActionsMocks'; -import * as eAct from './utils/ExtendedAct'; +import {ExtendedAct} from './utils/ExtendedAct'; import * as utils from './utils/utils'; jest.setTimeout(90 * 1000); @@ -29,7 +28,7 @@ describe('test workflow validateGithubActions', () => { 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, @@ -51,7 +50,7 @@ describe('test workflow validateGithubActions', () => { it('executes verification', async () => { const repoPath = mockGithub.repo.getPath('testValidateGithubActionsWorkflowRepo') ?? ''; const workflowPath = path.join(repoPath, '.github', 'workflows', 'validateGithubActions.yml'); - let act = new eAct.ExtendedAct(repoPath, workflowPath); + let act = new ExtendedAct(repoPath, workflowPath); act = utils.setUpActParams(act, event, eventOptions, {}, githubToken); const testMockSteps = { verify: mocks.VALIDATEGITHUBACTIONS__VERIFY__STEP_MOCKS, @@ -74,7 +73,7 @@ describe('test workflow validateGithubActions', () => { it('executes verification', async () => { const repoPath = mockGithub.repo.getPath('testValidateGithubActionsWorkflowRepo') ?? ''; const workflowPath = path.join(repoPath, '.github', 'workflows', 'validateGithubActions.yml'); - let act = new eAct.ExtendedAct(repoPath, workflowPath); + let act = new ExtendedAct(repoPath, workflowPath); act = utils.setUpActParams(act, event, eventOptions, {}, githubToken); const testMockSteps = { verify: mocks.VALIDATEGITHUBACTIONS__VERIFY__STEP_MOCKS, diff --git a/workflow_tests/verifyPodfile.test.ts b/workflow_tests/verifyPodfile.test.ts index b5ccfc46c336..2748eae25542 100644 --- a/workflow_tests/verifyPodfile.test.ts +++ b/workflow_tests/verifyPodfile.test.ts @@ -1,6 +1,5 @@ /* eslint-disable @typescript-eslint/require-await */ -import kieMockGithub from '@kie/mock-github'; -import type {MockGithub} from '@kie/mock-github'; +import {MockGithub} from '@kie/mock-github'; import path from 'path'; import assertions from './assertions/verifyPodfileAssertions'; import mocks from './mocks/verifyPodfileMocks'; @@ -31,7 +30,7 @@ describe('test workflow verifyPodfile', () => { beforeEach(async () => { // create a local repository and copy required files - mockGithub = new kieMockGithub.MockGithub({ + mockGithub = new MockGithub({ repo: { testVerifyPodfileWorkflowRepo: { files: FILES_TO_COPY_INTO_TEST_REPO, diff --git a/workflow_tests/verifySignedCommits.test.ts b/workflow_tests/verifySignedCommits.test.ts index 9319829118e6..c861597368c3 100644 --- a/workflow_tests/verifySignedCommits.test.ts +++ b/workflow_tests/verifySignedCommits.test.ts @@ -1,6 +1,5 @@ /* eslint-disable @typescript-eslint/require-await */ -import type {MockGithub} from '@kie/mock-github'; -import kieMockGithub from '@kie/mock-github'; +import {MockGithub} from '@kie/mock-github'; import path from 'path'; import assertions from './assertions/verifySignedCommitsAssertions'; import mocks from './mocks/verifySignedCommitsMocks'; @@ -30,7 +29,7 @@ describe('test workflow verifySignedCommits', () => { beforeEach(async () => { // create a local repository and copy required files - mockGithub = new kieMockGithub.MockGithub({ + mockGithub = new MockGithub({ repo: { testVerifySignedCommitsWorkflowRepo: { files: FILES_TO_COPY_INTO_TEST_REPO, From 125f18120c3dbc336c7af0a44d4a20ca923b7879 Mon Sep 17 00:00:00 2001 From: Tomasz Misiukiewicz Date: Thu, 21 Mar 2024 16:00:09 +0100 Subject: [PATCH 07/54] add client side logging tool to hidden menu --- .../ClientSideLoggingToolMenu/index.tsx | 50 +++++++++++++++++++ src/components/TestToolsModal.tsx | 2 + 2 files changed, 52 insertions(+) create mode 100644 src/components/ClientSideLoggingToolMenu/index.tsx diff --git a/src/components/ClientSideLoggingToolMenu/index.tsx b/src/components/ClientSideLoggingToolMenu/index.tsx new file mode 100644 index 000000000000..94baed584e1f --- /dev/null +++ b/src/components/ClientSideLoggingToolMenu/index.tsx @@ -0,0 +1,50 @@ +import React from 'react'; +import {withOnyx} from 'react-native-onyx'; +import type {OnyxEntry} from 'react-native-onyx'; +import Switch from '@components/Switch'; +import TestToolRow from '@components/TestToolRow'; +import * as Console from '@libs/actions/Console'; +import type {Log} from '@libs/Console'; +import ONYXKEYS from '@src/ONYXKEYS'; + +type CapturedLogs = Record; + +type ClientSideLoggingToolMenuOnyxProps = { + /** Logs captured on the current device */ + capturedLogs: OnyxEntry; + + /** Whether or not logs should be stored */ + shouldStoreLogs: OnyxEntry; +}; + +type ClientSideLoggingToolProps = ClientSideLoggingToolMenuOnyxProps; + +function ClientSideLoggingToolMenu({shouldStoreLogs, capturedLogs}: ClientSideLoggingToolProps) { + const onToggle = () => { + if (!shouldStoreLogs) { + Console.setShouldStoreLogs(true); + } else { + console.log({capturedLogs}); + Console.disableLoggingAndFlushLogs(); + } + }; + + return ( + + + + ); +} + +export default withOnyx({ + capturedLogs: { + key: ONYXKEYS.LOGS, + }, + shouldStoreLogs: { + key: ONYXKEYS.SHOULD_STORE_LOGS, + }, +})(ClientSideLoggingToolMenu); diff --git a/src/components/TestToolsModal.tsx b/src/components/TestToolsModal.tsx index 824162e63c51..4c6777a6b7d1 100644 --- a/src/components/TestToolsModal.tsx +++ b/src/components/TestToolsModal.tsx @@ -8,6 +8,7 @@ import useWindowDimensions from '@hooks/useWindowDimensions'; import toggleTestToolsModal from '@userActions/TestTool'; import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; +import ClientSideLoggingToolMenu from './ClientSideLoggingToolMenu'; import Modal from './Modal'; import ProfilingToolMenu from './ProfilingToolMenu'; import TestToolMenu from './TestToolMenu'; @@ -32,6 +33,7 @@ function TestToolsModal({isTestToolsModalOpen = false}: TestToolsModalProps) { > {isDevelopment && } + From 576786c9c3d483b25660a834b443f306813673da Mon Sep 17 00:00:00 2001 From: Tomasz Misiukiewicz Date: Fri, 22 Mar 2024 10:31:27 +0100 Subject: [PATCH 08/54] save and share logs from hidden menu --- .../ClientSideLoggingToolMenu/index.tsx | 54 +++++++++++++++---- .../ProfilingToolMenu/index.native.tsx | 25 ++++----- src/components/TestToolsModal.tsx | 11 +++- src/libs/Console/index.ts | 27 +++++++++- src/pages/settings/AboutPage/ConsolePage.tsx | 27 +--------- 5 files changed, 92 insertions(+), 52 deletions(-) diff --git a/src/components/ClientSideLoggingToolMenu/index.tsx b/src/components/ClientSideLoggingToolMenu/index.tsx index 94baed584e1f..43f895c8068d 100644 --- a/src/components/ClientSideLoggingToolMenu/index.tsx +++ b/src/components/ClientSideLoggingToolMenu/index.tsx @@ -1,10 +1,16 @@ -import React from 'react'; +import React, {useState} from 'react'; +import {Share} from 'react-native'; import {withOnyx} from 'react-native-onyx'; import type {OnyxEntry} from 'react-native-onyx'; +import Button from '@components/Button'; import Switch from '@components/Switch'; import TestToolRow from '@components/TestToolRow'; +import Text from '@components/Text'; +import useThemeStyles from '@hooks/useThemeStyles'; import * as Console from '@libs/actions/Console'; +import {parseStringifyMessages} from '@libs/Console'; import type {Log} from '@libs/Console'; +import localFileCreate from '@libs/localFileCreate'; import ONYXKEYS from '@src/ONYXKEYS'; type CapturedLogs = Record; @@ -20,23 +26,53 @@ type ClientSideLoggingToolMenuOnyxProps = { type ClientSideLoggingToolProps = ClientSideLoggingToolMenuOnyxProps; function ClientSideLoggingToolMenu({shouldStoreLogs, capturedLogs}: ClientSideLoggingToolProps) { + const [file, setFile] = useState<{path: string; newFileName: string; size: number}>(); + const styles = useThemeStyles(); + const onToggle = () => { if (!shouldStoreLogs) { + setFile(undefined); Console.setShouldStoreLogs(true); } else { - console.log({capturedLogs}); + const logs = Object.values(capturedLogs as Log[]); + const logsWithParsedMessages = parseStringifyMessages(logs); + localFileCreate('logs', JSON.stringify(logsWithParsedMessages, null, 2)).then((localFile) => { + setFile(localFile); + }); Console.disableLoggingAndFlushLogs(); } }; + const shareLogs = () => { + if (!file) { + return; + } + + Share.share({url: file.path, title: file.newFileName}); + }; + return ( - - - + <> + + + + {!!file && ( + <> + {`path: ${file.path}`} + +