Testing
Run the deterministic verification path and targeted database integration tests.
bun test runs every suite except the Start edition's. Test files import describe, test,
expect and vi from vitest; Bun provides that module, and bun-types/vitest types it, so the
vitest package itself is not installed. apps/start keeps Vitest because its tests run inside
workerd through @cloudflare/vitest-plugin, which bun test cannot host.
| Workspace | Command |
|---|---|
| every workspace with tests except the two below | bun test --parallel --randomize |
apps/server | bun test --isolate --randomize (serial) |
apps/start | vitest run |
The suites need the Bun canary pinned in CI (.github/actions/setup-toolchain), currently
1.4.5-canary.20261121.1: stable Bun 1.4.5 lacks vi.stubGlobal, vi.stubEnv,
vi.advanceTimersByTimeAsync and vi.resetModules. Install it with
npm install --global bun@1.4.5-canary.20261121.1. Production builds still use stable Bun.
Every file gets a fresh global object, and files run in a random order printed as a seed; rerun an
ordering failure with --seed=<seed>. apps/server runs its files one at a time because the
DB-gated suites share one Postgres database. Setup lives in each workspace's bunfig.toml
preload: apps/server/src/test-setup.ts provides safe env defaults because src/config/env.ts
validates process.env at import time, and apps/web restores mocks, globals and env after each
test.
The split is enforced by types, not convention. Only apps/server and apps/web declare
@types/bun in buyer workspaces; Node-targeted packages such as packages/create-app,
packages/billing, packages/email, and apps/docs declare @types/node while apps/start pins
Cloudflare/Vite test types and packages/ui sets "types": [], so Bun is not an ambient global
outside its intended workspaces and a stray Bun.file() fails vp run -r typecheck instead of
failing at runtime.
packages/email has no standalone test script:
vp run --filter @app/email deployThat command regenerates and inventory-checks buyer HTML. Run renderer, local-fallback, and provider tests through the server suite.
Commands
bun run test # root: `bun --filter '*' test`, every workspace suite
bun --filter @app/server test:unit # fast inner-loop server unit tests (no integration files)
bun --filter ./apps/server test # full server suite standalone
cd packages/contracts && bun test # any workspace standalone; add --watch to rerun on changeDB-gated integration tests
Unit tests never touch the database. Integration tests run only when RUN_DB_INTEGRATION_TESTS=1
and DATABASE_URL are both set before the run; they skip visibly otherwise. The explicit flag
prevents an unrelated DATABASE_URL in your shell from changing the default test suite:
docker compose up -d
bun run --cwd apps/server db:migrate
RUN_DB_INTEGRATION_TESTS=1 DATABASE_URL=postgres://... bun run testapps/server/src/domains/notifications/repository.integration.test.ts is the repository-test
template: initDb() in beforeAll, clean up your fixtures and closePool() in afterAll, and
gate with describe.skipIf. src/test-setup.ts forcibly disables external email, Slack, Google,
and rate limit side effects even if a developer .env was loaded.
Better Auth opens one pg pool per loaded module graph. bun test --isolate loads each test file
fresh, so each file gets its own pool and src/test-setup.ts closes it in afterAll. Individual
suites must still not call closeAuthPool() themselves: it latches closed, and later HTTP cases in
the same file would lose session storage.
apps/server/src/infra/db/migrate.integration.test.ts is the migration-failure fixture. It applies
one valid temporary migration followed by intentionally invalid transactional DDL, then proves the
valid version remains recorded while the failed file leaves neither its table nor a version row.
Never point destructive migration tests at a shared database.
Billing and authentication coverage
Billing remains covered by its DB-gated integration suite. Better Auth's HTTP suite exercises the real Hono handler and Postgres adapter across password signup, verification, authenticated user resolution, logout, password reset and session revocation, magic-link signup, single-use replay rejection, and the optional-Google failure state. The compiled-server smoke test separately proves that the same flow survives the standalone Bun build. When you change buyer UI flows, providers, cookies, redirects, or auth plugins, walk the affected flow in a real browser yourself — no automated suite covers it.
apps/server/src/domains/billing/service.integration.test.tsapps/server/src/lib/auth.integration.test.ts
The upload suite uses a fake provider adapter plus real Postgres to prove owner scoping, expiry, actual metadata validation, failed-object cleanup, replay, and concurrent confirmation without requiring storage credentials:
apps/server/src/domains/upload/service.test.tsapps/server/src/domains/upload/service.integration.test.ts
CI supplies both variables, so these suites run against its Postgres service instead of skipping. CI
also starts the compiled server from the repository root, verifies that all rendered email templates
(10/10) preload cleanly, and sends a real magic-link request. This guards the external-resource
layout used by the standalone binary rather than proving only source execution.
What the suite does not cover
There is no browser automation in this repository. Focus order, pointer interaction, portals,
element measurement, animation, service-worker updates, and real navigation are unverified by
bun run test, and so are the redirect and cookie behaviors that only appear in a browser.
Treat that as a deliberate boundary rather than a gap to work around. Verify those flows by hand in
bun run dev before release, and keep the checks that do run — contracts, server units,
real-Postgres integration, the compiled-binary smoke, and the production build — as the automated
gate. If your product later earns browser automation, add it as its own workspace with its own
runner rather than widening a unit-test suite to drive a browser.
Web bundle budget
Every web build runs apps/web/scripts/verify-bundle-budget.ts after Vite emits dist/. It reads
the built HTML rather than guessing from source imports and fails when:
- the module entry plus its module-preload dependencies exceed 568 KiB; or
- any individual JavaScript chunk exceeds 450 KiB.
Route-lazy JavaScript is not charged to initial startup, but it remains subject to the per-chunk limit. The budget does not claim that the complete PWA precache is downloaded on first navigation; measure transfer, parse, and interaction timing in a real browser before making a performance claim. When the budget fails, inspect eager route/layout imports before adding manual vendor chunk rules or raising the limit.