Testing and Acceptance
Spec, Code, Verify, Test, Green and real-platform verification boundaries.
Deliver non-trivial behavior through Spec → Code → Verify → Test → Green. Define acceptance first and maintain tests/e2e/SCENARIOS.md for browser journeys. New package behavior, schemas, and bug fixes start with a minimal failing test.
Test Layers
| Location | What it proves |
|---|---|
packages/<name>/tests | Package factories, pure logic, schema/query behavior |
tests/unit | App logic, orchestration, transformations, validation |
tests/api | Real HTTP against a running app: auth, permissions, validation, response contracts |
tests/e2e | Playwright navigation, auth UX, redirects, signed-in journeys |
tests/utils | Shared environment/Better Auth plumbing, not feature assertions |
Coverage floors in packages/testing/coverage-floors.json may only rise. Database tests include Postgres/PGlite and SQLite queries. Passing one dialect does not verify the other platform.
Local Workers Setup
pnpm muse:init --yes --app cloudflare
pnpm db:seed:d1
pnpm dev:cfManual password login uses [email protected] / [email protected], with MUSE_SEED_PASSWORD (default musemvp). Normal runs keep BETTER_AUTH_ENABLE_TEST_UTILS=false.
Reuse tests/utils/better-auth.ts and tests/e2e/utils/session.ts. Test processes enable Better Auth testUtils; APIs use getAuthHeaders, browsers use getCookies, and OTP uses capture helpers. Do not reinvent login bootstrap in each spec.
Commands and Limits
| Command | Scope |
|---|---|
pnpm test:unit | Package and app logic |
pnpm test:unit:coverage | Coverage and floor checks |
pnpm test:e2e:cf | Current config runs build:cf + next start on 3001, not actual Wrangler Worker bindings |
pnpm cf:preview | OpenNext Worker preview for D1/R2/mail platform paths |
pnpm apps:parity | Page/content copy consistency, not behavior |
Prepare Workers with pnpm muse:init --yes --app cloudflare and pnpm db:seed:d1, without Postgres. The current test:e2e:cf server does not prove native D1/R2 runtime success. Verify platform behavior in Wrangler preview/actual deployment rather than inferring coverage from the script name.
Select Coverage by Change
Use unit tests for logic and HTTP contracts for routes. Combine lower-level and browser checks for auth, billing, role gates, uploads, and cross-route navigation. Walk the critical path before locking assertions, including empty states, service errors, invalid input, and cross-user denial. Report passed, unrun, and deferred checks explicitly; rendering/types alone are not completion.