@@ -370,6 +370,48 @@ ${ansis.green('✔')} Uploaded report to portal ${ansis.gray('(42 ms)')}
370370 ) ;
371371 } ) ;
372372
373+ it ( 'should allow spinners to be run in sequence' , async ( ) => {
374+ performanceNowSpy
375+ . mockReset ( )
376+ . mockReturnValueOnce ( 0 )
377+ . mockReturnValueOnce ( 30_000 ) // 1st task duration: 30 s
378+ . mockReturnValueOnce ( 0 )
379+ . mockReturnValueOnce ( 1_000 ) ; // 2nd task duration: 1 s
380+
381+ const task1 = new Logger ( ) . task (
382+ 'Collecting report' ,
383+ async ( ) => 'Collected report' ,
384+ ) ;
385+
386+ expect ( output ) . toBe ( `${ ansis . cyan ( '⠋' ) } Collecting report` ) ;
387+
388+ await expect ( task1 ) . resolves . toBeUndefined ( ) ;
389+
390+ expect ( output ) . toBe (
391+ `${ ansis . green ( '✔' ) } Collected report ${ ansis . gray ( '(30 s)' ) } \n` ,
392+ ) ;
393+
394+ const task2 = new Logger ( ) . task (
395+ 'Uploading report to portal' ,
396+ async ( ) => 'Uploaded report to portal' ,
397+ ) ;
398+
399+ expect ( output ) . toBe (
400+ `
401+ ${ ansis . green ( '✔' ) } Collected report ${ ansis . gray ( '(30 s)' ) }
402+ ${ ansis . cyan ( '⠋' ) } Uploading report to portal`. trimStart ( ) ,
403+ ) ;
404+
405+ await expect ( task2 ) . resolves . toBeUndefined ( ) ;
406+
407+ expect ( output ) . toBe (
408+ `
409+ ${ ansis . green ( '✔' ) } Collected report ${ ansis . gray ( '(30 s)' ) }
410+ ${ ansis . green ( '✔' ) } Uploaded report to portal ${ ansis . gray ( '(1 s)' ) }
411+ ` . trimStart ( ) ,
412+ ) ;
413+ } ) ;
414+
373415 it ( 'should fail spinner and exit if SIGINT received' , async ( ) => {
374416 vi . spyOn ( process , 'exit' ) . mockReturnValue ( undefined as never ) ;
375417 vi . spyOn ( os , 'platform' ) . mockReturnValue ( 'linux' ) ;
@@ -896,4 +938,17 @@ ${ansis.red.bold('Cancelled by SIGINT')}
896938 ) ;
897939 } ) ;
898940 } ) ;
941+
942+ it ( 'should throw if spinners are nested' , async ( ) => {
943+ const logger = new Logger ( ) ;
944+
945+ await expect (
946+ logger . task ( 'Task 1' , async ( ) => {
947+ await logger . task ( 'Task 2' , async ( ) => 'DONE' ) ;
948+ return 'DONE' ;
949+ } ) ,
950+ ) . rejects . toThrow (
951+ 'Internal Logger error - concurrent spinners are not supported' ,
952+ ) ;
953+ } ) ;
899954} ) ;
0 commit comments