supabase / cli

Supabase CLI. Manage postgres migrations, run Supabase locally, deploy edge functions. Postgres backups. Generating types from your database schema.
https://supabase.com/docs/reference/cli/about
MIT License
1.02k stars 201 forks source link

Support xUnit style tests with pg_prove --runtests flag in supabase db test #2602

Closed parkernilson closed 1 month ago

parkernilson commented 1 month ago

Is your feature request related to a problem? Please describe. I like to write my tests in functions so that I can debug them with a debugger, but currently you can only write tests in SQL script files.

While (I think) debugging with breakpoints is not possible with the current supabase cli, I have my own fork of supabase/postgres where I installed the pldebugger extension, and I can step through functions with a debugger on pgAdmin4. If I wrote my tests in functions, then I could also run them individually in the debugger, which would be really nice.

Describe the solution you'd like I would love the option to either specify in the supabase db test command or in the supabase/config.toml that I want the pg_prove command to be run with the --runtests, --schema, and/or --match flags.

Describe alternatives you've considered I've considered writing test files, and then when I want to debug them, copy/pasting them into the body of a function in the database, so that I can run it in the debugger. However, this doesn't work very well because in a test script you use select to run functions, and in a plpgsql function you use perform, so it's not as easy as copy/pasting.

parkernilson commented 1 month ago

I guess this may actually not be necessary, since I just realized I can make a test script like this:

// supabase/tests/database/run_tests.sql
BEGIN;
CREATE EXTENSION IF NOT EXISTS "pgtap";
CREATE EXTENSION IF NOT EXISTS "basejump-supabase_test_helpers";
select * from runtests();
ROLLBACK;

And it is functionally equivalent to what I requested above