From 068553ae1977f96c4fea5d769b8a99c2c0559795 Mon Sep 17 00:00:00 2001 From: Eva Decker Date: Sat, 7 Sep 2024 17:40:26 -0400 Subject: [PATCH] chore: Add coverage reporting (#32) --- .github/workflows/coverage.yml | 83 ++++++++++++++++++++++++++++++++++ .github/workflows/release.yml | 4 +- tsconfig.node.json | 2 +- vite.config.ts | 23 ++++++++++ vitest.config.mts | 25 ---------- 5 files changed, 109 insertions(+), 28 deletions(-) create mode 100644 .github/workflows/coverage.yml delete mode 100644 vitest.config.mts diff --git a/.github/workflows/coverage.yml b/.github/workflows/coverage.yml new file mode 100644 index 0000000..a64573d --- /dev/null +++ b/.github/workflows/coverage.yml @@ -0,0 +1,83 @@ +name: Coverage + +on: + pull_request: + branches: + - main + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + +permissions: + contents: read + pull-requests: write + +jobs: + test-coverage: + name: Test Coverage + runs-on: ubuntu-latest + strategy: + matrix: + branch: + - ${{ github.head_ref }} + - main + + steps: + - name: Checkout repo + uses: actions/checkout@v4 + with: + ref: ${{ matrix.branch }} + repository: ${{ github.event.pull_request.head.repo.full_name }} + + - name: Setup pnpm + uses: pnpm/action-setup@v4 + with: + run_install: false + + - name: Setup Node.js 20 + uses: actions/setup-node@v4 + with: + node-version: 20 + cache: 'pnpm' + + - name: Install dependencies + run: pnpm install + + - name: Test coverage + run: npx vitest --coverage.enabled true + + - name: Upload coverage + uses: actions/upload-artifact@v4 + with: + name: coverage-${{ matrix.branch }} + path: coverage + overwrite: true + + report-coverage: + needs: test-coverage + name: Report Coverage + runs-on: ubuntu-latest + + steps: + - name: Checkout repo + uses: actions/checkout@v4 + + - name: Download coverage (${{ github.head_ref }}) + uses: actions/download-artifact@v4 + with: + name: coverage-${{ github.head_ref }} + path: coverage + + - name: Download coverage (main) + uses: actions/download-artifact@v4 + with: + name: coverage-main + path: coverage + + - name: Report coverage + if: always() + uses: davelosert/vitest-coverage-report-action@v2.5.1 + with: + file-coverage-mode: all + json-summary-compare-path: coverage-main/coverage-summary.json diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 27aaee2..550d030 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -14,7 +14,7 @@ jobs: permissions: write-all steps: - name: Checkout repo - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Setup pnpm uses: pnpm/action-setup@v4 @@ -22,7 +22,7 @@ jobs: run_install: false - name: Setup Node.js 20 - uses: actions/setup-node@v3 + uses: actions/setup-node@v4 with: node-version: 20 cache: 'pnpm' diff --git a/tsconfig.node.json b/tsconfig.node.json index 93e4863..8e5b203 100644 --- a/tsconfig.node.json +++ b/tsconfig.node.json @@ -14,5 +14,5 @@ "noUnusedParameters": true, "noFallthroughCasesInSwitch": true }, - "include": ["vite.config.ts", "vitest.config.mts"] + "include": ["vite.config.ts"] } diff --git a/vite.config.ts b/vite.config.ts index 1cb7361..479dc1e 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -1,9 +1,12 @@ +/// + import { TanStackRouterVite } from "@tanstack/router-plugin/vite"; import react from "@vitejs/plugin-react-swc"; import autoprefixer from "autoprefixer"; import cssnano from "cssnano"; import tailwindcss from "tailwindcss"; import { defineConfig } from "vite"; +import { configDefaults, coverageConfigDefaults } from "vitest/config"; // https://vitejs.dev/config/ export default defineConfig({ @@ -16,4 +19,24 @@ export default defineConfig({ plugins: [autoprefixer(), tailwindcss(), cssnano()], }, }, + test: { + environment: "edge-runtime", + environmentMatchGlobs: [ + ["convex/**", "edge-runtime"], + ["**", "jsdom"], + ], + server: { deps: { inline: ["convex-test"] } }, + exclude: [...configDefaults.exclude], + coverage: { + reporter: ["text", "json-summary", "json"], + reportOnFailure: true, + include: ["src/**", "convex/**"], + exclude: [ + ...coverageConfigDefaults.exclude, + "**/*.config.?(c|m)[jt]s?(x)", + "convex/_generated/**", + "src/routeTree.gen.ts", + ], + }, + }, }); diff --git a/vitest.config.mts b/vitest.config.mts deleted file mode 100644 index d305a1b..0000000 --- a/vitest.config.mts +++ /dev/null @@ -1,25 +0,0 @@ -import { - configDefaults, - coverageConfigDefaults, - defineConfig, -} from "vitest/config"; - -export default defineConfig({ - test: { - environment: "edge-runtime", - environmentMatchGlobs: [ - ["convex/**", "edge-runtime"], - ["**", "jsdom"], - ], - server: { deps: { inline: ["convex-test"] } }, - exclude: [...configDefaults.exclude], - coverage: { - exclude: [ - ...coverageConfigDefaults.exclude, - "**/*.config.?(c|m)[jt]s?(x)", - "convex/_generated/**", - "src/routeTree.gen.ts", - ], - }, - }, -});