Skip to content

In development. Expect rough edges and changes. The source code is not public yet.

Neon 8 min read How-to mediumAdept

Stop Mocking Auth (It’s Breaking Your Tests)

Mocking authentication in tests hides real failures: password hashing and verification, UNIQUE-constraint enforcement under concurrent signups, session handling, and SQL joins between auth and application data. Neon Auth stores users, sessions and tokens in a neon_auth Postgres schema, so a copy-on-write database branch (created in about a second) also branches auth with its own isolated Auth URL. A GitHub Actions workflow can create a branch per pull request, run tests against real auth and data, then delete the branch, giving isolation without mocks or shared staging databases.

Related posts

  • Handling Auth in a Staging Environment

    Neon mediumAdept

    Neon Auth stores users, sessions and OAuth data in a neon_auth schema inside the Postgres database, so branching the database also branches auth state via copy-on-write. Each branch gets its own auth endpoint, which lets preview and staging environments test role, permission and OAuth changes against a copy of production users without touching production or creating test accounts by hand. Deleting the branch removes all copied users. It is built on Better Auth, used through the @neondatabase/neon-js SDK, and can be provisioned per PR with a GitHub Action that outputs the branch's auth URL.

  • 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.

  • 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.

  • Neon Testing: a Vitest Library for Your Integration Tests

    Neon mediumAdept

    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.

The quest for software engineering knowledge.

Look:
Layout: