Skip to content

Commit 04c703f

Browse files
committed
chore: 📦 it up and ready to ship to npm
1 parent 9fe0515 commit 04c703f

File tree

6 files changed

+304
-9
lines changed

6 files changed

+304
-9
lines changed

.npmignore

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# Source files
2+
src/
3+
test-src/
4+
5+
# Configuration files
6+
vitest.config.js
7+
tsconfig.json
8+
.npmignore
9+
10+
# Development files
11+
.git/
12+
.gitignore
13+
14+
# Test coverage
15+
coverage/
16+
17+
# Node modules
18+
node_modules/
19+
20+
# Package lock
21+
package-lock.json
22+
23+
# IDE files
24+
.vscode/
25+
.idea/
26+
*.swp
27+
*.swo
28+
29+
# OS files
30+
.DS_Store
31+
Thumbs.db
32+
33+
# Test files in dist
34+
dist/*.test.*

README.md

Lines changed: 187 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,188 @@
1-
# Vitest Structured Summary
1+
# Vitest V8 JSON Coverage Summary
22

3-
A vitest plugin that generates a JSON file with structured summary output.
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.
4+
5+
## Features
6+
7+
- ✅ Generates structured JSON coverage summary
8+
- ✅ Supports V8 coverage provider
9+
- ✅ Includes file-level and overall coverage statistics
10+
- ✅ Tracks uncovered lines for detailed analysis
11+
- ✅ Compatible with Vitest 3.0+
12+
13+
## Installation
14+
15+
```bash
16+
npm install --save-dev vitest-v8-json-coverage-summary
17+
```
18+
19+
## Usage
20+
21+
### Basic Setup
22+
23+
Add the reporter to your Vitest configuration:
24+
25+
```javascript
26+
// vitest.config.js
27+
import { defineConfig } from "vitest/config";
28+
import V8JSONSummaryReporter from "vitest-v8-json-coverage-summary";
29+
30+
export default defineConfig({
31+
test: {
32+
coverage: {
33+
provider: "v8",
34+
reporter: ["text", "json"],
35+
reportsDirectory: "./coverage",
36+
},
37+
reporters: ["default", new V8JSONSummaryReporter()],
38+
},
39+
});
40+
```
41+
42+
### TypeScript Configuration
43+
44+
```typescript
45+
// vitest.config.ts
46+
import { defineConfig } from "vitest/config";
47+
import V8JSONSummaryReporter from "vitest-v8-json-coverage-summary";
48+
49+
export default defineConfig({
50+
test: {
51+
coverage: {
52+
provider: "v8",
53+
reporter: ["text", "json"],
54+
reportsDirectory: "./coverage",
55+
},
56+
reporters: ["default", new V8JSONSummaryReporter()],
57+
},
58+
});
59+
```
60+
61+
## Output Format
62+
63+
The reporter generates a `coverage-summary.json` file in your coverage directory with the following structure:
64+
65+
```json
66+
{
67+
"summary": {
68+
"statements": 85.5,
69+
"branches": 72.3,
70+
"functions": 90.1,
71+
"lines": 85.5
72+
},
73+
"files": [
74+
{
75+
"file": "src/example.js",
76+
"statements": 95.2,
77+
"branches": 80.0,
78+
"functions": 100.0,
79+
"lines": 95.2,
80+
"uncoveredLines": [15, 23, 45]
81+
}
82+
]
83+
}
84+
```
85+
86+
### Coverage Metrics
87+
88+
- **statements**: Percentage of statements covered
89+
- **branches**: Percentage of branch paths covered
90+
- **functions**: Percentage of functions covered
91+
- **lines**: Percentage of lines covered (matches statements for V8)
92+
- **uncoveredLines**: Array of line numbers that are not covered (optional)
93+
94+
## API Reference
95+
96+
### V8JSONSummaryReporter
97+
98+
The main reporter class that implements Vitest's Reporter interface.
99+
100+
#### Methods
101+
102+
- `onInit(vitest: Vitest)`: Called when the reporter is initialized
103+
- `onCoverage(coverage: any)`: Called when coverage data is available
104+
- `onTestRunEnd()`: Called when the test run ends (kept for compatibility)
105+
106+
### generateV8CoverageSummary(coverage: any): CoverageSummary
107+
108+
Utility function that processes V8 coverage data and returns a structured summary.
109+
110+
## Configuration Options
111+
112+
The reporter uses the coverage configuration from your Vitest config:
113+
114+
- `coverage.reportsDirectory`: Directory where the summary file will be written (default: `./coverage`)
115+
- `coverage.provider`: Must be set to `'v8'` for this reporter to work
116+
117+
## Example Output
118+
119+
After running your tests with coverage, you'll find a `coverage-summary.json` file that looks like this:
120+
121+
```json
122+
{
123+
"summary": {
124+
"statements": 87.5,
125+
"branches": 75.0,
126+
"functions": 92.3,
127+
"lines": 87.5
128+
},
129+
"files": [
130+
{
131+
"file": "src/utils.js",
132+
"statements": 100.0,
133+
"branches": 100.0,
134+
"functions": 100.0,
135+
"lines": 100.0
136+
},
137+
{
138+
"file": "src/main.js",
139+
"statements": 75.0,
140+
"branches": 50.0,
141+
"functions": 85.7,
142+
"lines": 75.0,
143+
"uncoveredLines": [12, 15, 23]
144+
}
145+
]
146+
}
147+
```
148+
149+
## Integration Examples
150+
151+
### With CI/CD
152+
153+
```yaml
154+
# GitHub Actions example
155+
- name: Run tests with coverage
156+
run: npm test
157+
158+
- name: Upload coverage summary
159+
uses: actions/upload-artifact@v3
160+
with:
161+
name: coverage-summary
162+
path: coverage/coverage-summary.json
163+
```
164+
165+
### With Coverage Badges
166+
167+
You can use the generated JSON to create coverage badges or integrate with coverage reporting services.
168+
169+
## Contributing
170+
171+
1. Fork the repository
172+
2. Create a feature branch
173+
3. Make your changes
174+
4. Add tests if applicable
175+
5. Submit a pull request
176+
177+
## License
178+
179+
MIT License - see [LICENSE](LICENSE) file for details.
180+
181+
## Changelog
182+
183+
### 1.0.0
184+
185+
- Initial release
186+
- V8 coverage support
187+
- JSON summary generation
188+
- File-level and overall coverage statistics

index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export { default } from "./dist/v8.json.summary.reporter.js";

package-lock.json

Lines changed: 19 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,55 @@
11
{
22
"name": "vitest-v8-json-coverage-summary",
3-
"version": "1.0.0",
3+
"version": "0.0.0-beta",
44
"description": "A plugin for vitest that generates a coverage summary in json format",
5+
"type": "module",
56
"main": "index.js",
7+
"types": "dist/v8.json.summary.reporter.d.ts",
8+
"exports": {
9+
".": {
10+
"import": "./index.js",
11+
"types": "./dist/v8.json.summary.reporter.d.ts"
12+
}
13+
},
14+
"files": [
15+
"dist/v8.json.summary.reporter.js",
16+
"dist/v8.json.summary.reporter.d.ts",
17+
"dist/v8.json.summary.reporter.js.map",
18+
"dist/v8.json.summary.reporter.d.ts.map",
19+
"index.js",
20+
"README.md",
21+
"LICENSE"
22+
],
623
"scripts": {
7-
"test": "vitest run --coverage"
24+
"build": "tsc",
25+
"test": "vitest run --coverage",
26+
"prepublishOnly": "npm run build"
827
},
28+
"keywords": [
29+
"vitest",
30+
"coverage",
31+
"reporter",
32+
"json",
33+
"v8",
34+
"testing"
35+
],
936
"author": "Typeguard Inc.",
1037
"license": "MIT",
38+
"repository": {
39+
"type": "git",
40+
"url": "https://github.com/typeguard/vitest-v8-json-coverage-summary.git"
41+
},
42+
"bugs": {
43+
"url": "https://github.com/typeguard/vitest-v8-json-coverage-summary/issues"
44+
},
45+
"homepage": "https://github.com/typeguard/vitest-v8-json-coverage-summary#readme",
46+
"peerDependencies": {
47+
"vitest": ">=3.0.0"
48+
},
1149
"devDependencies": {
50+
"@types/node": "^20.0.0",
1251
"@vitest/coverage-v8": "^3.2.4",
52+
"typescript": "^5.0.0",
1353
"vitest": "^3.2.4"
1454
}
1555
}

tsconfig.json

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"compilerOptions": {
3+
"target": "ES2020",
4+
"module": "ESNext",
5+
"lib": ["ES2020"],
6+
"outDir": "./dist",
7+
"rootDir": "./src",
8+
"strict": true,
9+
"esModuleInterop": true,
10+
"skipLibCheck": true,
11+
"forceConsistentCasingInFileNames": true,
12+
"declaration": true,
13+
"declarationMap": true,
14+
"sourceMap": true,
15+
"moduleResolution": "bundler",
16+
"allowSyntheticDefaultImports": true,
17+
"resolveJsonModule": true
18+
},
19+
"include": ["src/**/*"],
20+
"exclude": ["node_modules", "dist", "test-src", "coverage"]
21+
}

0 commit comments

Comments
 (0)