搜尋說明文件

搜尋文件頁面與標題。

JustHold Testing

When to Use

  • Adding or updating unit tests for pure apps/web/lib/ helpers
  • Writing Supabase RLS / RPC integration tests
  • Extending Playwright e2e flows
  • Updating Vitest coverage.include after solidly covering a pure module

Layout

Vitest is orchestrated from the repo root (tawny-style Projects). Web owns project configs; @justhold/ui and @justhold/tokens are not unit-tested.

FileRole
vitest.config.ts (root)test.projects + coverage thresholds
apps/web/vitest.unit.config.tsdefineProject for unit
apps/web/vitest.integration.config.tsdefineProject for integration
apps/web/vitest.shared.ts@/ aliases + Next stubs

Instructions

Layers

LayerLocationRunnerUse for
Unitapps/web/tests/unit/Vitest (node)Pure helpers in apps/web/lib/ — no DB/network
Integrationapps/web/tests/integration/Vitest + local SupabaseRLS, RPCs, DB behaviour
E2Eapps/web/tests/e2e/PlaywrightCritical user flows

Scripts (run from repo root)

  • pnpm test / pnpm test:watch — unit
  • pnpm test:coverage — unit + coverage thresholds (CI)
  • pnpm test:int — integration (local only)
  • pnpm test:e2e — Playwright (local only)

Unit tests

  • Prefer pure, stable domain logic in apps/web/lib/ (money FIFO, hold-days, formatters, sort keys).
  • Mirror fixture style from apps/web/tests/unit/money.test.ts and apps/web/tests/unit/holdings-math.test.ts.
  • @/ aliases work; server-only / next/headers are stubbed via apps/web/tests/stubs/ (see vitest.shared.ts).
  • Do not invent new test roots (__tests__, colocated *.test.ts next to source).

Coverage

  • coverage.include in root vitest.config.ts lists only fully-pure, well-tested modules (apps/web/lib/…) so thresholds stay meaningful.
  • After solidly covering a new pure module, add its path to that include list.

Integration / e2e

  • Integration uses apps/web/.env.test.local + skip guards when no test DB.
  • Prefer existing helpers under apps/web/tests/helpers/ over ad-hoc Supabase clients.
  • E2E reuses the app via Playwright config; keep specs serial and focused on signup / holdings gating patterns already in apps/web/tests/e2e/.
  • Marketing CTA funnel smoke: apps/web/tests/e2e/try-for-free.spec.ts (guest CTAs → /signup; signed-in /signup//login/member). Unit coverage for the same funnel lives in apps/web/tests/unit/auth-redirect.test.ts (MARKETING_SIGNUP_HREF, getSignedInLoginNext). See .cursor/rules/try-for-free-cta.mdc.