@@ -308,8 +308,8 @@ describe('tracingHandler', () => {
308
308
} ) ;
309
309
} ) ;
310
310
311
- it ( 'lets all spans being finished before calling ` finish` itself, despite being registered to `res.finish` event first' , done => {
312
- const transaction = new Transaction ( { name : 'mockTransaction' } ) ;
311
+ it ( 'waits to finish transaction until all spans are finished, even though `transaction. finish()` is registered on `res.finish` event first' , done => {
312
+ const transaction = new Transaction ( { name : 'mockTransaction' , sampled : true } ) ;
313
313
transaction . initSpanRecorder ( ) ;
314
314
const span = transaction . startChild ( {
315
315
description : 'reallyCoolHandler' ,
@@ -319,6 +319,11 @@ describe('tracingHandler', () => {
319
319
const finishSpan = jest . spyOn ( span , 'finish' ) ;
320
320
const finishTransaction = jest . spyOn ( transaction , 'finish' ) ;
321
321
322
+ let sentEvent : Event ;
323
+ jest . spyOn ( ( transaction as any ) . _hub , 'captureEvent' ) . mockImplementation ( event => {
324
+ sentEvent = event as Event ;
325
+ } ) ;
326
+
322
327
sentryTracingMiddleware ( req , res , next ) ;
323
328
res . once ( 'finish' , ( ) => {
324
329
span . finish ( ) ;
@@ -328,7 +333,9 @@ describe('tracingHandler', () => {
328
333
setImmediate ( ( ) => {
329
334
expect ( finishSpan ) . toHaveBeenCalled ( ) ;
330
335
expect ( finishTransaction ) . toHaveBeenCalled ( ) ;
331
- expect ( span . endTimestamp ) . toBeLessThan ( transaction . endTimestamp ! ) ;
336
+ expect ( span . endTimestamp ) . toBeLessThanOrEqual ( transaction . endTimestamp ! ) ;
337
+ expect ( sentEvent . spans ?. length ) . toEqual ( 1 ) ;
338
+ expect ( sentEvent . spans ?. [ 0 ] . spanId ) . toEqual ( span . spanId ) ;
332
339
done ( ) ;
333
340
} ) ;
334
341
} ) ;
0 commit comments