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

This commit is contained in:
Pavel Feldman 2020-08-14 13:42:03 -07:00 committed by GitHub
parent ae4280a12b
commit d537088af8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 26 additions and 7 deletions

View File

@ -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');
});
}

View File

@ -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;