Skip to content

Commit

Permalink
Fix missing console log output in verbose mode (#6871)
Browse files Browse the repository at this point in the history
* fix missing logs

* calculate FORCE_COLOR

* always force_color=0 from runJest

* strip ansi codes from buggy version of supportsColor

* jest-worker test: add FORCE_COLOR env var

* address style issues

* update changelog

* Update CHANGELOG.md

* nohoist seems unnecessary
  • Loading branch information
spion authored and thymikee committed Dec 18, 2018
1 parent 873c641 commit b21ab21
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 11 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
- `[jest-haste-map]` [**BREAKING**] Recover files correctly after haste name collisions are fixed ([#7329](https://github.com/facebook/jest/pull/7329))
- `[pretty-format]` [**BREAKING**] Omit non-enumerable symbol properties ([#7448](https://github.com/facebook/jest/pull/7448))
- `[*]` [**BREAKING**] Upgrade to Babel 7, dropping support for Babel 6 ([#7016](https://github.com/facebook/jest/pull/7016))
- `[jest-runner/jest-worker]` Fix missing console output in verbose mode ([#6871](https://github.com/facebook/jest/pull/6871))
- `[expect]` Standardize file naming in `expect` ([#7306](https://github.com/facebook/jest/pull/7306))
- `[jest-each]` Add empty array validation check ([#7249](https://github.com/facebook/jest/pull/7249))
- `[jest-cli]` Interrupt tests if interactive watch plugin key is pressed ([#7222](https://github.com/facebook/jest/pull/7222))
Expand Down
5 changes: 0 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -97,11 +97,6 @@
"packages/*",
"website",
"examples/*"
],
"nohoist": [
"**/react-native",
"**/react-native/**",
"examples/react-native/**"
]
},
"prettier": {
Expand Down
5 changes: 4 additions & 1 deletion packages/jest-runner/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,11 +97,14 @@ class TestRunner {
// $FlowFixMe: class object is augmented with worker when instantiating.
const worker: WorkerInterface = new Worker(TEST_WORKER_PATH, {
exposedMethods: ['worker'],
forkOptions: {stdio: 'inherit'},
forkOptions: {stdio: 'pipe'},
maxRetries: 3,
numWorkers: this._globalConfig.maxWorkers,
});

if (worker.getStdout()) worker.getStdout().pipe(process.stdout);
if (worker.getStderr()) worker.getStderr().pipe(process.stderr);

const mutex = throat(this._globalConfig.maxWorkers);

// Send test suites to workers continuously instead of all at once to track
Expand Down
3 changes: 2 additions & 1 deletion packages/jest-worker/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
"license": "MIT",
"main": "build/index.js",
"dependencies": {
"merge-stream": "^1.0.1"
"merge-stream": "^1.0.1",
"supports-color": "^5.5.0"
},
"engines": {
"node": ">= 6"
Expand Down
14 changes: 11 additions & 3 deletions packages/jest-worker/src/workers/ChildProcessWorker.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ import type {Readable} from 'stream';

import type {ChildMessage, OnEnd, OnStart, WorkerOptions} from '../types';

import supportsColor from 'supports-color';

/**
* This class wraps the child process and provides a nice interface to
* communicate with. It takes care of:
Expand Down Expand Up @@ -54,15 +56,21 @@ export default class ChildProcessWorker implements WorkerInterface {
}

initialize() {
const forceColor = supportsColor.stdout ? {FORCE_COLOR: '1'} : {};
const child = childProcess.fork(
require.resolve('./processChild'),
// $FlowFixMe: Flow does not work well with Object.assign.
Object.assign(
{
cwd: process.cwd(),
env: Object.assign({}, process.env, {
JEST_WORKER_ID: this._options.workerId,
}),
env: Object.assign(
{},
process.env,
{
JEST_WORKER_ID: this._options.workerId,
},
forceColor,
),
// Suppress --debug / --inspect flags while preserving others (like --harmony).
execArgv: process.execArgv.filter(v => !/^--(debug|inspect)/.test(v)),
silent: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
/* eslint-disable no-new */

import EventEmitter from 'events';
import supportsColor from 'supports-color';

import {
CHILD_MESSAGE_CALL,
Expand Down Expand Up @@ -64,7 +65,9 @@ it('passes fork options down to child_process.fork, adding the defaults', () =>
expect(childProcess.fork.mock.calls[0][0]).toBe(child);
expect(childProcess.fork.mock.calls[0][1]).toEqual({
cwd: '/tmp', // Overridden default option.
env: process.env, // Default option.
env: Object.assign({}, process.env, {
FORCE_COLOR: supportsColor.stdout ? '1' : undefined,
}), // Default option.
execArgv: ['-p'], // Filtered option.
execPath: 'hello', // Added option.
silent: true, // Default option.
Expand Down

0 comments on commit b21ab21

Please sign in to comment.