From 47dca53afaab49604a242cb438d03f29a33cacab Mon Sep 17 00:00:00 2001 From: Danilo Alonso Date: Wed, 26 Jun 2024 17:52:02 -0400 Subject: [PATCH] test: fix leaky globals --- lib/client.js | 4 +++- test/client.js | 2 ++ test/listener.js | 7 ------- 3 files changed, 5 insertions(+), 8 deletions(-) diff --git a/lib/client.js b/lib/client.js index 3801937..943b5f0 100755 --- a/lib/client.js +++ b/lib/client.js @@ -104,7 +104,9 @@ options = options || {}; - this._isBrowser = typeof WebSocket !== 'undefined' && global.window !== undefined; + // $lab:coverage:off$ + this._isBrowser = typeof WebSocket !== 'undefined' && typeof window !== 'undefined'; + // $lab:coverage:on$ if (!this._isBrowser) { options.ws = options.ws || {}; diff --git a/test/client.js b/test/client.js index 01baa0f..0445fce 100755 --- a/test/client.js +++ b/test/client.js @@ -54,6 +54,8 @@ describe('Client', () => { delete global.WebSocket; } + delete global.window; + Nes.Client.WebSocket = Ws; return new Ws(...args); diff --git a/test/listener.js b/test/listener.js index 5dba72f..cd98ef3 100755 --- a/test/listener.js +++ b/test/listener.js @@ -106,15 +106,8 @@ describe('Listener', () => { await server.register({ plugin: Nes, options: { auth: false, origin: ['http://localhost:12345'] } }); await server.start(); - - // mimick a server connection because WebSocket in node 22 - // does not work like it does in the browser - const orig = global.WebSocket; - delete global.WebSocket; const client = new Nes.Client(getUri(server.info), { ws: { origin: 'http://localhost:12345' } }); await client.connect(); - - global.WebSocket = orig; client.disconnect(); await server.stop(); });