From c70a3262487592afba7aa38a24f96053a04ae77e Mon Sep 17 00:00:00 2001 From: William Putra Intan <61998484+williamputraintan@users.noreply.github.com> Date: Tue, 6 Feb 2024 14:01:11 +1100 Subject: [PATCH] junit --- .gitignore | 2 + jest.config.js | 10 ++++ .../orcabus-stateless-pipeline-stack.ts | 55 +++++++++++++++++-- .../stateless/metadata_manager/jest.config.js | 10 ++++ .../stateless/metadata_manager/package.json | 1 + .../stateless/metadata_manager/yarn.lock | 31 ++++++++++- .../stateless/sequence_run_manager/Makefile | 9 +-- package.json | 1 + yarn.lock | 31 ++++++++++- 9 files changed, 135 insertions(+), 15 deletions(-) diff --git a/.gitignore b/.gitignore index f91e2d7d5..6c1075b69 100644 --- a/.gitignore +++ b/.gitignore @@ -54,3 +54,5 @@ data/ Brewfile.lock.json *.xml + +target/ diff --git a/jest.config.js b/jest.config.js index 44ead8540..6b107fd0f 100644 --- a/jest.config.js +++ b/jest.config.js @@ -5,4 +5,14 @@ module.exports = { transform: { '^.+\\.tsx?$': 'ts-jest', }, + reporters: [ + 'default', + [ + 'jest-junit', + { + outputDirectory: 'target/report', + outputName: 'infrastructureTest.xml', + }, + ], + ], }; diff --git a/lib/pipeline/orcabus-stateless-pipeline-stack.ts b/lib/pipeline/orcabus-stateless-pipeline-stack.ts index c653d4c2a..b56fcb282 100644 --- a/lib/pipeline/orcabus-stateless-pipeline-stack.ts +++ b/lib/pipeline/orcabus-stateless-pipeline-stack.ts @@ -17,13 +17,56 @@ export class StatelessPipelineStack extends cdk.Stack { connectionArn: codeStarArn, }); - const synthAction = new pipelines.CodeBuildStep('Synth', { - commands: [ - 'yarn install --frozen-lockfile', - 'make suite', - 'yarn run cdk-stateless-pipeline synth', - ], + const unitTestReports = new codebuild.ReportGroup(this, `CodebuildTestReport`, { + reportGroupName: `UnitTestReport`, + removalPolicy: cdk.RemovalPolicy.DESTROY, + }); + + const unitTest = new pipelines.CodeBuildStep('UnitTest', { + commands: ['yarn install --frozen-lockfile', 'make suite'], input: sourceFile, + primaryOutputDirectory: '.', + buildEnvironment: { + privileged: true, + computeType: codebuild.ComputeType.LARGE, + buildImage: codebuild.LinuxArmBuildImage.AMAZON_LINUX_2_STANDARD_3_0, + environmentVariables: { + NODE_OPTIONS: { + value: '--max-old-space-size=8192', + }, + }, + }, + partialBuildSpec: codebuild.BuildSpec.fromObject({ + reports: { + infrastructureReports: { + files: ['target/report/*.xml'], + 'file-format': 'JUNITXML', + }, + microserviceReports: { + files: ['**/target/report/*.xml'], + 'file-format': 'JUNITXML', + }, + }, + version: '0.2', + }), + rolePolicyStatements: [ + new iam.PolicyStatement({ + effect: iam.Effect.ALLOW, + actions: [ + 'codebuild:CreateReportGroup', + 'codebuild:CreateReport', + 'codebuild:UpdateReport', + 'codebuild:BatchPutTestCases', + 'codebuild:BatchPutCodeCoverages', + ], + resources: [unitTestReports.reportGroupArn], + }), + ], + }); + + const synthAction = new pipelines.CodeBuildStep('Synth', { + commands: ['yarn install --frozen-lockfile', 'yarn run cdk-stateless-pipeline synth'], + input: unitTest, primaryOutputDirectory: 'cdk.out', rolePolicyStatements: [ new iam.PolicyStatement({ diff --git a/lib/workload/stateless/metadata_manager/jest.config.js b/lib/workload/stateless/metadata_manager/jest.config.js index c865147a9..4cdb675e9 100644 --- a/lib/workload/stateless/metadata_manager/jest.config.js +++ b/lib/workload/stateless/metadata_manager/jest.config.js @@ -2,4 +2,14 @@ module.exports = { preset: 'ts-jest', testEnvironment: 'node', roots: ['/tests/'], + reporters: [ + 'default', + [ + 'jest-junit', + { + outputDirectory: 'target/report', + outputName: 'metadataManager.xml', + }, + ], + ], }; diff --git a/lib/workload/stateless/metadata_manager/package.json b/lib/workload/stateless/metadata_manager/package.json index 4d9953b15..9b96aad6e 100644 --- a/lib/workload/stateless/metadata_manager/package.json +++ b/lib/workload/stateless/metadata_manager/package.json @@ -36,6 +36,7 @@ "@types/lodash": "^4.14.202", "@types/node": "^20.11.5", "jest": "^29.7.0", + "jest-junit": "^16.0.0", "nodemon": "^3.0.3", "ts-jest": "^29.1.1", "ts-to-zod": "^3.6.1", diff --git a/lib/workload/stateless/metadata_manager/yarn.lock b/lib/workload/stateless/metadata_manager/yarn.lock index 92f2ea861..f5c73f0d0 100644 --- a/lib/workload/stateless/metadata_manager/yarn.lock +++ b/lib/workload/stateless/metadata_manager/yarn.lock @@ -3670,6 +3670,18 @@ __metadata: languageName: node linkType: hard +"jest-junit@npm:^16.0.0": + version: 16.0.0 + resolution: "jest-junit@npm:16.0.0" + dependencies: + mkdirp: ^1.0.4 + strip-ansi: ^6.0.1 + uuid: ^8.3.2 + xml: ^1.0.1 + checksum: 412aa4bfeec4254a9b34f417fda79107c7cbd295e56ffeb299ac9c977545910fbabe57c91c6cd1f12b700d4a1f60f79872b0075003f02da87d463e30fc2d9d78 + languageName: node + linkType: hard + "jest-leak-detector@npm:^29.7.0": version: 29.7.0 resolution: "jest-leak-detector@npm:29.7.0" @@ -4382,7 +4394,7 @@ __metadata: languageName: node linkType: hard -"mkdirp@npm:^1.0.3": +"mkdirp@npm:^1.0.3, mkdirp@npm:^1.0.4": version: 1.0.4 resolution: "mkdirp@npm:1.0.4" bin: @@ -5384,6 +5396,7 @@ __metadata: google-auth-library: ^9.4.2 google-spreadsheet: ^4.1.1 jest: ^29.7.0 + jest-junit: ^16.0.0 lodash: ^4.17.21 nodemon: ^3.0.3 pino: ^8.17.2 @@ -5953,6 +5966,15 @@ __metadata: languageName: node linkType: hard +"uuid@npm:^8.3.2": + version: 8.3.2 + resolution: "uuid@npm:8.3.2" + bin: + uuid: dist/bin/uuid + checksum: 5575a8a75c13120e2f10e6ddc801b2c7ed7d8f3c8ac22c7ed0c7b2ba6383ec0abda88c905085d630e251719e0777045ae3236f04c812184b7c765f63a70e58df + languageName: node + linkType: hard + "v8-compile-cache-lib@npm:^3.0.1": version: 3.0.1 resolution: "v8-compile-cache-lib@npm:3.0.1" @@ -6138,6 +6160,13 @@ __metadata: languageName: node linkType: hard +"xml@npm:^1.0.1": + version: 1.0.1 + resolution: "xml@npm:1.0.1" + checksum: 11b5545ef3f8fec3fa29ce251f50ad7b6c97c103ed4d851306ec23366f5fa4699dd6a942262df52313a0cd1840ab26256da253c023bad3309d8ce46fe6020ca0 + languageName: node + linkType: hard + "y18n@npm:^5.0.5": version: 5.0.8 resolution: "y18n@npm:5.0.8" diff --git a/lib/workload/stateless/sequence_run_manager/Makefile b/lib/workload/stateless/sequence_run_manager/Makefile index 33b2065ac..355195f94 100644 --- a/lib/workload/stateless/sequence_run_manager/Makefile +++ b/lib/workload/stateless/sequence_run_manager/Makefile @@ -11,13 +11,8 @@ lint: lint-fix: @black -t py312 ./src --exclude skel --exclude .venv -# full mock suite test pipeline - install deps, bring up compose stack, wait a bit, run suite, bring down compose stack -test: install up wait suite down - -# heuristic wait 8s to make sure the database is fully up -# todo we could improve this -wait: - @sleep 8 +# full mock suite test pipeline - install deps, bring up compose stack, run suite, bring down compose stack +test: install up suite down suite: @python manage.py test diff --git a/package.json b/package.json index ee2759b45..2eccfb29e 100644 --- a/package.json +++ b/package.json @@ -46,6 +46,7 @@ "eslint-config-prettier": "^9.1.0", "eslint-plugin-prettier": "^5.1.3", "jest": "^29.6.1", + "jest-junit": "^16.0.0", "prettier": "^3.2.4", "ts-jest": "^29.1.1", "ts-node": "^10.9.1", diff --git a/yarn.lock b/yarn.lock index 6b02032a0..35f2a707f 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3156,6 +3156,18 @@ __metadata: languageName: node linkType: hard +"jest-junit@npm:^16.0.0": + version: 16.0.0 + resolution: "jest-junit@npm:16.0.0" + dependencies: + mkdirp: ^1.0.4 + strip-ansi: ^6.0.1 + uuid: ^8.3.2 + xml: ^1.0.1 + checksum: 412aa4bfeec4254a9b34f417fda79107c7cbd295e56ffeb299ac9c977545910fbabe57c91c6cd1f12b700d4a1f60f79872b0075003f02da87d463e30fc2d9d78 + languageName: node + linkType: hard + "jest-leak-detector@npm:^29.7.0": version: 29.7.0 resolution: "jest-leak-detector@npm:29.7.0" @@ -3812,7 +3824,7 @@ __metadata: languageName: node linkType: hard -"mkdirp@npm:^1.0.3": +"mkdirp@npm:^1.0.3, mkdirp@npm:^1.0.4": version: 1.0.4 resolution: "mkdirp@npm:1.0.4" bin: @@ -3974,6 +3986,7 @@ __metadata: eslint-config-prettier: ^9.1.0 eslint-plugin-prettier: ^5.1.3 jest: ^29.6.1 + jest-junit: ^16.0.0 prettier: ^3.2.4 rust.aws-cdk-lambda: ^1.2.1 source-map-support: ^0.5.21 @@ -4933,6 +4946,15 @@ __metadata: languageName: node linkType: hard +"uuid@npm:^8.3.2": + version: 8.3.2 + resolution: "uuid@npm:8.3.2" + bin: + uuid: dist/bin/uuid + checksum: 5575a8a75c13120e2f10e6ddc801b2c7ed7d8f3c8ac22c7ed0c7b2ba6383ec0abda88c905085d630e251719e0777045ae3236f04c812184b7c765f63a70e58df + languageName: node + linkType: hard + "v8-compile-cache-lib@npm:^3.0.1": version: 3.0.1 resolution: "v8-compile-cache-lib@npm:3.0.1" @@ -5028,6 +5050,13 @@ __metadata: languageName: node linkType: hard +"xml@npm:^1.0.1": + version: 1.0.1 + resolution: "xml@npm:1.0.1" + checksum: 11b5545ef3f8fec3fa29ce251f50ad7b6c97c103ed4d851306ec23366f5fa4699dd6a942262df52313a0cd1840ab26256da253c023bad3309d8ce46fe6020ca0 + languageName: node + linkType: hard + "y18n@npm:^5.0.5": version: 5.0.8 resolution: "y18n@npm:5.0.8"