Skip to content

Commit 7103dab

Browse files
committed
project: add test coverage collection and PR reporting
Add @vitest/coverage-v8 with coverage config (disabled by default, enabled via --coverage flag in CI). On the base Node version, the test job collects coverage and posts a summary to PRs via vitest-coverage-report-action.
1 parent 4e8ddc8 commit 7103dab

4 files changed

Lines changed: 234 additions & 50 deletions

File tree

.github/workflows/dev.yml

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@ jobs:
4444

4545
test:
4646
runs-on: ubuntu-latest
47+
permissions:
48+
contents: read
49+
pull-requests: write
4750
strategy:
4851
fail-fast: false
4952
matrix:
@@ -58,7 +61,22 @@ jobs:
5861
node-version: ${{ matrix.node-version }}
5962
cache: npm
6063
- run: npm ci
61-
- run: npm test
64+
# Only collect coverage on the base Node version to avoid redundant work
65+
- name: test with coverage
66+
if: ${{ matrix.node-version == env.BASE_NODE_VERSION }}
67+
run: npm test -- --coverage
68+
- name: test
69+
if: ${{ matrix.node-version != env.BASE_NODE_VERSION }}
70+
run: npm test
71+
# Post coverage summary as a PR comment. Restricted to PRs from the main
72+
# repo (not forks) because the action needs write permissions that fork
73+
# PRs don't have. Runs even if tests fail so we still get the report.
74+
- uses: davelosert/vitest-coverage-report-action@v2
75+
if: >-
76+
github.event_name == 'pull_request' &&
77+
github.event.pull_request.head.repo.full_name == 'ably/ably-ai-transport-js' &&
78+
matrix.node-version == env.BASE_NODE_VERSION &&
79+
(failure() || success())
6280
6381
test-integration:
6482
runs-on: ubuntu-latest

0 commit comments

Comments
 (0)