Implement browser.stdout and browser.stderr streams

This patch adds browser.stdout and browser.stderr streams.

These streams allow to get the browser instance output, e.g.

```js
browser.stderr.pipe(process.stdout);
```
This commit is contained in:
Andrey Lushnikov 2017-07-07 20:49:17 +03:00 committed by GitHub
parent aa5419a577
commit 34f043d821

View File

@ -14,6 +14,7 @@
* limitations under the License.
*/
let {Duplex} = require('stream');
let http = require('http');
let path = require('path');
let removeRecursive = require('rimraf').sync;
@ -64,6 +65,9 @@ class Browser {
this._terminated = false;
this._chromeProcess = null;
this._launchPromise = null;
this.stderr = new ProxyStream();
this.stdout = new ProxyStream();
}
/**
@ -112,6 +116,8 @@ class Browser {
this._terminated = true;
removeRecursive(this._userDataDir);
});
this._chromeProcess.stderr.pipe(this.stderr);
this._chromeProcess.stdout.pipe(this.stdout);
await waitForChromeResponsive(this._remoteDebuggingPort, () => !this._terminated);
if (this._terminated)
@ -153,3 +159,17 @@ function waitForChromeResponsive(remoteDebuggingPort, shouldWaitCallback) {
req.end();
}
}
class ProxyStream extends Duplex {
_read() { }
/**
* @param {?} chunk
* @param {string} encoding
* @param {function()} callback
*/
_write(chunk, encoding, callback) {
this.push(chunk, encoding);
callback();
}
}