Skip to content

Commit 02a572e

Browse files
authored
feat: add test coverage reporting with GitHub Pages deployment (#188)
* feat(ci): add test coverage reporting with GitHub Pages deployment Add coverage script to package.json and update CI workflow to: - Run CI on all pushes (not just main branch) - Execute tests with coverage on main branch only - Upload coverage reports to GitHub Pages for main branch - Run regular tests without coverage on other branches/PRs This addresses the need for visibility into test coverage metrics while keeping PR builds fast by only generating coverage on main. Closes #184 * chore(deps): upgrade vitest to v4.0.15 Update vitest and @vitest/coverage-v8 from v3.2.4 to v4.0.15. Vitest v4 introduces several improvements including: - Stable browser mode - Visual regression testing support - Rewritten pool architecture without Tinypool - Workspace renamed to projects configuration This upgrade prepares the codebase for using v4's projects feature for monorepo test aggregation. Closes #186 * feat(test): configure vitest projects for monorepo coverage Refactor vitest configuration to use v4's projects feature for unified monorepo test execution and coverage reporting. Changes: - Add projects configuration with 'root' and 'examples' workspaces - Simplify package.json test scripts (remove test:submodules, test:root) - Extend coverage.include to capture examples/**/*.ts files - Enable automatic test discovery in examples when tests are added This allows running all tests across the monorepo with a single 'pnpm test' command and generates unified coverage reports that include both src and examples directories. * chore: update actionss * feat(ci): add coverage badge generation Add automatic coverage badge SVG generation using jaywcjlove/coverage-badges-cli action. Changes: - Add json-summary reporter to vitest coverage config - Generate badges.svg from coverage-summary.json in CI - Badge will be available at GitHub Pages URL/badges.svg This enables adding a coverage badge to README that automatically updates when coverage changes. * chore(ci): update actions Update coverage-badges-cli action reference to v2.2.0 with correct SHA.
1 parent c53c441 commit 02a572e

File tree

5 files changed

+154
-353
lines changed

5 files changed

+154
-353
lines changed

.github/workflows/ci.yaml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
name: CI
22

33
on:
4+
push:
45
pull_request:
56
branches:
67
- main
@@ -9,6 +10,11 @@ concurrency:
910
group: ${{ github.workflow }}-${{ github.ref }}
1011
cancel-in-progress: true
1112

13+
permissions:
14+
contents: read
15+
pages: write
16+
id-token: write
17+
1218
jobs:
1319
ci:
1420
runs-on: ubuntu-latest
@@ -32,4 +38,34 @@ jobs:
3238
run: nix develop --command pnpm run build
3339

3440
- name: Run Tests
41+
if: github.ref != 'refs/heads/main'
3542
run: nix develop --command pnpm test
43+
44+
- name: Run Tests with Coverage
45+
if: github.ref == 'refs/heads/main'
46+
run: nix develop --command pnpm run coverage
47+
48+
- name: Create Coverage Badge
49+
if: github.ref == 'refs/heads/main'
50+
uses: jaywcjlove/coverage-badges-cli@bd6ccbf422c0ed54c01f283019fd2bc648f58541 # v2.2.0
51+
with:
52+
source: coverage/coverage-summary.json
53+
output: coverage/badges.svg
54+
55+
- name: Upload coverage artifact
56+
if: github.ref == 'refs/heads/main'
57+
uses: actions/upload-pages-artifact@7b1f4a764d45c48632c6b24a0339c27f5614fb0b # v4.0.0
58+
with:
59+
path: coverage
60+
61+
deploy-coverage:
62+
if: github.ref == 'refs/heads/main'
63+
needs: ci
64+
runs-on: ubuntu-latest
65+
environment:
66+
name: github-pages
67+
url: ${{ steps.deployment.outputs.page_url }}
68+
steps:
69+
- name: Deploy to GitHub Pages
70+
id: deployment
71+
uses: actions/deploy-pages@d6db90164ac5ed86f2b6aed7e0febac5b3c0c03e # v4.0.5

package.json

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,8 @@
2727
"lint:knip": "knip",
2828
"preinstall": "npx only-allow pnpm",
2929
"prepack": "npm pkg delete scripts.preinstall && pnpm run build",
30-
"test": "pnpm --aggregate-output run '/^test:/'",
31-
"test:submodules": "pnpm --parallel -r --aggregate-output test",
32-
"test:root": "vitest",
30+
"test": "vitest",
31+
"coverage": "vitest run --coverage",
3332
"typecheck": "pnpm --aggregate-output run '/^typecheck:/'",
3433
"typecheck:submodules": "pnpm --parallel -r --aggregate-output typecheck",
3534
"typecheck:root": "tsgo --noEmit"

0 commit comments

Comments
 (0)