Skip to content

Commit e8528eb

Browse files
committed
Ensure verbose mode prints output synchronously
Fixes #8208
1 parent c174ada commit e8528eb

File tree

2 files changed

+28
-11
lines changed

2 files changed

+28
-11
lines changed

packages/jest-reporters/src/DefaultReporter.ts

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -43,16 +43,18 @@ export default class DefaultReporter extends BaseReporter {
4343
this._err = process.stderr.write.bind(process.stderr);
4444
this._status = new Status();
4545
this._bufferedOutput = new Set();
46-
this._wrapStdio(process.stdout);
47-
this._wrapStdio(process.stderr);
46+
this.__wrapStdio(process.stdout);
47+
this.__wrapStdio(process.stderr);
4848
this._status.onChange(() => {
49-
this._clearStatus();
50-
this._printStatus();
49+
this.__clearStatus();
50+
this.__printStatus();
5151
});
5252
}
5353

54-
private _wrapStdio(stream: NodeJS.WritableStream | NodeJS.WriteStream) {
55-
const originalWrite = stream.write;
54+
protected __wrapStdio(
55+
stream: NodeJS.WritableStream | NodeJS.WriteStream,
56+
): void {
57+
const write = stream.write.bind(stream);
5658

5759
let buffer: Array<string> = [];
5860
let timeout: NodeJS.Timeout | null = null;
@@ -62,11 +64,11 @@ export default class DefaultReporter extends BaseReporter {
6264
buffer = [];
6365

6466
// This is to avoid conflicts between random output and status text
65-
this._clearStatus();
67+
this.__clearStatus();
6668
if (string) {
67-
originalWrite.call(stream, string);
69+
write(string);
6870
}
69-
this._printStatus();
71+
this.__printStatus();
7072

7173
this._bufferedOutput.delete(flushBufferedOutput);
7274
};
@@ -103,7 +105,7 @@ export default class DefaultReporter extends BaseReporter {
103105
}
104106
}
105107

106-
private _clearStatus() {
108+
protected __clearStatus() {
107109
if (isInteractive) {
108110
if (this._globalConfig.useStderr) {
109111
this._err(this._clear);
@@ -113,7 +115,7 @@ export default class DefaultReporter extends BaseReporter {
113115
}
114116
}
115117

116-
private _printStatus() {
118+
protected __printStatus() {
117119
const {content, clear} = this._status.get();
118120
this._clear = clear;
119121
if (isInteractive) {

packages/jest-reporters/src/VerboseReporter.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,21 @@ export default class VerboseReporter extends DefaultReporter {
2929
this._globalConfig = globalConfig;
3030
}
3131

32+
// Verbose mode is for debugging. Buffering of output is undesirable.
33+
// See https://github.com/facebook/jest/issues/8208
34+
protected __wrapStdio(
35+
stream: NodeJS.WritableStream | NodeJS.WriteStream,
36+
): void {
37+
const write = stream.write.bind(stream);
38+
39+
stream.write = (chunk: string) => {
40+
this.__clearStatus();
41+
write(chunk);
42+
this.__printStatus();
43+
return true;
44+
};
45+
}
46+
3247
static filterTestResults(
3348
testResults: Array<AssertionResult>,
3449
): Array<AssertionResult> {

0 commit comments

Comments
 (0)