From d537088af8e9bf8ba536d3f3d8c6f4c72baf3348 Mon Sep 17 00:00:00 2001 From: Pavel Feldman Date: Fri, 14 Aug 2020 13:42:03 -0700 Subject: [PATCH] test: deliver colorful debug messages, do not pipe stdio (#3477) --- test/runner/runner.js | 19 +++++++++++++------ test/runner/worker.js | 14 +++++++++++++- 2 files changed, 26 insertions(+), 7 deletions(-) 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;