@@ -2,7 +2,7 @@ import type { Writable } from 'node:stream'
22import type { Vitest } from '../../core'
33import { stripVTControlCharacters } from 'node:util'
44
5- const DEFAULT_RENDER_INTERVAL = 16
5+ const DEFAULT_RENDER_INTERVAL_MS = 1_000
66
77const ESC = '\x1B['
88const CLEAR_LINE = `${ ESC } K`
@@ -27,14 +27,15 @@ export class WindowRenderer {
2727 private streams ! : Record < StreamType , Vitest [ 'logger' ] [ 'outputStream' | 'errorStream' ] [ 'write' ] >
2828 private buffer : { type : StreamType ; message : string } [ ] = [ ]
2929 private renderInterval : NodeJS . Timeout | undefined = undefined
30+ private renderScheduled = false
3031
3132 private windowHeight = 0
3233 private finished = false
3334 private cleanups : ( ( ) => void ) [ ] = [ ]
3435
3536 constructor ( options : Options ) {
3637 this . options = {
37- interval : DEFAULT_RENDER_INTERVAL ,
38+ interval : DEFAULT_RENDER_INTERVAL_MS ,
3839 ...options ,
3940 }
4041
@@ -59,7 +60,7 @@ export class WindowRenderer {
5960
6061 start ( ) {
6162 this . finished = false
62- this . renderInterval = setInterval ( ( ) => this . flushBuffer ( ) , this . options . interval ) . unref ( )
63+ this . renderInterval = setInterval ( ( ) => this . schedule ( ) , this . options . interval ) . unref ( )
6364 }
6465
6566 stop ( ) {
@@ -77,6 +78,20 @@ export class WindowRenderer {
7778 clearInterval ( this . renderInterval )
7879 }
7980
81+ /**
82+ * Queue new render update
83+ */
84+ schedule ( ) {
85+ if ( ! this . renderScheduled ) {
86+ this . renderScheduled = true
87+ this . flushBuffer ( )
88+
89+ setTimeout ( ( ) => {
90+ this . renderScheduled = false
91+ } , 100 ) . unref ( )
92+ }
93+ }
94+
8095 private flushBuffer ( ) {
8196 if ( this . buffer . length === 0 ) {
8297 return this . render ( )
0 commit comments