diff --git a/lib/Connection.js b/lib/Connection.js index ade5eb72..a5006df4 100644 --- a/lib/Connection.js +++ b/lib/Connection.js @@ -76,6 +76,8 @@ class Connection extends EventEmitter { _onClose() { this._ws.removeAllListeners(); this._ws.close(); + for (let callback of this._callbacks.values()) + callback.reject(new Error(`Protocol error (${callback.method}): Target closed.`)); } /** diff --git a/test/server/SimpleServer.js b/test/server/SimpleServer.js index c5f5cccf..3ba3ec7f 100644 --- a/test/server/SimpleServer.js +++ b/test/server/SimpleServer.js @@ -79,6 +79,12 @@ class SimpleServer { _onSocket(socket) { this._sockets.add(socket); + // ECONNRESET is a legit error given + // that tab closing simply kills process. + socket.on('error', error => { + if (error.code !== 'ECONNRESET') + throw error; + }); socket.once('close', () => this._sockets.delete(socket)); } diff --git a/test/test.js b/test/test.js index 8f535285..9f69309d 100644 --- a/test/test.js +++ b/test/test.js @@ -628,8 +628,8 @@ describe('Puppeteer', function() { } })); } - let screenshot = await promises[1]; - expect(screenshot).toBeGolden('screenshot-parallel-calls.png'); + let screenshots = await Promise.all(promises); + expect(screenshots[1]).toBeGolden('screenshot-parallel-calls.png'); })); it('should take fullPage screenshots', SX(async function() { await page.setViewport({width: 500, height: 500});