Skip to content

Commit

Permalink
fix: respect clearScreen option in vite, close #1125
Browse files Browse the repository at this point in the history
  • Loading branch information
antfu committed Apr 10, 2022
1 parent ce53037 commit d482992
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 6 deletions.
1 change: 0 additions & 1 deletion packages/vite-node/src/cli.ts
Expand Up @@ -68,7 +68,6 @@ async function run(options: CliOptions = {}) {
const files = options.files || options._ || []
const server = await createServer({
logLevel: 'error',
clearScreen: false,
configFile: options.config,
root: options.root,
})
Expand Down
13 changes: 12 additions & 1 deletion packages/vitest/src/node/core.ts
@@ -1,4 +1,5 @@
import { existsSync, promises as fs } from 'fs'
import readline from 'readline'
import type { ViteDevServer } from 'vite'
import { relative, toNamespacedPath } from 'pathe'
import fg from 'fast-glob'
Expand Down Expand Up @@ -274,6 +275,17 @@ export class Vitest {
this.console.error(...args)
}

clearScreen() {
if (this.server.config.clearScreen === false)
return

const repeatCount = process.stdout.rows - 2
const blank = repeatCount > 0 ? '\n'.repeat(repeatCount) : ''
this.console.log(blank)
readline.cursorTo(process.stdout, 0, 0)
readline.clearScreenDown(process.stdout)
}

private _rerunTimer: any
private async scheduleRerun(triggerId: string) {
const currentCount = this.restartsCount
Expand Down Expand Up @@ -308,7 +320,6 @@ export class Vitest {
const files = Array.from(this.changedTests)
this.changedTests.clear()

this.log('return')
if (this.config.coverage.enabled && this.config.coverage.cleanOnRerun)
await cleanCoverage(this.config.coverage)

Expand Down
1 change: 0 additions & 1 deletion packages/vitest/src/node/plugins/index.ts
Expand Up @@ -64,7 +64,6 @@ export async function VitestPlugin(options: UserConfig = {}, ctx = new Vitest())
(options as ResolvedConfig).defines = defines

return {
clearScreen: false,
resolve: {
// by default Vite resolves `module` field, which not always a native ESM module
// setting this option can bypass that and fallback to cjs version
Expand Down
4 changes: 2 additions & 2 deletions packages/vitest/src/node/reporters/base.ts
Expand Up @@ -108,8 +108,8 @@ export abstract class BaseReporter implements Reporter {
async onWatcherRerun(files: string[], trigger?: string) {
this.watchFilters = files

this.ctx.console.clear()
this.ctx.log(c.blue('Re-running tests...') + (trigger ? c.dim(` [ ${this.relative(trigger)} ]\n`) : ''))
this.ctx.clearScreen()
this.ctx.log(`\n${c.inverse(c.bold(c.blue(' RERUN ')))}${trigger ? c.dim(` ${this.relative(trigger)}\n`) : ''}`)
this.start = performance.now()
}

Expand Down
2 changes: 1 addition & 1 deletion packages/vitest/src/node/reporters/default.ts
Expand Up @@ -10,7 +10,7 @@ export class DefaultReporter extends BaseReporter {

async onTestRemoved(trigger?: string) {
await this.stopListRender()
this.ctx.console.clear()
this.ctx.clearScreen()
this.ctx.log(c.yellow('Test removed...') + (trigger ? c.dim(` [ ${this.relative(trigger)} ]\n`) : ''))
const files = this.ctx.state.getFiles(this.watchFilters)
createListRenderer(files, this.rendererOptions).stop()
Expand Down

0 comments on commit d482992

Please sign in to comment.