Skip to content

Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.

test: deliver colorful debug messages, do not pipe stdio (#3477)

Pavel Feldmand537088af8e9
diff --git a/test/runner/runner.js b/test/runner/runner.js
index dad8051f45..90c14d2663 100644
--- a/test/runner/runner.js
+++ b/test/runner/runner.js
@@ -184,9 +184,11 @@ class Worker extends EventEmitter {
detached: false,
env: {
FORCE_COLOR: process.stdout.isTTY ? 1 : 0,
+ DEBUG_COLORS: process.stdout.isTTY ? 1 : 0,
...process.env
},
- stdio: ['ignore', 'pipe', 'pipe', 'ipc']
+ // Can't pipe since piping slows down termination for some reason.
+ stdio: ['ignore', 'ignore', 'ignore', 'ipc']
});
this.process.on('exit', () => this.emit('exit'));
this.process.on('message', message => {
@@ -195,18 +197,23 @@ class Worker extends EventEmitter {
});
this.stdout = [];
this.stderr = [];
- this.process.stdout.on('data', data => {
+ this.on('stdout', data => {
if (runner._options.dumpio)
process.stdout.write(data);
else
- this.stdout.push(data.toString());
+ this.stdout.push(data);
});
-
- this.process.stderr.on('data', data => {
+ this.on('stderr', data => {
if (runner._options.dumpio)
process.stderr.write(data);
else
- this.stderr.push(data.toString());
+ this.stderr.push(data);
+ });
+ this.on('debug', data => {
+ if (runner._options.dumpio)
+ process.stderr.write(data + '\n');
+ else
+ this.stderr.push(data + '\n');
});
}
diff --git a/test/runner/worker.js b/test/runner/worker.js
index 87a7dc0023..3cd678b55d 100644
--- a/test/runner/worker.js
+++ b/test/runner/worker.js
@@ -14,7 +14,7 @@
* limitations under the License.
*/
-const path = require('path');
+const debug = require('debug');
const Mocha = require('mocha');
const { fixturesUI, fixturePool } = require('./fixturesUI');
const { gracefullyCloseAll } = require('../../lib/server/processLauncher');
@@ -29,6 +29,18 @@ extendExpects();
let closed = false;
+process.stdout.write = chunk => {
+ sendMessageToParent('stdout', chunk);
+};
+
+process.stderr.write = chunk => {
+ sendMessageToParent('stderr', chunk);
+};
+
+debug.log = data => {
+ sendMessageToParent('debug', data);
+};
+
process.on('message', async message => {
if (message.method === 'init')
process.env.JEST_WORKER_ID = message.params.workerId;