diff --git a/packages/vitest/src/reporters/console.ts b/packages/vitest/src/reporters/console.ts index 7260d1331..fa161a2f1 100644 --- a/packages/vitest/src/reporters/console.ts +++ b/packages/vitest/src/reporters/console.ts @@ -15,18 +15,17 @@ export class ConsoleReporter implements Reporter { end = 0 renderer?: ReturnType watchFilters?: string[] - console = globalThis.console log(...args: any[]) { if (this.ctx.config.silent) return - this.console.log(...args) + this.ctx.console.log(...args) } error(...args: any[]) { if (this.ctx.config.silent) return - this.console.error(...args) + this.ctx.console.error(...args) } constructor(public ctx: Vitest) { @@ -151,8 +150,10 @@ export class ConsoleReporter implements Reporter { this.watchFilters = files - this.console.clear() - this.log(c.blue('Re-running tests...') + c.dim(` [ ${this.relative(trigger)} ]\n`)) + if (!this.ctx.config.silent) { + this.ctx.console.clear() + this.log(c.blue('Re-running tests...') + c.dim(` [ ${this.relative(trigger)} ]\n`)) + } } async stopListRender() { diff --git a/packages/vitest/src/reporters/error.ts b/packages/vitest/src/reporters/error.ts index 978885ef0..93e328e12 100644 --- a/packages/vitest/src/reporters/error.ts +++ b/packages/vitest/src/reporters/error.ts @@ -134,14 +134,16 @@ async function printStack( const color = frame === highlight ? c.yellow : c.gray const path = relative(ctx.config.root, frame.file) - ctx.console.log(color(` ${c.dim(F_POINTER)} ${[frame.method, c.dim(`${path}:${pos.line}:${pos.column}`)].filter(Boolean).join(' ')}`)) + if (!ctx.config.silent) + ctx.console.log(color(` ${c.dim(F_POINTER)} ${[frame.method, c.dim(`${path}:${pos.line}:${pos.column}`)].filter(Boolean).join(' ')}`)) await onStack?.(frame, pos) // reached at test file, skip the follow stack if (frame.file in ctx.state.filesMap) break } - ctx.console.log() + if (!ctx.config.silent) + ctx.console.log() } function getOriginalPos(map: RawSourceMap | null | undefined, { line, column }: Position): Promise {