feat: add Supabase CLI scaffold and client SDK setup
Initializes the local Supabase project (supabase/config.toml) and adds a thin src/lib/supabase.ts wrapper around @supabase/supabase-js that reads connection details from Vite env vars, tested with a mocked createClient.
This commit is contained in:
22
src/lib/supabase.test.ts
Normal file
22
src/lib/supabase.test.ts
Normal file
@@ -0,0 +1,22 @@
|
||||
import { describe, it, expect, vi, beforeEach } from 'vitest'
|
||||
|
||||
const createClientMock = vi.fn(() => ({ type: 'mock-supabase-client' }))
|
||||
|
||||
vi.mock('@supabase/supabase-js', () => ({ createClient: createClientMock }))
|
||||
|
||||
describe('supabase client setup', () => {
|
||||
beforeEach(() => {
|
||||
vi.resetModules()
|
||||
createClientMock.mockClear()
|
||||
})
|
||||
|
||||
it('creates the client with the URL and anon key read from Vite env vars', async () => {
|
||||
vi.stubEnv('VITE_SUPABASE_URL', 'https://test-project.supabase.co')
|
||||
vi.stubEnv('VITE_SUPABASE_ANON_KEY', 'test-anon-key')
|
||||
|
||||
const { supabase } = await import('./supabase')
|
||||
|
||||
expect(createClientMock).toHaveBeenCalledWith('https://test-project.supabase.co', 'test-anon-key')
|
||||
expect(supabase).toEqual({ type: 'mock-supabase-client' })
|
||||
})
|
||||
})
|
||||
6
src/lib/supabase.ts
Normal file
6
src/lib/supabase.ts
Normal file
@@ -0,0 +1,6 @@
|
||||
import { createClient } from '@supabase/supabase-js'
|
||||
|
||||
export const supabase = createClient(
|
||||
import.meta.env.VITE_SUPABASE_URL,
|
||||
import.meta.env.VITE_SUPABASE_ANON_KEY,
|
||||
)
|
||||
Reference in New Issue
Block a user