From d47f140162bf44fbe3cdecd03987ecd6008a3ae9 Mon Sep 17 00:00:00 2001 From: Aidan Bleser Date: Wed, 13 Nov 2024 16:53:25 -0600 Subject: [PATCH] adds coverage reporting on PR --- .github/workflows/ci.yml | 3 --- .github/workflows/tests.yml | 34 ++++++++++++++++++++++++++++++++++ src/utilities/sleep.test.ts | 2 +- vite.config.ts | 1 + 4 files changed, 36 insertions(+), 4 deletions(-) create mode 100644 .github/workflows/tests.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c71e65d..6f4fae9 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -29,9 +29,6 @@ jobs: - name: Lint run: pnpm check - - name: Lint - run: pnpm test - - name: Build run: pnpm build diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml new file mode 100644 index 0000000..5e1373b --- /dev/null +++ b/.github/workflows/tests.yml @@ -0,0 +1,34 @@ +name: "Test" +on: + pull_request: + +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 + with: + fetch-depth: 0 + - uses: pnpm/action-setup@v4 + - uses: actions/setup-node@v4 + with: + node-version: "20" + + - name: Install Deps + run: pnpm install + + - name: Test + run: pnpm dlx 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 diff --git a/src/utilities/sleep.test.ts b/src/utilities/sleep.test.ts index e6c0ec1..20a228c 100644 --- a/src/utilities/sleep.test.ts +++ b/src/utilities/sleep.test.ts @@ -10,5 +10,5 @@ test('Expect time elapsed', async () => { const end = Date.now(); - expect(end - start).toBeGreaterThanOrEqual(duration); + expect(end - start + 10).toBeGreaterThanOrEqual(duration); }); diff --git a/vite.config.ts b/vite.config.ts index 538bdaf..2b8ad64 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -3,6 +3,7 @@ import { defineConfig } from 'vitest/config'; export default defineConfig({ test: { coverage: { + reportOnFailure: true, provider: 'v8', reporter: ['json-summary'], exclude: ['node_modules/', '**/*.d.ts', '**/*.test.ts'],