Skip to content

Commit

Permalink
ci: add vitest coverage reports for github
Browse files Browse the repository at this point in the history
Signed-off-by: Till Sanders <[email protected]>
  • Loading branch information
tillsanders committed Mar 22, 2024
1 parent ff1fc5e commit 4915d42
Showing 2 changed files with 45 additions and 2 deletions.
37 changes: 35 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -7,6 +7,11 @@ on:
jobs:
test:
runs-on: ubuntu-latest
permissions:
# Required to checkout the code
contents: read
# Required to put a comment into the pull-request
pull-requests: write
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
@@ -15,8 +20,36 @@ jobs:
- name: Install
run: npm ci
- name: Run tests
run: npx vitest run --coverage
run: npx vitest --coverage.enabled true
- name: 'Report Coverage'
# Set if: always() to also generate the report if tests are failing
# Only works if you set `reportOnFailure: true` in your vite config as specified above
if: always()
uses: davelosert/vitest-coverage-report-action@v2
- name: "Upload Coverage"
uses: actions/upload-artifact@v4
with:
name: coverage-${{ matrix.branch }}
path: coverage
- name: Run linting
run: npm run lint
- name: Check formatting
run: npx prettier . --check
run: npx prettier . --check

report-coverage:
needs: test
runs-on: ubuntu-latest
steps:
- name: "Download Coverage Artifacts"
uses: actions/download-artifact@v4
with:
name: coverage-${{ github.head_ref }}
path: coverage
- uses: actions/download-artifact@v4
with:
name: coverage-main
path: coverage-main
- name: "Report Coverage"
uses: davelosert/vitest-coverage-report-action@v2
with:
json-summary-compare-path: coverage-main/coverage-summary.json
10 changes: 10 additions & 0 deletions vitest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { defineConfig } from 'vitest/config';

export default defineConfig({
test: {
coverage: {
reporter: ['text', 'json-summary', 'json'],
reportOnFailure: true,
}
}
});

0 comments on commit 4915d42

Please sign in to comment.