From 81c1c5e51af3a9746f49984cfcea0234a55bfa70 Mon Sep 17 00:00:00 2001 From: Copple <10214025+kiwicopple@users.noreply.github.com> Date: Thu, 3 Aug 2023 11:40:01 +0200 Subject: [PATCH] Adds a guide for testing --- docs/testing.md | 57 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 docs/testing.md diff --git a/docs/testing.md b/docs/testing.md new file mode 100644 index 0000000..a00385e --- /dev/null +++ b/docs/testing.md @@ -0,0 +1,57 @@ +# Automated testing + +You can use the Supabase CLI to run automated tests. + +## Testing your database + +After you have [created unit tests](https://supabase.com/docs/guides/database/testing) for your database, you can use the GitHub Action to run the tests. + +Inside your repository, create a new file inside the `.github/workflows` folder called `database-tests.yml`. Copy this snippet inside the file, and the action will run whenever a new PR is created: + +```yaml +name: 'database-tests' +on: + pull_request: + +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: supabase/setup-cli@v1 + with: + version: 1.11.4 + - run: supabase db start + - run: supabase test db + +``` + +## Testing your Edge Functions + +After you have [created unit tests](https://supabase.com/docs/guides/functions/unit-test) for your Edge Functions, you can use the GitHub Action to run the tests. + +Inside your repository, create a new file inside the `.github/workflows` folder called `functions-tests.yml`. Copy this snippet inside the file, and the action will run whenever a new PR is created: + +```yaml +name: 'functions-tests' +on: + pull_request: + +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: supabase/setup-cli@v1 + with: + version: 1.11.4 + - run: supabase start + - run: supabase functions serve + - run: deno test --allow-all deno-test.ts --env-file .env.local + +``` + +## More resources + +- Learn more about the [pgTAP extension](https://supabase.com/docs/guides/database/extensions/pgtap) for database testing. +- Official pgTAP Documentation: [pgtap.org](https://pgtap.org/)