@@ -14,6 +14,7 @@ import {
14
14
getFullName ,
15
15
getSafeTimers ,
16
16
getSuites ,
17
+ getTestName ,
17
18
getTests ,
18
19
hasFailed ,
19
20
hasFailedSnapshot ,
@@ -33,8 +34,8 @@ import {
33
34
formatTimeString ,
34
35
getStateString ,
35
36
getStateSymbol ,
36
- pointer ,
37
37
renderSnapshotSummary ,
38
+ taskFail ,
38
39
} from './renderers/utils'
39
40
40
41
const BADGE_PADDING = ' '
@@ -63,6 +64,7 @@ export abstract class BaseReporter implements Reporter {
63
64
start = 0
64
65
end = 0
65
66
watchFilters ?: string [ ]
67
+ failedUnwatchedFiles : Task [ ] = [ ]
66
68
isTTY : boolean
67
69
ctx : Vitest = undefined !
68
70
@@ -115,59 +117,65 @@ export abstract class BaseReporter implements Reporter {
115
117
if ( this . isTTY ) {
116
118
return
117
119
}
118
- const logger = this . ctx . logger
119
120
for ( const pack of packs ) {
120
121
const task = this . ctx . state . idMap . get ( pack [ 0 ] )
121
- if (
122
- task
123
- && 'filepath' in task
124
- && task . result ?. state
125
- && task . result ?. state !== 'run'
126
- ) {
127
- const tests = getTests ( task )
128
- const failed = tests . filter ( t => t . result ?. state === 'fail' )
129
- const skipped = tests . filter (
130
- t => t . mode === 'skip' || t . mode === 'todo' ,
131
- )
132
- let state = c . dim ( `${ tests . length } test${ tests . length > 1 ? 's' : '' } ` )
133
- if ( failed . length ) {
134
- state += ` ${ c . dim ( '|' ) } ${ c . red ( `${ failed . length } failed` ) } `
135
- }
136
- if ( skipped . length ) {
137
- state += ` ${ c . dim ( '|' ) } ${ c . yellow ( `${ skipped . length } skipped` ) } `
138
- }
139
- let suffix = c . dim ( ' (' ) + state + c . dim ( ')' )
140
- if ( task . result . duration ) {
141
- const color
142
- = task . result . duration > this . ctx . config . slowTestThreshold
143
- ? c . yellow
144
- : c . gray
145
- suffix += color ( ` ${ Math . round ( task . result . duration ) } ${ c . dim ( 'ms' ) } ` )
146
- }
147
- if ( this . ctx . config . logHeapUsage && task . result . heap != null ) {
148
- suffix += c . magenta (
149
- ` ${ Math . floor ( task . result . heap / 1024 / 1024 ) } MB heap used` ,
150
- )
151
- }
152
-
153
- let title = ` ${ getStateSymbol ( task ) } `
154
- if ( task . projectName ) {
155
- title += formatProjectName ( task . projectName )
156
- }
157
- title += `${ task . name } ${ suffix } `
158
- logger . log ( title )
159
-
160
- // print short errors, full errors will be at the end in summary
161
- for ( const test of failed ) {
162
- logger . log ( c . red ( ` ${ pointer } ${ getFullName ( test , c . dim ( ' > ' ) ) } ` ) )
163
- test . result ?. errors ?. forEach ( ( e ) => {
164
- logger . log ( c . red ( ` ${ F_RIGHT } ${ ( e as any ) ?. message } ` ) )
165
- } )
166
- }
122
+ if ( task ) {
123
+ this . printTask ( task )
167
124
}
168
125
}
169
126
}
170
127
128
+ protected printTask ( task : Task ) {
129
+ if (
130
+ ! ( 'filepath' in task )
131
+ || ! task . result ?. state
132
+ || task . result ?. state === 'run' ) {
133
+ return
134
+ }
135
+ const logger = this . ctx . logger
136
+
137
+ const tests = getTests ( task )
138
+ const failed = tests . filter ( t => t . result ?. state === 'fail' )
139
+ const skipped = tests . filter (
140
+ t => t . mode === 'skip' || t . mode === 'todo' ,
141
+ )
142
+ let state = c . dim ( `${ tests . length } test${ tests . length > 1 ? 's' : '' } ` )
143
+ if ( failed . length ) {
144
+ state += ` ${ c . dim ( '|' ) } ${ c . red ( `${ failed . length } failed` ) } `
145
+ }
146
+ if ( skipped . length ) {
147
+ state += ` ${ c . dim ( '|' ) } ${ c . yellow ( `${ skipped . length } skipped` ) } `
148
+ }
149
+ let suffix = c . dim ( ' (' ) + state + c . dim ( ')' )
150
+ if ( task . result . duration ) {
151
+ const color
152
+ = task . result . duration > this . ctx . config . slowTestThreshold
153
+ ? c . yellow
154
+ : c . gray
155
+ suffix += color ( ` ${ Math . round ( task . result . duration ) } ${ c . dim ( 'ms' ) } ` )
156
+ }
157
+ if ( this . ctx . config . logHeapUsage && task . result . heap != null ) {
158
+ suffix += c . magenta (
159
+ ` ${ Math . floor ( task . result . heap / 1024 / 1024 ) } MB heap used` ,
160
+ )
161
+ }
162
+
163
+ let title = ` ${ getStateSymbol ( task ) } `
164
+ if ( task . projectName ) {
165
+ title += formatProjectName ( task . projectName )
166
+ }
167
+ title += `${ task . name } ${ suffix } `
168
+ logger . log ( title )
169
+
170
+ // print short errors, full errors will be at the end in summary
171
+ for ( const test of failed ) {
172
+ logger . log ( c . red ( ` ${ taskFail } ${ getTestName ( test , c . dim ( ' > ' ) ) } ` ) )
173
+ test . result ?. errors ?. forEach ( ( e ) => {
174
+ logger . log ( c . red ( ` ${ F_RIGHT } ${ ( e as any ) ?. message } ` ) )
175
+ } )
176
+ }
177
+ }
178
+
171
179
onWatcherStart (
172
180
files = this . ctx . state . getFiles ( ) ,
173
181
errors = this . ctx . state . getUnhandledErrors ( ) ,
@@ -233,6 +241,9 @@ export abstract class BaseReporter implements Reporter {
233
241
onWatcherRerun ( files : string [ ] , trigger ?: string ) {
234
242
this . resetLastRunLog ( )
235
243
this . watchFilters = files
244
+ this . failedUnwatchedFiles = this . ctx . state . getFiles ( ) . filter ( ( file ) => {
245
+ return ! files . includes ( file . filepath ) && hasFailed ( file )
246
+ } )
236
247
237
248
files . forEach ( ( filepath ) => {
238
249
let reruns = this . _filesInWatchMode . get ( filepath ) ?? 0
@@ -274,6 +285,12 @@ export abstract class BaseReporter implements Reporter {
274
285
)
275
286
}
276
287
288
+ if ( ! this . isTTY ) {
289
+ for ( const task of this . failedUnwatchedFiles ) {
290
+ this . printTask ( task )
291
+ }
292
+ }
293
+
277
294
this . _timeStart = new Date ( )
278
295
this . start = performance . now ( )
279
296
}
@@ -375,7 +392,11 @@ export abstract class BaseReporter implements Reporter {
375
392
}
376
393
377
394
reportTestSummary ( files : File [ ] , errors : unknown [ ] ) {
378
- const tests = getTests ( files )
395
+ const affectedFiles = [
396
+ ...this . failedUnwatchedFiles ,
397
+ ...files ,
398
+ ]
399
+ const tests = getTests ( affectedFiles )
379
400
const logger = this . ctx . logger
380
401
381
402
const executionTime = this . end - this . start
@@ -437,7 +458,7 @@ export abstract class BaseReporter implements Reporter {
437
458
}
438
459
}
439
460
440
- logger . log ( padTitle ( 'Test Files' ) , getStateString ( files ) )
461
+ logger . log ( padTitle ( 'Test Files' ) , getStateString ( affectedFiles ) )
441
462
logger . log ( padTitle ( 'Tests' ) , getStateString ( tests ) )
442
463
if ( this . ctx . projects . some ( c => c . config . typecheck . enabled ) ) {
443
464
const failed = tests . filter (
0 commit comments