77import type { Task , TaskResultPack } from '@vitest/runner'
88import { getNames , getTests } from '@vitest/runner/utils'
99import colors , { type Colors } from 'tinyrainbow'
10- import type { RunnerTask } from 'vitest'
10+ import type { RunnerTask , RunnerTestFile } from 'vitest'
1111import { DefaultReporter , type Reporter } from 'vitest/reporters'
1212
13- /**
14- * Verbose reporter options.
15- */
16- interface Options {
17- /**
18- * Enable summary reporter?
19- *
20- * @default true
21- */
22- summary ?: boolean | null | undefined
23- }
24-
2513/**
2614 * Verbose reporter.
2715 *
@@ -43,13 +31,12 @@ class VerboseReporter extends DefaultReporter implements Reporter {
4331
4432 /**
4533 * Create a new verbose reporter.
46- *
47- * @param {Options | null | undefined } [options]
48- * Reporter options
4934 */
50- constructor ( options ?: Options | null | undefined ) {
51- super ( { summary : options ?. summary ?? true } )
35+ constructor ( ) {
36+ super ( { summary : true } )
37+
5238 this . colors = colors
39+ this . renderSucceed = true
5340 this . verbose = true
5441 }
5542
@@ -113,6 +100,29 @@ class VerboseReporter extends DefaultReporter implements Reporter {
113100 /**
114101 * Print tasks.
115102 *
103+ * @see {@linkcode RunnerTestFile }
104+ *
105+ * @public
106+ * @override
107+ * @instance
108+ *
109+ * @param {RunnerTestFile[] | undefined } [files]
110+ * List of test files
111+ * @param {unknown[] | undefined } [errors]
112+ * List of unhandled errors
113+ * @return {undefined }
114+ */
115+ public override onFinished (
116+ files ?: RunnerTestFile [ ] | undefined ,
117+ errors ?: unknown [ ] | undefined
118+ ) : undefined {
119+ if ( files ) { for ( const task of files ) this . printTask ( task , true ) }
120+ return void super . onFinished ( files , errors )
121+ }
122+
123+ /**
124+ * Handle task updates.
125+ *
116126 * @see {@linkcode TaskResultPack }
117127 *
118128 * @public
@@ -124,20 +134,7 @@ class VerboseReporter extends DefaultReporter implements Reporter {
124134 * @return {undefined }
125135 */
126136 public override onTaskUpdate ( packs : TaskResultPack [ ] ) : undefined {
127- for ( const pack of packs ) {
128- /**
129- * Current task.
130- *
131- * @const {Task | undefined} task
132- */
133- const task : Task | undefined = this . ctx . state . idMap . get ( pack [ 0 ] )
134-
135- // print top-level suite task and recursively print tests
136- if ( task && task . type === 'suite' && 'filepath' in task ) {
137- void this . printTask ( task )
138- }
139- }
140-
137+ this . isTTY && void super . onTaskUpdate ( packs )
141138 return void packs
142139 }
143140
@@ -152,10 +149,20 @@ class VerboseReporter extends DefaultReporter implements Reporter {
152149 *
153150 * @param {Task | null | undefined } task
154151 * The task to handle
152+ * @param {boolean | null | undefined } [force]
153+ * Print `task` even when {@linkcode isTTY} is `false`?
155154 * @return {undefined }
156155 */
157- protected override printTask ( task : Task | null | undefined ) : undefined {
158- if ( task && task . result ?. state !== 'run' ) {
156+ protected override printTask (
157+ task : Task | null | undefined ,
158+ force ?: boolean | null | undefined
159+ ) : undefined {
160+ if (
161+ ( ! this . isTTY || force ) &&
162+ task ?. result ?. state &&
163+ task . result . state !== 'queued' &&
164+ task . result . state !== 'run'
165+ ) {
159166 /**
160167 * Task skipped?
161168 *
@@ -197,7 +204,10 @@ class VerboseReporter extends DefaultReporter implements Reporter {
197204 state += skip ? this . colors . blackBright ( suite ) : suite
198205
199206 this . log ( state )
200- if ( ! skip ) { for ( const tsk of task . tasks ) void this . printTask ( tsk ) }
207+
208+ if ( ! skip ) {
209+ for ( const subtask of task . tasks ) void this . printTask ( subtask , force )
210+ }
201211 }
202212 }
203213
0 commit comments