@@ -71,6 +71,7 @@ class MyReporter {
71
71
this . _paths = new PathHelper ( { cwd : process . cwd ( ) } , this . _testEnv . location_prefix ) ;
72
72
this . currentTestSteps = [ ] ;
73
73
this . currentTestCucumberSteps = [ ] ;
74
+ this . hooksStarted = { } ;
74
75
this . beforeHooks = [ ] ;
75
76
this . platformDetailsMap = { } ;
76
77
this . runStatusMarkedHash = { } ;
@@ -93,7 +94,6 @@ class MyReporter {
93
94
delete this . runStatusMarkedHash [ hook . hookAnalyticsId ] ;
94
95
hook . hookAnalyticsId = uuidv4 ( ) ;
95
96
}
96
- console . log ( "At hook begin " , hook . hookAnalyticsId + hook . fullTitle ( ) )
97
97
hook . hook_started_at = ( new Date ( ) ) . toISOString ( ) ;
98
98
hook . started_at = ( new Date ( ) ) . toISOString ( ) ;
99
99
this . current_hook = hook ;
@@ -102,7 +102,6 @@ class MyReporter {
102
102
} )
103
103
104
104
. on ( EVENT_HOOK_END , async ( hook ) => {
105
- console . log ( "At hook end " , this . current_hook . hookAnalyticsId , hook . fullTitle ( ) )
106
105
if ( this . testObservability == true ) {
107
106
// console.log("At hook end bool", this.runStatusMarkedHash[hook.hookAnalyticsId])
108
107
if ( ! this . runStatusMarkedHash [ hook . hookAnalyticsId ] ) {
@@ -114,6 +113,8 @@ class MyReporter {
114
113
this . runStatusMarkedHash [ hook . hookAnalyticsId ] = true ;
115
114
}
116
115
console . log ( "Sending hook finished " , hook . hookAnalyticsId ) ;
116
+ // Remove hooks added at hook start
117
+ delete this . hooksStarted [ hook . hookAnalyticsId ] ;
117
118
await this . sendTestRunEvent ( hook , undefined , false , "HookRunFinished" ) ;
118
119
}
119
120
}
@@ -151,22 +152,19 @@ class MyReporter {
151
152
if ( ! test . testAnalyticsId ) test . testAnalyticsId = uuidv4 ( ) ;
152
153
if ( ! this . runStatusMarkedHash [ test . testAnalyticsId ] ) {
153
154
this . runStatusMarkedHash [ test . testAnalyticsId ] = true ;
154
- consoleHolder . log ( "Inside event for event_test_pending " + test . state ) ;
155
155
await this . sendTestRunEvent ( test , undefined , false , "TestRunSkipped" ) ;
156
156
}
157
157
}
158
158
} )
159
159
160
160
. on ( EVENT_TEST_BEGIN , async ( test ) => {
161
- consoleHolder . log ( "Inside event for event_test_begin " + test . state + " " + test . isSkipped ) ;
162
161
if ( test . isSkipped ) return ;
163
162
if ( this . testObservability == true ) {
164
163
await this . testStarted ( test ) ;
165
164
}
166
165
} )
167
166
168
167
. on ( EVENT_TEST_END , async ( test ) => {
169
- consoleHolder . log ( "Inside event for event_test_end " + test . state + " " + test . isSkipped ) ;
170
168
if ( test . isSkipped ) return ;
171
169
if ( this . testObservability == true ) {
172
170
if ( ! this . runStatusMarkedHash [ test . testAnalyticsId ] ) {
@@ -263,8 +261,6 @@ class MyReporter {
263
261
}
264
262
265
263
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 )
268
264
try {
269
265
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 ;
270
266
let failureArgs = [ ] ;
@@ -447,6 +443,27 @@ class MyReporter {
447
443
} ;
448
444
await uploadEventData ( buildUpdateData ) ;
449
445
}
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
+ }
450
467
} catch ( error ) {
451
468
debug ( `Exception in populating test data for event ${ eventType } with error : ${ error } ` , true , error ) ;
452
469
}
0 commit comments