Skip to content

fix(node): Fix failing test #3057

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Nov 18, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions packages/node/test/handlers.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -308,8 +308,8 @@ describe('tracingHandler', () => {
});
});

it('lets all spans being finished before calling `finish` itself, despite being registered to `res.finish` event first', done => {
const transaction = new Transaction({ name: 'mockTransaction' });
it('waits to finish transaction until all spans are finished, even though `transaction.finish()` is registered on `res.finish` event first', done => {
const transaction = new Transaction({ name: 'mockTransaction', sampled: true });
transaction.initSpanRecorder();
const span = transaction.startChild({
description: 'reallyCoolHandler',
Expand All @@ -319,6 +319,11 @@ describe('tracingHandler', () => {
const finishSpan = jest.spyOn(span, 'finish');
const finishTransaction = jest.spyOn(transaction, 'finish');

let sentEvent: Event;
jest.spyOn((transaction as any)._hub, 'captureEvent').mockImplementation(event => {
sentEvent = event as Event;
});

sentryTracingMiddleware(req, res, next);
res.once('finish', () => {
span.finish();
Expand All @@ -328,7 +333,9 @@ describe('tracingHandler', () => {
setImmediate(() => {
expect(finishSpan).toHaveBeenCalled();
expect(finishTransaction).toHaveBeenCalled();
expect(span.endTimestamp).toBeLessThan(transaction.endTimestamp!);
expect(span.endTimestamp).toBeLessThanOrEqual(transaction.endTimestamp!);
expect(sentEvent.spans?.length).toEqual(1);
expect(sentEvent.spans?.[0].spanId).toEqual(span.spanId);
done();
});
});
Expand Down