Skip to content

Commit c8de1b1

Browse files
committed
chore: move __{begin,end}SynchronizedUpdate functions to BaseReporter
1 parent c1895b8 commit c8de1b1

File tree

2 files changed

+27
-25
lines changed

2 files changed

+27
-25
lines changed

packages/jest-reporters/src/BaseReporter.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,15 @@
55
* LICENSE file in the root directory of this source tree.
66
*/
77

8+
import type {WriteStream} from 'tty';
89
import type {
910
AggregatedResult,
1011
Test,
1112
TestCaseResult,
1213
TestContext,
1314
TestResult,
1415
} from '@jest/test-result';
15-
import {preRunMessage} from 'jest-util';
16+
import {isInteractive, preRunMessage} from 'jest-util';
1617
import type {Reporter, ReporterOnStartOptions} from './types';
1718

1819
const {remove: preRunMessageRemove} = preRunMessage;
@@ -57,4 +58,16 @@ export default class BaseReporter implements Reporter {
5758
getLastError(): Error | undefined {
5859
return this._error;
5960
}
61+
62+
protected __beginSynchronizedUpdate(write: WriteStream['write']): void {
63+
if (isInteractive) {
64+
write('\u001B[?2026h');
65+
}
66+
}
67+
68+
protected __endSynchronizedUpdate(write: WriteStream['write']): void {
69+
if (isInteractive) {
70+
write('\u001B[?2026l');
71+
}
72+
}
6073
}

packages/jest-reporters/src/DefaultReporter.ts

Lines changed: 13 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ export default class DefaultReporter extends BaseReporter {
3939
private readonly _out: write;
4040
private readonly _status: Status;
4141
private readonly _bufferedOutput: Set<FlushBufferedOutput>;
42+
private readonly _bufferedOutput: Set<FlushBufferedOutput>;
4243

4344
static readonly filename = __filename;
4445

@@ -53,10 +54,14 @@ export default class DefaultReporter extends BaseReporter {
5354
this.__wrapStdio(process.stdout);
5455
this.__wrapStdio(process.stderr);
5556
this._status.onChange(() => {
56-
this.__beginSynchronizedUpdate();
57+
this.__beginSynchronizedUpdate(
58+
this._globalConfig.useStderr ? this._err : this._out,
59+
);
5760
this.__clearStatus();
5861
this.__printStatus();
59-
this.__endSynchronizedUpdate();
62+
this.__endSynchronizedUpdate(
63+
this._globalConfig.useStderr ? this._err : this._out,
64+
);
6065
});
6166
}
6267

@@ -71,13 +76,17 @@ export default class DefaultReporter extends BaseReporter {
7176
buffer = [];
7277

7378
// This is to avoid conflicts between random output and status text
74-
this.__beginSynchronizedUpdate();
79+
this.__beginSynchronizedUpdate(
80+
this._globalConfig.useStderr ? this._err : this._out,
81+
);
7582
this.__clearStatus();
7683
if (string) {
7784
write(string);
7885
}
7986
this.__printStatus();
80-
this.__endSynchronizedUpdate();
87+
this.__endSynchronizedUpdate(
88+
this._globalConfig.useStderr ? this._err : this._out,
89+
);
8190

8291
this._bufferedOutput.delete(flushBufferedOutput);
8392
};
@@ -124,26 +133,6 @@ export default class DefaultReporter extends BaseReporter {
124133
}
125134
}
126135

127-
protected __beginSynchronizedUpdate(): void {
128-
if (isInteractive) {
129-
if (this._globalConfig.useStderr) {
130-
this._err('\x1b[?2026h');
131-
} else {
132-
this._out('\x1b[?2026h');
133-
}
134-
}
135-
}
136-
137-
protected __endSynchronizedUpdate(): void {
138-
if (isInteractive) {
139-
if (this._globalConfig.useStderr) {
140-
this._err('\x1b[?2026l');
141-
} else {
142-
this._out('\x1b[?2026l');
143-
}
144-
}
145-
}
146-
147136
protected __printStatus(): void {
148137
const {content, clear} = this._status.get();
149138
this._clear = clear;

0 commit comments

Comments
 (0)