From 9a0c50521dc010caad2237f11e56ce82b5800b65 Mon Sep 17 00:00:00 2001 From: Il Harper Date: Sat, 6 Apr 2024 03:11:22 +0800 Subject: [PATCH] ci: show test reports in job summary --- .github/workflows/test.yml | 21 +++++++++++++++++++-- jest.config.ts | 17 +++++++++++++++++ package.json | 1 + yarn.lock | 20 ++++++++++++++++++++ 4 files changed, 57 insertions(+), 2 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 02a64b8..bd74298 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -5,6 +5,11 @@ on: pull_request: workflow_dispatch: +permissions: + contents: read + actions: read + checks: write + jobs: test: name: test @@ -21,15 +26,27 @@ jobs: - name: Setup Node.js uses: actions/setup-node@v4 with: - node-version: '20.3.1' + node-version: '20.12.0' - - name: Test + - name: Build Packages run: | corepack enable yarn install --immutable yarn build + shell: bash + + - name: Test + run: | yarn test shell: bash + - name: Test Report + uses: dorny/test-reporter@v1 + if: success() || failure() + with: + name: Chronocat Unit Tests + path: coverage/jest-junit.xml # Path to test results + reporter: jest-junit # Format of test results + - name: Upload Coverage Reports to Codecov uses: codecov/codecov-action@v3 diff --git a/jest.config.ts b/jest.config.ts index b2c54fc..0b01baf 100644 --- a/jest.config.ts +++ b/jest.config.ts @@ -17,6 +17,23 @@ const config: JestConfigWithTsJest = { collectCoverage: true, coverageDirectory: 'coverage', coverageProvider: 'v8', + + reporters: [ + 'default', + [ + 'jest-junit', + { + suiteName: 'Chronocat Unit Tests', + outputDirectory: 'coverage', + outputName: 'jest-junit.xml', + ancestorSeparator: ' › ', + uniqueOutputName: 'false', + suiteNameTemplate: '{filepath}', + classNameTemplate: '{classname}', + titleTemplate: '{title}', + }, + ], + ], } // eslint-disable-next-line import/no-default-export diff --git a/package.json b/package.json index 35932bd..ebeef22 100644 --- a/package.json +++ b/package.json @@ -36,6 +36,7 @@ "eslint-plugin-import": "^2.28.1", "eslint-plugin-prettier": "^5.0.0", "jest": "^29.6.3", + "jest-junit": "^16.0.0", "prettier": "^3.0.2", "ts-jest": "^29.1.1", "ts-node": "^10.9.1", diff --git a/yarn.lock b/yarn.lock index c603352..2d02590 100644 --- a/yarn.lock +++ b/yarn.lock @@ -6405,6 +6405,7 @@ __metadata: eslint-plugin-import: "npm:^2.28.1" eslint-plugin-prettier: "npm:^5.0.0" jest: "npm:^29.6.3" + jest-junit: "npm:^16.0.0" prettier: "npm:^3.0.2" ts-jest: "npm:^29.1.1" ts-node: "npm:^10.9.1" @@ -10988,6 +10989,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: "npm:^1.0.4" + strip-ansi: "npm:^6.0.1" + uuid: "npm:^8.3.2" + xml: "npm:^1.0.1" + checksum: 10c0/d813d4d142341c2b51b634db7ad6ceb9849514cb58f96ec5e7e4cf4031a557133490452710c2d9dec9b1dd546334d9ca663e042d3070c3e8f102ce6217bd8e2e + languageName: node + linkType: hard + "jest-leak-detector@npm:^29.7.0": version: 29.7.0 resolution: "jest-leak-detector@npm:29.7.0" @@ -18017,6 +18030,13 @@ __metadata: languageName: node linkType: hard +"xml@npm:^1.0.1": + version: 1.0.1 + resolution: "xml@npm:1.0.1" + checksum: 10c0/04bcc9b8b5e7b49392072fbd9c6b0f0958bd8e8f8606fee460318e43991349a68cbc5384038d179ff15aef7d222285f69ca0f067f53d071084eb14c7fdb30411 + languageName: node + linkType: hard + "xtend@npm:^4.0.0, xtend@npm:^4.0.1, xtend@npm:~4.0.1": version: 4.0.2 resolution: "xtend@npm:4.0.2"