@@ -29,13 +29,15 @@ class HoneycombReporter {
29
29
suite . honeycombEvent = this . honey . newEvent ( )
30
30
suite . honeycombEvent . timestamp = Date . now ( )
31
31
suite . honeycombEvent . add ( {
32
+ ...suite . parent . honeycombEvent . data ,
32
33
suite : suite . title ,
33
34
specFile : path . basename ( suite . file ) ,
34
35
35
36
spanId : uuidv4 ( ) ,
36
37
parentId : suite . parent . honeycombEvent . data . spanId ,
37
- traceId : suite . parent . honeycombEvent . data . traceId ,
38
38
} )
39
+
40
+ this . addAsyncInfo ( suite . honeycombEvent )
39
41
} )
40
42
41
43
runner . on ( 'test' , ( test ) => {
@@ -50,13 +52,15 @@ class HoneycombReporter {
50
52
test . honeycombEvent = this . honey . newEvent ( )
51
53
test . honeycombEvent . timestamp = Date . now ( )
52
54
test . honeycombEvent . add ( {
55
+ ...test . parent . honeycombEvent . data ,
53
56
test : testTitle ,
54
57
browser,
55
58
56
59
spanId : uuidv4 ( ) ,
57
60
parentId : test . parent . honeycombEvent . data . spanId ,
58
- traceId : test . parent . honeycombEvent . data . traceId ,
59
61
} )
62
+
63
+ this . addAsyncInfo ( test . honeycombEvent )
60
64
} )
61
65
62
66
runner . on ( 'test end' , ( test ) => {
@@ -72,7 +76,8 @@ class HoneycombReporter {
72
76
durationMs : Date . now ( ) - test . honeycombEvent . timestamp ,
73
77
} )
74
78
75
- test . honeycombEvent . send ( )
79
+ console . log ( test . honeycombEvent . data )
80
+ // test.honeycombEvent.send()
76
81
} )
77
82
78
83
runner . on ( 'suite end' , ( suite ) => {
@@ -104,20 +109,31 @@ class HoneycombReporter {
104
109
traceId : uuidv4 ( ) ,
105
110
} )
106
111
107
- commitInfo ( ) . then ( ( commitInformation ) => {
108
- const ciInformation = ciProvider . commitParams ( ) || { }
112
+ this . addAsyncInfo ( honeycombEvent )
109
113
110
- honeycombEvent . add ( {
111
- branch : commitInformation . branch || ciInformation . branch ,
112
- commitSha : commitInformation . sha || ciInformation . sha ,
113
- } )
114
- } )
114
+ return honeycombEvent
115
+ }
115
116
116
- getNextVersionForPath ( '../../packages' ) . then ( ( next ) => {
117
- honeycombEvent . add ( { nextVersion : next } )
118
- } )
117
+ // Because mocha has no way to wait on async functions inside hooks,
118
+ // and we need to call various async functions to gather data about
119
+ // the testing environment, we create a promise that can be used by each
120
+ // honeycomb event to add async data that won't be initialized by the
121
+ // time mocha starts running tests.
122
+ addAsyncInfo ( honeycombEvent ) {
123
+ if ( ! this . asyncInfo ) {
124
+ this . asyncInfo = Promise . all ( [ getNextVersionForPath ( '../../packages' ) , commitInfo ( ) ] )
125
+ . then ( ( [ nextVersion , commitInformation ] ) => {
126
+ const ciInformation = ciProvider . commitParams ( ) || { }
127
+
128
+ return {
129
+ nextVersion,
130
+ branch : commitInformation . branch || ciInformation . branch ,
131
+ commitSha : commitInformation . sha || ciInformation . sha ,
132
+ }
133
+ } )
134
+ }
119
135
120
- return honeycombEvent
136
+ this . asyncInfo . then ( ( info ) => honeycombEvent . add ( info ) )
121
137
}
122
138
}
123
139
0 commit comments