Skip to content

Commit 9371d48

Browse files
author
Luca Forstner
committed
Further fix node tests
1 parent 68165d5 commit 9371d48

File tree

1 file changed

+20
-10
lines changed

1 file changed

+20
-10
lines changed

packages/node/test/handlers.test.ts

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,16 @@ import {
1919
} from '../src/handlers';
2020
import * as SDK from '../src/sdk';
2121
import { setupNodeTransport } from '../src/transports';
22+
import { NodeClientOptions } from '../src/types';
23+
24+
function getDefaultNodeClientOptions(options: Partial<NodeClientOptions> = {}): NodeClientOptions {
25+
return {
26+
integrations: [],
27+
transport: sentryCore.NoopTransport,
28+
stackParser: () => [],
29+
...options,
30+
};
31+
}
2232

2333
describe('parseRequest', () => {
2434
let mockReq: { [key: string]: any };
@@ -224,7 +234,7 @@ describe('requestHandler', () => {
224234
});
225235

226236
it('autoSessionTracking is enabled, sets requestSession status to ok, when handling a request', () => {
227-
const options = { autoSessionTracking: true, release: '1.2' };
237+
const options = getDefaultNodeClientOptions({ autoSessionTracking: true, release: '1.2' });
228238
client = new NodeClient(options, setupNodeTransport(options).transport);
229239
const hub = new Hub(client);
230240

@@ -237,7 +247,7 @@ describe('requestHandler', () => {
237247
});
238248

239249
it('autoSessionTracking is disabled, does not set requestSession, when handling a request', () => {
240-
const options = { autoSessionTracking: false, release: '1.2' };
250+
const options = getDefaultNodeClientOptions({ autoSessionTracking: false, release: '1.2' });
241251
client = new NodeClient(options, setupNodeTransport(options).transport);
242252
const hub = new Hub(client);
243253

@@ -250,7 +260,7 @@ describe('requestHandler', () => {
250260
});
251261

252262
it('autoSessionTracking is enabled, calls _captureRequestSession, on response finish', done => {
253-
const options = { autoSessionTracking: true, release: '1.2' };
263+
const options = getDefaultNodeClientOptions({ autoSessionTracking: true, release: '1.2' });
254264
client = new NodeClient(options, setupNodeTransport(options).transport);
255265
const hub = new Hub(client);
256266

@@ -271,7 +281,7 @@ describe('requestHandler', () => {
271281
});
272282

273283
it('autoSessionTracking is disabled, does not call _captureRequestSession, on response finish', done => {
274-
const options = { autoSessionTracking: false, release: '1.2' };
284+
const options = getDefaultNodeClientOptions({ autoSessionTracking: false, release: '1.2' });
275285
client = new NodeClient(options, setupNodeTransport(options).transport);
276286
const hub = new Hub(client);
277287
jest.spyOn(sentryCore, 'getCurrentHub').mockReturnValue(hub);
@@ -372,7 +382,7 @@ describe('tracingHandler', () => {
372382

373383
it('extracts request data for sampling context', () => {
374384
const tracesSampler = jest.fn();
375-
const options = { tracesSampler };
385+
const options = getDefaultNodeClientOptions({ tracesSampler });
376386
const hub = new Hub(new NodeClient(options, setupNodeTransport(options).transport));
377387
// we need to mock both of these because the tracing handler relies on `@sentry/core` while the sampler relies on
378388
// `@sentry/hub`, and mocking breaks the link between the two
@@ -395,7 +405,7 @@ describe('tracingHandler', () => {
395405
});
396406

397407
it('puts its transaction on the scope', () => {
398-
const options = { tracesSampleRate: 1.0 };
408+
const options = getDefaultNodeClientOptions({ tracesSampleRate: 1.0 });
399409
const hub = new Hub(new NodeClient(options, setupNodeTransport(options).transport));
400410
// we need to mock both of these because the tracing handler relies on `@sentry/core` while the sampler relies on
401411
// `@sentry/hub`, and mocking breaks the link between the two
@@ -727,7 +737,7 @@ describe('errorHandler()', () => {
727737
jest.restoreAllMocks();
728738
});
729739
it('when autoSessionTracking is disabled, does not set requestSession status on Crash', () => {
730-
const options = { autoSessionTracking: false, release: '3.3' };
740+
const options = getDefaultNodeClientOptions({ autoSessionTracking: false, release: '3.3' });
731741
client = new NodeClient(options, setupNodeTransport(options).transport);
732742
// It is required to initialise SessionFlusher to capture Session Aggregates (it is usually initialised
733743
// by the`requestHandler`)
@@ -747,7 +757,7 @@ describe('errorHandler()', () => {
747757
});
748758

749759
it('autoSessionTracking is enabled + requestHandler is not used -> does not set requestSession status on Crash', () => {
750-
const options = { autoSessionTracking: false, release: '3.3' };
760+
const options = getDefaultNodeClientOptions({ autoSessionTracking: false, release: '3.3' });
751761
client = new NodeClient(options, setupNodeTransport(options).transport);
752762

753763
const scope = sentryCore.getCurrentHub().getScope();
@@ -764,7 +774,7 @@ describe('errorHandler()', () => {
764774
});
765775

766776
it('when autoSessionTracking is enabled, should set requestSession status to Crashed when an unhandled error occurs within the bounds of a request', () => {
767-
const options = { autoSessionTracking: true, release: '1.1' };
777+
const options = getDefaultNodeClientOptions({ autoSessionTracking: true, release: '1.1' });
768778
client = new NodeClient(options, setupNodeTransport(options).transport);
769779
// It is required to initialise SessionFlusher to capture Session Aggregates (it is usually initialised
770780
// by the`requestHandler`)
@@ -783,7 +793,7 @@ describe('errorHandler()', () => {
783793
});
784794

785795
it('when autoSessionTracking is enabled, should not set requestSession status on Crash when it occurs outside the bounds of a request', () => {
786-
const options = { autoSessionTracking: true, release: '2.2' };
796+
const options = getDefaultNodeClientOptions({ autoSessionTracking: true, release: '2.2' });
787797
client = new NodeClient(options, setupNodeTransport(options).transport);
788798
// It is required to initialise SessionFlusher to capture Session Aggregates (it is usually initialised
789799
// by the`requestHandler`)

0 commit comments

Comments
 (0)