|
| 1 | +# Vitest Coverage Reporter GitHub Action |
| 2 | + |
| 3 | +A GitHub Action that automatically creates beautiful coverage reports in pull requests using vitest coverage data. |
| 4 | + |
| 5 | +## Features |
| 6 | + |
| 7 | +- 📊 **Beautiful Coverage Reports**: Creates formatted markdown tables with coverage metrics |
| 8 | +- 🎯 **Configurable Thresholds**: Set minimum coverage requirements with visual indicators |
| 9 | +- 📁 **File-level Details**: Option to show individual file coverage breakdowns |
| 10 | +- 🔄 **Smart Updates**: Updates existing comments instead of creating duplicates |
| 11 | +- 🎨 **Visual Indicators**: Uses emojis to quickly identify coverage status |
| 12 | +- ⚡ **Lightweight**: Fast execution with minimal dependencies |
| 13 | + |
| 14 | +## Usage |
| 15 | + |
| 16 | +### Basic Usage |
| 17 | + |
| 18 | +```yaml |
| 19 | +name: Coverage Report |
| 20 | +on: |
| 21 | + pull_request: |
| 22 | + branches: [main] |
| 23 | + |
| 24 | +permissions: |
| 25 | + pull-requests: write |
| 26 | + |
| 27 | +jobs: |
| 28 | + coverage: |
| 29 | + runs-on: ubuntu-latest |
| 30 | + steps: |
| 31 | + - uses: actions/checkout@v4 |
| 32 | + |
| 33 | + - name: Setup Node.js |
| 34 | + uses: actions/setup-node@v4 |
| 35 | + with: |
| 36 | + node-version: "20" |
| 37 | + |
| 38 | + - name: Install dependencies |
| 39 | + run: npm ci |
| 40 | + |
| 41 | + - name: Run tests with coverage |
| 42 | + run: npm test |
| 43 | + |
| 44 | + - name: Report Coverage |
| 45 | + uses: glideapps/vitest-coverage-tools@v1 |
| 46 | +``` |
| 47 | +
|
| 48 | +### Advanced Usage |
| 49 | +
|
| 50 | +```yaml |
| 51 | +name: Coverage Report |
| 52 | +on: |
| 53 | + pull_request: |
| 54 | + branches: [main] |
| 55 | + |
| 56 | +permissions: |
| 57 | + pull-requests: write |
| 58 | + |
| 59 | +jobs: |
| 60 | + coverage: |
| 61 | + runs-on: ubuntu-latest |
| 62 | + steps: |
| 63 | + - uses: actions/checkout@v4 |
| 64 | + |
| 65 | + - name: Setup Node.js |
| 66 | + uses: actions/setup-node@v4 |
| 67 | + with: |
| 68 | + node-version: "20" |
| 69 | + |
| 70 | + - name: Install dependencies |
| 71 | + run: npm ci |
| 72 | + |
| 73 | + - name: Run tests with coverage |
| 74 | + run: npm test |
| 75 | + |
| 76 | + - name: Report Coverage |
| 77 | + uses: glideapps/vitest-coverage-tools@v1 |
| 78 | + with: |
| 79 | + coverage-file: "coverage/coverage-summary.json" |
| 80 | + title: "🧪 Test Coverage Report" |
| 81 | + show-files: "true" |
| 82 | + coverage-threshold: "90" |
| 83 | +``` |
| 84 | +
|
| 85 | +## Inputs |
| 86 | +
|
| 87 | +| Input | Description | Required | Default | |
| 88 | +| -------------------- | ------------------------------------------------------- | -------- | -------------------------------- | |
| 89 | +| `coverage-file` | Path to the coverage summary JSON file | No | `coverage/coverage-summary.json` | |
| 90 | +| `token` | GitHub token for creating comments | No | `${{ github.token }}` | |
| 91 | +| `title` | Title for the coverage report comment | No | `📊 Coverage Report` | |
| 92 | +| `show-files` | Whether to show individual file coverage details | No | `true` | |
| 93 | +| `coverage-threshold` | Minimum coverage percentage to consider as good (0-100) | No | `80` | |
| 94 | + |
| 95 | +## Coverage File Format |
| 96 | + |
| 97 | +The action expects a JSON file with the following structure (generated by the vitest-v8-json-coverage-summary reporter): |
| 98 | + |
| 99 | +```json |
| 100 | +{ |
| 101 | + "summary": { |
| 102 | + "statements": 89.82, |
| 103 | + "branches": 94.29, |
| 104 | + "functions": 58.82, |
| 105 | + "lines": 89.82 |
| 106 | + }, |
| 107 | + "files": [ |
| 108 | + { |
| 109 | + "file": "src/example.ts", |
| 110 | + "statements": 90.84, |
| 111 | + "branches": 91.89, |
| 112 | + "functions": 25, |
| 113 | + "lines": 90.84, |
| 114 | + "uncoveredLines": [39, 40, 45] |
| 115 | + } |
| 116 | + ] |
| 117 | +} |
| 118 | +``` |
| 119 | + |
| 120 | +## Example Output |
| 121 | + |
| 122 | +The action creates a comment like this: |
| 123 | + |
| 124 | +```markdown |
| 125 | +## 📊 Coverage Report |
| 126 | +
|
| 127 | +### 📈 Coverage Summary |
| 128 | +
|
| 129 | +| Metric | Coverage | Status | |
| 130 | +| -------------- | -------- | ------ | |
| 131 | +| **Statements** | 89.8% | 🟢 | |
| 132 | +| **Branches** | 94.3% | 🟢 | |
| 133 | +| **Functions** | 58.8% | 🔴 | |
| 134 | +| **Lines** | 89.8% | 🟢 | |
| 135 | +
|
| 136 | +**Overall Coverage: 83.2% 🟡** |
| 137 | +
|
| 138 | +### 📁 File Details |
| 139 | +
|
| 140 | +| File | Statements | Branches | Functions | Lines | |
| 141 | +| ---------------- | ---------- | -------- | --------- | ----- | |
| 142 | +| `src/example.ts` | 90.8% | 91.9% | 25.0% | 90.8% | |
| 143 | + |
| 144 | +--- |
| 145 | + |
| 146 | +_Generated by [@glideapps/vitest-coverage-tools](https://github.com/glideapps/vitest-coverage-tools)_ |
| 147 | +``` |
| 148 | + |
| 149 | +## Status Indicators |
| 150 | + |
| 151 | +- 🟢 **Green**: Coverage meets or exceeds the threshold |
| 152 | +- 🟡 **Yellow**: Coverage is at least 80% of the threshold |
| 153 | +- 🔴 **Red**: Coverage is below 80% of the threshold |
| 154 | + |
| 155 | +## Setup with Vitest |
| 156 | + |
| 157 | +1. Install the coverage reporter: |
| 158 | + |
| 159 | + ```bash |
| 160 | + npm install vitest-v8-json-coverage-summary |
| 161 | + ``` |
| 162 | + |
| 163 | +2. Configure vitest to use the reporter: |
| 164 | + |
| 165 | + ```javascript |
| 166 | + // vitest.config.js |
| 167 | + export default { |
| 168 | + coverage: { |
| 169 | + provider: "v8", |
| 170 | + reporter: ["text", "json-summary"], |
| 171 | + reportsDirectory: "./coverage", |
| 172 | + }, |
| 173 | + }; |
| 174 | + ``` |
| 175 | + |
| 176 | +3. Add the GitHub Action to your workflow as shown above. |
| 177 | + |
| 178 | +## Contributing |
| 179 | + |
| 180 | +Contributions are welcome! Please feel free to submit a Pull Request. |
| 181 | + |
| 182 | +## License |
| 183 | + |
| 184 | +MIT License - see the [LICENSE](LICENSE) file for details. |
0 commit comments