1
+ import type { UserConsoleLog } from 'vitest'
1
2
import type {
2
3
ReportedHookContext ,
3
4
Reporter ,
@@ -159,7 +160,10 @@ describe('TestCase', () => {
159
160
test ( 'single test case' , async ( ) => {
160
161
const report = await run ( {
161
162
'example.test.ts' : ts `
162
- test('single test case', () => {});
163
+ test('single test case', async () => {
164
+ await new Promise(resolve => setTimeout(resolve, 150))
165
+ console.log("Test running!")
166
+ });
163
167
` ,
164
168
} )
165
169
@@ -169,6 +173,7 @@ describe('TestCase', () => {
169
173
onTestModuleCollected (example.test.ts)
170
174
onTestModuleStart (example.test.ts)
171
175
onTestCaseReady (example.test.ts) |single test case|
176
+ onUserConsoleLog (example.test.ts) |single test case| > Test running!
172
177
onTestCaseResult (example.test.ts) |single test case|
173
178
onTestModuleEnd (example.test.ts)"
174
179
` )
@@ -1141,9 +1146,14 @@ async function run(
1141
1146
1142
1147
class CustomReporter implements Reporter {
1143
1148
calls : string [ ] = [ ]
1149
+ ctx ! : Vitest
1144
1150
1145
1151
constructor ( private options : ReporterOptions = { } ) { }
1146
1152
1153
+ onInit ( ctx : Vitest ) {
1154
+ this . ctx = ctx
1155
+ }
1156
+
1147
1157
onTestRunStart ( specifications : ReadonlyArray < TestSpecification > ) {
1148
1158
if ( this . options . printTestRunEvents ) {
1149
1159
this . calls . push ( `onTestRunStart (${ specifications . length } specifications)` )
@@ -1188,6 +1198,13 @@ class CustomReporter implements Reporter {
1188
1198
this . calls . push ( `${ padded ( test , 'onTestCaseResult' ) } (${ this . normalizeFilename ( test . module ) } ) |${ test . name } |` )
1189
1199
}
1190
1200
1201
+ onUserConsoleLog ( log : UserConsoleLog ) {
1202
+ const task = this . ctx . state . idMap . get ( log . taskId ! )
1203
+ const test = task && this . ctx . state . getReportedEntity ( task ) as TestCase
1204
+
1205
+ this . calls . push ( `${ padded ( test ! , 'onUserConsoleLog' ) } (${ this . normalizeFilename ( test ! . module ) } ) |${ test ! . name } | > ${ log . content . replaceAll ( '\n' , '' ) } ` )
1206
+ }
1207
+
1191
1208
onHookStart ( hook : ReportedHookContext ) {
1192
1209
const module = hook . entity . type === 'module' ? hook . entity : hook . entity . module
1193
1210
const name = hook . entity . type !== 'module' ? ` |${ hook . entity . name } |` : ''
0 commit comments