From 75fdfa9a2bb0f6f0cba2cd9e1b77b90cc1f5a6ff Mon Sep 17 00:00:00 2001 From: Luigi Pinca Date: Fri, 4 Feb 2022 22:17:50 +0100 Subject: [PATCH] [test] Fix nits --- test/websocket.test.js | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/test/websocket.test.js b/test/websocket.test.js index fe15ed7ca..1b1293fc6 100644 --- a/test/websocket.test.js +++ b/test/websocket.test.js @@ -1101,11 +1101,9 @@ describe('WebSocket', () => { }); it('emits an error if the redirect URL is invalid (1/2)', (done) => { - const onUpgrade = (req, socket) => { + server.once('upgrade', (req, socket) => { socket.end('HTTP/1.1 302 Found\r\nLocation: ws://\r\n\r\n'); - }; - - server.on('upgrade', onUpgrade); + }); const ws = new WebSocket(`ws://localhost:${server.address().port}`, { followRedirects: true @@ -1117,17 +1115,14 @@ describe('WebSocket', () => { assert.strictEqual(err.message, 'Invalid URL: ws://'); assert.strictEqual(ws._redirects, 1); - server.removeListener('upgrade', onUpgrade); ws.on('close', () => done()); }); }); it('emits an error if the redirect URL is invalid (2/2)', (done) => { - const onUpgrade = (req, socket) => { + server.once('upgrade', (req, socket) => { socket.end('HTTP/1.1 302 Found\r\nLocation: http://localhost\r\n\r\n'); - }; - - server.on('upgrade', onUpgrade); + }); const ws = new WebSocket(`ws://localhost:${server.address().port}`, { followRedirects: true @@ -1142,7 +1137,6 @@ describe('WebSocket', () => { ); assert.strictEqual(ws._redirects, 1); - server.removeListener('upgrade', onUpgrade); ws.on('close', () => done()); }); });