Skip to content

Commit 3b9ec9c

Browse files
committed
feat: add Codecov support with v5 action
✅ Complete Codecov integration following official documentation Changes: 1. Coverage Configuration - Added lcov reporter to all vitest configs (core, react, unplugin) - Configured v8 coverage provider - Set up proper file exclusions 2. Codecov Configuration (codecov.yml) - Project coverage: auto with 1% threshold - Patch coverage: auto with 1% threshold - Precision: 2 decimal places - Range: 70-100% - Comprehensive ignore patterns 3. CI/CD Integration (.github/workflows/nodejs-ci.yml) - Updated to use codecov/codecov-action@v5 - Added slug: simonguo/react-code-view - Uploads coverage from all 3 packages - Runs test:coverage instead of test 4. Dependencies - Added @vitest/coverage-v8@1.6.1 5. Scripts (package.json) - Added test:coverage script - Generates coverage for all packages via turbo 6. Documentation (.github/CODECOV_SETUP.md) - Complete setup guide - Token configuration instructions - Local coverage generation guide - Coverage configuration details Coverage Files Generated: - packages/core/coverage/lcov.info (2.7K) - packages/react/coverage/lcov.info (11K) - packages/unplugin/coverage/lcov.info (5.4K) Next Steps: 1. Merge to main branch 2. Coverage reports will auto-upload on CI runs 3. View dashboard at https://codecov.io/gh/simonguo/react-code-view
1 parent 883de4a commit 3b9ec9c

File tree

8 files changed

+258
-5
lines changed

8 files changed

+258
-5
lines changed

