diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 7db0c65..7a195c1 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -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 \ No newline at end of file + 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 \ No newline at end of file diff --git a/vitest.config.ts b/vitest.config.ts new file mode 100644 index 0000000..618341a --- /dev/null +++ b/vitest.config.ts @@ -0,0 +1,10 @@ +import { defineConfig } from 'vitest/config'; + +export default defineConfig({ + test: { + coverage: { + reporter: ['text', 'json-summary', 'json'], + reportOnFailure: true, + } + } +}); \ No newline at end of file