Skip to content

Commit 97872e7

Browse files
committed
test(repo): test module resolution
1 parent 5cfe464 commit 97872e7

File tree

9 files changed

+247
-28
lines changed

9 files changed

+247
-28
lines changed

.github/workflows/ci-supabase-js.yml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,42 @@ jobs:
110110
parallel-finished: true
111111
fail-on-error: false
112112
continue-on-error: true
113+
114+
module-resolution:
115+
name: Module Resolution Tests
116+
runs-on: ubuntu-latest
117+
needs: build-package
118+
steps:
119+
- name: Checkout code
120+
uses: actions/checkout@v4
121+
with:
122+
filter: tree:0
123+
fetch-depth: 0
124+
125+
- name: Setup Node.js
126+
uses: actions/setup-node@v4
127+
with:
128+
node-version: ${{ env.NODE_VERSION }}
129+
cache: 'npm'
130+
131+
- name: Install dependencies
132+
run: npm ci
133+
134+
- name: Download build artifacts
135+
uses: actions/download-artifact@v4
136+
with:
137+
name: packages-dist
138+
path: ./packages/core
139+
140+
- name: Validate package exports (attw)
141+
run: npx nx test:exports supabase-js
142+
143+
- name: Test ESM imports
144+
run: npx nx test:esm supabase-js
145+
146+
- name: Test CJS requires
147+
run: npx nx test:cjs supabase-js
148+
113149
deno-tests:
114150
name: Deno Tests
115151
runs-on: ubuntu-latest

package-lock.json

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

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
},
2020
"private": true,
2121
"devDependencies": {
22+
"@arethetypeswrong/cli": "^0.18.2",
2223
"@commitlint/cli": "^19.8.1",
2324
"@commitlint/config-conventional": "^19.8.1",
2425
"@commitlint/cz-commitlint": "^19.8.1",

packages/core/realtime-js/example/package-lock.json

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

packages/core/realtime-js/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@
4646
"ws": "^8.18.2"
4747
},
4848
"devDependencies": {
49-
"@arethetypeswrong/cli": "^0.16.4",
5049
"@vitest/coverage-v8": "^3.1.4",
5150
"esm": "^3.2.25",
5251
"jsdom": "^16.7.0",

packages/core/supabase-js/package.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,10 @@
5656
"test:expo": "cd test/integration/expo && npm test",
5757
"test:next": "cd test/integration/next && npm test",
5858
"test:types": "tsd --files test/types/*.test-d.ts && jsr publish --dry-run --allow-dirty",
59+
"test:exports": "attw --pack .",
60+
"test:esm": "node test/module-resolution.test.mjs",
61+
"test:cjs": "node test/module-resolution.test.cjs",
62+
"test:module-resolution": "npm run test:exports && npm run test:esm && npm run test:cjs",
5963
"docs": "typedoc --entryPoints src/index.ts --out docs/v2",
6064
"docs:json": "typedoc --entryPoints src/index.ts --json docs/v2/spec.json --excludeExternals",
6165
"serve:coverage": "npx nx test:coverage supabase-js && serve test/coverage",

packages/core/supabase-js/test/integration/node-browser/index.html

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,19 @@
8181
return originalSetInterval.apply(this, [fn, delay, ...args])
8282
}
8383

