#!/usr/bin/env bash # Run the full verify suite: lint, typecheck, vitest, Playwright e2e. # Uses the dedicated touchbase_test DB (reset + seeded) and a Next.js # server on E2E_PORT (3010) so it never touches the dev DB or dev server. set -euo pipefail cd "$(dirname "$0")/.." bold() { printf "\n\033[1m==> %s\033[0m\n" "$*"; } fail() { printf "\033[31merror:\033[0m %s\n" "$*" >&2; exit 1; } E2E_PORT="${E2E_PORT:-3010}" export E2E_PORT # --- Pre-flight --------------------------------------------------------------- bold "Pre-flight" curl -sf http://localhost:5432 -o /dev/null || true # informational curl -sf "http://localhost:8025/api/v1/info" >/dev/null \ || fail "Mailpit not reachable on http://localhost:8025. Run: docker compose up -d mailpit" if ! docker ps --format '{{.Names}}' | grep -q '^touchbase-postgres-1$'; then fail "Postgres container 'touchbase-postgres-1' not running. Run: docker compose up -d postgres" fi # Next 16 enforces one `next dev` per project. If one is running it'll block # the e2e test server from starting on E2E_PORT. if pgrep -f "next dev" >/dev/null 2>&1; then fail "Another \`next dev\` is running (Next 16 enforces one per project). Stop it before running verify: pkill -f 'next dev' Then re-run: pnpm verify" fi # --- Lint --------------------------------------------------------------------- bold "Lint" pnpm lint # --- Typecheck ---------------------------------------------------------------- bold "Typecheck" pnpm exec tsc --noEmit # --- Test DB: ensure schema is current --------------------------------------- bold "Apply migrations to test DB" pnpm exec dotenv -e .env.test -- prisma migrate deploy # --- Vitest ------------------------------------------------------------------- # Vitest tests load .env.test via test/setup.ts and manage their own data; # we don't need to reset before this step. bold "Vitest" pnpm test # --- Truncate + seed test DB before Playwright ------------------------------ # Vitest may have left rows around. Playwright fixtures (admin/therapist/ # customer accounts, services, rooms) need a known seeded state. # Truncate via psql (faster than `migrate reset`, avoids Prisma's AI guard). bold "Truncate + seed test DB" docker exec -i touchbase-postgres-1 \ psql -U touchbase -d touchbase_test -v ON_ERROR_STOP=1 -q \ < scripts/db-test-truncate.sql pnpm exec dotenv -e .env.test -- tsx prisma/seed.ts # --- Playwright e2e ----------------------------------------------------------- # playwright.config.ts has a webServer block that boots `next dev` on # E2E_PORT against .env.test, so we don't manage the server here. bold "Playwright e2e (port $E2E_PORT)" pnpm exec playwright test bold "All green"