@@ -12,7 +12,7 @@ import { createLogUpdate } from 'log-update'
12
12
import c from 'tinyrainbow'
13
13
import { highlightCode } from '../utils/colors'
14
14
import { printError } from './error'
15
- import { divider } from './reporters/renderers/utils'
15
+ import { divider , withLabel } from './reporters/renderers/utils'
16
16
import { RandomSequencer } from './sequencers/RandomSequencer'
17
17
18
18
export interface ErrorOptions {
@@ -25,6 +25,8 @@ export interface ErrorOptions {
25
25
showCodeFrame ?: boolean
26
26
}
27
27
28
+ const PAD = ' '
29
+
28
30
const ESC = '\x1B['
29
31
const ERASE_DOWN = `${ ESC } J`
30
32
const ERASE_SCROLLBACK = `${ ESC } 3J`
@@ -64,13 +66,18 @@ export class Logger {
64
66
this . console . warn ( ...args )
65
67
}
66
68
67
- clearFullScreen ( message : string ) {
69
+ clearFullScreen ( message = '' ) {
68
70
if ( ! this . ctx . config . clearScreen ) {
69
71
this . console . log ( message )
70
72
return
71
73
}
72
74
73
- this . console . log ( `${ CLEAR_SCREEN } ${ ERASE_SCROLLBACK } ${ message } ` )
75
+ if ( message ) {
76
+ this . console . log ( `${ CLEAR_SCREEN } ${ ERASE_SCROLLBACK } ${ message } ` )
77
+ }
78
+ else {
79
+ ( this . outputStream as Writable ) . write ( `${ CLEAR_SCREEN } ${ ERASE_SCROLLBACK } ` )
80
+ }
74
81
}
75
82
76
83
clearScreen ( message : string , force = false ) {
@@ -201,23 +208,13 @@ export class Logger {
201
208
printBanner ( ) {
202
209
this . log ( )
203
210
204
- const versionTest = this . ctx . config . watch
205
- ? c . blue ( `v${ this . ctx . version } ` )
206
- : c . cyan ( `v${ this . ctx . version } ` )
207
- const mode = this . ctx . config . watch ? c . blue ( ' DEV ' ) : c . cyan ( ' RUN ' )
211
+ const color = this . ctx . config . watch ? 'blue' : 'cyan'
212
+ const mode = this . ctx . config . watch ? 'DEV' : 'RUN'
208
213
209
- this . log (
210
- `${ c . inverse ( c . bold ( mode ) ) } ${ versionTest } ${ c . gray (
211
- this . ctx . config . root ,
212
- ) } `,
213
- )
214
+ this . log ( withLabel ( color , mode , `v${ this . ctx . version } ` ) + c . gray ( this . ctx . config . root ) )
214
215
215
216
if ( this . ctx . config . sequence . sequencer === RandomSequencer ) {
216
- this . log (
217
- c . gray (
218
- ` Running tests with seed "${ this . ctx . config . sequence . seed } "` ,
219
- ) ,
220
- )
217
+ this . log ( PAD + c . gray ( `Running tests with seed "${ this . ctx . config . sequence . seed } "` ) )
221
218
}
222
219
223
220
this . ctx . projects . forEach ( ( project ) => {
@@ -231,52 +228,32 @@ export class Logger {
231
228
const origin = resolvedUrls ?. local [ 0 ] ?? resolvedUrls ?. network [ 0 ]
232
229
const provider = project . browser . provider . name
233
230
const providerString = provider === 'preview' ? '' : ` by ${ provider } `
234
- this . log (
235
- c . dim (
236
- c . green (
237
- ` ${ output } Browser runner started${ providerString } at ${ new URL ( '/' , origin ) } ` ,
238
- ) ,
239
- ) ,
240
- )
231
+
232
+ this . log ( PAD + c . dim ( c . green ( `${ output } Browser runner started${ providerString } at ${ new URL ( '/' , origin ) } ` ) ) )
241
233
} )
242
234
243
235
if ( this . ctx . config . ui ) {
244
- this . log (
245
- c . dim (
246
- c . green (
247
- ` UI started at http://${
248
- this . ctx . config . api ?. host || 'localhost'
249
- } :${ c . bold ( `${ this . ctx . server . config . server . port } ` ) } ${
250
- this . ctx . config . uiBase
251
- } `,
252
- ) ,
253
- ) ,
254
- )
236
+ const host = this . ctx . config . api ?. host || 'localhost'
237
+ const port = this . ctx . server . config . server . port
238
+ const base = this . ctx . config . uiBase
239
+
240
+ this . log ( PAD + c . dim ( c . green ( `UI started at http://${ host } :${ c . bold ( port ) } ${ base } ` ) ) )
255
241
}
256
242
else if ( this . ctx . config . api ?. port ) {
257
243
const resolvedUrls = this . ctx . server . resolvedUrls
258
244
// workaround for https://github.com/vitejs/vite/issues/15438, it was fixed in vite 5.1
259
- const fallbackUrl = `http://${ this . ctx . config . api . host || 'localhost' } :${
260
- this . ctx . config . api . port
261
- } `
262
- const origin
263
- = resolvedUrls ?. local [ 0 ] ?? resolvedUrls ?. network [ 0 ] ?? fallbackUrl
264
- this . log ( c . dim ( c . green ( ` API started at ${ new URL ( '/' , origin ) } ` ) ) )
245
+ const fallbackUrl = `http://${ this . ctx . config . api . host || 'localhost' } :${ this . ctx . config . api . port } `
246
+ const origin = resolvedUrls ?. local [ 0 ] ?? resolvedUrls ?. network [ 0 ] ?? fallbackUrl
247
+
248
+ this . log ( PAD + c . dim ( c . green ( `API started at ${ new URL ( '/' , origin ) } ` ) ) )
265
249
}
266
250
267
251
if ( this . ctx . coverageProvider ) {
268
- this . log (
269
- c . dim ( ' Coverage enabled with ' )
270
- + c . yellow ( this . ctx . coverageProvider . name ) ,
271
- )
252
+ this . log ( PAD + c . dim ( 'Coverage enabled with ' ) + c . yellow ( this . ctx . coverageProvider . name ) )
272
253
}
273
254
274
255
if ( this . ctx . config . standalone ) {
275
- this . log (
276
- c . yellow (
277
- `\nVitest is running in standalone mode. Edit a test file to rerun tests.` ,
278
- ) ,
279
- )
256
+ this . log ( c . yellow ( `\nVitest is running in standalone mode. Edit a test file to rerun tests.` ) )
280
257
}
281
258
else {
282
259
this . log ( )
0 commit comments