This guide will help you get started with testing your database and API in the Nexpo monorepo.
-
Install dependencies:
yarn install
-
Start Supabase locally:
yarn supabase:start
Database tests use pgTAP and run via Supabase CLI.
Run database tests:
yarn test:dbTest files location:
supabase/tests/database/schema.test.sql- Schema structure testssupabase/tests/database/rls.test.sql- Row Level Security testssupabase/tests/database/triggers.test.sql- Trigger testssupabase/tests/database/functions.test.sql- Function tests
API tests use Vitest and test tRPC procedures.
Install dependencies (if not already installed):
cd packages/api
yarn installRun API tests:
# From project root
yarn test:api
# Or from packages/api
cd packages/api
yarn testWatch mode (for development):
cd packages/api
yarn test:watchUI mode (interactive):
cd packages/api
yarn test:uiCoverage report:
cd packages/api
yarn test:coverage- schema.test.sql - Tests table structure, columns, types, indexes
- rls.test.sql - Tests Row Level Security policies
- triggers.test.sql - Tests database triggers
- functions.test.sql - Tests database functions
Unit Tests:
- helpers.test.ts - Unit tests for helper functions (createMockUser, wait, etc.)
- trpc.test.ts - Unit tests for tRPC middleware (protectedProcedure)
Integration Tests:
- router.test.ts - Integration tests for tRPC procedures
- helpers.ts - Test helper functions
- setup.ts - Test environment setup
- supabase.ts - Mock Supabase client for testing
BEGIN;
SELECT plan(2);
SELECT has_table('public', 'my_table', 'my_table should exist');
SELECT has_column('public', 'my_table', 'id', 'id column should exist');
SELECT * FROM finish();
ROLLBACK;import { describe, it, expect } from 'vitest'
import { appRouter } from '../index'
import { createTestContext } from './helpers'
describe('My Procedure', () => {
const ctx = createTestContext()
const caller = appRouter.createCaller(ctx)
it('should do something', async () => {
const result = await caller.myProcedure()
expect(result).toBeDefined()
})
})yarn test # Run all tests (via Turbo)
yarn test:db # Run database tests
yarn test:api # Run API tests
yarn test:watch # Watch mode for all tests
yarn test:coverage # Coverage report for all testscd packages/api
yarn test # Run tests once
yarn test:watch # Watch mode
yarn test:ui # Interactive UI
yarn test:coverage # Coverage report-
Run the tests to verify everything works:
yarn test:db yarn test:api
-
Add more tests for your specific use cases:
- Add database tests for new tables/columns
- Add API tests for new tRPC procedures
- Add integration tests for end-to-end flows
-
Set up CI/CD (see
TESTING_PLAN.mdfor GitHub Actions example)
- Ensure Supabase is running:
yarn supabase:start - Check Supabase CLI version:
supabase --version(should be v1.11.4+) - Verify tests are in
supabase/tests/database/directory
- Ensure dependencies are installed:
cd packages/api && yarn install - Check that test environment variables are set
- Verify Vitest is installed:
yarn list vitest
- Check if Supabase is running and accessible
- Verify environment variables are correct
- Check for port conflicts (54321, 54322, 54323)
- Full Testing Plan - Comprehensive testing strategy
- Database Tests README - Database testing guide
- API Tests README - API testing guide
- Supabase Testing Docs
- Vitest Documentation