11# Vitest V8 JSON Coverage Summary
22
3- A plugin for [ Vitest] ( https://vitest.dev/ ) that generates a structured JSON coverage summary from V8 coverage data. This reporter creates a ` coverage-summary.json ` file with detailed coverage information for statements, branches, functions, and lines .
3+ A plugin for [ Vitest] ( https://vitest.dev/ ) that generates a structured JSON coverage summary from V8 coverage data. This package also includes GitHub Actions for coverage reporting and badge management .
44
55## Features
66
@@ -9,22 +9,63 @@ A plugin for [Vitest](https://vitest.dev/) that generates a structured JSON cove
99- ✅ Includes file-level and overall coverage statistics
1010- ✅ Tracks uncovered lines for detailed analysis
1111- ✅ Compatible with Vitest 3.0+
12- - 🚀 ** NEW** : GitHub Action for automatic PR coverage reporting
13- - 🏷️ ** NEW** : Automatic coverage badge generation for GitHub Pages
14- - 🚀 ** NEW** : Automatic upload of badges to GitHub Pages
15- - 🔧 ** NEW** : Pure YAML implementation - no JavaScript complexity
12+ - 🚀 ** GitHub Actions** : Coverage reporting, badge generation, and badge upload
13+ - 🏷️ ** Coverage Badges** : Shields.io compatible badges
14+ - 🔧 ** Modular Design** : Separate actions for different use cases
1615
1716## Installation
1817
1918``` bash
2019npm install --save-dev vitest-v8-json-coverage-summary
2120```
2221
23- ## GitHub Action
22+ ## GitHub Actions
2423
25- This package also includes a GitHub Action that automatically creates beautiful coverage reports in pull requests and uploads coverage badges to GitHub Pages. Built with pure YAML and shell commands for maximum reliability.
24+ This package includes three separate GitHub Actions that can be used independently:
2625
27- ### Quick Start
26+ ### 1. Coverage Reporter
27+
28+ Creates beautiful coverage reports in pull requests.
29+
30+ ``` yaml
31+ - name : Report Coverage
32+ uses :
glideapps/vitest-v8-json-coverage-summary/actions/[email protected] 33+ with :
34+ coverage-file : " coverage/coverage-summary.json"
35+ title : " 🧪 Test Coverage Report"
36+ show-files : " true"
37+ coverage-threshold : " 80"
38+ ` ` `
39+
40+ ### 2. Badge Generator
41+
42+ Generates coverage badges from coverage data.
43+
44+ ` ` ` yaml
45+ - name : Generate Badges
46+ uses :
glideapps/vitest-v8-json-coverage-summary/actions/[email protected] 47+ with :
48+ coverage-file : " coverage/coverage-summary.json"
49+ badges-dir : " badges"
50+ ` ` `
51+
52+ ### 3. Badge Uploader
53+
54+ Uploads badges to GitHub Pages.
55+
56+ ` ` ` yaml
57+ - name : Upload Badges to GitHub Pages
58+ uses :
glideapps/vitest-v8-json-coverage-summary/actions/[email protected] 59+ with :
60+ coverage-file : " coverage/coverage-summary.json"
61+ badges-dir : " badges"
62+ pages-branch : " gh-pages"
63+ generate-badges : " true"
64+ ` ` `
65+
66+ ## Quick Start
67+
68+ ### Basic Coverage Reporting
2869
2970` ` ` yaml
3071name : Coverage Report
3475
3576permissions :
3677 pull-requests : write
37- contents : write # Required for GitHub Pages upload
3878
3979jobs :
4080 coverage :
@@ -46,20 +86,86 @@ jobs:
4686 node-version : " 20"
4787 - run : npm ci
4888 - run : npm test
49- -
uses :
glideapps/[email protected] 89+ - uses : glideapps/vitest-v8-json-coverage-summary/actions/coverage-reporter @v0.0.0-echo
5090 with :
5191 coverage-file : " coverage/coverage-summary.json"
5292` ` `
5393
54- The action will automatically:
94+ ### Full Workflow with Badges
5595
56- - Create coverage reports in pull request comments
57- - Generate coverage badges
58- - Upload badges to the ` gh-pages` branch for GitHub Pages
96+ ` ` ` yaml
97+ name : Coverage with Badges
98+ on :
99+ pull_request :
100+ branches : [main]
101+ push :
102+ branches : [main]
59103
60- **Built with pure YAML and shell commands** - no JavaScript complexity, no module system issues, no permission headaches!
104+ permissions :
105+ pull-requests : write
106+ contents : write
61107
62- # ## Badge URLs
108+ jobs :
109+ coverage :
110+ runs-on : ubuntu-latest
111+ steps :
112+ - uses : actions/checkout@v4
113+ - uses : actions/setup-node@v4
114+ with :
115+ node-version : " 20"
116+ - run : npm ci
117+ - run : npm test
118+ -
uses :
glideapps/vitest-v8-json-coverage-summary/actions/[email protected] 119+
120+ badges :
121+ if : github.ref == 'refs/heads/main'
122+ runs-on : ubuntu-latest
123+ needs : coverage
124+ steps :
125+ - uses : actions/checkout@v4
126+ with :
127+ fetch-depth : 0
128+ - uses : actions/setup-node@v4
129+ with :
130+ node-version : " 20"
131+ - run : npm ci
132+ - run : npm test
133+ -
uses :
glideapps/vitest-v8-json-coverage-summary/actions/[email protected] 134+ with :
135+ generate-badges : " true"
136+ ` ` `
137+
138+ ## Action Reference
139+
140+ ### Coverage Reporter
141+
142+ | Input | Description | Required | Default |
143+ | -------------------- | ------------------------------------------------------- | -------- | -------------------------------- |
144+ | ` coverage-file` | Path to the coverage summary JSON file | No | `coverage/coverage-summary.json` |
145+ | `token` | GitHub token for creating comments | No | `${{ github.token }}` |
146+ | `title` | Title for the coverage report comment | No | `📊 Coverage Report` |
147+ | `show-files` | Whether to show individual file coverage details | No | `true` |
148+ | `coverage-threshold` | Minimum coverage percentage to consider as good (0-100) | No | `80` |
149+
150+ # ## Badge Generator
151+
152+ | Input | Description | Required | Default |
153+ | --------------- | ---------------------------------------- | -------- | -------------------------------- |
154+ | `coverage-file` | Path to the coverage summary JSON file | No | `coverage/coverage-summary.json` |
155+ | `badges-dir` | Directory to output the generated badges | No | `badges` |
156+
157+ # ## Badge Uploader
158+
159+ | Input | Description | Required | Default |
160+ | ------------------ | ------------------------------------------------- | -------- | ---------------------------------- |
161+ | `coverage-file` | Path to the coverage summary JSON file | No | `coverage/coverage-summary.json` |
162+ | `badges-dir` | Directory containing the badges to upload | No | `badges` |
163+ | `pages-branch` | Branch to upload badges to for GitHub Pages | No | `gh-pages` |
164+ | `pages-badges-dir` | Directory within the pages branch to store badges | No | `badges` |
165+ | `commit-message` | Commit message for badge updates | No | `Update coverage badges [skip ci]` |
166+ | `generate-badges` | Whether to generate badges if they don't exist | No | `true` |
167+
168+ # # Badge URLs
63169
64170When GitHub Pages is enabled, badges are available at :
65171
@@ -77,35 +183,45 @@ Use in your README.md:
77183
78184` ` `
79185
80- For detailed documentation, see [ACTION_README.md](ACTION_README.md).
186+ # # Examples
81187
82- # # Usage
188+ See the `examples/` directory for complete workflow examples :
83189
84- # ## Basic Setup
190+ - ` coverage-only.yml` - Only coverage reporting
191+ - ` badge-generator-only.yml` - Only badge generation
192+ - ` badge-uploader-only.yml` - Only badge upload
193+ - ` full-workflow.yml` - Complete workflow with all actions
85194
86- Add the reporter to your Vitest configuration :
195+ # # Setup
196+
197+ # ## Configure Vitest
87198
88199` ` ` javascript
89200// vitest.config.js
90- import { defineConfig } from "vitest/config";
91- import V8JSONSummaryReporter from "vitest-v8-json-coverage-summary";
92-
93- export default defineConfig({
94- test: {
95- coverage: {
96- provider: "v8",
97- reporter: ["text", "json"],
98- reportsDirectory: "./coverage",
99- },
100- reporters: ["default", new V8JSONSummaryReporter()],
201+ export default {
202+ coverage: {
203+ provider: "v8",
204+ reporter: ["json-summary"],
205+ reportsDirectory: "coverage",
101206 },
102- }) ;
207+ };
103208` ` `
104209
105- # ## TypeScript Configuration
210+ # ## Enable GitHub Pages
211+
212+ 1. Go to Settings → Pages
213+ 2. Set source to "Deploy from a branch"
214+ 3. Select `gh-pages` branch
215+ 4. Set folder to `/ (root)` or `/badges`
216+
217+ # # Usage
218+
219+ # ## Basic Setup
220+
221+ Add the reporter to your Vitest configuration :
106222
107- ` ` ` typescript
108- // vitest.config.ts
223+ ` ` ` javascript
224+ // vitest.config.js
109225import { defineConfig } from "vitest/config";
110226import V8JSONSummaryReporter from "vitest-v8-json-coverage-summary";
111227
0 commit comments