@@ -213,7 +213,84 @@ describe('utils', () => {
213
213
) ;
214
214
} ) ;
215
215
} ) ;
216
+ describe ( 'when entries contain invalid performance timing' , ( ) => {
217
+ it ( 'should only add events with time greater that or equal to reference value to span' , ( ) => {
218
+ const addEventSpy = sinon . spy ( ) ;
219
+ const span = {
220
+ addEvent : addEventSpy ,
221
+ } as unknown as tracing . Span ;
222
+ const entries = {
223
+ [ PTN . FETCH_START ] : 123 , // default reference time
224
+ [ PTN . CONNECT_START ] : 0 ,
225
+ [ PTN . REQUEST_START ] : 140 ,
226
+ } as PerformanceEntries ;
227
+
228
+ assert . strictEqual ( addEventSpy . callCount , 0 ) ;
229
+
230
+ addSpanNetworkEvent ( span , PTN . CONNECT_START , entries ) ;
231
+
232
+ assert . strictEqual (
233
+ addEventSpy . callCount ,
234
+ 0 ,
235
+ 'should not call addEvent'
236
+ ) ;
237
+
238
+ addSpanNetworkEvent ( span , PTN . REQUEST_START , entries ) ;
239
+
240
+ assert . strictEqual (
241
+ addEventSpy . callCount ,
242
+ 1 ,
243
+ 'should call addEvent for valid value'
244
+ ) ;
245
+ } ) ;
246
+ } ) ;
247
+
248
+ describe ( 'when entries contain invalid performance timing and a reference event' , ( ) => {
249
+ it ( 'should only add events with time greater that or equal to reference value to span' , ( ) => {
250
+ const addEventSpy = sinon . spy ( ) ;
251
+ const span = {
252
+ addEvent : addEventSpy ,
253
+ } as unknown as tracing . Span ;
254
+ const entries = {
255
+ [ PTN . FETCH_START ] : 120 ,
256
+ [ PTN . CONNECT_START ] : 120 , // this is used as reference time here
257
+ [ PTN . REQUEST_START ] : 10 ,
258
+ } as PerformanceEntries ;
259
+
260
+ assert . strictEqual ( addEventSpy . callCount , 0 ) ;
261
+
262
+ addSpanNetworkEvent (
263
+ span ,
264
+ PTN . REQUEST_START ,
265
+ entries ,
266
+ PTN . CONNECT_START
267
+ ) ;
268
+
269
+ assert . strictEqual (
270
+ addEventSpy . callCount ,
271
+ 0 ,
272
+ 'should not call addEvent'
273
+ ) ;
274
+
275
+ addSpanNetworkEvent ( span , PTN . FETCH_START , entries , PTN . CONNECT_START ) ;
276
+
277
+ assert . strictEqual (
278
+ addEventSpy . callCount ,
279
+ 1 ,
280
+ 'should call addEvent for valid value'
281
+ ) ;
282
+
283
+ addEventSpy . resetHistory ( ) ;
284
+ addSpanNetworkEvent ( span , PTN . CONNECT_START , entries , 'foo' ) ; // invalid reference , not adding event to span
285
+ assert . strictEqual (
286
+ addEventSpy . callCount ,
287
+ 0 ,
288
+ 'should not call addEvent for invalid reference(non-existent)'
289
+ ) ;
290
+ } ) ;
291
+ } ) ;
216
292
} ) ;
293
+
217
294
describe ( 'getResource' , ( ) => {
218
295
const startTime = [ 0 , 123123123 ] as HrTime ;
219
296
beforeEach ( ( ) => {
0 commit comments