diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 0b215bb07..4d24f900f 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -1,26 +1,46 @@ ---- -name: Run tests +name: Testing on: workflow_dispatch: push: branches: - "main" - pull_request: {} - -defaults: - run: - shell: bash + pull_request: jobs: - test: + check-test-secrets: + name: Check for test secrets + runs-on: ubuntu-22.04 + outputs: + available: ${{ steps.check-test-secrets.outputs.available }} + permissions: + contents: read + + steps: + - name: Check + id: check-test-secrets + run: | + if [ "${{ secrets.CODECOV_TOKEN }}" != '' ]; then + echo "available=true" >> $GITHUB_OUTPUT; + else + echo "available=false" >> $GITHUB_OUTPUT; + fi + + testing: name: Run tests + if: ${{ startsWith(github.head_ref, 'version_bump_') == false }} runs-on: ubuntu-22.04 + needs: check-test-secrets + permissions: + checks: write + contents: read + pull-requests: write + steps: - - name: Checkout repo + - name: Check out repo uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7 - - name: Get Node Version + - name: Get Node version id: retrieve-node-version run: | NODE_NVMRC=$(cat .nvmrc) @@ -34,11 +54,6 @@ jobs: cache-dependency-path: '**/package-lock.json' node-version: ${{ steps.retrieve-node-version.outputs.node_version }} - - name: Print environment - run: | - node --version - npm --version - - name: Install Node dependencies run: npm ci @@ -49,4 +64,25 @@ jobs: run: npm run test:types --coverage - name: Run tests - run: npm run test + run: npm run test --coverage + + - name: Report test results + uses: dorny/test-reporter@31a54ee7ebcacc03a09ea97a7e5465a47b84aea5 # v1.9.1 + if: ${{ needs.check-test-secrets.outputs.available == 'true' && !cancelled() }} + with: + name: Test Results + path: "junit.xml" + reporter: jest-junit + fail-on-error: true + + - name: Upload coverage to codecov.io + uses: codecov/codecov-action@e28ff129e5465c2c0dcc6f003fc735cb6ae0c673 # v4.5.0 + if: ${{ needs.check-test-secrets.outputs.available == 'true' }} + env: + CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} + + - name: Upload results to codecov.io + uses: codecov/test-results-action@1b5b448b98e58ba90d1a1a1d9fcb72ca2263be46 # v1.0.0 + if: ${{ needs.check-test-secrets.outputs.available == 'true' }} + env: + CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} diff --git a/jest.config.js b/jest.config.js index 5aad2b0aa..94b2cd7ea 100644 --- a/jest.config.js +++ b/jest.config.js @@ -11,6 +11,14 @@ module.exports = { // ...angularPreset, preset: "jest-preset-angular", + reporters: ["default", "jest-junit"], + + collectCoverage: true, + // Ensure we collect coverage from files without tests + collectCoverageFrom: ["src/**/*.ts"], + coverageReporters: ["html", "lcov"], + coverageDirectory: "coverage", + testEnvironment: "jsdom", testMatch: ["**/+(*.)+(spec).+(ts)"], diff --git a/package-lock.json b/package-lock.json index 1ded5af31..1349f096d 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@bitwarden/directory-connector", - "version": "2024.2.2", + "version": "2024.7.0", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@bitwarden/directory-connector", - "version": "2024.2.2", + "version": "2024.7.0", "hasInstallScript": true, "license": "GPL-3.0", "dependencies": { @@ -91,6 +91,7 @@ "html-webpack-plugin": "5.6.0", "husky": "9.0.10", "jest": "29.7.0", + "jest-junit": "16.0.0", "jest-preset-angular": "13.1.1", "lint-staged": "15.2.0", "mini-css-extract-plugin": "2.7.7", @@ -13513,6 +13514,22 @@ "fsevents": "^2.3.2" } }, + "node_modules/jest-junit": { + "version": "16.0.0", + "resolved": "https://registry.npmjs.org/jest-junit/-/jest-junit-16.0.0.tgz", + "integrity": "sha512-A94mmw6NfJab4Fg/BlvVOUXzXgF0XIH6EmTgJ5NDPp4xoKq0Kr7sErb+4Xs9nZvu58pJojz5RFGpqnZYJTrRfQ==", + "dev": true, + "license": "Apache-2.0", + "dependencies": { + "mkdirp": "^1.0.4", + "strip-ansi": "^6.0.1", + "uuid": "^8.3.2", + "xml": "^1.0.1" + }, + "engines": { + "node": ">=10.12.0" + } + }, "node_modules/jest-leak-detector": { "version": "29.7.0", "resolved": "https://registry.npmjs.org/jest-leak-detector/-/jest-leak-detector-29.7.0.tgz", @@ -20910,6 +20927,13 @@ } } }, + "node_modules/xml": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/xml/-/xml-1.0.1.tgz", + "integrity": "sha512-huCv9IH9Tcf95zuYCsQraZtWnJvBtLVE0QHMOs8bWyZAFZNDcYjsPq1nEx8jKA9y+Beo9v+7OBPRisQTjinQMw==", + "dev": true, + "license": "MIT" + }, "node_modules/xml-name-validator": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/xml-name-validator/-/xml-name-validator-3.0.0.tgz", diff --git a/package.json b/package.json index e8b32d0ae..7914f5dce 100644 --- a/package.json +++ b/package.json @@ -114,6 +114,7 @@ "html-webpack-plugin": "5.6.0", "husky": "9.0.10", "jest": "29.7.0", + "jest-junit": "16.0.0", "jest-preset-angular": "13.1.1", "lint-staged": "15.2.0", "mini-css-extract-plugin": "2.7.7",