Skip to content

Commit f3ae7aa

Browse files
committed
feat: Add DEC mode 2026 support (Synchronized Output) to Jest
This commit introduces support for DEC private mode 2026, also known as Synchronized Output, to DefaultReporter. The Synchronized Output mode is a terminal feature that helps mitigate screen tearing effects that can occur when the terminal is rendering output while the application is still writing to the screen. Two new methods have been added to the DefaultReporter: - `__beginSynchronizedUpdate`: This method sends the control sequence to enable Synchronized Output mode to the terminal. - `__endSynchronizedUpdate`: This method sends the control sequence to disable Synchronized Output mode to the terminal. These methods are called before and after the reporter updates the status, respectively. By doing this, we ensure that the terminal renders a consistent state of the screen for each status update, even if we're writing to the screen frequently. Read more: https://gist.github.com/christianparpart/d8a62cc1ab659194337d73e399004036
1 parent 6c49a41 commit f3ae7aa

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

packages/jest-reporters/src/DefaultReporter.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,10 @@ export default class DefaultReporter extends BaseReporter {
5353
this.__wrapStdio(process.stdout);
5454
this.__wrapStdio(process.stderr);
5555
this._status.onChange(() => {
56+
this.__beginSynchronizedUpdate();
5657
this.__clearStatus();
5758
this.__printStatus();
59+
this.__endSynchronizedUpdate();
5860
});
5961
}
6062

@@ -69,11 +71,13 @@ export default class DefaultReporter extends BaseReporter {
6971
buffer = [];
7072

7173
// This is to avoid conflicts between random output and status text
74+
this.__beginSynchronizedUpdate();
7275
this.__clearStatus();
7376
if (string) {
7477
write(string);
7578
}
7679
this.__printStatus();
80+
this.__endSynchronizedUpdate();
7781

7882
this._bufferedOutput.delete(flushBufferedOutput);
7983
};
@@ -120,6 +124,26 @@ export default class DefaultReporter extends BaseReporter {
120124
}
121125
}
122126

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+
123147
protected __printStatus(): void {
124148
const {content, clear} = this._status.get();
125149
this._clear = clear;

0 commit comments

Comments
 (0)