Skip to content

Commit dd140f8

Browse files
committed
feat(FR-2744): restore Vitest coverage reporting in CI (#7065)
Resolves #7064(FR-2744) ## Summary FR-2611 dropped `ArtiomTr/jest-coverage-report-action` (Jest-only) when CI moved to Vitest, so PRs lost the coverage diff comment and inline test-failure annotations. This restores the equivalent surface using `davelosert/vitest-coverage-report-action@v2`. ### Local setup - Add `@vitest/coverage-v8@^4.1.4` as devDependency in `react/`, `packages/backend.ai-ui/`, root. - Coverage block in each `vitest.config.ts`: - `provider: 'v8'` — uses Node's V8 inspector, no Babel transform needed (fastest provider). - `reporter: ['text', 'json', 'json-summary', 'html']` — `json-summary` is what the GitHub Action consumes; `text` keeps a console summary; `html` lets devs open `coverage/index.html` locally. - `exclude` patterns trim test files, stories, generated Relay artifacts, and zero-logic entries (`src/index.tsx`, `reportWebVitals`, BUI locale catalog, `wsproxy`, bundled `backend.ai-client-node.*`). - `/coverage` added to `packages/backend.ai-ui/.gitignore` (root and react/ already had it). ### CI setup - `.github/workflows/vitest.yml` gains `pull-requests: write` permission so the action can post / update its PR comment. - Each of the three jobs (`react-vitest`, `backend-ai-ui-vitest`, `root-vitest`) runs `pnpm exec vitest run --coverage` and follows it with a `davelosert/vitest-coverage-report-action@v2` step keyed by a unique `name:` so the three PR comments don't collide. - The action runs with `if: always()` so a coverage comment posts even when tests fail (matches the prior Jest behaviour, which surfaced failed-test annotations). ## Verification ``` === react/ === Lines 7.23% (1645/22722) === BUI === Lines 7.91% (317/4006) === root === Lines 3.66% (282/7703) ``` - [x] All three workspaces produce `coverage/coverage-summary.json` in the shape the action expects - [x] Test pass counts unchanged (react 856/856, BUI 315 + 5 skip, root 90 + 1 skip) - [x] No regression in lint / format ## Out of scope - **No coverage threshold gates** — baseline %s above are intentionally low (mostly UI code without unit tests). Gating now would block normal PRs. A separate decision on thresholds belongs to a follow-up after the team agrees on a target. - README coverage badge. - Backfilling the 6 `TODO(FR-2609)` skipped tests. ## Stack Top of the Vite migration stack (now 12 PRs). Builds on PR #6879 (`fix(FR-2606)` webpackIgnore → @vite-ignore).
1 parent c303197 commit dd140f8

8 files changed

Lines changed: 89 additions & 9 deletions

File tree

.github/workflows/vitest.yml

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ on:
1515

1616
permissions:
1717
contents: read
18+
# `davelosert/vitest-coverage-report-action` writes a PR comment with the
19+
# coverage diff; needs write access on pull-requests for that.
20+
pull-requests: write
1821

1922
jobs:
2023
check-changes:
@@ -80,8 +83,14 @@ jobs:
8083
run: pnpm run lint
8184
- name: Run relay-compiler
8285
run: pnpm run relay
83-
- name: Run Vitest
84-
run: pnpm run vitest
86+
- name: Run Vitest with coverage
87+
run: pnpm exec vitest run --coverage
88+
- name: Report coverage on PR
89+
if: always()
90+
uses: davelosert/vitest-coverage-report-action@v2
91+
with:
92+
working-directory: ./react
93+
name: react-coverage
8594

8695
backend-ai-ui-vitest:
8796
needs: check-changes
@@ -119,8 +128,14 @@ jobs:
119128
run: pnpm run lint
120129
- name: Run relay-compiler
121130
run: cd ../.. && pnpm run relay
122-
- name: Run Vitest
123-
run: pnpm run vitest
131+
- name: Run Vitest with coverage
132+
run: pnpm exec vitest run --coverage
133+
- name: Report coverage on PR
134+
if: always()
135+
uses: davelosert/vitest-coverage-report-action@v2
136+
with:
137+
working-directory: ./packages/backend.ai-ui
138+
name: backend-ai-ui-coverage
124139

125140
root-vitest:
126141
needs: check-changes
@@ -150,5 +165,10 @@ jobs:
150165
${{ runner.os }}-pnpm-store-
151166
- name: Install dependencies
152167
run: pnpm install --merge-git-branch-lockfiles --no-frozen-lockfile
153-
- name: Run Vitest
154-
run: pnpm run vitest
168+
- name: Run Vitest with coverage
169+
run: pnpm exec vitest run --coverage
170+
- name: Report coverage on PR
171+
if: always()
172+
uses: davelosert/vitest-coverage-report-action@v2
173+
with:
174+
name: root-coverage

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@
9494
"tslib": "^2.8.1",
9595
"typescript": "~5.5.4",
9696
"vitest": "^4.1.4",
97+
"@vitest/coverage-v8": "^4.1.4",
9798
"webpack": "catalog:",
9899
"webpack-cli": "^6.0.1",
99100
"workbox-expiration": "^7.4.0",

packages/backend.ai-ui/.gitignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,7 @@ storybook-static
3030
.vscode/*
3131
!.vscode/settings.json.sample
3232

33-
dist
33+
dist
34+
35+
# vitest coverage output
36+
/coverage

packages/backend.ai-ui/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,8 @@
118118
"vite-plugin-dts": "^4.5.4",
119119
"vite-plugin-relay-lite": "^0.11.0",
120120
"vite-plugin-svgr": "^4.5.0",
121-
"vitest": "^4.1.4"
121+
"vitest": "^4.1.4",
122+
"@vitest/coverage-v8": "^4.1.4"
122123
},
123124
"type": "module"
124125
}

packages/backend.ai-ui/vitest.config.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,5 +59,24 @@ export default defineConfig({
5959
],
6060
include: ['src/**/*.{test,spec}.{ts,tsx}'],
6161
exclude: ['**/node_modules/**', '**/dist/**', '**/__generated__/**'],
62+
63+
// Coverage settings — see comment in `react/vitest.config.ts`. The
64+
// `davelosert/vitest-coverage-report-action` GitHub Action consumes the
65+
// `json-summary` reporter to post a PR comment with line/branch/function/
66+
// statement coverage diffs.
67+
coverage: {
68+
provider: 'v8',
69+
reporter: ['text', 'json', 'json-summary', 'html'],
70+
reportsDirectory: 'coverage',
71+
include: ['src/**/*.{ts,tsx}'],
72+
exclude: [
73+
'src/**/*.{test,spec}.{ts,tsx}',
74+
'src/**/*.stories.{ts,tsx}',
75+
'src/__generated__/**',
76+
'src/**/__generated__/**',
77+
'src/index.ts',
78+
'src/locale/**',
79+
],
80+
},
6281
},
6382
});

