Skip to content

Commit 119dbc4

Browse files
spioncaptain-yossarian
authored andcommitted
Fix missing console log output in verbose mode (jestjs#6871)
* 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
1 parent b4fa4d9 commit 119dbc4

File tree

6 files changed

+22
-11
lines changed

6 files changed

+22
-11
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
- `[jest-haste-map]` [**BREAKING**] Recover files correctly after haste name collisions are fixed ([#7329](https://github.com/facebook/jest/pull/7329))
4646
- `[pretty-format]` [**BREAKING**] Omit non-enumerable symbol properties ([#7448](https://github.com/facebook/jest/pull/7448))
4747
- `[*]` [**BREAKING**] Upgrade to Babel 7, dropping support for Babel 6 ([#7016](https://github.com/facebook/jest/pull/7016))
48+
- `[jest-runner/jest-worker]` Fix missing console output in verbose mode ([#6871](https://github.com/facebook/jest/pull/6871))
4849
- `[expect]` Standardize file naming in `expect` ([#7306](https://github.com/facebook/jest/pull/7306))
4950
- `[jest-each]` Add empty array validation check ([#7249](https://github.com/facebook/jest/pull/7249))
5051
- `[jest-cli]` Interrupt tests if interactive watch plugin key is pressed ([#7222](https://github.com/facebook/jest/pull/7222))

package.json

-5
Original file line numberDiff line numberDiff line change
@@ -97,11 +97,6 @@
9797
"packages/*",
9898
"website",
9999
"examples/*"
100-
],
101-
"nohoist": [
102-
"**/react-native",
103-
"**/react-native/**",
104-
"examples/react-native/**"
105100
]
106101
},
107102
"prettier": {

packages/jest-runner/src/index.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -97,11 +97,14 @@ class TestRunner {
9797
// $FlowFixMe: class object is augmented with worker when instantiating.
9898
const worker: WorkerInterface = new Worker(TEST_WORKER_PATH, {
9999
exposedMethods: ['worker'],
100-
forkOptions: {stdio: 'inherit'},
100+
forkOptions: {stdio: 'pipe'},
101101
maxRetries: 3,
102102
numWorkers: this._globalConfig.maxWorkers,
103103
});
104104

105+
if (worker.getStdout()) worker.getStdout().pipe(process.stdout);
106+
if (worker.getStderr()) worker.getStderr().pipe(process.stderr);
107+
105108
const mutex = throat(this._globalConfig.maxWorkers);
106109

107110
// Send test suites to workers continuously instead of all at once to track

packages/jest-worker/package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
"license": "MIT",
99
"main": "build/index.js",
1010
"dependencies": {
11-
"merge-stream": "^1.0.1"
11+
"merge-stream": "^1.0.1",
12+
"supports-color": "^5.5.0"
1213
},
1314
"engines": {
1415
"node": ">= 6"

packages/jest-worker/src/workers/ChildProcessWorker.js

+11-3
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ import type {Readable} from 'stream';
2424

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

27+
import supportsColor from 'supports-color';
28+
2729
/**
2830
* This class wraps the child process and provides a nice interface to
2931
* communicate with. It takes care of:
@@ -54,15 +56,21 @@ export default class ChildProcessWorker implements WorkerInterface {
5456
}
5557

5658
initialize() {
59+
const forceColor = supportsColor.stdout ? {FORCE_COLOR: '1'} : {};
5760
const child = childProcess.fork(
5861
require.resolve('./processChild'),
5962
// $FlowFixMe: Flow does not work well with Object.assign.
6063
Object.assign(
6164
{
6265
cwd: process.cwd(),
63-
env: Object.assign({}, process.env, {
64-
JEST_WORKER_ID: this._options.workerId,
65-
}),
66+
env: Object.assign(
67+
{},
68+
process.env,
69+
{
70+
JEST_WORKER_ID: this._options.workerId,
71+
},
72+
forceColor,
73+
),
6674
// Suppress --debug / --inspect flags while preserving others (like --harmony).
6775
execArgv: process.execArgv.filter(v => !/^--(debug|inspect)/.test(v)),
6876
silent: true,

packages/jest-worker/src/workers/__tests__/ChildProcessWorker.test.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
/* eslint-disable no-new */
1111

1212
import EventEmitter from 'events';
13+
import supportsColor from 'supports-color';
1314

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

0 commit comments

Comments
 (0)