@@ -71,6 +71,7 @@ class MyReporter {
7171 this . _paths = new PathHelper ( { cwd : process . cwd ( ) } , this . _testEnv . location_prefix ) ;
7272 this . currentTestSteps = [ ] ;
7373 this . currentTestCucumberSteps = [ ] ;
74+ this . hooksStarted = { } ;
7475 this . beforeHooks = [ ] ;
7576 this . platformDetailsMap = { } ;
7677 this . runStatusMarkedHash = { } ;
@@ -93,7 +94,6 @@ class MyReporter {
9394 delete this . runStatusMarkedHash [ hook . hookAnalyticsId ] ;
9495 hook . hookAnalyticsId = uuidv4 ( ) ;
9596 }
96- console . log ( "At hook begin " , hook . hookAnalyticsId + hook . fullTitle ( ) )
9797 hook . hook_started_at = ( new Date ( ) ) . toISOString ( ) ;
9898 hook . started_at = ( new Date ( ) ) . toISOString ( ) ;
9999 this . current_hook = hook ;
@@ -102,7 +102,6 @@ class MyReporter {
102102 } )
103103
104104 . on ( EVENT_HOOK_END , async ( hook ) => {
105- console . log ( "At hook end " , this . current_hook . hookAnalyticsId , hook . fullTitle ( ) )
106105 if ( this . testObservability == true ) {
107106 // console.log("At hook end bool", this.runStatusMarkedHash[hook.hookAnalyticsId])
108107 if ( ! this . runStatusMarkedHash [ hook . hookAnalyticsId ] ) {
@@ -114,6 +113,8 @@ class MyReporter {
114113 this . runStatusMarkedHash [ hook . hookAnalyticsId ] = true ;
115114 }
116115 console . log ( "Sending hook finished " , hook . hookAnalyticsId ) ;
116+ // Remove hooks added at hook start
117+ delete this . hooksStarted [ hook . hookAnalyticsId ] ;
117118 await this . sendTestRunEvent ( hook , undefined , false , "HookRunFinished" ) ;
118119 }
119120 }
@@ -151,22 +152,19 @@ class MyReporter {
151152 if ( ! test . testAnalyticsId ) test . testAnalyticsId = uuidv4 ( ) ;
152153 if ( ! this . runStatusMarkedHash [ test . testAnalyticsId ] ) {
153154 this . runStatusMarkedHash [ test . testAnalyticsId ] = true ;
154- consoleHolder . log ( "Inside event for event_test_pending " + test . state ) ;
155155 await this . sendTestRunEvent ( test , undefined , false , "TestRunSkipped" ) ;
156156 }
157157 }
158158 } )
159159
160160 . on ( EVENT_TEST_BEGIN , async ( test ) => {
161- consoleHolder . log ( "Inside event for event_test_begin " + test . state + " " + test . isSkipped ) ;
162161 if ( test . isSkipped ) return ;
163162 if ( this . testObservability == true ) {
164163 await this . testStarted ( test ) ;
165164 }
166165 } )
167166
168167 . on ( EVENT_TEST_END , async ( test ) => {
169- consoleHolder . log ( "Inside event for event_test_end " + test . state + " " + test . isSkipped ) ;
170168 if ( test . isSkipped ) return ;
171169 if ( this . testObservability == true ) {
172170 if ( ! this . runStatusMarkedHash [ test . testAnalyticsId ] ) {
@@ -263,8 +261,6 @@ class MyReporter {
263261 }
264262
265263 sendTestRunEvent = async ( test , err = undefined , customFinished = false , eventType = "TestRunFinished" ) => {
266- debug ( "Sending test run event for " + eventType ) ;
267- consoleHolder . log ( "Sending test run event for " + eventType )
268264 try {
269265 if ( test . body && test . body . match ( / b r o w s e r s t a c k i n t e r n a l h e l p e r h o o k / ) ) return ;
270266 let failureArgs = [ ] ;
@@ -447,6 +443,27 @@ class MyReporter {
447443 } ;
448444 await uploadEventData ( buildUpdateData ) ;
449445 }
446+
447+ // Add started hooks to the hash
448+ if ( eventType === 'HookRunStarted' && [ 'BEFORE_EACH' , 'AFTER_EACH' , 'BEFORE_ALL' ] . includes ( testData [ 'hook_type' ] ) ) {
449+ this . hooksStarted [ testData . uuid ] = uploadData ;
450+ }
451+
452+ // Send pending hook finsihed events for hook starts
453+ if ( eventType === 'TestRunFinished' ) {
454+ Object . values ( this . hooksStarted ) . forEach ( async hookData => {
455+ hookData [ 'hook_run' ] . finished_at = hookData [ 'hook_run' ] . started_at ;
456+ hookData [ 'hook_run' ] . duration = 0 ;
457+ hookData [ 'hook_run' ] . result = uploadData [ 'test_run' ] . result ;
458+ hookData [ 'hook_run' ] . failure = uploadData [ 'test_run' ] . failure ;
459+ hookData [ 'hook_run' ] . failure_type = uploadData [ 'test_run' ] . failure_type ;
460+ hookData [ 'hook_run' ] . failure_reason = uploadData [ 'test_run' ] . failure_reason ;
461+ hookData [ 'hook_run' ] . failure_reason_expanded = uploadData [ 'test_run' ] . failure_reason_expanded ;
462+ hookData [ 'hook_run' ] . failure_backtrace = uploadData [ 'test_run' ] . failure_backtrace ;
463+ await uploadEventData ( hookData ) ;
464+ } )
465+ this . hooksStarted = { } ;
466+ }
450467 } catch ( error ) {
451468 debug ( `Exception in populating test data for event ${ eventType } with error : ${ error } ` , true , error ) ;
452469 }
0 commit comments