Skip to content

Commit 62ee92a

Browse files
georgRusanovgeorgiy.rusanov
andauthored
test: add bun test (#1478)
* use tgz for next and deno * added bun test --------- Co-authored-by: georgiy.rusanov <georgiy.rusanov@ringcentral.com>
1 parent 6fbcfca commit 62ee92a

File tree

11 files changed

+227
-7697
lines changed

11 files changed

+227
-7697
lines changed

.github/workflows/ci.yml

Lines changed: 54 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ jobs:
9696
deno-tests:
9797
name: Deno Tests / ${{ matrix.deno }}
9898
runs-on: ubuntu-latest
99+
needs: build-package
99100
strategy:
100101
matrix:
101102
deno: ['1.x', '2.x']
@@ -119,6 +120,11 @@ jobs:
119120
with:
120121
node-version: ${{ env.NODE_VERSION }}
121122
cache: 'npm'
123+
- name: Download artifact
124+
uses: actions/download-artifact@v4
125+
with:
126+
name: supabase-tgz
127+
path: ./supabase-pkg
122128

123129
- name: Start Supabase
124130
run: supabase start
@@ -131,7 +137,8 @@ jobs:
131137
- name: Run Deno Tests
132138
run: |
133139
cd test/deno
134-
npm ci
140+
cp ../../supabase-pkg/supabase-supabase-js-0.0.0-automated.tgz .
141+
npm install
135142
npm test || npm test
136143
137144
- name: Run integration and browser tests on Deno 2.x only
@@ -190,6 +197,12 @@ jobs:
190197
node-version: ${{ env.NODE_VERSION }}
191198
cache: 'npm'
192199

200+
- name: Download artifact
201+
uses: actions/download-artifact@v4
202+
with:
203+
name: supabase-tgz
204+
path: ./supabase-pkg
205+
193206
- name: Setup Supabase CLI
194207
uses: supabase/setup-cli@v1
195208
with:
@@ -204,7 +217,8 @@ jobs:
204217
- name: Run integration tests
205218
run: |
206219
cd test/integration/next
207-
npm ci
220+
cp ../../../supabase-pkg/supabase-supabase-js-0.0.0-automated.tgz .
221+
npm install --legacy-peer-deps
208222
npx playwright install
209223
npm run test
210224
@@ -251,6 +265,44 @@ jobs:
251265
if: always()
252266
run: supabase stop
253267

268+
bun-integration:
269+
name: Bun Integration
270+
runs-on: ubuntu-latest
271+
needs: build-package
272+
steps:
273+
- name: Checkout code
274+
uses: actions/checkout@v4
275+
276+
- name: Setup Bun
277+
uses: oven-sh/setup-bun@v1
278+
with:
279+
bun-version: latest
280+
281+
- name: Setup Supabase CLI
282+
uses: supabase/setup-cli@v1
283+
with:
284+
version: latest
285+
286+
- name: Download artifact
287+
uses: actions/download-artifact@v4
288+
with:
289+
name: supabase-tgz
290+
path: ./supabase-pkg
291+
292+
- name: Start Supabase
293+
run: supabase start
294+
295+
- name: Install dependencies and run tests
296+
run: |
297+
cd test/integration/bun
298+
cp ../../../supabase-pkg/supabase-supabase-js-0.0.0-automated.tgz .
299+
bun install
300+
bun test
301+
302+
- name: Stop Supabase
303+
if: always()
304+
run: supabase stop
305+
254306
websocket-browser-tests:
255307
name: WebSocket Browser Tests
256308
runs-on: ubuntu-latest

README.md

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,47 @@ supabase start
9898
pnpm run test:integration
9999
```
100100

101+
### Expo Testing
102+
103+
The project includes Expo integration tests to ensure compatibility with React Native environments.
104+
105+
### Next.js Testing
106+
107+
The project includes Next.js integration tests to ensure compatibility with React SSR environments.
108+
109+
### Deno Testing
110+
111+
The project includes Deno integration tests to ensure compatibility with Deno runtime.
112+
113+
### Bun Testing
114+
115+
The project includes Bun integration tests to ensure compatibility with Bun runtime.
116+
117+
#### CI/CD Testing
118+
119+
When running on CI, the tests automatically use the latest dependencies from the root project. The CI pipeline:
120+
121+
1. Builds the main project with current dependencies
122+
2. Creates a package archive (`.tgz`) with the latest versions
123+
3. Uses this archive in Expo, Next.js, and Deno tests to ensure consistency
124+
125+
#### Local Development
126+
127+
For local development of Expo, Next.js, and Deno tests, you can update dependencies using automated scripts:
128+
129+
```bash
130+
# Update all test dependencies at once
131+
npm run update:test-deps
132+
133+
# Or update specific test environments:
134+
npm run update:test-deps:expo # Expo tests only
135+
npm run update:test-deps:next # Next.js tests only
136+
npm run update:test-deps:deno # Deno tests only
137+
npm run update:test-deps:bun # Bun tests only
138+
```
139+
140+
**Note:** The CI automatically handles dependency synchronization, so manual updates are only needed for local development and testing.
141+
101142
## Badges
102143

103144
[![Coverage Status](https://coveralls.io/repos/github/supabase/supabase-js/badge.svg?branch=master)](https://coveralls.io/github/supabase/supabase-js?branch=master)

package.json

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,16 @@
3737
"test:integration:browser": "deno test --allow-all test/integration.browser.test.ts",
3838
"test:watch": "jest --watch --verbose false --silent false",
3939
"test:node:playwright": "cd test/integration/node-browser && npm install && cp ../../../dist/umd/supabase.js . && npm run test",
40+
"test:bun": "cd test/integration/bun && bun install && bun test",
4041
"test:types": "run-s build:module && tsd --files test/types/*.test-d.ts",
4142
"docs": "typedoc --entryPoints src/index.ts --out docs/v2 --includes src/**/*.ts",
4243
"docs:json": "typedoc --entryPoints src/index.ts --includes src/**/*.ts --json docs/v2/spec.json --excludeExternals",
43-
"serve:coverage": "npm run test:coverage && serve test/coverage"
44+
"serve:coverage": "npm run test:coverage && serve test/coverage",
45+
"update:test-deps": "npm run build && npm pack && cp supabase-supabase-js-*.tgz test/integration/expo/supabase-supabase-js-0.0.0-automated.tgz && cp supabase-supabase-js-*.tgz test/integration/next/supabase-supabase-js-0.0.0-automated.tgz && cp supabase-supabase-js-*.tgz test/deno/supabase-supabase-js-0.0.0-automated.tgz && cp supabase-supabase-js-*.tgz test/integration/bun/supabase-supabase-js-0.0.0-automated.tgz && cd test/integration/expo && npm install && cd ../next && npm install --legacy-peer-deps && cd ../../deno && npm install && cd ../integration/bun && bun install",
46+
"update:test-deps:expo": "npm run build && npm pack && cp supabase-supabase-js-*.tgz test/integration/expo/supabase-supabase-js-0.0.0-automated.tgz && cd test/integration/expo && npm install",
47+
"update:test-deps:next": "npm run build && npm pack && cp supabase-supabase-js-*.tgz test/integration/next/supabase-supabase-js-0.0.0-automated.tgz && cd test/integration/next && npm install --legacy-peer-deps",
48+
"update:test-deps:deno": "npm run build && npm pack && cp supabase-supabase-js-*.tgz test/deno/supabase-supabase-js-0.0.0-automated.tgz && cd test/deno && npm install",
49+
"update:test-deps:bun": "npm run build && npm pack && cp supabase-supabase-js-*.tgz test/integration/bun/supabase-supabase-js-0.0.0-automated.tgz && cd test/integration/bun && bun install"
4450
},
4551
"dependencies": {
4652
"@supabase/auth-js": "2.70.0",

test/deno/package-lock.json

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

test/deno/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@
66
"setup-deps": "node setup-deps.js"
77
},
88
"dependencies": {
9-
"@supabase/supabase-js": "file:../../"
9+
"@supabase/supabase-js": "file:supabase-supabase-js-0.0.0-automated.tgz"
1010
}
1111
}

test/deno/setup-deps.js

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,17 @@ const path = require('node:path')
77
const scriptDir = __dirname
88
const projectRoot = path.dirname(path.dirname(scriptDir))
99

10-
// Read package-lock.json
11-
const packageLockPath = path.join(projectRoot, 'package-lock.json')
12-
const packageLock = JSON.parse(fs.readFileSync(packageLockPath, 'utf8'))
10+
// Read package.json from main project
11+
const packageJsonPath = path.join(projectRoot, 'package.json')
12+
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'))
1313

14-
// Extract versions from package-lock.json
14+
// Extract versions from package.json dependencies
1515
const getVersion = (packageName) => {
16-
const packagePath = `node_modules/${packageName}`
17-
return packageLock.packages[packagePath]?.version
16+
const dependencies = packageJson.dependencies || {}
17+
const devDependencies = packageJson.devDependencies || {}
18+
19+
// Check both dependencies and devDependencies
20+
return dependencies[packageName] || devDependencies[packageName] || null
1821
}
1922

2023
const versions = {
@@ -54,4 +57,5 @@ denoJson.imports = {
5457
// Write updated deno.json
5558
fs.writeFileSync(denoJsonPath, JSON.stringify(denoJson, null, 2) + '\n')
5659

57-
console.log('Updated deno.json with versions from package-lock.json')
60+
console.log('Updated deno.json with versions from package.json')
61+
console.log('Versions used:', versions)

test/integration/bun/bun.lock

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
{
2+
"lockfileVersion": 1,
3+
"workspaces": {
4+
"": {
5+
"name": "test-bun",
6+
"dependencies": {
7+
"@supabase/supabase-js": "file:supabase-supabase-js-0.0.0-automated.tgz",
8+
},
9+
"devDependencies": {
10+
"bun-types": "latest",
11+
},
12+
},
13+
},
14+
"packages": {
15+
"@supabase/auth-js": ["@supabase/auth-js@2.70.0", "", { "dependencies": { "@supabase/node-fetch": "^2.6.14" } }, "sha512-BaAK/tOAZFJtzF1sE3gJ2FwTjLf4ky3PSvcvLGEgEmO4BSBkwWKu8l67rLLIBZPDnCyV7Owk2uPyKHa0kj5QGg=="],
16+
17+
"@supabase/functions-js": ["@supabase/functions-js@2.4.5", "", { "dependencies": { "@supabase/node-fetch": "^2.6.14" } }, "sha512-v5GSqb9zbosquTo6gBwIiq7W9eQ7rE5QazsK/ezNiQXdCbY+bH8D9qEaBIkhVvX4ZRW5rP03gEfw5yw9tiq4EQ=="],
18+
19+
"@supabase/node-fetch": ["@supabase/node-fetch@2.6.15", "", { "dependencies": { "whatwg-url": "^5.0.0" } }, "sha512-1ibVeYUacxWYi9i0cf5efil6adJ9WRyZBLivgjs+AUpewx1F3xPi7gLgaASI2SmIQxPoCEjAsLAzKPgMJVgOUQ=="],
20+
21+
"@supabase/postgrest-js": ["@supabase/postgrest-js@1.19.4", "", { "dependencies": { "@supabase/node-fetch": "^2.6.14" } }, "sha512-O4soKqKtZIW3olqmbXXbKugUtByD2jPa8kL2m2c1oozAO11uCcGrRhkZL0kVxjBLrXHE0mdSkFsMj7jDSfyNpw=="],
22+
23+
"@supabase/realtime-js": ["@supabase/realtime-js@2.11.15", "", { "dependencies": { "@supabase/node-fetch": "^2.6.13", "@types/phoenix": "^1.6.6", "@types/ws": "^8.18.1", "isows": "^1.0.7", "ws": "^8.18.2" } }, "sha512-HQKRnwAqdVqJW/P9TjKVK+/ETpW4yQ8tyDPPtRMKOH4Uh3vQD74vmj353CYs8+YwVBKubeUOOEpI9CT8mT4obw=="],
24+
25+
"@supabase/storage-js": ["@supabase/storage-js@2.7.1", "", { "dependencies": { "@supabase/node-fetch": "^2.6.14" } }, "sha512-asYHcyDR1fKqrMpytAS1zjyEfvxuOIp1CIXX7ji4lHHcJKqyk+sLl/Vxgm4sN6u8zvuUtae9e4kDxQP2qrwWBA=="],
26+
27+
"@supabase/supabase-js": ["@supabase/supabase-js@supabase-supabase-js-0.0.0-automated.tgz", { "dependencies": { "@supabase/auth-js": "2.70.0", "@supabase/functions-js": "2.4.5", "@supabase/node-fetch": "2.6.15", "@supabase/postgrest-js": "1.19.4", "@supabase/realtime-js": "2.11.15", "@supabase/storage-js": "2.7.1" } }],
28+
29+
"@types/node": ["@types/node@24.0.10", "", { "dependencies": { "undici-types": "~7.8.0" } }, "sha512-ENHwaH+JIRTDIEEbDK6QSQntAYGtbvdDXnMXnZaZ6k13Du1dPMmprkEHIL7ok2Wl2aZevetwTAb5S+7yIF+enA=="],
30+
31+
"@types/phoenix": ["@types/phoenix@1.6.6", "", {}, "sha512-PIzZZlEppgrpoT2QgbnDU+MMzuR6BbCjllj0bM70lWoejMeNJAxCchxnv7J3XFkI8MpygtRpzXrIlmWUBclP5A=="],
32+
33+
"@types/react": ["@types/react@19.1.8", "", { "dependencies": { "csstype": "^3.0.2" } }, "sha512-AwAfQ2Wa5bCx9WP8nZL2uMZWod7J7/JSplxbTmBQ5ms6QpqNYm672H0Vu9ZVKVngQ+ii4R/byguVEUZQyeg44g=="],
34+
35+
"@types/ws": ["@types/ws@8.18.1", "", { "dependencies": { "@types/node": "*" } }, "sha512-ThVF6DCVhA8kUGy+aazFQ4kXQ7E1Ty7A3ypFOe0IcJV8O/M511G99AW24irKrW56Wt44yG9+ij8FaqoBGkuBXg=="],
36+
37+
"bun-types": ["bun-types@1.2.18", "", { "dependencies": { "@types/node": "*" }, "peerDependencies": { "@types/react": "^19" } }, "sha512-04+Eha5NP7Z0A9YgDAzMk5PHR16ZuLVa83b26kH5+cp1qZW4F6FmAURngE7INf4tKOvCE69vYvDEwoNl1tGiWw=="],
38+
39+
"csstype": ["csstype@3.1.3", "", {}, "sha512-M1uQkMl8rQK/szD0LNhtqxIPLpimGm8sOBwU7lLnCpSbTyY3yeU1Vc7l4KT5zT4s/yOxHH5O7tIuuLOCnLADRw=="],
40+
41+
"isows": ["isows@1.0.7", "", { "peerDependencies": { "ws": "*" } }, "sha512-I1fSfDCZL5P0v33sVqeTDSpcstAg/N+wF5HS033mogOVIp4B+oHC7oOCsA3axAbBSGTJ8QubbNmnIRN/h8U7hg=="],
42+
43+
"tr46": ["tr46@0.0.3", "", {}, "sha512-N3WMsuqV66lT30CrXNbEjx4GEwlow3v6rr4mCcv6prnfwhS01rkgyFdjPNBYd9br7LpXV1+Emh01fHnq2Gdgrw=="],
44+
45+
"undici-types": ["undici-types@7.8.0", "", {}, "sha512-9UJ2xGDvQ43tYyVMpuHlsgApydB8ZKfVYTsLDhXkFL/6gfkp+U8xTGdh8pMJv1SpZna0zxG1DwsKZsreLbXBxw=="],
46+
47+
"webidl-conversions": ["webidl-conversions@3.0.1", "", {}, "sha512-2JAn3z8AR6rjK8Sm8orRC0h/bcl/DqL7tRPdGZ4I1CjdF+EaMLmYxBHyXuKL849eucPFhvBoxMsflfOb8kxaeQ=="],
48+
49+
"whatwg-url": ["whatwg-url@5.0.0", "", { "dependencies": { "tr46": "~0.0.3", "webidl-conversions": "^3.0.0" } }, "sha512-saE57nupxk6v3HY35+jzBwYa0rKSy0XR8JSxZPwgLr7ys0IBzhGviA1/TUGJLmSVqs8pb9AnvICXEuOHLprYTw=="],
50+
51+
"ws": ["ws@8.18.3", "", { "peerDependencies": { "bufferutil": "^4.0.1", "utf-8-validate": ">=5.0.2" }, "optionalPeers": ["bufferutil", "utf-8-validate"] }, "sha512-PEIGCY5tSlUt50cqyMXfCzX+oOPqN0vuGqWzbcJ2xvnkzkq46oOpz7dQaTDBdfICb4N14+GARUDw2XV2N4tvzg=="],
52+
}
53+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import { test, expect } from 'bun:test'
2+
import { createClient } from '@supabase/supabase-js'
3+
4+
test('should subscribe to realtime channel', async () => {
5+
const SUPABASE_URL = 'http://127.0.0.1:54321'
6+
const ANON_KEY =
7+
'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZS1kZW1vIiwicm9sZSI6ImFub24iLCJleHAiOjE5ODM4MTI5OTZ9.CRXP1A7WOeoJeXxjNni43kdQwgnWNReilDMblYTn_I0'
8+
9+
const supabase = createClient(SUPABASE_URL, ANON_KEY, {
10+
realtime: { heartbeatIntervalMs: 500 },
11+
})
12+
13+
// Setup authentication
14+
await supabase.auth.signOut()
15+
const email = `bun-test-${Date.now()}@example.com`
16+
const password = 'password123'
17+
await supabase.auth.signUp({ email, password })
18+
await supabase.realtime.setAuth()
19+
20+
const channelName = `bun-channel-${crypto.randomUUID()}`
21+
const config = { broadcast: { self: true }, private: true }
22+
const channel = supabase.channel(channelName, { config })
23+
24+
let subscribed = false
25+
let attempts = 0
26+
27+
channel.subscribe((status) => {
28+
if (status === 'SUBSCRIBED') {
29+
subscribed = true
30+
}
31+
})
32+
33+
// Wait for subscription
34+
while (!subscribed) {
35+
if (attempts > 100) throw new Error('Timeout waiting for subscription')
36+
await new Promise((resolve) => setTimeout(resolve, 100))
37+
attempts++
38+
}
39+
40+
expect(subscribed).toBe(true)
41+
expect(supabase.realtime.getChannels().length).toBe(1)
42+
43+
// Cleanup
44+
await supabase.removeAllChannels()
45+
}, 10000)

test/integration/bun/package.json

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"name": "test-bun",
3+
"private": true,
4+
"scripts": {
5+
"test": "bun test integration.test.ts",
6+
"test:watch": "bun test --watch integration.test.ts"
7+
},
8+
"dependencies": {
9+
"@supabase/supabase-js": "file:supabase-supabase-js-0.0.0-automated.tgz"
10+
},
11+
"devDependencies": {
12+
"bun-types": "latest"
13+
}
14+
}

0 commit comments

Comments
 (0)