Neon Testing: a Vitest Library for Your Integration Tests
Neon Testing is an open-source Vitest utility that automates creating and tearing down Neon Postgres branches so each test file runs integration tests against its own isolated, schema-accurate database. Files run in parallel on separate branches. Tests within a file share one branch, and a beforeEach reset gives per-test isolation. A Vite plugin clears DATABASE_URL so tests can't accidentally hit local or production databases, and an autoCloseWebSockets option handles Neon's WebSocket driver. A worked example tests a unique email constraint, the kind of behavior mocks can't reproduce.
Related posts
- Branching Postgres databases with the Neon API
Neon mediumAdept
Neon branches are copy-on-write clones of a Postgres database that can be created and deleted through the Neon API, giving CI pipelines an isolated copy of production data for end-to-end tests. Two experimental GitHub Actions, neondatabase/create-branch-action and neondatabase/delete-branch-action, wrap the API. A sample pull-request workflow creates a branch from a parent branch, runs the test steps, then deletes the branch. The actions were beta at the time and still being hardened for production use.
- Test Your Database Without Mocks
Neon mediumAdept
Database mocks are brittle, expensive to maintain, and test little beyond the mock itself, since they skip real behaviour like transactions, isolation levels, foreign keys and referential integrity. The usual reasons to mock, isolation and speed, are better served by copy-on-write database branches than by test containers, which bring resource overhead, port conflicts, cleanup and CI orchestration problems. Neon branches give each developer, test suite or pull request an isolated Postgres copy with real data, created via neonctl or a GitHub Action, optionally from a point in time for debugging. Shared storage and scale-to-zero compute keep the cost low.
- Adopting Neon branching in CI/CD pipelines: a practical story by Shepherd
Neon mediumAdept
Shepherd, an insurtech startup that moved its Alchemist pricing engine from SQLite to Postgres, uses Neon's copy-on-write database branches to give every pull request an ephemeral test database. GitHub Actions call the Neon API to create a branch when a PR opens and delete it on merge. Changes then flow from per-developer and per-PR branches to staging and production, with Render pre-deploy commands applying migrations tracked in a dedicated timestamped table. The team credits branching with removing the cost and effort of keeping test instances synced with production, and notes that scale-to-zero means it no longer pays for idle databases.
- A database for every preview environment using Neon, GitHub Actions, and Vercel
Neon mediumAdept
Neon's copy-on-write branching can give every pull request its own production-like Postgres database, avoiding the bottlenecks of shared staging or shared preview databases. Branches are isolated, are created in about a second regardless of database size, and bill only for unique data. A GitHub Actions pipeline creates a Neon branch per PR, runs Prisma migrations against it, deploys a Vercel preview wired to that branch, and comments the URLs on the PR. Merging applies migrations to the primary branch, deploys to production and deletes the preview branch.
- From days to minutes: how Neo.Tax accelerated their development lifecycle
Neon mediumAdept
Neo.Tax replaced a multi-day manual QA loop (product-created test customers, hand-verified PDFs, engineers hand-copying values into E2E fixtures via SQL dumps) with per-PR Neon database branches created by the Neon CLI, named after the GitHub branch, injected into Cloud Run via CircleCI environment variables, and deleted on merge. For bug fixing, they branch from production per ticket and share the connection URL so developers reproduce issues on identical data without copying sensitive data locally, resetting a branch in about a second. Separate Neon projects cover development, staging and production, with schema-based isolation for most customers and dedicated projects for enterprise tenants.