This document is the single reference for testing Supabase Edge Functions and the Functions API from your IDE and local environment. It covers local stack workflow, debugging with breakpoints, Deno unit tests, integration tests against local functions, and troubleshooting. See also: TESTING_SETUP_AND_RUN.md (all test types), EDGE_FUNCTIONS.md (function reference and deployment). Verification results: EDGE_AND_API_VERIFICATION_RESULTS.md.Documentation Index
Fetch the complete documentation index at: https://docs.encoreos.io/llms.txt
Use this file to discover all available pages before exploring further.
Prerequisites
- Supabase CLI — Install globally or use
npx supabasefrom the project root. See Install the Supabase CLI. - Docker — Required for
supabase start(local Postgres, Auth, etc.). - Deno (optional) — For running Edge Function unit tests (
deno test). Install from deno.land if you want to runnpm run test:functionslocally.
Full local stack
-
Start the local Supabase stack (Postgres, Auth, Realtime, Storage, etc.):
Or:
npm run supabase:start(if you use the npm script). Get the API URL and anon key with: -
Serve Edge Functions with hot-reload:
Or:
supabase functions serve. Omitting a function name serves all functions. Hot-reload is on by default. -
Invoke locally:
- From the app: Point
VITE_SUPABASE_URLathttp://localhost:54321and usesupabase.functions.invoke('my-func', { body }). - From terminal (cURL):
Use the anon key from
npx supabase status.
- From the app: Point
Local env for Edge/API
For local function and API testing, use a.env.local (or shell export) with:
VITE_SUPABASE_URL=http://localhost:54321VITE_SUPABASE_PUBLISHABLE_KEY=<anon key from npx supabase status>
supabase start:
Debugging with breakpoints
-
Start functions in inspect mode:
This runs
supabase functions serve --inspect-mode brk. Execution pauses on the first line when a request hits a function. -
Attach Chrome DevTools:
- Open Chrome and go to
chrome://inspect. - Click Configure and add target
127.0.0.1:8083. - Under “Remote Target”, click Open dedicated DevTools for Node.
- Open Chrome and go to
- Trigger a function (e.g. cURL or the app). Execution will pause so you can set breakpoints, step through code, and inspect variables.
Deno unit tests
Location: Tests are co-located with functions, e.g.:supabase/functions/<name>/index.test.tssupabase/functions/<name>/index_test.ts
- generate-templated-pdf and similar: Set
VITE_SUPABASE_URL=http://localhost:54321andVITE_SUPABASE_PUBLISHABLE_KEY=<anon from npx supabase status>. - hr-encrypt-bank-account: Set
SUPABASE_URL=http://localhost:54321(and optionallyTEST_AUTH_TOKENfor authenticated tests).
supabase/functions. Ensure the local stack and supabase functions serve are running if tests call the HTTP endpoint.
IDE: Use the Deno extension in VS Code/Cursor and the task “Run Edge Function (Deno) tests” to run the same command from the editor. If your workspace has no .vscode/tasks.json, copy or merge from docs/development/vscode-tasks-edge-functions.json into .vscode/tasks.json.
API Gateway parity (local vs production)
| Environment | Base URL |
|---|---|
| Local | http://localhost:54321/functions/v1/ |
| Production | https://<project-ref>.supabase.co/functions/v1/ |
supabase functions serve without --no-verify-jwt and send a valid Authorization: Bearer <token> header (anon key or user JWT). The default npm run supabase:functions:serve uses --no-verify-jwt for easier local iteration; use inspect or a separate serve command when testing JWT verification.
Logs
- Local: Function stdout/stderr appear in the terminal where you ran
supabase functions serve. - Production: Use the Supabase Dashboard (Edge Function logs) or the CLI. Use structured logging in code (e.g.
logger.infowithcorrelationId, no PHI) for easier filtering.
Integration tests against local
To run Vitest integration tests that invoke Edge Functions against your local stack:- Set
VITE_SUPABASE_URL=http://localhost:54321andSUPABASE_SERVICE_ROLE_KEY(andVITE_SUPABASE_PUBLISHABLE_KEYif tests use anon client). Get keys fromnpx supabase statusaftersupabase start. - Run
npm run supabase:functions:servein a separate terminal. - Run integration tests, e.g.:
Or a subset, e.g.:
VITE_SUPABASE_URL and supabase.functions.invoke. With the URL pointing at local and functions serve running, those tests hit your local functions.
Fast prod checks
- Dashboard: Use the Test tab for each function in the Supabase Dashboard to try different headers, payloads, and JWTs.
- cURL:
Troubleshooting checklist
| Issue | What to check |
|---|---|
| 401/403 locally | Missing or invalid Authorization header. Confirm anon key (or user JWT). If the function has verify_jwt = true in production, run serve without --no-verify-jwt and send a valid token. |
| Import errors | Use npm: or jsr: specifiers in Edge Functions and pin versions. Do not use Node-style imports. |
| File writes | Writes are allowed only under /tmp. |
| Hanging requests | Look for unawaited Promises. Offload background work with EdgeRuntime.waitUntil(promise) so the response is not delayed. |
See also
- TESTING_SETUP_AND_RUN.md — All test types and env vars
- EDGE_FUNCTIONS.md — Function reference, deployment, and JWT config
- SUPABASE_CLI_LOCAL_WORKFLOW.md — Migrations and local DB workflow