From 59b4084b18f488614904512e80d18df37b90c5b7 Mon Sep 17 00:00:00 2001 From: "georgiy.rusanov" Date: Mon, 28 Jul 2025 00:58:45 +0200 Subject: [PATCH] added test for issue 1470 --- .github/workflows/ci.yml | 3 + package.json | 1 + test/isowsAbsentsCompatibility.test.ts | 79 ++++++++++++++++++++++++++ 3 files changed, 83 insertions(+) create mode 100644 test/isowsAbsentsCompatibility.test.ts diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index b5105729..6ba045d5 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -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: diff --git a/package.json b/package.json index 8dab6ac8..1175f2e6 100644 --- a/package.json +++ b/package.json @@ -36,6 +36,7 @@ "test:integration": "jest --runInBand --detectOpenHandles test/integration.test.ts", "test:integration:browser": "deno test --allow-all test/integration.browser.test.ts", "test:edge-functions": "deno test --allow-all --no-check test/deno/edge-functions-integration.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", diff --git a/test/isowsAbsentsCompatibility.test.ts b/test/isowsAbsentsCompatibility.test.ts new file mode 100644 index 00000000..3cc96f45 --- /dev/null +++ b/test/isowsAbsentsCompatibility.test.ts @@ -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 + }) +})