|
| 1 | +import * as fs from 'fs' |
| 2 | +import * as path from 'path' |
| 3 | + |
| 4 | +// Simulates isows removal (like in server environments) |
| 5 | +function simulateIsowsRemoval(): { backupPath: string; originalPath: string } { |
| 6 | + const originalPath = path.join(__dirname, '..', 'node_modules', 'isows') |
| 7 | + const backupPath = path.join(__dirname, '..', 'node_modules', 'isows_backup') |
| 8 | + |
| 9 | + try { |
| 10 | + if (fs.existsSync(originalPath)) { |
| 11 | + fs.renameSync(originalPath, backupPath) |
| 12 | + console.log('📦 isows temporarily removed (server environment simulation)') |
| 13 | + } |
| 14 | + } catch (error) { |
| 15 | + console.log('⚠️ Failed to remove isows:', (error as Error).message) |
| 16 | + } |
| 17 | + |
| 18 | + return { backupPath, originalPath } |
| 19 | +} |
| 20 | + |
| 21 | +// Restores isows |
| 22 | +function restoreIsows(backupPath: string, originalPath: string): void { |
| 23 | + try { |
| 24 | + if (fs.existsSync(backupPath)) { |
| 25 | + fs.renameSync(backupPath, originalPath) |
| 26 | + console.log('📦 isows restored') |
| 27 | + } |
| 28 | + } catch (error) { |
| 29 | + console.log('⚠️ Failed to restore isows:', (error as Error).message) |
| 30 | + } |
| 31 | +} |
| 32 | + |
| 33 | +function testIsowsAvailability(): boolean { |
| 34 | + try { |
| 35 | + require('isows') |
| 36 | + return true |
| 37 | + } catch { |
| 38 | + console.log('isows is not available') |
| 39 | + return false |
| 40 | + } |
| 41 | +} |
| 42 | + |
| 43 | +function testRealtimeClientCreation(): boolean { |
| 44 | + try { |
| 45 | + const { RealtimeClient } = require('@supabase/realtime-js') |
| 46 | + new RealtimeClient('ws://localhost:54321/realtime/v1') |
| 47 | + return true |
| 48 | + } catch { |
| 49 | + console.log('realtime client is not available') |
| 50 | + return false |
| 51 | + } |
| 52 | +} |
| 53 | + |
| 54 | +/** |
| 55 | + * Jest test for isows compatibility |
| 56 | + */ |
| 57 | + |
| 58 | +describe('isows compatibility', () => { |
| 59 | + let backupPath: string |
| 60 | + let originalPath: string |
| 61 | + |
| 62 | + beforeEach(() => { |
| 63 | + ;({ backupPath, originalPath } = simulateIsowsRemoval()) |
| 64 | + console.log('backupPath', backupPath) |
| 65 | + console.log('originalPath', originalPath) |
| 66 | + }) |
| 67 | + |
| 68 | + afterEach(() => { |
| 69 | + restoreIsows(backupPath, originalPath) |
| 70 | + }) |
| 71 | + |
| 72 | + it('should work without isows dependency', () => { |
| 73 | + const isowsAvailable = testIsowsAvailability() |
| 74 | + const isRealtimeClientWorks = testRealtimeClientCreation() |
| 75 | + |
| 76 | + expect(isowsAvailable).toBe(false) |
| 77 | + expect(isRealtimeClientWorks).toBe(true) // should be true because realtime-js doesn't use isows |
| 78 | + }) |
| 79 | +}) |
0 commit comments