Skip to content

Commit

Permalink
test: enable test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
judofyr committed Nov 11, 2024
1 parent 23ca786 commit e3fb1a1
Show file tree
Hide file tree
Showing 5 changed files with 123 additions and 12 deletions.
74 changes: 73 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,78 @@ jobs:
- name: Test
id: test
run: |
pnpm test:vitest --shard=${{ matrix.shardIndex}}/${{ matrix.shardTotal }}
ARGS="--shard=${{ matrix.shardIndex}}/${{ matrix.shardTotal }}"
if [ "${{ matrix.node }}" == "20" ]; then
# We only gather coverage from a single Node version.
# We pass in `--reporter=blob` so that we can combine the results from all shards.
ARGS="$ARGS --coverage --reporter=default --reporter=blob"
fi
pnpm test:vitest $ARGS
env:
GITHUB_SHARD_IDENTIFIER: ${{ matrix.shardIndex }}-${{ matrix.shardTotal }}

- name: Upload blob report to GitHub Actions Artifacts
if: ${{ !cancelled() && matrix.node == '20' }}
uses: actions/upload-artifact@v4
with:
name: blob-report-${{ github.run_id }}-${{ matrix.shardIndex }}
path: '.vitest-reports/*'
include-hidden-files: true
retention-days: 1

report-coverage:
if: ${{ !cancelled() }}
needs: test
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Setup node
uses: actions/setup-node@v4
with:
node-version: 20

- uses: pnpm/action-setup@v4
name: Install pnpm
id: pnpm-install
with:
run_install: false

- name: Get pnpm store directory
id: pnpm-cache
shell: bash
run: |
echo "STORE_PATH=$(pnpm store path)" >> $GITHUB_OUTPUT
- name: Cache node modules
id: cache-node-modules
uses: actions/cache@v4
env:
cache-name: cache-node-modules
with:
path: ${{ steps.pnpm-cache.outputs.STORE_PATH }}
key: ${{ runner.os }}-pnpm-store-${{ env.cache-name }}-${{ hashFiles('**/pnpm-lock.yaml') }}
restore-keys: |
v1-${{ runner.os }}-pnpm-store-${{ env.cache-name }}-
v1-${{ runner.os }}-pnpm-store-
v1-${{ runner.os }}-
- name: Install project dependencies
run: pnpm install

- name: "Download coverage artifacts"
uses: actions/download-artifact@v4
with:
path: .vitest-reports
pattern: blob-report-${{ github.run_id }}-*
merge-multiple: true

- name: Merged report
run: |
pnpm vitest run --merge-reports --coverage
- name: Report coverage
uses: davelosert/vitest-coverage-report-action@v2

3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ pids
*.pid
*.seed

# Combined blobs used from Vitest sharding
.vitest-reports

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@
"@typescript-eslint/eslint-plugin": "^7.18.0",
"@typescript-eslint/parser": "^7.18.0",
"@vitejs/plugin-react": "^4.3.3",
"@vitest/coverage-v8": "^2.1.1",
"cac": "^6.7.12",
"chalk": "^4.1.2",
"depcheck": "^1.4.7",
Expand Down
43 changes: 32 additions & 11 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions vitest.config.mts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// eslint-disable-next-line import/no-extraneous-dependencies, import/no-unassigned-import
import '@vitest/coverage-v8'

import {defineConfig} from 'vitest/config'

export default defineConfig({
test: {
coverage: {
provider: 'v8',
reporter: ['html', 'json-summary'],
include: ['**/packages/**/src/**'],
},
},
})

0 comments on commit e3fb1a1

Please sign in to comment.