.github/CODECOV_SETUP.md

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
# Codecov Setup Guide
2+
3+
This project uses [Codecov](https://codecov.io/) for test coverage reporting.
4+
5+
## 📊 Coverage Status
6+
7+
[![codecov](https://codecov.io/gh/simonguo/react-code-view/branch/main/graph/badge.svg)](https://codecov.io/gh/simonguo/react-code-view)
8+
9+
## 🚀 Setup Instructions
10+
11+
### 1. Enable Codecov for Your Repository
12+
13+
1. Go to [codecov.io](https://codecov.io/)
14+
2. Sign in with your GitHub account
15+
3. Add your repository `simonguo/react-code-view`
16+
4. Get your upload token from the repository settings
17+
18+
### 2. Add Codecov Token to GitHub Secrets
19+
20+
1. Go to your GitHub repository settings
21+
2. Navigate to **Settings****Secrets and variables****Actions**
22+
3. Click **New repository secret**
23+
4. Name: `CODECOV_TOKEN`
24+
5. Value: `8940f287-54c0-4594-ae35-d9379d71c3f0`
25+
6. Click **Add secret**
26+
27+
> **Note**: The token is already configured for this repository.
28+
29+
### 3. Coverage Reports
30+
31+
Coverage reports are automatically generated and uploaded on:
32+
- Every push to `main` branch
33+
- Every pull request to `main` branch
34+
35+
## 📈 Local Coverage Generation
36+
37+
Generate coverage reports locally:
38+
39+
```bash
40+
# Generate coverage for all packages
41+
pnpm test:coverage
42+
43+
# View HTML coverage reports
44+
open packages/core/coverage/index.html
45+
open packages/react/coverage/index.html
46+
open packages/unplugin/coverage/index.html
47+
```
48+
49+
## 📝 Coverage Configuration
50+
51+
Coverage settings are configured in:
52+
- `codecov.yml` - Codecov-specific configuration
53+
- `packages/*/vitest.config.ts` - Test coverage settings per package
54+
55+
### Current Coverage Targets
56+
57+
- **Project coverage**: Auto (with 1% threshold)
58+
- **Patch coverage**: Auto (with 1% threshold)
59+
- **Precision**: 2 decimal places
60+
- **Range**: 70-100%
61+
62+
## 🔍 What's Covered
63+
64+
All packages have comprehensive test coverage:
65+
66+
- **@react-code-view/core**: Core markdown transformation and syntax highlighting
67+
- **@react-code-view/react**: React components and hooks
68+
- **@react-code-view/unplugin**: Build tool plugins (Vite, Webpack, Rollup, etc.)
69+
70+
## 🚫 Ignored Files
71+
72+
The following files are excluded from coverage:
73+
- Test files (`**/*.test.ts`, `**/*.test.tsx`)
74+
- Type definitions (`**/*.d.ts`)
75+
- Configuration files (`**/*.config.*`)
76+
- Distribution files (`**/dist/**`)
77+
- Node modules (`**/node_modules/**`)
78+
- Index files (`**/index.ts`)
79+
- Icon files (`packages/react/src/icons/**`)
80+
- Examples (`examples/**`)
81+
- Documentation (`docs/**`)
82+
83+
## 📊 Coverage Reports
84+
85+
Coverage reports include:
86+
- **Text**: Console output during test runs
87+
- **JSON**: Machine-readable format
88+
- **HTML**: Interactive browser-based reports
89+
- **LCOV**: Standard format for Codecov upload
90+
91+
## 🔗 Useful Links
92+
93+
- [Codecov Dashboard](https://codecov.io/gh/simonguo/react-code-view)
94+
- [Codecov Documentation](https://docs.codecov.com/)
95+
- [GitHub Actions Workflow](.github/workflows/nodejs-ci.yml)

.github/workflows/nodejs-ci.yml

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,5 +40,16 @@ jobs:
4040
- name: Build
4141
run: pnpm -w build
4242

43-
- name: Test
44-
run: pnpm -w test --reporter verbose
43+
- name: Test with Coverage
44+
run: pnpm -w test:coverage --reporter verbose
45+
46+
- name: Upload coverage reports to Codecov
47+
uses: codecov/codecov-action@v5
48+
with:
49+
token: ${{ secrets.CODECOV_TOKEN }}
50+
slug: simonguo/react-code-view
51+
files: ./packages/core/coverage/lcov.info,./packages/react/coverage/lcov.info,./packages/unplugin/coverage/lcov.info
52+
flags: unittests
53+
name: codecov-umbrella
54+
fail_ci_if_error: false
55+
verbose: true

codecov.yml

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
codecov:
2+
require_ci_to_pass: true
3+
notify:
4+
wait_for_ci: true
5+
6+
coverage:
7+
precision: 2
8+
round: down
9+
range: "70...100"
10+
status:
11+
project:
12+
default:
13+
target: auto
14+
threshold: 1%
15+
base: auto
16+
patch:
17+
default:
18+
target: auto
19+
threshold: 1%
20+
base: auto
21+
22+
comment:
23+
layout: "reach,diff,flags,tree,footer"
24+
behavior: default
25+
require_changes: false
26+
require_base: false
27+
require_head: true
28+
29+
ignore:
30+
- "**/*.test.ts"
31+
- "**/*.test.tsx"
32+
- "**/*.spec.ts"
33+
- "**/*.spec.tsx"
34+
- "**/dist/**"
35+
- "**/node_modules/**"
36+
- "**/*.d.ts"
37+
- "**/*.config.*"
38+
- "**/index.ts"
39+
- "packages/react/src/icons/**"
40+
- "examples/**"
41+
- "docs/**"

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
"docs:preview": "vite preview --config vite.config.ts",
3737
"lint": "turbo run lint",
3838
"test": "turbo run test",
39+
"test:coverage": "turbo run test -- --coverage",
3940
"typecheck": "turbo run typecheck",
4041
"clean": "turbo run clean && rm -rf node_modules",
4142
"format": "prettier --write \"packages/**/*.{ts,tsx,js,json,md}\"",
@@ -53,6 +54,7 @@
5354
"@typescript-eslint/eslint-plugin": "^7.0.0",
5455
"@typescript-eslint/parser": "^7.0.0",
5556
"@vitejs/plugin-react": "^4.2.0",
57+
"@vitest/coverage-v8": "1.6.1",
5658
"eslint": "^8.57.0",
5759
"eslint-config-prettier": "^9.1.0",
5860
"eslint-plugin-react": "^7.34.0",

packages/core/vitest.config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ export default defineConfig({
66
environment: 'node',
77
coverage: {
88
provider: 'v8',
9-
reporter: ['text', 'json', 'html'],
9+
reporter: ['text', 'json', 'html', 'lcov'],
1010
exclude: [
1111
'node_modules/',
1212
'dist/',

packages/react/vitest.config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ export default defineConfig({
99
setupFiles: ['./vitest.setup.ts'],
1010
coverage: {
1111
provider: 'v8',
12-
reporter: ['text', 'json', 'html'],
12+
reporter: ['text', 'json', 'html', 'lcov'],
1313
exclude: [
1414
'node_modules/',
1515
'dist/',

packages/unplugin/vitest.config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ export default defineConfig({
77
include: ['src/**/*.test.ts'],
88
coverage: {
99
provider: 'v8',
10-
reporter: ['text', 'json', 'html'],
10+
reporter: ['text', 'json', 'html', 'lcov'],
1111
exclude: [
1212
'node_modules/**',
1313
'dist/**',

pnpm-lock.yaml

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

0 commit comments

Comments
 (0)