If you plan to continue building out your app on Supabase, we recommend that you start writing tests for your database. This will help you catch bugs early, and ensure that your app is working as expected.
To help make testing with Supabase and Basejump easier, we've created a companion library called supabase-test-helpers.
If you haven't written tests for your Supabase apps yet, we highly recommend you start! It's not too difficult once you get used to the structure - especially now that the Supabase CLI has pgTAP support built in. Check out the official guide here, but we've also included a quick start guide below.
1. Install dbdev extension manager
2. Installing Supabase Test Helpers
Either add a migration file to your project for the installation, or install it directly into your Supabase instance.
3. Setting up your Supabase project for testing
mkdir -p ./supabase/tests/database
Now your'e ready to write your first tests. You can check out a few resources we've pulled together for you to get started:
- A Guide to testing on Supabase using pgTAP - a blog post we wrote on the topic with commonly used testing formats for your RLS policies
- Supabase Test Helpers function overview - a list of all the functions available to you in the Supabase Test Helpers library
- Official Supabase testing docs - a bit lightweight for now, but I suspect these get fleshed out more over time
-- We activate the extension INSIDE a test so that it's never activated in production
CREATE EXTENSION "basejump-supabase_test_helpers";
-- Indicate how many tests we expect to run
-- create users for testing
-- create an example post for testing
insert into posts (title, body, user_id) values ('test post', 'this is a test post', tests.get_supabase_uid('test_owner'));
-- ensure you're anon
$$ select * from posts $$,
'Anon cannot select posts'
select * from finish();
Now that you've written your first test, you can run it using the Supabase CLI:
supabase test db