Skip to content

Commit e56dd9d

Browse files
committed
test: enable test coverage
1 parent 23ca786 commit e56dd9d

File tree

5 files changed

+123
-12
lines changed

5 files changed

+123
-12
lines changed

.github/workflows/test.yml

+73-1
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,78 @@ jobs:
7171
- name: Test
7272
id: test
7373
run: |
74-
pnpm test:vitest --shard=${{ matrix.shardIndex}}/${{ matrix.shardTotal }}
74+
ARGS="--shard=${{ matrix.shardIndex}}/${{ matrix.shardTotal }}"
75+
if [ "${{ matrix.node }}" == "20" ]; then
76+
# We only gather coverage from a single Node version.
77+
# We pass in `--reporter=blob` so that we can combine the results from all shards.
78+
ARGS="$ARGS --coverage --reporter=default --reporter=blob"
79+
fi
80+
pnpm test:vitest $ARGS
7581
env:
7682
GITHUB_SHARD_IDENTIFIER: ${{ matrix.shardIndex }}-${{ matrix.shardTotal }}
83+
84+
- name: Upload blob report to GitHub Actions Artifacts
85+
if: ${{ !cancelled() && matrix.node == '20' }}
86+
uses: actions/upload-artifact@v4
87+
with:
88+
name: blob-report-${{ github.run_id }}-${{ matrix.shardIndex }}
89+
path: '.vitest-reports/*'
90+
include-hidden-files: true
91+
retention-days: 1
92+
93+
report-coverage:
94+
if: ${{ !cancelled() }}
95+
needs: test
96+
runs-on: ubuntu-latest
97+
98+
steps:
99+
- name: Checkout
100+
uses: actions/checkout@v4
101+
102+
- name: Setup node
103+
uses: actions/setup-node@v4
104+
with:
105+
node-version: 20
106+
107+
- uses: pnpm/action-setup@v4
108+
name: Install pnpm
109+
id: pnpm-install
110+
with:
111+
run_install: false
112+
113+
- name: Get pnpm store directory
114+
id: pnpm-cache
115+
shell: bash
116+
run: |
117+
echo "STORE_PATH=$(pnpm store path)" >> $GITHUB_OUTPUT
118+
119+
- name: Cache node modules
120+
id: cache-node-modules
121+
uses: actions/cache@v4
122+
env:
123+
cache-name: cache-node-modules
124+
with:
125+
path: ${{ steps.pnpm-cache.outputs.STORE_PATH }}
126+
key: ${{ runner.os }}-pnpm-store-${{ env.cache-name }}-${{ hashFiles('**/pnpm-lock.yaml') }}
127+
restore-keys: |
128+
v1-${{ runner.os }}-pnpm-store-${{ env.cache-name }}-
129+
v1-${{ runner.os }}-pnpm-store-
130+
v1-${{ runner.os }}-
131+
132+
- name: Install project dependencies
133+
run: pnpm install
134+
135+
- name: "Download coverage artifacts"
136+
uses: actions/download-artifact@v4
137+
with:
138+
path: .vitest-reports
139+
name: blob-report-${{ github.run_id }}-*
140+
merge-multiple: true
141+
142+
- name: Merged report
143+
run: |
144+
pnpm vitest run --merge-reports --coverage
145+
146+
- name: Report coverage
147+
uses: davelosert/vitest-coverage-report-action@v2
148+

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ pids
88
*.pid
99
*.seed
1010

11+
# Combined blobs used from Vitest sharding
12+
.vitest-reports
13+
1114
# Directory for instrumented libs generated by jscoverage/JSCover
1215
lib-cov
1316

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@
126126
"@typescript-eslint/eslint-plugin": "^7.18.0",
127127
"@typescript-eslint/parser": "^7.18.0",
128128
"@vitejs/plugin-react": "^4.3.3",
129+
"@vitest/coverage-v8": "^2.1.1",
129130
"cac": "^6.7.12",
130131
"chalk": "^4.1.2",
131132
"depcheck": "^1.4.7",

pnpm-lock.yaml

+32-11
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vitest.config.mts

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// eslint-disable-next-line import/no-extraneous-dependencies, import/no-unassigned-import
2+
import '@vitest/coverage-v8'
3+
4+
import {defineConfig} from 'vitest/config'
5+
6+
export default defineConfig({
7+
test: {
8+
coverage: {
9+
provider: 'v8',
10+
reporter: ['html', 'json-summary'],
11+
include: ['**/packages/**/src/**'],
12+
},
13+
},
14+
})

0 commit comments

Comments
 (0)