Skip to content

Commit

Permalink
fix: clear full screen only in watch mode
Browse files Browse the repository at this point in the history
  • Loading branch information
sheremet-va committed Nov 2, 2022
1 parent fb93a7e commit c3d8950
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
15 changes: 13 additions & 2 deletions packages/vitest/src/node/logger.ts
Expand Up @@ -35,6 +35,15 @@ export class Logger {
this.console.warn(...args)
}

clearFullScreen(message: string) {
if (this.ctx.server.config.clearScreen === false) {
this.console.log(message)
return
}

this.console.log(`\x1Bc${message}`)
}

clearScreen(message: string, force = false) {
if (this.ctx.server.config.clearScreen === false) {
this.console.log(message)
Expand All @@ -52,7 +61,9 @@ export class Logger {

const log = this._clearScreenPending
this._clearScreenPending = undefined
this.console.log(`\x1Bc${log}`)
// equivalent to ansi-escapes:
// stdout.write(ansiEscapes.cursorTo(0, 0) + ansiEscapes.eraseDown + log)
this.console.log(`\u001B[1;1H\u001B[J${log}`)
}

printError(err: unknown, fullStack = false, type?: string) {
Expand Down Expand Up @@ -82,7 +93,7 @@ export class Logger {
}

printBanner() {
this.clearScreen('', true)
this.log()

const versionTest = this.ctx.config.watch
? c.blue(`v${version}`)
Expand Down
4 changes: 2 additions & 2 deletions packages/vitest/src/node/reporters/base.ts
Expand Up @@ -154,13 +154,13 @@ export abstract class BaseReporter implements Reporter {
const TRIGGER = trigger ? c.dim(` ${this.relative(trigger)}`) : ''
if (files.length > 1) {
// we need to figure out how to handle rerun all from stdin
this.ctx.logger.clearScreen(`\n${BADGE}${TRIGGER}\n`, true)
this.ctx.logger.clearFullScreen(`\n${BADGE}${TRIGGER}\n`)
this._lastRunCount = 0
}
else if (files.length === 1) {
const rerun = this._filesInWatchMode.get(files[0]) ?? 1
this._lastRunCount = rerun
this.ctx.logger.clearScreen(`\n${BADGE}${TRIGGER} ${c.blue(`x${rerun}`)}\n`)
this.ctx.logger.clearFullScreen(`\n${BADGE}${TRIGGER} ${c.blue(`x${rerun}`)}\n`)
}

this._timeStart = new Date()
Expand Down

0 comments on commit c3d8950

Please sign in to comment.