FIELD GUIDE 001 · TYPESCRIPT + POSTGRESReal database tests. Nothing left behind.
A runnable reference for transaction rollback, typed fixtures, factories, authorization seams, and the tests that refuse to fit inside one transaction.
A runnable reference for transaction rollback, typed fixtures, factories, authorization seams, and the tests that refuse to fit inside one transaction.
baselinefixtures already committed↓beginone transaction for the test↓exercisereal queries + real authorization↓rollbackevery write disappearsdatabase restored
The short version
Mock the person who signed in—not the authorization decision. Read shared fixture rows through the real schema. Create the unusual state with factories. Call the same server function production calls. Then roll the whole test back.
This is deliberately a reference to copy, not a package to install. Database test infrastructure sits directly on your application's seams: its connection owner, migrations, schema types, authorization boundary, and test runner. Those seams should stay visible.
A few committed, label-addressed fixtures make the shared world readable without rebuilding it for every test.
Factories create only what the example changes. Lazy associations keep setup small without making it magical.
The test runs inside an interactive transaction. A sentinel throw guarantees that a passing callback never commits.
Honest by construction
One transaction owns one connection. That makes isolation cheap. It also means concurrency is fake, database now() is frozen, and an expected SQL error can abort the transaction. The kit pins those facts with tests and gives race-sensitive work an explicit committed-mode exit.
Where it fits
These are endpoint tests: a real server function or route handler, a real schema and a real authorization decision, run in-process in milliseconds. They catch what mocks cannot (a missing tenant filter, a constraint violation, a forgotten audit write) without the browser, server and teardown cost of end-to-end tests. See where the line falls →
Choose your route
The root project uses Drizzle + PGlite for a zero-service first run, then exercises the same suite against Postgres. The Prisma 7 variant uses real Postgres and carries its own exact toolchain pins, fixture types, loader, and caveat tests.
For humans and agents
The rendered guide, raw Markdown, RECREATE.md, Agent Skill, llms.txt, and generated full-text reference all describe the same system.