Loading...
Loading...
End-to-end testing scenarios for Supabase - complete workflow tests from project creation to AI features, validation scripts, and comprehensive test suites. Use when testing Supabase integrations, validating AI workflows, running E2E tests, verifying production readiness, or when user mentions Supabase testing, E2E tests, integration testing, pgvector testing, auth testing, or test automation.
npx skill4agent add vanman2024/ai-dev-marketplace e2e-test-scenariosbash scripts/setup-test-env.shSUPABASE_TEST_URLSUPABASE_TEST_ANON_KEYnpm install --save-dev @supabase/supabase-js jest @types/jest
# or
pnpm add -D @supabase/supabase-js vitestbash scripts/test-database-workflow.sh# Run all database tests
supabase test db
# Run specific test file
supabase test db --file tests/database/users.test.sql# Test migration up/down
supabase db reset --linked
supabase db push
# Verify schema state
bash scripts/validate-schema.shbash scripts/test-auth-workflow.sh// See templates/auth-tests.ts for complete examples
test('authenticated users see only their data', async () => {
const { data, error } = await supabase
.from('private_notes')
.select('*');
expect(data).toHaveLength(userNoteCount);
expect(data.every(note => note.user_id === userId)).toBe(true);
});# Run session validation tests
npm test -- auth-session.test.tsbash scripts/test-ai-features.sh// See templates/vector-search-tests.ts
test('semantic search returns relevant results', async () => {
const queryEmbedding = await generateEmbedding('machine learning');
const { data } = await supabase.rpc('match_documents', {
query_embedding: queryEmbedding
match_threshold: 0.7
match_count: 5
});
expect(data.length).toBeGreaterThan(0);
expect(data[0].similarity).toBeGreaterThan(0.7);
});# Validate embedding pipeline
npm test -- embedding-workflow.test.ts# Run performance tests
bash scripts/benchmark-vector-search.sh [TABLE_NAME] [VECTOR_DIM]bash scripts/test-realtime-workflow.sh// See templates/realtime-tests.ts
test('receives real-time updates on insert', async () => {
const updates = [];
const subscription = supabase
.channel('test-channel')
.on('postgres_changes'
{ event: 'INSERT', schema: 'public', table: 'messages' }
(payload) => updates.push(payload)
)
.subscribe();
await supabase.from('messages').insert({ content: 'test' });
await waitFor(() => expect(updates).toHaveLength(1));
});# Run presence tests
npm test -- presence.test.tsbash scripts/run-e2e-tests.sh# Run all test suites
npm test -- --maxWorkers=4
# Run specific workflow
npm test -- workflows/document-rag.test.ts# Generate coverage report
npm test -- --coverage
# Generate HTML report
npm test -- --coverage --coverageReporters=html# Copy CI config to your repo
cp templates/ci-config.yml .github/workflows/supabase-tests.ymlSUPABASE_TEST_URLSUPABASE_TEST_ANON_KEYSUPABASE_TEST_SERVICE_ROLE_KEYbash scripts/cleanup-test-resources.sh# Reset to clean state
supabase db reset --linked
# Or use migration-based reset
bash scripts/reset-test-db.sh// Load test fixtures
const testData = await loadFixtures('users', 'posts', 'comments');
// Seed database
await seedDatabase(testData);
// Cleanup after tests
afterAll(async () => {
await cleanupFixtures();
});// Create test users with factories
const user = await createTestUser({
email: 'test@example.com'
metadata: { role: 'admin' }
});
// Create related data
const posts = await createTestPosts(user.id, 5);test_test('authenticated user CRUD operations', async () => {
// 1. Sign up user
const { user } = await supabase.auth.signUp({
email: 'test@example.com'
password: 'test123'
});
// 2. Create resource
const { data } = await supabase
.from('notes')
.insert({ content: 'test note' })
.select()
.single();
// 3. Verify ownership
expect(data.user_id).toBe(user.id);
// 4. Update resource
await supabase
.from('notes')
.update({ content: 'updated' })
.eq('id', data.id);
// 5. Delete resource
await supabase.from('notes').delete().eq('id', data.id);
});test('document RAG workflow', async () => {
// 1. Upload document
const doc = await uploadDocument('test.pdf');
// 2. Generate embeddings
const chunks = await chunkDocument(doc);
const embeddings = await generateEmbeddings(chunks);
// 3. Store in database
await supabase.from('document_chunks').insert(
chunks.map((chunk, i) => ({
content: chunk
embedding: embeddings[i]
document_id: doc.id
}))
);
// 4. Perform semantic search
const query = 'What is the main topic?';
const queryEmbedding = await generateEmbedding(query);
const { data } = await supabase.rpc('match_documents', {
query_embedding: queryEmbedding
match_count: 5
});
// 5. Verify results
expect(data.length).toBeGreaterThan(0);
expect(data[0].similarity).toBeGreaterThan(0.7);
});test('multi-user realtime chat', async () => {
// 1. Create two users
const user1 = await createTestUser();
const user2 = await createTestUser();
// 2. Subscribe to messages
const user1Messages = [];
const user2Messages = [];
const sub1 = await subscribeToMessages(user1, user1Messages);
const sub2 = await subscribeToMessages(user2, user2Messages);
// 3. User 1 sends message
await sendMessage(user1, 'Hello from user 1');
// 4. Verify both users receive it
await waitFor(() => {
expect(user1Messages).toHaveLength(1);
expect(user2Messages).toHaveLength(1);
});
// 5. Cleanup subscriptions
await sub1.unsubscribe();
await sub2.unsubscribe();
});--maxWorkersscripts/setup-test-env.shscripts/run-e2e-tests.shscripts/test-database-workflow.shscripts/test-auth-workflow.shscripts/test-ai-features.shscripts/test-realtime-workflow.shscripts/cleanup-test-resources.shscripts/validate-schema.shscripts/benchmark-vector-search.shscripts/reset-test-db.shtemplates/test-suite-template.tstemplates/database-tests.tstemplates/auth-tests.tstemplates/vector-search-tests.tstemplates/realtime-tests.tstemplates/ci-config.ymltemplates/jest.config.jstemplates/vitest.config.tsexamples/complete-test-workflow.mdexamples/ci-cd-integration.mdexamples/test-data-strategies.mdexamples/performance-benchmarks.mdexamples/mocking-strategies.md