84+
// Verify all clients are bundled (catches AuthClient null bug from 2.86.1)
85+
log('Verifying bundled clients...')
86+
const testClient = createClient('https://example.supabase.co', 'test-key')
87+
if (!testClient.auth) throw new Error('auth client missing (AuthClient null bug)')
88+
if (typeof testClient.auth.signUp !== 'function') throw new Error('auth.signUp missing')
89+
if (typeof testClient.auth.getSession !== 'function')
90+
throw new Error('auth.getSession missing')
91+
if (!testClient.storage) throw new Error('storage client missing')
92+
if (!testClient.functions) throw new Error('functions client missing')
93+
if (typeof testClient.from !== 'function') throw new Error('postgrest client missing')
94+
if (typeof testClient.channel !== 'function') throw new Error('realtime client missing')
95+
log('All clients bundled correctly')
96+
8497
log('Creating Supabase client with WebSocket transport and vsn: ' + vsn + '...')
8598
const supabase = createClient(
8699
'http://127.0.0.1:54321',
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
/**
2+
* Module Resolution Tests (CommonJS)
3+
*
4+
* Tests that the package works correctly when required via CommonJS.
5+
* This catches issues like the wrapper.mjs bug that broke jsdelivr CDN imports.
6+
*
7+
* Run with: node test/module-resolution.test.cjs
8+
*/
9+
10+
const assert = require('assert')
11+
12+
console.log('Testing CommonJS require...\n')
13+
14+
// Test 1: Main export works
15+
console.log('1. Testing main export...')
16+
const supabase = require('../dist/index.cjs')
17+
assert(supabase, 'Main export should exist')
18+
assert(typeof supabase.createClient === 'function', 'createClient should be a function')
19+
console.log(' ✅ Main export works\n')
20+
21+
// Test 2: createClient works
22+
console.log('2. Testing createClient...')
23+
const { createClient } = supabase
24+
const client = createClient('https://example.supabase.co', 'test-key')
25+
assert(client, 'Client should be created')
26+
console.log(' ✅ createClient works\n')
27+
28+
// Test 3: Auth client exists and has methods
29+
console.log('3. Testing Auth client...')
30+
assert(client.auth, 'client.auth should exist')
31+
assert(typeof client.auth.signUp === 'function', 'auth.signUp should be a function')
32+
assert(
33+
typeof client.auth.signInWithPassword === 'function',
34+
'auth.signInWithPassword should be a function'
35+
)
36+
assert(typeof client.auth.signOut === 'function', 'auth.signOut should be a function')
37+
assert(typeof client.auth.getSession === 'function', 'auth.getSession should be a function')
38+
assert(typeof client.auth.getUser === 'function', 'auth.getUser should be a function')
39+
assert(
40+
typeof client.auth.onAuthStateChange === 'function',
41+
'auth.onAuthStateChange should be a function'
42+
)
43+
console.log(' ✅ Auth client works\n')
44+
45+
// Test 4: PostgREST client exists
46+
console.log('4. Testing PostgREST client...')
47+
assert(typeof client.from === 'function', 'client.from should be a function')
48+
const query = client.from('test')
49+
assert(query, 'from() should return a query builder')
50+
console.log(' ✅ PostgREST client works\n')
51+
52+
// Test 5: Storage client exists
53+
console.log('5. Testing Storage client...')
54+
assert(client.storage, 'client.storage should exist')
55+
assert(typeof client.storage.from === 'function', 'storage.from should be a function')
56+
console.log(' ✅ Storage client works\n')
57+
58+
// Test 6: Functions client exists
59+
console.log('6. Testing Functions client...')
60+
assert(client.functions, 'client.functions should exist')
61+
assert(typeof client.functions.invoke === 'function', 'functions.invoke should be a function')
62+
console.log(' ✅ Functions client works\n')
63+
64+
// Test 7: Realtime client exists
65+
console.log('7. Testing Realtime client...')
66+
assert(typeof client.channel === 'function', 'client.channel should be a function')
67+
assert(typeof client.removeChannel === 'function', 'client.removeChannel should be a function')
68+
console.log(' ✅ Realtime client works\n')
69+
70+
console.log('🎉 All CommonJS tests passed!')
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
/**
2+
* Module Resolution Tests (ESM)
3+
*
4+
* Tests that the package works correctly when imported via ESM.
5+
* This catches issues like the wrapper.mjs bug that broke jsdelivr CDN imports.
6+
*
7+
* Run with: node test/module-resolution.test.mjs
8+
*/
9+
10+
import assert from 'assert'
11+
12+
console.log('Testing ESM import...\n')
13+
14+
// Test 1: Named exports work
15+
console.log('1. Testing named exports...')
16+
const { createClient } = await import('../dist/index.mjs')
17+
assert(typeof createClient === 'function', 'createClient should be a function')
18+
console.log(' ✅ Named exports work\n')
19+
20+
// Test 2: createClient works
21+
console.log('2. Testing createClient...')
22+
const client = createClient('https://example.supabase.co', 'test-key')
23+
assert(client, 'Client should be created')
24+
console.log(' ✅ createClient works\n')
25+
26+
// Test 3: Auth client exists and has methods (this is what broke in 2.86.1)
27+
console.log('3. Testing Auth client (AuthClient null bug check)...')
28+
assert(client.auth, 'client.auth should exist (was null in 2.86.1 bug)')
29+
assert(typeof client.auth.signUp === 'function', 'auth.signUp should be a function')
30+
assert(
31+
typeof client.auth.signInWithPassword === 'function',
32+
'auth.signInWithPassword should be a function'
33+
)
34+
assert(typeof client.auth.signOut === 'function', 'auth.signOut should be a function')
35+
assert(typeof client.auth.getSession === 'function', 'auth.getSession should be a function')
36+
assert(typeof client.auth.getUser === 'function', 'auth.getUser should be a function')
37+
assert(
38+
typeof client.auth.onAuthStateChange === 'function',
39+
'auth.onAuthStateChange should be a function'
40+
)
41+
console.log(' ✅ Auth client works (no AuthClient null bug)\n')
42+
43+
// Test 4: PostgREST client exists
44+
console.log('4. Testing PostgREST client...')
45+
assert(typeof client.from === 'function', 'client.from should be a function')
46+
const query = client.from('test')
47+
assert(query, 'from() should return a query builder')
48+
console.log(' ✅ PostgREST client works\n')
49+
50+
// Test 5: Storage client exists
51+
console.log('5. Testing Storage client...')
52+
assert(client.storage, 'client.storage should exist')
53+
assert(typeof client.storage.from === 'function', 'storage.from should be a function')
54+
console.log(' ✅ Storage client works\n')
55+
56+
// Test 6: Functions client exists
57+
console.log('6. Testing Functions client...')
58+
assert(client.functions, 'client.functions should exist')
59+
assert(typeof client.functions.invoke === 'function', 'functions.invoke should be a function')
60+
console.log(' ✅ Functions client works\n')
61+
62+
// Test 7: Realtime client exists
63+
console.log('7. Testing Realtime client...')
64+
assert(typeof client.channel === 'function', 'client.channel should be a function')
65+
assert(typeof client.removeChannel === 'function', 'client.removeChannel should be a function')
66+
console.log(' ✅ Realtime client works\n')
67+
68+
// Test 8: Type exports (check they don't throw)
69+
console.log('8. Testing type re-exports...')
70+
const mod = await import('../dist/index.mjs')
71+
// These should all be importable without errors
72+
const exports = Object.keys(mod)
73+
assert(exports.includes('createClient'), 'Should export createClient')
74+
console.log(` ✅ Module exports ${exports.length} items\n`)
75+
76+
console.log('🎉 All ESM tests passed!')

0 commit comments

Comments
 (0)