Skip to content

Commit

Permalink
fix(pipe): dispatch "disconnected" event when browser is terminated (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
aslushnikov committed Oct 31, 2018
1 parent 9800b2c commit 3dd5c28
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
6 changes: 5 additions & 1 deletion lib/PipeTransport.js
Expand Up @@ -27,7 +27,11 @@ class PipeTransport {
this._pipeWrite = pipeWrite;
this._pendingMessage = '';
this._eventListeners = [
helper.addEventListener(pipeRead, 'data', buffer => this._dispatch(buffer))
helper.addEventListener(pipeRead, 'data', buffer => this._dispatch(buffer)),
helper.addEventListener(pipeRead, 'close', () => {
if (this.onclose)
this.onclose.call(null);
})
];
this.onmessage = null;
this.onclose = null;
Expand Down
8 changes: 8 additions & 0 deletions test/puppeteer.spec.js
Expand Up @@ -217,6 +217,14 @@ module.exports.addTests = function({testRunner, expect, defaultBrowserOptions})
await page.close();
await browser.close();
});
it('should fire "disconnected" when closing with pipe', async() => {
const options = Object.assign({pipe: true}, defaultBrowserOptions);
const browser = await puppeteer.launch(options);
const disconnectedEventPromise = new Promise(resolve => browser.once('disconnected', resolve));
// Emulate user exiting browser.
browser.process().kill();
await disconnectedEventPromise;
});
it('should work with no default arguments', async() => {
const options = Object.assign({}, defaultBrowserOptions);
options.ignoreDefaultArgs = true;
Expand Down

0 comments on commit 3dd5c28

Please sign in to comment.