react/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,7 @@
163163
"vite-plugin-node-polyfills": "^0.24.0",
164164
"vite-plugin-pwa": "^1.2.0",
165165
"vite-plugin-svgr": "^4.5.0",
166-
"vitest": "^4.1.4"
166+
"vitest": "^4.1.4",
167+
"@vitest/coverage-v8": "^4.1.4"
167168
}
168169
}

react/vitest.config.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,5 +97,25 @@ export default defineConfig({
9797
],
9898
include: ['src/**/*.{test,spec}.{ts,tsx}'],
9999
exclude: ['**/node_modules/**', '**/build/**', '**/__generated__/**'],
100+
101+
// Coverage settings: V8 provider is the fastest (Node's built-in V8
102+
// inspector with no Babel transform). `json-summary` is what
103+
// `davelosert/vitest-coverage-report-action` consumes for the PR comment;
104+
// `text` keeps a console summary; `html` lets developers open
105+
// `coverage/index.html` locally for inline drill-down.
106+
coverage: {
107+
provider: 'v8',
108+
reporter: ['text', 'json', 'json-summary', 'html'],
109+
reportsDirectory: 'coverage',
110+
include: ['src/**/*.{ts,tsx}'],
111+
exclude: [
112+
'src/**/*.{test,spec}.{ts,tsx}',
113+
'src/**/*.stories.{ts,tsx}',
114+
'src/__generated__/**',
115+
'src/**/__generated__/**',
116+
'src/index.tsx',
117+
'src/reportWebVitals.ts',
118+
],
119+
},
100120
},
101121
});

vitest.config.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,5 +31,20 @@ export default defineConfig({
3131
"react/**",
3232
"packages/**",
3333
],
34+
35+
// Coverage settings — see comment in `react/vitest.config.ts`. Same
36+
// reporters and provider so the `davelosert/vitest-coverage-report-action`
37+
// PR comment shape is consistent across the three workspaces.
38+
coverage: {
39+
provider: "v8",
40+
reporter: ["text", "json", "json-summary", "html"],
41+
reportsDirectory: "coverage",
42+
include: ["{src,scripts}/**/*.{ts,js,cjs}"],
43+
exclude: [
44+
"{src,scripts}/**/*.{test,spec}.ts",
45+
"src/wsproxy/**",
46+
"src/lib/backend.ai-client-node.*",
47+
],
48+
},
3449
},
3550
});

0 commit comments

Comments
 (0)