@@ -57,13 +57,15 @@ it('returns same commands', () => {
5757
5858it ( "does not log timings and doesn't throw if no logger is provided" , ( ) => {
5959 controller = new LogTimings ( { } ) ;
60- controller . handle ( commands ) ;
60+ const { onFinish } = controller . handle ( commands ) ;
6161
6262 commands [ 0 ] . timer . next ( { startDate : startDate0 } ) ;
6363 commands [ 1 ] . timer . next ( { startDate : startDate1 } ) ;
6464 commands [ 1 ] . timer . next ( { startDate : startDate1 , endDate : endDate1 } ) ;
6565 commands [ 0 ] . timer . next ( { startDate : startDate0 , endDate : endDate0 } ) ;
6666
67+ onFinish ?.( ) ;
68+
6769 expect ( logger . logCommandEvent ) . toHaveBeenCalledTimes ( 0 ) ;
6870} ) ;
6971
@@ -101,20 +103,26 @@ it('logs the timings at the start and end (ie complete or error) event of each c
101103} ) ;
102104
103105it ( 'does not log timings summary if there was an error' , ( ) => {
104- controller . handle ( commands ) ;
106+ const { onFinish } = controller . handle ( commands ) ;
105107
106108 commands [ 0 ] . close . next ( command0ExitInfo ) ;
107109 commands [ 1 ] . error . next ( undefined ) ;
108110
111+ onFinish ?.( ) ;
112+
109113 expect ( logger . logTable ) . toHaveBeenCalledTimes ( 0 ) ;
110114} ) ;
111115
112- it ( 'logs the sorted timings summary when all processes close successfully' , ( ) => {
113- controller . handle ( commands ) ;
116+ it ( 'logs the sorted timings summary when all processes close successfully after onFinish is called ' , ( ) => {
117+ const { onFinish } = controller . handle ( commands ) ;
114118
115119 commands [ 0 ] . close . next ( command0ExitInfo ) ;
116120 commands [ 1 ] . close . next ( command1ExitInfo ) ;
117121
122+ expect ( logger . logGlobalEvent ) . toHaveBeenCalledTimes ( 0 ) ;
123+
124+ onFinish ?.( ) ;
125+
118126 expect ( logger . logGlobalEvent ) . toHaveBeenCalledTimes ( 1 ) ;
119127 expect ( logger . logGlobalEvent ) . toHaveBeenCalledWith ( 'Timings:' ) ;
120128 expect ( logger . logTable ) . toHaveBeenCalledTimes ( 1 ) ;
0 commit comments