Skip to content

Commit ec8231f

Browse files
authored
Merge pull request #364 from knockout/test/coverage
feat: add test coverage run with vitest + v8
2 parents 681f036 + 503c5c3 commit ec8231f

7 files changed

Lines changed: 169 additions & 177 deletions

File tree

.github/workflows/coverage.yml

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
# Run vitest+v8 coverage on PRs and main pushes.
2+
#
3+
# Uploads the coverage report as an artifact for human download and
4+
# writes a summary table to the workflow run page. Currently does NOT
5+
# gate on threshold and does NOT post deltas to PRs — coverage is
6+
# informational. Closed-loop dark-factory feedback (PR comment + delta
7+
# gate) is tracked as a follow-up issue.
8+
#
9+
# Runs against the chromium browser project only. Firefox/WebKit
10+
# coverage is not measurable (JSC and SpiderMonkey don't expose V8's
11+
# coverage protocol). See vitest.config.ts coverage block for details.
12+
name: Coverage
13+
14+
on:
15+
pull_request:
16+
push:
17+
branches: [main]
18+
19+
# One coverage run per ref; cancel in-progress runs when a new push
20+
# arrives so we always report on the current tip.
21+
concurrency:
22+
group: ${{ github.workflow }}-${{ github.ref }}
23+
cancel-in-progress: true
24+
25+
jobs:
26+
coverage:
27+
name: vitest+v8 coverage
28+
runs-on: ubuntu-latest
29+
container:
30+
image: mcr.microsoft.com/playwright:v1.59.1-noble
31+
32+
steps:
33+
- name: Checkout code
34+
uses: actions/checkout@v6
35+
36+
- name: Install Bun
37+
run: python3 tools/install-bun
38+
39+
# The Playwright noble image ships without jq; the coverage-summary
40+
# step needs it to format the workflow run summary table.
41+
- name: Install jq
42+
run: apt-get update && apt-get install -y --no-install-recommends jq
43+
44+
- name: Install dependencies
45+
run: bun install --frozen-lockfile
46+
47+
- name: Run coverage
48+
run: bun run test:coverage
49+
env:
50+
HOME: /root
51+
52+
- name: Coverage summary
53+
if: always()
54+
run: |
55+
if [ -f coverage/coverage-summary.json ]; then
56+
echo "## Coverage summary" >> "$GITHUB_STEP_SUMMARY"
57+
echo "" >> "$GITHUB_STEP_SUMMARY"
58+
echo "| Metric | Pct | Covered/Total |" >> "$GITHUB_STEP_SUMMARY"
59+
echo "|---|---|---|" >> "$GITHUB_STEP_SUMMARY"
60+
jq -r '
61+
.total |
62+
"| Lines | \(.lines.pct)% | \(.lines.covered)/\(.lines.total) |\n" +
63+
"| Statements | \(.statements.pct)% | \(.statements.covered)/\(.statements.total) |\n" +
64+
"| Branches | \(.branches.pct)% | \(.branches.covered)/\(.branches.total) |\n" +
65+
"| Functions | \(.functions.pct)% | \(.functions.covered)/\(.functions.total) |"
66+
' coverage/coverage-summary.json >> "$GITHUB_STEP_SUMMARY"
67+
fi
68+
69+
# Machine-readable artifacts (~220 KB), retained 30 days. Designed
70+
# so a future closed-loop coverage workflow can download a base
71+
# commit's data to compute deltas.
72+
- name: Upload coverage data
73+
if: always()
74+
uses: actions/upload-artifact@v7
75+
with:
76+
name: coverage-data
77+
path: |
78+
coverage/coverage-summary.json
79+
coverage/lcov.info
80+
retention-days: 30
81+
82+
# Human-readable HTML report (~5 MB). Only on main pushes; short
83+
# retention since PR runs don't benefit from it.
84+
- name: Upload coverage HTML (main only)
85+
if: always() && github.event_name == 'push' && github.ref == 'refs/heads/main'
86+
uses: actions/upload-artifact@v7
87+
with:
88+
name: coverage-html
89+
path: coverage/lcov-report
90+
retention-days: 7

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ node_modules
2222
_repo
2323
coverage
2424
coverage-temp
25+
COVERAGE.md
2526
builds/**/meta
2627
.nyc_output
2728
**/dist/*

0 commit comments

Comments
 (0)