Skip to content

Commit

Permalink
test: deliver colorful debug messages, do not pipe stdio (#3477)
Browse files Browse the repository at this point in the history
  • Loading branch information
pavelfeldman authored Aug 14, 2020
1 parent ae4280a commit d537088
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 7 deletions.
19 changes: 13 additions & 6 deletions test/runner/runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 => {
Expand All @@ -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');
});
}

Expand Down
14 changes: 13 additions & 1 deletion test/runner/worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -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;
Expand Down

0 comments on commit d537088

Please sign in to comment.