Setting Up Local Supabase Database Testing
Testing your Supabase database shouldn't require deploying to the cloud or sharing a development database. With supabase-test and @pgpm/supabase, you get instant, isolated Postgres databases that mirror your Supabase environment—perfect for fast, reliable tests.
Prerequisites
See Prerequisites.
Install pgpm
Installs the pgpm command globally so you can use it anywhere. If your shell cannot find pgpm after install, open a new terminal or add the npm global bin to your PATH.
Create a Workspace for Your Supabase Project
Create a pgpm workspace to organize your Supabase project:
When prompted, enter your workspace name:
Install dependencies:
Create a Module for Your Supabase Testing
Create a pgpm module to organize your Supabase database code:
Enter module details when prompted:
Install Supabase Testing Dependencies
Install supabase-test in your module:
The supabase-test package is built on top of pgsql-test with Supabase defaults baked in. It automatically configures connection settings for the local Supabase stack.
Install the Supabase testing harness via pgpm (not pnpm):
This installs the @pgpm/supabase package, which provides Supabase's auth schema and other core modules. This allows you to import Supabase schemas into your temporary test databases, giving you a complete Supabase environment for testing.
Install Supabase CLI and Start Local Stack
Initialize Supabase in your workspace (from the module directory):
Start the local Supabase stack:
This provisions a complete Supabase environment locally, including Postgres, Auth, Storage, and all system schemas. Note the connection details—you'll need the database port (typically 54322).
What You've Accomplished
You now have a complete Supabase testing environment:
- pgpm workspace organized for your Supabase project
- Local Supabase stack running with all system schemas
supabase-testconfigured for instant, isolated test databases@pgpm/supabasetesting harness
Next, you'll learn how to write your first supabase test using TypeScript.
