Skip to content

The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.

Corrected use of environment file with deno test and edge functions (#21302)

David Dikman6a79a5f2669d
diff --git a/apps/docs/content/guides/functions/unit-test.mdx b/apps/docs/content/guides/functions/unit-test.mdx
index 0430bbc3254..5dc3e942fb2 100644
--- a/apps/docs/content/guides/functions/unit-test.mdx
+++ b/apps/docs/content/guides/functions/unit-test.mdx
@@ -37,6 +37,9 @@ The following script is a good example to get started with testing your Edge Fun
import { assert, assertEquals } from 'https://deno.land/[email protected]/testing/asserts.ts'
import { createClient, SupabaseClient } from 'jsr:@supabase/supabase-js@2'
+// Will load the .env file to Deno.env
+import 'https://deno.land/x/[email protected]/load.ts'
+
// Set up the configuration for the Supabase client
const supabaseUrl = Deno.env.get('SUPABASE_URL') ?? ''
const supabaseKey = Deno.env.get('SUPABASE_ANON_KEY') ?? ''
@@ -130,19 +133,19 @@ To locally test and debug Edge Functions, you can utilize the Supabase CLI. Let'
```bash
# creates the file
- touch .env.local
+ touch .env
# adds the SUPABASE_URL secret
- echo "SUPABASE_URL=http://localhost:54321" >> .env.local
+ echo "SUPABASE_URL=http://localhost:54321" >> .env
# adds the SUPABASE_ANON_KEY secret
- echo "SUPABASE_ANON_KEY=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZS1kZW1vIiwicm9sZSI6ImFub24iLCJleHAiOjE5ODM4MTI5OTZ9.CRXP1A7WOeoJeXxjNni43kdQwgnWNReilDMblYTn_I0" >> .env.local
+ echo "SUPABASE_ANON_KEY=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZS1kZW1vIiwicm9sZSI6ImFub24iLCJleHAiOjE5ODM4MTI5OTZ9.CRXP1A7WOeoJeXxjNni43kdQwgnWNReilDMblYTn_I0" >> .env
# Alternatively, you can open it in your editor:
- open .env.local
+ open .env
```
4. To run the tests, use the following command in your terminal:
```bash
- deno test --allow-all supabase/functions/tests/function-one-test.ts --env=.env.local
+ deno test --allow-all supabase/functions/tests/function-one-test.ts
```
## Resources