cli
cli copied to clipboard
feat: add db test command using pgtap
What kind of change does this PR introduce?
feature: supabase db test
What is the current behavior?
no cli native way to run tests
What is the new behavior?
- adds pgtap extension to initial schema
- installs
pg_proveonsupabase_db_clicontainer - copies
supabase/testsintosupabase_db_clicontainer - runs
pg_provevia docker exec and prints out results
Additional context
Example order_test.pg
BEGIN;
SELECT plan(1);
SELECT has_column(
'public',
'order',
'status',
'status should exist'
);
SELECT * FROM finish();
ROLLBACK;
Output
$ supabase db test
supabase/tests/order_test.pg .. ok
supabase/tests/pet_test.pg .... ok
All tests successful.
Files=2, Tests=2, 1 wallclock secs ( 0.01 usr 0.00 sys + 0.04 cusr 0.02 csys = 0.07 CPU)
Result: PASS
Pull Request Test Coverage Report for Build 3172017203
- 30 of 78 (38.46%) changed or added relevant lines in 6 files are covered.
- 1 unchanged line in 1 file lost coverage.
- Overall coverage decreased (-0.08%) to 40.536%
| Changes Missing Coverage | Covered Lines | Changed/Added Lines | % |
|---|---|---|---|
| cmd/db.go | 2 | 8 | 25.0% |
| internal/db/test/test.go | 23 | 65 | 35.38% |
| <!-- | Total: | 30 | 78 |
| Files with Coverage Reduction | New Missed Lines | % |
|---|---|---|
| cmd/db.go | 1 | 44.94% |
| <!-- | Total: | 1 |
| Totals | |
|---|---|
| Change from base Build 3166989322: | -0.08% |
| Covered Lines: | 2041 |
| Relevant Lines: | 5035 |
💛 - Coveralls
this is awesome!! Are tests within nested directories also supported?
I think instead of manually traversing the dirs, we can instead use one file as an entrypoint and use the \i/\include directive to include other files.
Or use the --recurse flag from pg_prove.
I think instead of manually traversing the dirs, we can instead use one file as an entrypoint and use the
\i/\includedirective to include other files.Or use the
--recurseflag from pg_prove.
+1 for the recurse flag. The \include directive would require the user to manually include hundreds of files eventually.
You can also use wildcards with the include directive iirc, so both approaches should be fine.
(Somehow I can't find where the reference is for the directives, so we should probably put this up somewhere on the CLI docs)
Thanks for the suggestions! Added --recurse flag and undid changes to initial schema.
:tada: This PR is included in version 1.6.0 :tada:
The release is available on:
Your semantic-release bot :package::rocket:
@sweatybridge why do we only search for .pg files? All our tests are .sql. I can fix my nvim config, but still curious since most editors do not recognise .pg files.
EDIT: Created issue https://github.com/supabase/cli/issues/571