Skip to content

Commit d38413b

Browse files
grdsdevfilipecabacohfnyannyacha
authored
test(deno): add integration tests for deno (#1455)
* fix: bump realtime-js * fix: bump up realtime (#1443) * fix: bump realtime-js (#1453) * merge next into master (#1438) * fix: bump realtime-js * fix: bump up realtime (#1443) --------- Co-authored-by: Filipe Cabaço <[email protected]> * Next (#1444) * fix: bump realtime-js * fix: bump up realtime (#1443) --------- Co-authored-by: Guilherme Souza <[email protected]> * fix: bump up realtime (#1446) * fix: bump realtime-js * fix: bump up realtime --------- Co-authored-by: Guilherme Souza <[email protected]> * feat: bump auth-js to v2.70.0 (#1449) * fix: update realtime-js --------- Co-authored-by: Filipe Cabaço <[email protected]> Co-authored-by: Stojan Dimitrovski <[email protected]> * bump realtime-js * fix: bump realtime-js (#1456) * fix: bump realtime-js * fix: bump realtime-js to 2.11.11-next.5 * test(deno): add integration tests for deno * rollback running integration test twice * downgrade deno # Conflicts: # package-lock.json # pnpm-lock.yaml * run only for deno 2 * add example deno * move to test folder * use old deno lock * clean up * ignore memory leak errors on test * set broken supabase version for testing * use latest supabase-js version * regenerate deno.lock * deno test using npm * use clean-install * remove lock file * run build * run tests only for deno 2 * run deno test twice * run deno test twice * chore: add imports section to `deno.json` * chore: update `ci.yml` * chore: create script for generating deno.json file * remove deno.json * run browser integration after node * run setup-deps before running tests * revert realtime-js version * remove .tools-version --------- Co-authored-by: Filipe Cabaço <[email protected]> Co-authored-by: Stojan Dimitrovski <[email protected]> Co-authored-by: Nyannyacha <[email protected]>
1 parent a7fe11a commit d38413b

File tree

12 files changed

+290
-98
lines changed

12 files changed

+290
-98
lines changed

.github/workflows/ci.yml

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ jobs:
5353
matrix:
5454
os: [ubuntu-latest]
5555
node: ['20']
56-
deno: ['2.x']
56+
deno: ['1.x', '2.x']
5757

5858
runs-on: ${{ matrix.os }}
5959

@@ -78,12 +78,22 @@ jobs:
7878
run: |
7979
supabase start
8080
81-
- name: Run tests
81+
- name: Build
8282
run: |
8383
npm clean-install
84+
npm run build
85+
86+
- name: Run tests
87+
if: ${{ matrix.deno == '2.x' }}
88+
run: |
8489
npm run test:integration || npm run test:integration
8590
npm run test:integration:browser
8691
92+
- name: Run Deno tests
93+
run: |
94+
cd test/deno
95+
npm test || npm test
96+
8797
- name: Stop Supabase
8898
run: |
8999
supabase stop

deno.lock

Lines changed: 0 additions & 89 deletions
This file was deleted.

package-lock.json

Lines changed: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
"test": "run-s test:types test:run",
3232
"test:all": "run-s test:types test:run test:integration test:integration:browser",
3333
"test:run": "jest --runInBand --detectOpenHandles",
34-
"test:coverage": "jest --runInBand --coverage --testPathIgnorePatterns=\"test/integration.*\"",
34+
"test:coverage": "jest --runInBand --coverage --testPathIgnorePatterns=\"test/integration.*|test/deno.*\"",
3535
"test:integration": "jest --runInBand --detectOpenHandles test/integration.test.ts",
3636
"test:integration:browser": "deno test --allow-all test/integration.browser.test.ts",
3737
"test:db": "cd infra/db && docker-compose down && docker-compose up -d && sleep 5",
@@ -54,7 +54,7 @@
5454
"@sebbo2002/semantic-release-jsr": "^1.0.0",
5555
"@solana/wallet-standard-features": "^1.3.0",
5656
"@types/jest": "^29.2.5",
57-
"husky": "^4.3.0",
57+
"husky": "^4.3.8",
5858
"jest": "^29.3.1",
5959
"npm-run-all": "^4.1.5",
6060
"prettier": "^2.5.1",

pnpm-lock.yaml

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

supabase/.temp/cli-latest

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
v2.22.12
1+
v2.24.3

test/deno/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
deno.json

test/deno/integration.test.ts

Lines changed: 147 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,147 @@
1+
import { assertEquals, assertExists } from 'https://deno.land/[email protected]/assert/mod.ts'
2+
import { createClient, SupabaseClient } from '../../dist/module/index.js'
3+
import type { RealtimeChannel } from '../../dist/module/index.js'
4+
5+
// These tests assume that a local Supabase server is already running
6+
// Start a local Supabase instance with 'supabase start' before running these tests
7+
8+
// TODO: Remove sanitizeOps and sanitizeResources once the issue is fixed
9+
Deno.test(
10+
'Supabase Integration Tests',
11+
{ sanitizeOps: false, sanitizeResources: false },
12+
async (t) => {
13+
// Default local dev credentials from Supabase CLI
14+
const SUPABASE_URL = 'http://127.0.0.1:54321'
15+
const ANON_KEY =
16+
'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZS1kZW1vIiwicm9sZSI6ImFub24iLCJleHAiOjE5ODM4MTI5OTZ9.CRXP1A7WOeoJeXxjNni43kdQwgnWNReilDMblYTn_I0'
17+
18+
const supabase = createClient(SUPABASE_URL, ANON_KEY, {
19+
realtime: { heartbeatIntervalMs: 500 },
20+
})
21+
22+
// Cleanup function to be called after all tests
23+
const cleanup = async () => {
24+
await supabase.auth.signOut()
25+
await supabase.auth.stopAutoRefresh()
26+
await supabase.removeAllChannels()
27+
// Give some time for cleanup to complete
28+
await new Promise((resolve) => setTimeout(resolve, 1000))
29+
}
30+
31+
try {
32+
await t.step('should connect to Supabase instance', () => {
33+
assertExists(supabase)
34+
assertEquals(supabase instanceof SupabaseClient, true)
35+
})
36+
37+
await t.step('PostgREST - should query data from public schema', async () => {
38+
const { data, error } = await supabase.from('todos').select('*').limit(5)
39+
40+
// The default schema includes a 'todos' table, but it might be empty
41+
assertEquals(error, null)
42+
assertEquals(Array.isArray(data), true)
43+
})
44+
45+
await t.step('PostgREST - should create and delete a todo', async () => {
46+
// Create a new todo
47+
const { data: createdTodo, error: createError } = await supabase
48+
.from('todos')
49+
.insert({ task: 'Integration Test Todo', is_complete: false })
50+
.select()
51+
.single()
52+
53+
assertEquals(createError, null)
54+
assertExists(createdTodo)
55+
assertEquals(createdTodo!.task, 'Integration Test Todo')
56+
assertEquals(createdTodo!.is_complete, false)
57+
58+
// Delete the created todo
59+
const { error: deleteError } = await supabase
60+
.from('todos')
61+
.delete()
62+
.eq('id', createdTodo!.id)
63+
64+
assertEquals(deleteError, null)
65+
66+
// Verify the todo was deleted
67+
const { data: fetchedTodo, error: fetchError } = await supabase
68+
.from('todos')
69+
.select('*')
70+
.eq('id', createdTodo!.id)
71+
.single()
72+
73+
assertExists(fetchError)
74+
assertEquals(fetchedTodo, null)
75+
})
76+
77+
await t.step('Authentication - should sign up a user', async () => {
78+
const email = `test-${Date.now()}@example.com`
79+
const password = 'password123'
80+
81+
const { data, error } = await supabase.auth.signUp({
82+
email,
83+
password,
84+
})
85+
86+
assertEquals(error, null)
87+
assertExists(data.user)
88+
assertEquals(data.user!.email, email)
89+
})
90+
91+
await t.step('Realtime - is able to connect and broadcast', async () => {
92+
const channelName = `channel-${crypto.randomUUID()}`
93+
let channel: RealtimeChannel
94+
const email = `test-${Date.now()}@example.com`
95+
const password = 'password123'
96+
97+
// Sign up and create channel
98+
await supabase.auth.signUp({ email, password })
99+
const config = { broadcast: { self: true }, private: true }
100+
channel = supabase.channel(channelName, { config })
101+
await supabase.realtime.setAuth()
102+
103+
const testMessage = { message: 'test' }
104+
let receivedMessage: any
105+
let subscribed = false
106+
let attempts = 0
107+
108+
channel
109+
.on('broadcast', { event: '*' }, (payload: unknown) => (receivedMessage = payload))
110+
.subscribe((status: string) => {
111+
if (status == 'SUBSCRIBED') subscribed = true
112+
})
113+
114+
// Wait for subscription
115+
while (!subscribed) {
116+
if (attempts > 50) throw new Error('Timeout waiting for subscription')
117+
await new Promise((resolve) => setTimeout(resolve, 100))
118+
attempts++
119+
}
120+
121+
attempts = 0
122+
123+
channel.send({
124+
type: 'broadcast',
125+
event: 'test-event',
126+
payload: testMessage,
127+
})
128+
129+
// Wait on message
130+
while (!receivedMessage) {
131+
if (attempts > 50) throw new Error('Timeout waiting for message')
132+
await new Promise((resolve) => setTimeout(resolve, 100))
133+
attempts++
134+
}
135+
136+
assertExists(receivedMessage)
137+
assertEquals(supabase.realtime.getChannels().length, 1)
138+
139+
// Cleanup channel
140+
await channel.unsubscribe()
141+
})
142+
} finally {
143+
// Ensure cleanup runs even if tests fail
144+
await cleanup()
145+
}
146+
}
147+
)

test/deno/package-lock.json

Lines changed: 52 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/deno/package.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"name": "test-deno",
3+
"private": true,
4+
"scripts": {
5+
"test": "npm run setup-deps && deno test --allow-all --unstable-sloppy-imports integration.test.ts",
6+
"setup-deps": "node setup-deps.js"
7+
},
8+
"dependencies": {
9+
"@supabase/supabase-js": "file:../../"
10+
}
11+
}

0 commit comments

Comments
 (0)