diff --git a/packages/vitest/src/node/reporters/dot.ts b/packages/vitest/src/node/reporters/dot.ts index 7c47fbd3ba45..4d081f29154c 100644 --- a/packages/vitest/src/node/reporters/dot.ts +++ b/packages/vitest/src/node/reporters/dot.ts @@ -66,11 +66,13 @@ export class DotReporter extends BaseReporter { return } this.tests.set(test.id, test.result().state || 'run') + this.renderer?.schedule() } onTestCaseResult(test: TestCase) { this.finishedTests.add(test.id) this.tests.set(test.id, test.result().state || 'skipped') + this.renderer?.schedule() } onTestModuleEnd() { @@ -104,6 +106,7 @@ export class DotReporter extends BaseReporter { } this.ctx.logger.log(formatTests(states)) + this.renderer?.schedule() } private createSummary() { diff --git a/packages/vitest/src/node/reporters/renderers/windowedRenderer.ts b/packages/vitest/src/node/reporters/renderers/windowedRenderer.ts index 72d042d23afc..ea0f1019aa73 100644 --- a/packages/vitest/src/node/reporters/renderers/windowedRenderer.ts +++ b/packages/vitest/src/node/reporters/renderers/windowedRenderer.ts @@ -2,7 +2,7 @@ import type { Writable } from 'node:stream' import type { Vitest } from '../../core' import { stripVTControlCharacters } from 'node:util' -const DEFAULT_RENDER_INTERVAL = 16 +const DEFAULT_RENDER_INTERVAL_MS = 1_000 const ESC = '\x1B[' const CLEAR_LINE = `${ESC}K` @@ -27,6 +27,7 @@ export class WindowRenderer { private streams!: Record private buffer: { type: StreamType; message: string }[] = [] private renderInterval: NodeJS.Timeout | undefined = undefined + private renderScheduled = false private windowHeight = 0 private finished = false @@ -34,7 +35,7 @@ export class WindowRenderer { constructor(options: Options) { this.options = { - interval: DEFAULT_RENDER_INTERVAL, + interval: DEFAULT_RENDER_INTERVAL_MS, ...options, } @@ -59,7 +60,7 @@ export class WindowRenderer { start() { this.finished = false - this.renderInterval = setInterval(() => this.flushBuffer(), this.options.interval).unref() + this.renderInterval = setInterval(() => this.schedule(), this.options.interval).unref() } stop() { @@ -77,6 +78,20 @@ export class WindowRenderer { clearInterval(this.renderInterval) } + /** + * Queue new render update + */ + schedule() { + if (!this.renderScheduled) { + this.renderScheduled = true + this.flushBuffer() + + setTimeout(() => { + this.renderScheduled = false + }, 100).unref() + } + } + private flushBuffer() { if (this.buffer.length === 0) { return this.render() diff --git a/packages/vitest/src/node/reporters/summary.ts b/packages/vitest/src/node/reporters/summary.ts index 38c002f43ec4..2b47c4361875 100644 --- a/packages/vitest/src/node/reporters/summary.ts +++ b/packages/vitest/src/node/reporters/summary.ts @@ -109,6 +109,7 @@ export class SummaryReporter implements Reporter { } this.runningModules.set(module.id, initializeStats(module)) + this.renderer.schedule() } onTestModuleCollected(module: TestModule) { @@ -124,6 +125,7 @@ export class SummaryReporter implements Reporter { stats.total = total this.maxParallelTests = Math.max(this.maxParallelTests, this.runningModules.size) + this.renderer.schedule() } onHookStart(options: ReportedHookContext) { @@ -213,6 +215,8 @@ export class SummaryReporter implements Reporter { else if (!result?.state || result?.state === 'skipped') { this.tests.skipped++ } + + this.renderer.schedule() } onTestModuleEnd(module: TestModule) { @@ -247,6 +251,8 @@ export class SummaryReporter implements Reporter { // Remove finished test immediatelly. this.removeTestModule(module.id) } + + this.renderer.schedule() } private getHookStats({ entity }: ReportedHookContext) {