Repository navigation
Description
Clear and concise description of the problem
The github-actions reporter annotates failed tests, but coverage gets no annotations. When coverage.thresholds fails a CI job, the check page shows only "Process completed with exit code 1". To find the uncovered file and lines, you have to open the full job log and scroll the text coverage table.
In our monorepo, coverage thresholds were the most common reason a pull request's CI failed: 8 of 23 failed jobs in a sample of recent red PRs. Every test failure in that sample already had an annotation; none of the coverage failures did.
Suggested solution
Let the github-actions reporter emit one ::error workflow command per file that has uncovered statements, functions, or branches. Anchor each annotation at the file's first uncovered line and list the rest in the message:
::error file=src/render.ts,line=40,title=Uncovered code::Uncovered lines 40-42, 55
A single annotation per file matters because GitHub shows at most 10 error annotations per step and 50 per job.
The API could be an opt-in option on the reporter:
reporters: [["github-actions", { coverage: true }]]Another option is to annotate only when thresholds fail, which would require running after the threshold check (see below).
Alternative
We use a custom reporter that implements onCoverage(coverageMap). For each file it walks s/f/b from fileCoverageFor(path).data, collects the start line of every entry with zero hits, and posts one annotation per file with core.error from @actions/core, which formats and escapes the workflow command.
This approach has three rough edges, and all would go away upstream:
onCoverageruns before@vitest/coverage-v8checks thresholds, so the reporter cannot tell whether the gate failed. It is only correct when every threshold is 100%, where any uncovered line fails the gate.@actions/core3 is ESM-only, so the config file that defines the reporter must load as ESM (we renamed ours to.mts).- Adding the reporter means setting
reporters, and a non-empty list replaces the defaults. So you have to listdefaultandgithub-actionsagain by hand.
Reporter (about 30 lines)
import path from "node:path";
import { error } from "@actions/core";
import type { Reporter } from "vitest/node";
class CoverageAnnotations implements Reporter {
onCoverage(coverage: unknown) {
const map = coverage as {
files(): string[];
fileCoverageFor(f: string): { data: any };
};
for (const file of map.files()) {
const d = map.fileCoverageFor(file).data;
const lines = new Set<number>();
for (const [id, n] of Object.entries<number>(d.s)) if (n === 0) lines.add(d.statementMap[id].start.line);
for (const [id, n] of Object.entries<number>(d.f)) if (n === 0) lines.add(d.fnMap[id].loc.start.line);
for (const [id, hits] of Object.entries<number[]>(d.b))
hits.forEach((n, i) => n === 0 && lines.add(d.branchMap[id].locations[i].start.line));
if (lines.size === 0) continue;
const sorted = [...lines].sort((a, b) => a - b);
error(`Uncovered lines ${sorted.join(", ")}`, {
file: path.relative(process.cwd(), file),
startLine: sorted[0],
title: "Uncovered code",
});
}
}
}Additional context
- Seen on Vitest 4.1.12. The 5.1.1
github-actionsreporter has no coverage hook either: it implementsonInit,onTestCaseAnnotate, andonTestRunEnd, and its options areonWritePath,displayAnnotations, andjobSummary. - I searched existing issues and discussions and found no request for coverage annotations.
- Happy to send a PR if the API shape is agreed.
Validations
- Follow our Code of Conduct
- Read the Contributing Guidelines.
- Read the docs.
- Check that there isn't already an issue that request the same feature to avoid creating a duplicate.
Activity
AriPerkkio commentedon Nov 23, 2026
Could this be custom coverage reporter instead of test reporter, as it's reporting coverage results?
So something like this:
import { defineConfig } from 'vitest/config' export default defineConfig({ test: { coverage: { reporter: [ 'html', 'json', 'lcov', + 'github-actions', ], }, }, })sumanthratna commentedon Nov 23, 2026
Agreed, a coverage reporter fits better. I moved our reporter to one and it works in CI. It also leaves
test.reportersalone, so users no longer re-listdefaultandgithub-actions.The config adds the reporter by path on GitHub Actions:
And the reporter, excerpted (
uncoveredLinescollects the start line of every zero-hit entry ins/f/b;annotateCoveragegroups by file and callscore.errorfrom@actions/coreonce per file):Happy to send a PR for a built-in
github-actionscoverage reporter if that shape works for you.AriPerkkio commentedon Nov 25, 2026
Feel free to send PR at https://github.com/vitest-dev/istanbuljs for this. I'm interested to see what the actual output would look like on CI. 👀
sumanthratna commentedon Nov 25, 2026
Opened vitest-dev/istanbuljs#43 with a
github-actionsreport.CI output from a demo run on my fork, with that repo's own coverage going through the report: https://github.com/sumanthratna/istanbuljs/actions/runs/45694687030. It prints one warning per file, anchored at the first uncovered line, such as
Uncovered lines 20-21oncoverage-map.ts:20. Aleveloption switches toerrorfor projects where any uncovered line fails the build.There's one open question in the PR body, about lines where only some of the statements ran.