11import { relative } from 'pathe' ;
2- import type { TestFileResult , TestResult } from '../types' ;
3- import { color , prettyTestPath , prettyTime } from '../utils' ;
2+ import type { TestCaseInfo , TestFileResult , TestResult } from '../types' ;
3+ import {
4+ color ,
5+ getTaskNameWithPrefix ,
6+ POINTER ,
7+ prettyTestPath ,
8+ prettyTime ,
9+ } from '../utils' ;
410import {
511 DurationLabel ,
612 getSummaryStatusString ,
@@ -12,7 +18,10 @@ import { WindowRenderer } from './windowedRenderer';
1218export class StatusRenderer {
1319 private rootPath : string ;
1420 private renderer : WindowRenderer ;
15- private runningModules = new Map < string , TestResult [ ] > ( ) ;
21+ private runningModules = new Map <
22+ string ,
23+ { runningTests : TestCaseInfo [ ] ; results : TestResult [ ] }
24+ > ( ) ;
1625 private testModules : TestFileResult [ ] = [ ] ;
1726 private startTime : number | undefined = undefined ;
1827
@@ -32,13 +41,32 @@ export class StatusRenderer {
3241
3342 getContent ( ) : string [ ] {
3443 this . startTime ??= Date . now ( ) ;
44+ const now = Date . now ( ) ;
3545 const summary = [ ] ;
36- for ( const module of this . runningModules . keys ( ) ) {
46+
47+ // only display running tests if they have been running for more than 2 seconds
48+ const shouldDisplayRunningTests = ( runningTests : TestCaseInfo [ ] ) => {
49+ return (
50+ runningTests [ 0 ] ?. startTime && now - runningTests [ 0 ] . startTime > 2000
51+ ) ;
52+ } ;
53+
54+ for ( const [ module , { runningTests } ] of this . runningModules . entries ( ) ) {
3755 const relativePath = relative ( this . rootPath , module ) ;
3856 summary . push (
3957 `${ color . bgYellow ( color . bold ( ' RUNS ' ) ) } ${ prettyTestPath ( relativePath ) } ` ,
4058 ) ;
59+ if ( runningTests . length && shouldDisplayRunningTests ( runningTests ) ) {
60+ let caseLog = ` ${ color . gray ( POINTER ) } ${ getTaskNameWithPrefix ( runningTests [ 0 ] ! ) } ${ color . magenta ( prettyTime ( now - runningTests [ 0 ] ! . startTime ! ) ) } ` ;
61+
62+ if ( runningTests . length > 1 ) {
63+ caseLog += color . gray ( ` and ${ runningTests . length - 1 } more cases` ) ;
64+ }
65+
66+ summary . push ( caseLog ) ;
67+ }
4168 }
69+
4270 summary . push ( '' ) ;
4371
4472 if ( this . testModules . length === 0 ) {
@@ -50,7 +78,7 @@ export class StatusRenderer {
5078 }
5179
5280 const testResults : TestResult [ ] = Array . from ( this . runningModules . values ( ) )
53- . flat ( )
81+ . flatMap ( ( { results } ) => results )
5482 . concat ( this . testModules . flatMap ( ( mod ) => mod . results ) ) ;
5583
5684 if ( testResults . length ) {
@@ -67,15 +95,48 @@ export class StatusRenderer {
6795 }
6896
6997 onTestFileStart ( testPath : string ) : void {
70- this . runningModules . set ( testPath , [ ] ) ;
98+ this . runningModules . set ( testPath , { runningTests : [ ] , results : [ ] } ) ;
7199 this . renderer ?. schedule ( ) ;
72100 }
73101
74102 onTestCaseResult ( result : TestResult ) : void {
75- this . runningModules . set ( result . testPath , [
76- ...( this . runningModules . get ( result . testPath ) || [ ] ) ,
77- result ,
78- ] ) ;
103+ const currentModule = this . runningModules . get ( result . testPath ) ;
104+ if ( ! currentModule ) {
105+ this . runningModules . set ( result . testPath , {
106+ runningTests : [ ] ,
107+ results : [ result ] ,
108+ } ) ;
109+ } else {
110+ // Find and remove the test from runningTests by matching testId
111+ const filteredRunningTests = currentModule . runningTests . filter (
112+ ( t ) => t . testId !== result . testId ,
113+ ) ;
114+ this . runningModules . set ( result . testPath , {
115+ runningTests : filteredRunningTests ,
116+ results : [ ...currentModule . results , result ] ,
117+ } ) ;
118+ }
119+
120+ this . renderer ?. schedule ( ) ;
121+ }
122+
123+ onTestCaseStart ( test : TestCaseInfo ) : void {
124+ const currentModule = this . runningModules . get ( test . testPath ) ;
125+ if ( ! currentModule ) {
126+ this . runningModules . set ( test . testPath , {
127+ runningTests : [ test ] ,
128+ results : [ ] ,
129+ } ) ;
130+ } else {
131+ // Remove from runningTests if it exists (for restart scenarios)
132+ const filteredRunningTests = currentModule . runningTests . filter (
133+ ( t ) => t . testId !== test . testId ,
134+ ) ;
135+ this . runningModules . set ( test . testPath , {
136+ runningTests : [ ...filteredRunningTests , test ] ,
137+ results : currentModule . results ,
138+ } ) ;
139+ }
79140 }
80141
81142 onTestFileResult ( test : TestFileResult ) : void {
0 commit comments