Testing supabase-js Code In-Process with Vitest and tinbase, No Server Required
Supabase app tests typically either mock supabase-js, which skips real database rules like RLS and constraints, or run against a live backend that needs Docker or a cloud project. This guide proposes a third approach: running a Supabase-compatible backend inside the test process itself. The setup uses tinbase, an alpha open-source backend that runs on PGlite, Postgres compiled to WebAssembly, and it is intended for development and testing rather than production. supabase-js is pointed at the backend through a custom fetch function, so requests reach real Postgres without any ports or network. The example shows a notes table with row-level security and a check constraint, verified by Vitest tests that create authenticated anonymous users and confirm that invalid inserts are rejected.
This is an AI-generated summary. ShortSingh links to the original source for the complete article.
Discussion (0)
Log in to join the discussion and vote.
Log in