Skip to content

added test for issue 1470 #1512

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,9 @@ jobs:
- name: Run Unit Tests + Coverage
run: npm run test:coverage

- name: Run isows Compatibility Test
run: npm run test:isows-compatibility

- name: Upload coverage results to Coveralls
uses: coverallsapp/github-action@v2
with:
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
"test:coverage": "jest --runInBand --coverage --testPathIgnorePatterns=\"test/integration|test/deno\"",
"test:integration": "jest --runInBand --detectOpenHandles test/integration.test.ts",
"test:integration:browser": "deno test --allow-all test/integration.browser.test.ts",
"test:isows-compatibility": "jest --runInBand --detectOpenHandles test/isowsAbsentsCompatibility.test.ts",
"test:watch": "jest --watch --verbose false --silent false",
"test:node:playwright": "cd test/integration/node-browser && npm install && cp ../../../dist/umd/supabase.js . && npm run test",
"test:bun": "cd test/integration/bun && bun install && bun test",
Expand Down
79 changes: 79 additions & 0 deletions test/isowsAbsentsCompatibility.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
import * as fs from 'fs'
import * as path from 'path'

// Simulates isows removal (like in server environments)
function simulateIsowsRemoval(): { backupPath: string; originalPath: string } {
const originalPath = path.join(__dirname, '..', 'node_modules', 'isows')
const backupPath = path.join(__dirname, '..', 'node_modules', 'isows_backup')

try {
if (fs.existsSync(originalPath)) {
fs.renameSync(originalPath, backupPath)
console.log('📦 isows temporarily removed (server environment simulation)')
}
} catch (error) {
console.log('⚠️ Failed to remove isows:', (error as Error).message)
}

return { backupPath, originalPath }
}

// Restores isows
function restoreIsows(backupPath: string, originalPath: string): void {
try {
if (fs.existsSync(backupPath)) {
fs.renameSync(backupPath, originalPath)
console.log('📦 isows restored')
}
} catch (error) {
console.log('⚠️ Failed to restore isows:', (error as Error).message)
}
}

function testIsowsAvailability(): boolean {
try {
require('isows')
return true
} catch {
console.log('isows is not available')
return false
}
}

function testRealtimeClientCreation(): boolean {
try {
const { RealtimeClient } = require('@supabase/realtime-js')
new RealtimeClient('ws://localhost:54321/realtime/v1')
return true
} catch {
console.log('realtime client is not available')
return false
}
}

/**
* Jest test for isows compatibility
*/

describe('isows compatibility', () => {
let backupPath: string
let originalPath: string

beforeEach(() => {
;({ backupPath, originalPath } = simulateIsowsRemoval())
console.log('backupPath', backupPath)
console.log('originalPath', originalPath)
})

afterEach(() => {
restoreIsows(backupPath, originalPath)
})

it('should work without isows dependency', () => {
const isowsAvailable = testIsowsAvailability()
const isRealtimeClientWorks = testRealtimeClientCreation()

expect(isowsAvailable).toBe(false)
expect(isRealtimeClientWorks).toBe(true) // should be true because realtime-js doesn't use isows
})
})
Loading