Skip to content

Commit c579dde

Browse files
committed
feat(cli): add test coverage reporting with Bun
Enable V8-based code coverage for CLI tests: - Configure coverage in bunfig.toml (text + lcov reporters) - Add test:fast and test:coverage npm scripts - Update GitLab CI to capture coverage percentage and artifacts - Add coverage/ to .gitignore Coverage reports are now visible in GitLab MR pipelines. Closes #74 (CLI part)
1 parent f509de2 commit c579dde

4 files changed

Lines changed: 26 additions & 3 deletions

File tree

.gitlab-ci.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,16 @@ cli:node:tests:
218218
- su - pgtest -c "cd \"$CI_PROJECT_DIR/cli\" && export PATH=\"\$HOME/.bun/bin:\$PATH\" && bun install"
219219
script:
220220
# Use 'bun run test' (not 'bun test') to invoke the npm script which generates metrics-embedded.ts first
221+
# Coverage is enabled via bunfig.toml and outputs text + lcov reports
221222
- su - pgtest -c "cd \"$CI_PROJECT_DIR/cli\" && export PATH=\"\$HOME/.bun/bin:\$PATH\" && bun run test"
223+
# Fix ownership of coverage directory for artifact collection
224+
- chown -R root:root "$CI_PROJECT_DIR/cli/coverage" || true
225+
coverage: '/All files[^|]*\|[^|]*\|[^|]*\|[^|]*\|\s*([\d.]+)/'
226+
artifacts:
227+
when: always
228+
paths:
229+
- cli/coverage/
230+
expire_in: 7 days
222231
rules:
223232
- if: '$CI_PIPELINE_SOURCE == "merge_request_event"'
224233

cli/.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,4 @@
11
package-lock.json
2+
node_modules/
3+
dist/
4+
coverage/

cli/bunfig.toml

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,15 @@
66
# Integration tests that connect to databases need longer timeouts
77
timeout = 30000
88

9-
# Coverage settings (if needed in future)
10-
# coverage = true
11-
# coverageDir = "coverage"
9+
# Coverage settings - enabled by default for test runs
10+
# Uses V8's built-in coverage engine
11+
coverage = true
12+
coverageDir = "coverage"
13+
14+
# Skip coverage for test files and node_modules
15+
coverageSkipTestFiles = true
16+
17+
# Reporter format for CI integration
18+
# - text: console output with summary table
19+
# - lcov: standard format for coverage tools
20+
coverageReporter = ["text", "lcov"]

cli/package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@
3232
"start:node": "node ./dist/bin/postgres-ai.js --help",
3333
"dev": "bun run embed-metrics && bun --watch ./bin/postgres-ai.ts",
3434
"test": "bun run embed-metrics && bun test",
35+
"test:fast": "bun run embed-metrics && bun test --coverage=false",
36+
"test:coverage": "bun run embed-metrics && bun test --coverage && echo 'Coverage report: cli/coverage/lcov-report/index.html'",
3537
"typecheck": "bun run embed-metrics && bunx tsc --noEmit"
3638
},
3739
"dependencies": {

0 commit comments

Comments
 (0)