@@ -11,10 +11,9 @@ import c from 'tinyrainbow'
11
11
import { isCI , isDeno , isNode } from '../../utils/env'
12
12
import { hasFailedSnapshot } from '../../utils/tasks'
13
13
import { F_CHECK , F_POINTER , F_RIGHT } from './renderers/figures'
14
- import { countTestErrors , divider , formatProjectName , formatTimeString , getStateString , getStateSymbol , renderSnapshotSummary , taskFail , withLabel } from './renderers/utils'
14
+ import { countTestErrors , divider , formatProjectName , formatTime , formatTimeString , getStateString , getStateSymbol , padSummaryTitle , renderSnapshotSummary , taskFail , withLabel } from './renderers/utils'
15
15
16
16
const BADGE_PADDING = ' '
17
- const LAST_RUN_LOG_TIMEOUT = 1_500
18
17
19
18
export interface BaseOptions {
20
19
isTTY ?: boolean
@@ -27,14 +26,12 @@ export abstract class BaseReporter implements Reporter {
27
26
failedUnwatchedFiles : Task [ ] = [ ]
28
27
isTTY : boolean
29
28
ctx : Vitest = undefined !
29
+ renderSucceed = false
30
30
31
31
protected verbose = false
32
32
33
33
private _filesInWatchMode = new Map < string , number > ( )
34
34
private _timeStart = formatTimeString ( new Date ( ) )
35
- private _lastRunTimeout = 0
36
- private _lastRunTimer : NodeJS . Timeout | undefined
37
- private _lastRunCount = 0
38
35
39
36
constructor ( options : BaseOptions = { } ) {
40
37
this . isTTY = options . isTTY ?? ( ( isNode || isDeno ) && process . stdout ?. isTTY && ! isCI )
@@ -65,9 +62,6 @@ export abstract class BaseReporter implements Reporter {
65
62
}
66
63
67
64
onTaskUpdate ( packs : TaskResultPack [ ] ) {
68
- if ( this . isTTY ) {
69
- return
70
- }
71
65
for ( const pack of packs ) {
72
66
const task = this . ctx . state . idMap . get ( pack [ 0 ] )
73
67
@@ -117,6 +111,8 @@ export abstract class BaseReporter implements Reporter {
117
111
118
112
this . log ( ` ${ title } ${ task . name } ${ suffix } ` )
119
113
114
+ const anyFailed = tests . some ( test => test . result ?. state === 'fail' )
115
+
120
116
for ( const test of tests ) {
121
117
const duration = test . result ?. duration
122
118
@@ -137,6 +133,15 @@ export abstract class BaseReporter implements Reporter {
137
133
+ ` ${ c . yellow ( Math . round ( duration ) + c . dim ( 'ms' ) ) } ` ,
138
134
)
139
135
}
136
+
137
+ // also print skipped tests that have notes
138
+ else if ( test . result ?. state === 'skip' && test . result . note ) {
139
+ this . log ( ` ${ getStateSymbol ( test ) } ${ getTestName ( test ) } ${ c . dim ( c . gray ( ` [${ test . result . note } ]` ) ) } ` )
140
+ }
141
+
142
+ else if ( this . renderSucceed || anyFailed ) {
143
+ this . log ( ` ${ c . green ( c . dim ( F_CHECK ) ) } ${ getTestName ( test , c . dim ( ' > ' ) ) } ` )
144
+ }
140
145
}
141
146
}
142
147
@@ -153,8 +158,6 @@ export abstract class BaseReporter implements Reporter {
153
158
}
154
159
155
160
onWatcherStart ( files = this . ctx . state . getFiles ( ) , errors = this . ctx . state . getUnhandledErrors ( ) ) {
156
- this . resetLastRunLog ( )
157
-
158
161
const failed = errors . length > 0 || hasFailed ( files )
159
162
160
163
if ( failed ) {
@@ -177,38 +180,9 @@ export abstract class BaseReporter implements Reporter {
177
180
}
178
181
179
182
this . log ( BADGE_PADDING + hints . join ( c . dim ( ', ' ) ) )
180
-
181
- if ( this . _lastRunCount ) {
182
- const LAST_RUN_TEXT = `rerun x${ this . _lastRunCount } `
183
- const LAST_RUN_TEXTS = [
184
- c . blue ( LAST_RUN_TEXT ) ,
185
- c . gray ( LAST_RUN_TEXT ) ,
186
- c . dim ( c . gray ( LAST_RUN_TEXT ) ) ,
187
- ]
188
- this . ctx . logger . logUpdate ( BADGE_PADDING + LAST_RUN_TEXTS [ 0 ] )
189
- this . _lastRunTimeout = 0
190
- this . _lastRunTimer = setInterval ( ( ) => {
191
- this . _lastRunTimeout += 1
192
- if ( this . _lastRunTimeout >= LAST_RUN_TEXTS . length ) {
193
- this . resetLastRunLog ( )
194
- }
195
- else {
196
- this . ctx . logger . logUpdate (
197
- BADGE_PADDING + LAST_RUN_TEXTS [ this . _lastRunTimeout ] ,
198
- )
199
- }
200
- } , LAST_RUN_LOG_TIMEOUT / LAST_RUN_TEXTS . length )
201
- }
202
- }
203
-
204
- private resetLastRunLog ( ) {
205
- clearInterval ( this . _lastRunTimer )
206
- this . _lastRunTimer = undefined
207
- this . ctx . logger . logUpdate . clear ( )
208
183
}
209
184
210
185
onWatcherRerun ( files : string [ ] , trigger ?: string ) {
211
- this . resetLastRunLog ( )
212
186
this . watchFilters = files
213
187
this . failedUnwatchedFiles = this . ctx . state . getFiles ( ) . filter ( file =>
214
188
! files . includes ( file . filepath ) && hasFailed ( file ) ,
@@ -222,11 +196,7 @@ export abstract class BaseReporter implements Reporter {
222
196
223
197
let banner = trigger ? c . dim ( `${ this . relative ( trigger ) } ` ) : ''
224
198
225
- if ( files . length > 1 || ! files . length ) {
226
- // we need to figure out how to handle rerun all from stdin
227
- this . _lastRunCount = 0
228
- }
229
- else if ( files . length === 1 ) {
199
+ if ( files . length === 1 ) {
230
200
const rerun = this . _filesInWatchMode . get ( files [ 0 ] ) ?? 1
231
201
banner += c . blue ( `x${ rerun } ` )
232
202
}
@@ -248,10 +218,8 @@ export abstract class BaseReporter implements Reporter {
248
218
249
219
this . log ( '' )
250
220
251
- if ( ! this . isTTY ) {
252
- for ( const task of this . failedUnwatchedFiles ) {
253
- this . printTask ( task )
254
- }
221
+ for ( const task of this . failedUnwatchedFiles ) {
222
+ this . printTask ( task )
255
223
}
256
224
257
225
this . _timeStart = formatTimeString ( new Date ( ) )
@@ -351,6 +319,8 @@ export abstract class BaseReporter implements Reporter {
351
319
}
352
320
353
321
reportTestSummary ( files : File [ ] , errors : unknown [ ] ) {
322
+ this . log ( )
323
+
354
324
const affectedFiles = [
355
325
...this . failedUnwatchedFiles ,
356
326
...files ,
@@ -364,21 +334,21 @@ export abstract class BaseReporter implements Reporter {
364
334
365
335
for ( const [ index , snapshot ] of snapshotOutput . entries ( ) ) {
366
336
const title = index === 0 ? 'Snapshots' : ''
367
- this . log ( `${ padTitle ( title ) } ${ snapshot } ` )
337
+ this . log ( `${ padSummaryTitle ( title ) } ${ snapshot } ` )
368
338
}
369
339
370
340
if ( snapshotOutput . length > 1 ) {
371
341
this . log ( )
372
342
}
373
343
374
- this . log ( padTitle ( 'Test Files' ) , getStateString ( affectedFiles ) )
375
- this . log ( padTitle ( 'Tests' ) , getStateString ( tests ) )
344
+ this . log ( padSummaryTitle ( 'Test Files' ) , getStateString ( affectedFiles ) )
345
+ this . log ( padSummaryTitle ( 'Tests' ) , getStateString ( tests ) )
376
346
377
347
if ( this . ctx . projects . some ( c => c . config . typecheck . enabled ) ) {
378
348
const failed = tests . filter ( t => t . meta ?. typecheck && t . result ?. errors ?. length )
379
349
380
350
this . log (
381
- padTitle ( 'Type Errors' ) ,
351
+ padSummaryTitle ( 'Type Errors' ) ,
382
352
failed . length
383
353
? c . bold ( c . red ( `${ failed . length } failed` ) )
384
354
: c . dim ( 'no errors' ) ,
@@ -387,19 +357,19 @@ export abstract class BaseReporter implements Reporter {
387
357
388
358
if ( errors . length ) {
389
359
this . log (
390
- padTitle ( 'Errors' ) ,
360
+ padSummaryTitle ( 'Errors' ) ,
391
361
c . bold ( c . red ( `${ errors . length } error${ errors . length > 1 ? 's' : '' } ` ) ) ,
392
362
)
393
363
}
394
364
395
- this . log ( padTitle ( 'Start at' ) , this . _timeStart )
365
+ this . log ( padSummaryTitle ( 'Start at' ) , this . _timeStart )
396
366
397
367
const collectTime = sum ( files , file => file . collectDuration )
398
368
const testsTime = sum ( files , file => file . result ?. duration )
399
369
const setupTime = sum ( files , file => file . setupDuration )
400
370
401
371
if ( this . watchFilters ) {
402
- this . log ( padTitle ( 'Duration' ) , time ( collectTime + testsTime + setupTime ) )
372
+ this . log ( padSummaryTitle ( 'Duration' ) , formatTime ( collectTime + testsTime + setupTime ) )
403
373
}
404
374
else {
405
375
const executionTime = this . end - this . start
@@ -409,16 +379,16 @@ export abstract class BaseReporter implements Reporter {
409
379
const typecheck = sum ( this . ctx . projects , project => project . typechecker ?. getResult ( ) . time )
410
380
411
381
const timers = [
412
- `transform ${ time ( transformTime ) } ` ,
413
- `setup ${ time ( setupTime ) } ` ,
414
- `collect ${ time ( collectTime ) } ` ,
415
- `tests ${ time ( testsTime ) } ` ,
416
- `environment ${ time ( environmentTime ) } ` ,
417
- `prepare ${ time ( prepareTime ) } ` ,
418
- typecheck && `typecheck ${ time ( typecheck ) } ` ,
382
+ `transform ${ formatTime ( transformTime ) } ` ,
383
+ `setup ${ formatTime ( setupTime ) } ` ,
384
+ `collect ${ formatTime ( collectTime ) } ` ,
385
+ `tests ${ formatTime ( testsTime ) } ` ,
386
+ `environment ${ formatTime ( environmentTime ) } ` ,
387
+ `prepare ${ formatTime ( prepareTime ) } ` ,
388
+ typecheck && `typecheck ${ formatTime ( typecheck ) } ` ,
419
389
] . filter ( Boolean ) . join ( ', ' )
420
390
421
- this . log ( padTitle ( 'Duration' ) , time ( executionTime ) + c . dim ( ` (${ timers } )` ) )
391
+ this . log ( padSummaryTitle ( 'Duration' ) , formatTime ( executionTime ) + c . dim ( ` (${ timers } )` ) )
422
392
}
423
393
424
394
this . log ( )
@@ -544,17 +514,6 @@ function errorBanner(message: string) {
544
514
return c . red ( divider ( c . bold ( c . inverse ( ` ${ message } ` ) ) ) )
545
515
}
546
516
547
- function padTitle ( str : string ) {
548
- return c . dim ( `${ str . padStart ( 11 ) } ` )
549
- }
550
-
551
- function time ( time : number ) {
552
- if ( time > 1000 ) {
553
- return `${ ( time / 1000 ) . toFixed ( 2 ) } s`
554
- }
555
- return `${ Math . round ( time ) } ms`
556
- }
557
-
558
517
function sum < T > ( items : T [ ] , cb : ( _next : T ) => number | undefined ) {
559
518
return items . reduce ( ( total , next ) => {
560
519
return total + Math . max ( cb ( next ) || 0 , 0 )
0 commit comments