ci(coverage): measure frontend coverage with v8 and backend branch coverage (#5407)

* ci(coverage): measure frontend coverage with v8 and backend branch coverage

The frontend had no coverage measurement, and the backend's line-only
report counts a one-sided `if` as covered when its body never runs.

- Add @vitest/coverage-v8 and `npm run test:coverage`. Its include lists
  every source file, so a file no test imports reports 0% instead of
  disappearing. Generated types, locales, tokens, test utilities,
  stories, fixtures and play helpers are excluded.
- Frontend Checks runs tests with coverage and uploads the cobertura
  report to GitHub code coverage as code-coverage/vitest, mirroring
  pytest.yml: a separate job holds code-quality: write and fork PRs skip
  the upload.
- Turn on branch coverage in backend/.coveragerc.

Baseline on master: 407 test files pass; frontend lines 63.3%, branches
55.3%. The app project alone (no stories) gives 61.4% lines, so stories
add about two points.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01NH5s4iK9WRvZqdTHiRc9gY

* ci(coverage): include JavaScript sources in the frontend coverage report

The two audio worklets (gmeAudioWorklet.js, pico8AudioWorklet.js) are
production code that the `{ts,vue}` glob left out of the report, so they
now show at 0% instead of being omitted.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01NH5s4iK9WRvZqdTHiRc9gY

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Sam Dornan
2026-10-30 10:49:20 -05:00
committed by GitHub
parent 63faff8883
commit fec6e494f7
6 changed files with 163 additions and 1 deletions

View File

@@ -42,9 +42,45 @@ jobs:
working-directory: frontend
- name: Run tests (vitest, includes Storybook play() and a11y tests)
run: npm test
run: npm run test:coverage
working-directory: frontend
# Fork PRs can't upload.
- name: Upload coverage report artifact
if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository
uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
with:
name: frontend-coverage-report
path: frontend/coverage/cobertura-coverage.xml
if-no-files-found: error
retention-days: 1
# A separate job keeps code-quality: write away from the job that runs the PR's code.
upload-coverage:
needs: test
if: ${{ !cancelled() && needs.test.result == 'success' && (github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository) }}
runs-on: ubuntu-24.04
timeout-minutes: 10
permissions:
contents: read
# actionlint doesn't know the code-quality scope yet.
# trunk-ignore(actionlint)
code-quality: write
steps:
- name: Download coverage report
uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2
with:
name: frontend-coverage-report
# Best-effort while GitHub code coverage is in preview; errors still show as annotations.
- name: Upload coverage to GitHub
uses: actions/upload-code-coverage@2b21a77928be8d5168c2b9581a67f2adbebacc52 # v1.4.4
with:
file: cobertura-coverage.xml
language: TypeScript
label: code-coverage/vitest
fail-on-error: false
build:
runs-on: ubuntu-24.04
timeout-minutes: 15

View File

@@ -1,4 +1,5 @@
[run]
branch = True
omit =
alembic/*
*/tests/*

View File

@@ -14,6 +14,7 @@ npm run dev # dev server :3000
npm run typecheck # vue-tsc --build: the app, the Node tooling and the e2e suite
npm run typecheck:scripts # Node only: scripts/, eslint-plugin-romm/, tool configs, the e2e suite
npm run test # vitest (+ Storybook play() and a11y tests in Chromium)
npm run test:coverage # the same, with a v8 coverage report in coverage/ (open index.html)
npm run test:e2e # playwright, see e2e/README.md
npm run build # production build
npm run generate # regenerate types from backend OpenAPI (backend must be running)

View File

@@ -53,6 +53,7 @@
"@types/spark-md5": "^3.0.5",
"@vitejs/plugin-vue": "^6.0.7",
"@vitest/browser-playwright": "^5.0.5",
"@vitest/coverage-v8": "^5.0.5",
"@vitest/ui": "^5.0.5",
"@vue/eslint-config-typescript": "^14.9.0",
"@vue/test-utils": "^2.4.9",
@@ -1706,6 +1707,16 @@
"node": ">=6.9.0"
}
},
"node_modules/@bcoe/v8-coverage": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/@bcoe/v8-coverage/-/v8-coverage-1.0.2.tgz",
"integrity": "sha512-6zABk/ECA/QYSCQ1NGiVwwbQerUCZ+TQbp64Q3AgmfNvurHH0j8TtXa1qbShXA6qqkpAj4V5W8pP6mLe1mcMqA==",
"dev": true,
"license": "MIT",
"engines": {
"node": ">=18"
}
},
"node_modules/@blazediff/core": {
"version": "1.10.0",
"resolved": "https://registry.npmjs.org/@blazediff/core/-/core-1.10.0.tgz",
@@ -5908,6 +5919,35 @@
}
}
},
"node_modules/@vitest/coverage-v8": {
"version": "5.0.5",
"resolved": "https://registry.npmjs.org/@vitest/coverage-v8/-/coverage-v8-5.0.5.tgz",
"integrity": "sha512-4KpkGdIrSqBihx/JyP/e+S+IKB98etg1XDQiLAxksLfcShnwi1VReGeOT9NI43hLHbknosKp/1CCLn9Zgcs8mg==",
"dev": true,
"license": "MIT",
"dependencies": {
"@bcoe/v8-coverage": "^1.0.2",
"@vitest/istanbul-lib-coverage": "^1.0.2",
"@vitest/istanbul-lib-report": "^1.0.2",
"ast-v8-to-istanbul": "^1.0.7",
"magicast": "^0.5.5",
"obug": "^3.0.0",
"std-env": "^4.3.0",
"tinyrainbow": "^3.2.0"
},
"funding": {
"url": "https://opencollective.com/vitest"
},
"peerDependencies": {
"@vitest/browser": "5.0.5",
"vitest": "5.0.5"
},
"peerDependenciesMeta": {
"@vitest/browser": {
"optional": true
}
}
},
"node_modules/@vitest/expect": {
"version": "3.2.4",
"resolved": "https://registry.npmjs.org/@vitest/expect/-/expect-3.2.4.tgz",
@@ -5976,6 +6016,29 @@
"node": ">=14.0.0"
}
},
"node_modules/@vitest/istanbul-lib-coverage": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/@vitest/istanbul-lib-coverage/-/istanbul-lib-coverage-1.0.2.tgz",
"integrity": "sha512-9J/JMwOf9AoJhAywhrn7ScKTL38hsWQP/qPG60OtaAFcQ5OXPwKsxZFlbnuCKmZ61m8/lGgHYnFpdyQZUvG/iA==",
"dev": true,
"license": "MIT",
"engines": {
"node": ">=22"
}
},
"node_modules/@vitest/istanbul-lib-report": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/@vitest/istanbul-lib-report/-/istanbul-lib-report-1.0.2.tgz",
"integrity": "sha512-gUsfXZJbzPamoIY5TvHFiMMoXESBrUMo+xqaj+rYrWI69+EnvRlYBlP96ZnHPY4vX8kyUpgAnFUCg5wZG/HkDQ==",
"dev": true,
"license": "MIT",
"dependencies": {
"@vitest/istanbul-lib-coverage": "1.0.2"
},
"engines": {
"node": ">=22"
}
},
"node_modules/@vitest/mocker": {
"version": "5.0.5",
"resolved": "https://registry.npmjs.org/@vitest/mocker/-/mocker-5.0.5.tgz",
@@ -6718,6 +6781,35 @@
"node": ">=4"
}
},
"node_modules/ast-v8-to-istanbul": {
"version": "1.0.7",
"resolved": "https://registry.npmjs.org/ast-v8-to-istanbul/-/ast-v8-to-istanbul-1.0.7.tgz",
"integrity": "sha512-kFL68AG6ajd8fg248zwM9GQrUWEp79gsmjum34OEXjs4yHuUMZfYKwOLW9GMmB4oNvVrj+EAGxsP7ye2UR9UlA==",
"dev": true,
"license": "MIT",
"dependencies": {
"@jridgewell/trace-mapping": "^0.3.31",
"estree-walker": "^3.0.3",
"js-tokens": "^10.0.0"
}
},
"node_modules/ast-v8-to-istanbul/node_modules/estree-walker": {
"version": "3.0.3",
"resolved": "https://registry.npmjs.org/estree-walker/-/estree-walker-3.0.3.tgz",
"integrity": "sha512-7RUKfXgSMMkzt6ZuXmqapOurLGPPfgj6l9uRZ7lRGolvk0y2yocc35LdcxKC5PQZdn2DMqioAQ2NoWcrTKmm6g==",
"dev": true,
"license": "MIT",
"dependencies": {
"@types/estree": "^1.0.0"
}
},
"node_modules/ast-v8-to-istanbul/node_modules/js-tokens": {
"version": "10.0.0",
"resolved": "https://registry.npmjs.org/js-tokens/-/js-tokens-10.0.0.tgz",
"integrity": "sha512-lM/UBzQmfJRo9ABXbPWemivdCW8V2G8FHaHdypQaIy523snUjog0W71ayWXTjiR+ixeMyVHN2XcpnTd/liPg/Q==",
"dev": true,
"license": "MIT"
},
"node_modules/ast-walker-scope": {
"version": "0.10.0",
"resolved": "https://registry.npmjs.org/ast-walker-scope/-/ast-walker-scope-0.10.0.tgz",
@@ -10078,6 +10170,18 @@
"url": "https://github.com/sponsors/sxzz"
}
},
"node_modules/magicast": {
"version": "0.5.5",
"resolved": "https://registry.npmjs.org/magicast/-/magicast-0.5.5.tgz",
"integrity": "sha512-UicdXN8zQ3JHlxVq+28afMXPr1z7WNY6+7EJnzTdQWkTAlMLF5fNCCKxJHBQwGaNGR11581EiQmQzx73+MvszA==",
"dev": true,
"license": "MIT",
"dependencies": {
"@babel/parser": "^7.29.7",
"@babel/types": "^7.29.7",
"source-map-js": "^1.2.1"
}
},
"node_modules/markdown-it": {
"version": "14.3.3",
"resolved": "https://registry.npmjs.org/markdown-it/-/markdown-it-14.3.3.tgz",

View File

@@ -30,6 +30,7 @@
"typecheck:scripts": "tsc --build tsconfig.node.json",
"generate": "openapi --input http://127.0.0.1:3000/openapi.json --output ./src/__generated__ --client axios --useOptions --useUnionTypes --exportServices false --exportSchemas false --exportCore false",
"test": "vitest run",
"test:coverage": "vitest run --coverage",
"test:watch": "vitest",
"test:ui": "vitest --ui",
"storybook": "storybook dev -p 6006",
@@ -84,6 +85,7 @@
"@types/spark-md5": "^3.0.5",
"@vitejs/plugin-vue": "^6.0.7",
"@vitest/browser-playwright": "^5.0.5",
"@vitest/coverage-v8": "^5.0.5",
"@vitest/ui": "^5.0.5",
"@vue/eslint-config-typescript": "^14.9.0",
"@vue/test-utils": "^2.4.9",

View File

@@ -16,6 +16,24 @@ export default defineConfig({
inline: ["@vueuse/integrations"],
},
},
coverage: {
provider: "v8",
// Listing sources reports files no test imports at 0% instead of omitting them.
include: ["src/**/*.{ts,js,vue}"],
exclude: [
"src/__generated__/**",
"src/locales/**",
"src/tokens/**",
"src/test-utils/**",
"src/**/*.{test,spec}.ts",
"src/**/*.stories.ts",
"src/**/*.fixtures.ts",
"src/**/*.plays.ts",
"src/**/*.d.ts",
],
// projectRoot makes cobertura paths repo-relative (frontend/...), as code coverage expects.
reporter: ["text-summary", "html", ["cobertura", { projectRoot: ".." }]],
},
projects: [
{
extends: true,