Skip to content

Commit ddb0555

Browse files
authored
fix(node): Fix failing test (#3057)
allow timestamps to be equal and add an additional check for those cases
1 parent 73b9bbd commit ddb0555

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

packages/node/test/handlers.test.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -308,8 +308,8 @@ describe('tracingHandler', () => {
308308
});
309309
});
310310

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 });
313313
transaction.initSpanRecorder();
314314
const span = transaction.startChild({
315315
description: 'reallyCoolHandler',
@@ -319,6 +319,11 @@ describe('tracingHandler', () => {
319319
const finishSpan = jest.spyOn(span, 'finish');
320320
const finishTransaction = jest.spyOn(transaction, 'finish');
321321

322+
let sentEvent: Event;
323+
jest.spyOn((transaction as any)._hub, 'captureEvent').mockImplementation(event => {
324+
sentEvent = event as Event;
325+
});
326+
322327
sentryTracingMiddleware(req, res, next);
323328
res.once('finish', () => {
324329
span.finish();
@@ -328,7 +333,9 @@ describe('tracingHandler', () => {
328333
setImmediate(() => {
329334
expect(finishSpan).toHaveBeenCalled();
330335
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);
332339
done();
333340
});
334341
});

0 commit comments

Comments
 (0)