@@ -2,6 +2,7 @@ import type { File, Task, TaskResultPack } from '@vitest/runner'
2
2
import type { ErrorWithDiff , UserConsoleLog } from '../../types/general'
3
3
import type { Vitest } from '../core'
4
4
import type { Reporter } from '../types/reporter'
5
+ import type { TestCase , TestModule , TestSuite } from './reported-tasks'
5
6
import { performance } from 'node:perf_hooks'
6
7
import { getFullName , getSuites , getTestName , getTests , hasFailed } from '@vitest/runner/utils'
7
8
import { toArray } from '@vitest/utils'
@@ -66,6 +67,32 @@ export abstract class BaseReporter implements Reporter {
66
67
}
67
68
}
68
69
70
+ onTestCaseResult ( testCase : TestCase ) : void {
71
+ if ( testCase . result ( ) . state === 'failed' ) {
72
+ this . logFailedTask ( testCase . task )
73
+ }
74
+ }
75
+
76
+ onTestSuiteResult ( testSuite : TestSuite ) : void {
77
+ if ( testSuite . state ( ) === 'failed' ) {
78
+ this . logFailedTask ( testSuite . task )
79
+ }
80
+ }
81
+
82
+ onTestModuleEnd ( testModule : TestModule ) : void {
83
+ if ( testModule . state ( ) === 'failed' ) {
84
+ this . logFailedTask ( testModule . task )
85
+ }
86
+ }
87
+
88
+ private logFailedTask ( task : Task ) {
89
+ if ( this . ctx . config . silent === 'silent-passed-tests' ) {
90
+ for ( const log of task . logs || [ ] ) {
91
+ this . onUserConsoleLog ( log , true )
92
+ }
93
+ }
94
+ }
95
+
69
96
onTaskUpdate ( packs : TaskResultPack [ ] ) : void {
70
97
for ( const pack of packs ) {
71
98
const task = this . ctx . state . idMap . get ( pack [ 0 ] )
@@ -275,8 +302,8 @@ export abstract class BaseReporter implements Reporter {
275
302
this . start = performance . now ( )
276
303
}
277
304
278
- onUserConsoleLog ( log : UserConsoleLog ) : void {
279
- if ( ! this . shouldLog ( log ) ) {
305
+ onUserConsoleLog ( log : UserConsoleLog , force = false ) : void {
306
+ if ( ! force && ! this . shouldLog ( log ) ) {
280
307
return
281
308
}
282
309
0 commit comments