Enforce coverage thresholds in pre-commit via gradlew check.
Wire frontendCoverage (Vitest 70%/60%/70%) into the check task chain instead of plain unit tests so commits fail when line or branch coverage drops. Document thresholds in AGENTS.md and improve pre-commit failure hints. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
parent
aa2cb7c4a0
commit
764a620689
4 changed files with 26 additions and 12 deletions
12
AGENTS.md
12
AGENTS.md
|
|
@ -37,7 +37,7 @@ docker compose up -d # starts postgres, backend, frontend
|
|||
### All-in-one
|
||||
|
||||
```bash
|
||||
./gradlew check # frontend lint → frontend test → backend test+coverage → E2E (Docker)
|
||||
./gradlew check # lint → frontend/backend tests with coverage thresholds → E2E (Docker)
|
||||
./gradlew coverage # backend + frontend tests with coverage reports
|
||||
./gradlew up # docker compose up -d
|
||||
./gradlew down # docker compose down
|
||||
|
|
@ -170,10 +170,12 @@ export STRIPE_SECRET_KEY=sk_test_fake STRIPE_WEBHOOK_SECRET=whsec_fake STRIPE_PR
|
|||
./gradlew check
|
||||
```
|
||||
|
||||
This runs frontend lint, frontend unit tests (242), backend tests (163), coverage
|
||||
thresholds, Flyway checks, and **all 90 E2E tests in Docker**. **Do not commit or
|
||||
push if this fails.** Optional local guard: `./scripts/install-pre-commit-hook.sh`
|
||||
(runs the same `check` on every `git commit`).
|
||||
This runs frontend lint, frontend unit tests **with Vitest coverage thresholds**
|
||||
(70% lines, 60% branches, 70% functions), backend tests with **JaCoCo thresholds**
|
||||
(70% lines, 60% branches), Flyway checks, and **all 90 E2E tests in Docker**.
|
||||
**Do not commit or push if this fails.** Optional local guard:
|
||||
`./scripts/install-pre-commit-hook.sh` (runs the same `check` on every `git commit`;
|
||||
fails if line or branch coverage is below threshold).
|
||||
|
||||
### Frontend (Vue.js 3)
|
||||
- `<script setup>` with Composition API only. Never Options API.
|
||||
|
|
|
|||
|
|
@ -16,7 +16,8 @@ tasks.register('frontendTest', Exec) {
|
|||
}
|
||||
|
||||
tasks.register('frontendCoverage', Exec) {
|
||||
description = 'Run Vitest with coverage in the frontend directory'
|
||||
description = 'Run Vitest with coverage thresholds (70% lines, 60% branches, 70% functions)'
|
||||
dependsOn frontendLint
|
||||
workingDir = file("${rootProject.projectDir}/frontend")
|
||||
commandLine 'npm', 'run', 'test:coverage'
|
||||
}
|
||||
|
|
@ -30,7 +31,7 @@ tasks.register('coverage') {
|
|||
tasks.register('frontendE2E', Exec) {
|
||||
group = 'verification'
|
||||
description = 'Run Playwright E2E tests in Docker (same stack as Forgejo CI)'
|
||||
dependsOn frontendTest
|
||||
dependsOn frontendCoverage
|
||||
workingDir = rootProject.projectDir
|
||||
environment 'POSTGRES_DB', 'bilhej'
|
||||
environment 'POSTGRES_USER', 'bilhej'
|
||||
|
|
@ -44,7 +45,7 @@ tasks.register('frontendE2E', Exec) {
|
|||
}
|
||||
|
||||
tasks.named('check').configure {
|
||||
description = 'Full verification: frontend lint/tests, backend tests+coverage, E2E'
|
||||
description = 'Full verification: lint, unit tests with line/branch coverage thresholds, E2E'
|
||||
dependsOn ':backend:check', frontendE2E
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -12,4 +12,4 @@ ln -sf "../../scripts/pre-commit-check.sh" "$HOOK"
|
|||
chmod +x "$HOOK"
|
||||
|
||||
echo "Installed pre-commit hook -> scripts/pre-commit-check.sh"
|
||||
echo "Every commit will run: ./gradlew check"
|
||||
echo "Every commit will run: ./gradlew check (includes line/branch coverage thresholds)"
|
||||
|
|
|
|||
|
|
@ -1,6 +1,10 @@
|
|||
#!/usr/bin/env bash
|
||||
# Runs the same verification as CI before allowing a commit.
|
||||
# Install: ./scripts/install-pre-commit-hook.sh
|
||||
#
|
||||
# Fails if line/branch coverage falls below project thresholds:
|
||||
# Backend: 70% lines, 60% branches (JaCoCo jacocoTestCoverageVerification)
|
||||
# Frontend: 70% lines, 60% branches, 70% functions (Vitest test:coverage)
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
|
|
@ -15,6 +19,13 @@ export STRIPE_SECRET_KEY="${STRIPE_SECRET_KEY:-sk_test_fake}"
|
|||
export STRIPE_WEBHOOK_SECRET="${STRIPE_WEBHOOK_SECRET:-whsec_fake}"
|
||||
export STRIPE_PRICE_ID="${STRIPE_PRICE_ID:-price_fake}"
|
||||
|
||||
echo "pre-commit: running ./gradlew check (lint + unit + E2E in Docker)..."
|
||||
./gradlew check --no-daemon
|
||||
echo "pre-commit: all checks passed."
|
||||
echo "pre-commit: running ./gradlew check (lint, coverage thresholds, E2E in Docker)..."
|
||||
if ! ./gradlew check --no-daemon; then
|
||||
echo ""
|
||||
echo "pre-commit: FAILED."
|
||||
echo " - Backend coverage: ./gradlew :backend:jacocoTestCoverageVerification (70% lines, 60% branches)"
|
||||
echo " - Frontend coverage: cd frontend && npm run test:coverage (70% lines, 60% branches, 70% functions)"
|
||||
echo " - Reports: backend/build/reports/jacoco/test/html/ frontend/coverage/"
|
||||
exit 1
|
||||
fi
|
||||
echo "pre-commit: all checks passed (including line and branch coverage thresholds)."
|
||||
|
|
|
|||
Loading…
Reference in a new issue