From 37a0b41d1494cfd129e10ea1919edcc1c9ec44ee Mon Sep 17 00:00:00 2001 From: Luca Comellini Date: Mon, 23 Sep 2024 16:42:03 -0700 Subject: [PATCH 1/2] Unit tests report --- .github/workflows/ci.yml | 16 ++++++++++++++++ .gitignore | 5 +++++ Makefile | 2 +- .../static/nginx/modules/test/vitest.config.ts | 2 ++ 4 files changed, 24 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 535fd87623..a755da22ec 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -104,6 +104,14 @@ jobs: path: ${{ github.workspace }}/cover.html if: always() + - name: Test Report + uses: dorny/test-reporter@v1 + with: + name: Unit Tests Report + path: unit-tests.xml + reporter: jest-junit + if: always() + njs-unit-tests: name: NJS Unit Tests runs-on: ubuntu-22.04 @@ -125,6 +133,14 @@ jobs: with: token: ${{ secrets.CODECOV_TOKEN }} + - name: Test Report + uses: dorny/test-reporter@v1 + with: + name: Unit Tests Report + path: njs-unit-tests.xml + reporter: jest-junit + if: always() + binary: name: Build Binary runs-on: ubuntu-22.04 diff --git a/.gitignore b/.gitignore index 3615727c6d..a77d40be2e 100644 --- a/.gitignore +++ b/.gitignore @@ -58,3 +58,8 @@ internal/mode/static/nginx/modules/coverage # temporary files used for manifest generation config/base/deploy.yaml config/base/deploy.yaml.bak + +# test reports +unit-tests.xml +unit-tests.json +njs-unit-tests.xml diff --git a/Makefile b/Makefile index 98db3f2d49..0fda2c9e04 100644 --- a/Makefile +++ b/Makefile @@ -193,7 +193,7 @@ lint: ## Run golangci-lint against code unit-test: ## Run unit tests for the go code # We have to run the tests in the cmd package using `go test` because of a bug with the CLI library cobra. See https://github.com/spf13/cobra/issues/2104. go test -buildvcs ./cmd/... -race -shuffle=on -coverprofile=cmd-coverage.out -covermode=atomic - go run github.com/onsi/ginkgo/v2/ginkgo --randomize-all --randomize-suites --race --keep-going --fail-on-pending --fail-fast --trace --covermode=atomic --coverprofile=coverage.out --force-newlines $(GITHUB_OUTPUT) -p -v -r internal + go run github.com/onsi/ginkgo/v2/ginkgo --randomize-all --randomize-suites --race --keep-going --fail-on-pending --fail-on-empty --fail-fast --trace --covermode=atomic --coverprofile=coverage.out --junit-report=unit-tests.xml --json-report=unit-tests.json --force-newlines $(GITHUB_OUTPUT) -p -v -r internal go tool cover -html=coverage.out -o cover.html go tool cover -html=cmd-coverage.out -o cmd-cover.html diff --git a/internal/mode/static/nginx/modules/test/vitest.config.ts b/internal/mode/static/nginx/modules/test/vitest.config.ts index b951a942f7..ed26bb90b2 100644 --- a/internal/mode/static/nginx/modules/test/vitest.config.ts +++ b/internal/mode/static/nginx/modules/test/vitest.config.ts @@ -2,6 +2,8 @@ import { defineConfig } from 'vitest/config'; export default defineConfig({ test: { + reporters: ['verbose', 'junit'], + outputFile: './njs-unit-tests.xml', coverage: { reporter: ['text', 'json', 'html'], }, From aa1eb717c3f1e4cdc936afab860645b875dfd39b Mon Sep 17 00:00:00 2001 From: Luca Comellini Date: Mon, 23 Sep 2024 16:42:03 -0700 Subject: [PATCH 2/2] Unit tests report --- .github/workflows/ci.yml | 12 ++++++++++-- internal/mode/static/nginx/modules/package.json | 2 +- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index a755da22ec..525c2b0b01 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -77,6 +77,9 @@ jobs: name: Unit Tests runs-on: ubuntu-22.04 needs: vars + permissions: + checks: write + pull-requests: write steps: - name: Checkout Repository uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7 @@ -109,13 +112,17 @@ jobs: with: name: Unit Tests Report path: unit-tests.xml - reporter: jest-junit + reporter: java-junit + only-summary: true if: always() njs-unit-tests: name: NJS Unit Tests runs-on: ubuntu-22.04 needs: vars + permissions: + checks: write + pull-requests: write steps: - name: Checkout Repository uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7 @@ -137,8 +144,9 @@ jobs: uses: dorny/test-reporter@v1 with: name: Unit Tests Report - path: njs-unit-tests.xml + path: ${{ github.workspace }}/internal/mode/static/nginx/modules/njs-unit-tests.xml reporter: jest-junit + only-summary: true if: always() binary: diff --git a/internal/mode/static/nginx/modules/package.json b/internal/mode/static/nginx/modules/package.json index 1fc2f65398..81f8b686d3 100644 --- a/internal/mode/static/nginx/modules/package.json +++ b/internal/mode/static/nginx/modules/package.json @@ -6,7 +6,7 @@ "scripts": { "format": "prettier -w src/ test/", "lint": "prettier -c src/ test/", - "test": "vitest run --coverage", + "test": "vitest run --coverage --config test/vitest.config.ts", "clean": "rm -rf node_modules coverage" }, "devDependencies": {