diff --git a/.github/workflows/node.js.yml b/.github/workflows/node.js.yml index 4bf4d67..eaaf010 100644 --- a/.github/workflows/node.js.yml +++ b/.github/workflows/node.js.yml @@ -1,31 +1,61 @@ # This workflow will do a clean installation of node dependencies, cache/restore them, build the source code and run tests across different versions of node -# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-nodejs +# For more information see: https://github.com/marketplace/actions/vitest-coverage-report -name: Node.js CI +name: Node.js Test Coverage Report on: push: - branches: [ "main" ] + branches: ["main"] pull_request: - branches: [ "main" ] jobs: - build: - + test: runs-on: ubuntu-latest strategy: matrix: node-version: [20.x] - # See supported Node.js release schedule at https://nodejs.org/en/about/releases/ + branch: + - ${{ github.head_ref }} + - "main" + permissions: + # Required to checkout the code + contents: read + steps: + - uses: actions/checkout@v4 + with: + ref: ${{ matrix.branch }} + - name: Use Node.js 20.x + uses: actions/setup-node@v4 + with: + node-version: 20.x + cache: "npm" + - name: "Install Deps" + run: npm ci + - name: "Build" + run: npm run build + - name: "Test" + run: npm run coverage-summary + - name: "Upload Coverage" + uses: actions/upload-artifact@v4 + with: + name: coverage-${{ matrix.branch }} + path: coverage + report-coverage: + needs: test + runs-on: ubuntu-latest steps: - - uses: actions/checkout@v4 - - name: Use Node.js 20.x - uses: actions/setup-node@v4 - with: - node-version: 20.x - cache: 'npm' - - run: npm ci - - run: npm run build - - run: npm test + - name: "Download Coverage Artifacts" + uses: actions/download-artifact@v4 + with: + name: coverage-${{ github.head_ref }} + path: coverage + - uses: actions/download-artifact@v4 + with: + name: coverage-main + path: coverage-main + - name: "Vitest Coverage Differences from main" + uses: davelosert/vitest-coverage-report-action@v2 + with: + json-summary-compare-path: coverage-main/coverage-summary.json diff --git a/package.json b/package.json index e8ee624..976d002 100644 --- a/package.json +++ b/package.json @@ -6,6 +6,7 @@ "build": "node esbuild.js", "test": "vitest", "coverage": "vitest run --coverage", + "coverage-summary": "vitest run --coverage.enabled --reporter=json --coverage.reporter=json-summary", "watch": "npm-watch" }, "watch": { diff --git a/vitest.config.js b/vitest.config.js index 7aaa1a2..f5db62f 100644 --- a/vitest.config.js +++ b/vitest.config.js @@ -2,8 +2,16 @@ import { defineConfig } from "vitest/config"; export default defineConfig({ coverage: { enabled: true, + reporter: [ + ["json-summary", { file: "coverage-summary.json" }], + "json", + "json-summary-compare-path", + "text", + ], + reportOnFailure: true, }, test: { environment: "jsdom", + reporters: process.env.GITHUB_ACTIONS ? ["dot", "github-actions"] : ["dot"], }, });