diff --git a/lib.js b/lib.js index 4a9cc2c..d6b8e26 100644 --- a/lib.js +++ b/lib.js @@ -109,13 +109,13 @@ function request(options, data = "") { }); req.on("socket", (socket) => { - socket.on("lookup", () => { + socket.once("lookup", () => { dnsLookup = performance.now(); }); - socket.on("connect", () => { + socket.once("connect", () => { tcpHandshake = performance.now(); }); - socket.on("secureConnect", () => { + socket.once("secureConnect", () => { sslHandshake = performance.now(); }); }); diff --git a/test/cli.test.js b/test/cli.test.js index 51a1cbe..d7f20a3 100644 --- a/test/cli.test.js +++ b/test/cli.test.js @@ -157,7 +157,7 @@ describe('Speed Test CLI', () => { on: jest.fn((event, callback) => { if (event === 'socket') { const mockSocket = { - on: jest.fn((socketEvent, socketCallback) => { + once: jest.fn((socketEvent, socketCallback) => { if (socketEvent === 'lookup') setTimeout(() => socketCallback(), 1); if (socketEvent === 'connect') setTimeout(() => socketCallback(), 2); if (socketEvent === 'secureConnect') setTimeout(() => socketCallback(), 3); @@ -206,7 +206,7 @@ describe('Speed Test CLI', () => { on: jest.fn((event, callback) => { if (event === 'socket') { const mockSocket = { - on: jest.fn((socketEvent, socketCallback) => { + once: jest.fn((socketEvent, socketCallback) => { if (socketEvent === 'lookup') setTimeout(() => socketCallback(), 1); if (socketEvent === 'connect') setTimeout(() => socketCallback(), 2); if (socketEvent === 'secureConnect') setTimeout(() => socketCallback(), 3); @@ -255,7 +255,7 @@ describe('Speed Test CLI', () => { on: jest.fn((event, callback) => { if (event === 'socket') { const mockSocket = { - on: jest.fn((socketEvent, socketCallback) => { + once: jest.fn((socketEvent, socketCallback) => { if (socketEvent === 'lookup') setTimeout(() => socketCallback(), 1); if (socketEvent === 'connect') setTimeout(() => socketCallback(), 2); if (socketEvent === 'secureConnect') setTimeout(() => socketCallback(), 3);