Skip to content

Commit 1e8a5f2

Browse files
committed
fix node unit tests
1 parent 22f932a commit 1e8a5f2

File tree

2 files changed

+152
-139
lines changed

2 files changed

+152
-139
lines changed

packages/node/test/client.test.ts

Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { Scope, SessionFlusher } from '@sentry/hub';
22

33
import { NodeClient } from '../src';
4+
import { setupNodeTransport } from '../src/transports';
45

56
const PUBLIC_DSN = 'https://username@domain/123';
67

@@ -14,7 +15,8 @@ describe('NodeClient', () => {
1415

1516
describe('captureException', () => {
1617
test('when autoSessionTracking is enabled, and requestHandler is not used -> requestStatus should not be set', () => {
17-
client = new NodeClient({ dsn: PUBLIC_DSN, autoSessionTracking: true, release: '1.4' });
18+
const options = { dsn: PUBLIC_DSN, autoSessionTracking: true, release: '1.4' };
19+
client = new NodeClient(options, setupNodeTransport(options).transport);
1820
const scope = new Scope();
1921
scope.setRequestSession({ status: 'ok' });
2022

@@ -24,7 +26,8 @@ describe('NodeClient', () => {
2426
expect(requestSession!.status).toEqual('ok');
2527
});
2628
test('when autoSessionTracking is disabled -> requestStatus should not be set', () => {
27-
client = new NodeClient({ dsn: PUBLIC_DSN, autoSessionTracking: false, release: '1.4' });
29+
const options = { dsn: PUBLIC_DSN, autoSessionTracking: false, release: '1.4' };
30+
client = new NodeClient(options, setupNodeTransport(options).transport);
2831
// It is required to initialise SessionFlusher to capture Session Aggregates (it is usually initialised
2932
// by the`requestHandler`)
3033
client.initSessionFlusher();
@@ -38,7 +41,8 @@ describe('NodeClient', () => {
3841
expect(requestSession!.status).toEqual('ok');
3942
});
4043
test('when autoSessionTracking is enabled + requestSession status is Crashed -> requestStatus should not be overridden', () => {
41-
client = new NodeClient({ dsn: PUBLIC_DSN, autoSessionTracking: true, release: '1.4' });
44+
const options = { dsn: PUBLIC_DSN, autoSessionTracking: true, release: '1.4' };
45+
client = new NodeClient(options, setupNodeTransport(options).transport);
4246
// It is required to initialise SessionFlusher to capture Session Aggregates (it is usually initialised
4347
// by the`requestHandler`)
4448
client.initSessionFlusher();
@@ -52,7 +56,8 @@ describe('NodeClient', () => {
5256
expect(requestSession!.status).toEqual('crashed');
5357
});
5458
test('when autoSessionTracking is enabled + error occurs within request bounds -> requestStatus should be set to Errored', () => {
55-
client = new NodeClient({ dsn: PUBLIC_DSN, autoSessionTracking: true, release: '1.4' });
59+
const options = { dsn: PUBLIC_DSN, autoSessionTracking: true, release: '1.4' };
60+
client = new NodeClient(options, setupNodeTransport(options).transport);
5661
// It is required to initialise SessionFlusher to capture Session Aggregates (it is usually initialised
5762
// by the`requestHandler`)
5863
client.initSessionFlusher();
@@ -66,7 +71,8 @@ describe('NodeClient', () => {
6671
expect(requestSession!.status).toEqual('errored');
6772
});
6873
test('when autoSessionTracking is enabled + error occurs outside of request bounds -> requestStatus should not be set to Errored', () => {
69-
client = new NodeClient({ dsn: PUBLIC_DSN, autoSessionTracking: true, release: '1.4' });
74+
const options = { dsn: PUBLIC_DSN, autoSessionTracking: true, release: '1.4' };
75+
client = new NodeClient(options, setupNodeTransport(options).transport);
7076
// It is required to initialise SessionFlusher to capture Session Aggregates (it is usually initialised
7177
// by the`requestHandler`)
7278
client.initSessionFlusher();
@@ -82,7 +88,8 @@ describe('NodeClient', () => {
8288

8389
describe('captureEvent()', () => {
8490
test('If autoSessionTracking is disabled, requestSession status should not be set', () => {
85-
client = new NodeClient({ dsn: PUBLIC_DSN, autoSessionTracking: false, release: '1.4' });
91+
const options = { dsn: PUBLIC_DSN, autoSessionTracking: false, release: '1.4' };
92+
client = new NodeClient(options, setupNodeTransport(options).transport);
8693
// It is required to initialise SessionFlusher to capture Session Aggregates (it is usually initialised
8794
// by the`requestHandler`)
8895
client.initSessionFlusher();
@@ -100,7 +107,8 @@ describe('NodeClient', () => {
100107
});
101108

102109
test('When captureEvent is called with an exception, requestSession status should be set to Errored', () => {
103-
client = new NodeClient({ dsn: PUBLIC_DSN, autoSessionTracking: true, release: '2.2' });
110+
const options = { dsn: PUBLIC_DSN, autoSessionTracking: true, release: '2.2' };
111+
client = new NodeClient(options, setupNodeTransport(options).transport);
104112
// It is required to initialise SessionFlusher to capture Session Aggregates (it is usually initialised
105113
// by the`requestHandler`)
106114
client.initSessionFlusher();
@@ -115,7 +123,8 @@ describe('NodeClient', () => {
115123
});
116124

117125
test('When captureEvent is called without an exception, requestSession status should not be set to Errored', () => {
118-
client = new NodeClient({ dsn: PUBLIC_DSN, autoSessionTracking: true, release: '2.2' });
126+
const options = { dsn: PUBLIC_DSN, autoSessionTracking: true, release: '2.2' };
127+
client = new NodeClient(options, setupNodeTransport(options).transport);
119128
// It is required to initialise SessionFlusher to capture Session Aggregates (it is usually initialised
120129
// by the`requestHandler`)
121130
client.initSessionFlusher();
@@ -130,7 +139,8 @@ describe('NodeClient', () => {
130139
});
131140

132141
test('When captureEvent is called with an exception but outside of a request, then requestStatus should not be set', () => {
133-
client = new NodeClient({ dsn: PUBLIC_DSN, autoSessionTracking: true, release: '2.2' });
142+
const options = { dsn: PUBLIC_DSN, autoSessionTracking: true, release: '2.2' };
143+
client = new NodeClient(options, setupNodeTransport(options).transport);
134144
// It is required to initialise SessionFlusher to capture Session Aggregates (it is usually initialised
135145
// by the`requestHandler`)
136146
client.initSessionFlusher();
@@ -147,7 +157,8 @@ describe('NodeClient', () => {
147157
});
148158

149159
test('When captureEvent is called with a transaction, then requestSession status should not be set', () => {
150-
client = new NodeClient({ dsn: PUBLIC_DSN, autoSessionTracking: true, release: '1.3' });
160+
const options = { dsn: PUBLIC_DSN, autoSessionTracking: true, release: '1.3' };
161+
client = new NodeClient(options, setupNodeTransport(options).transport);
151162
// It is required to initialise SessionFlusher to capture Session Aggregates (it is usually initialised
152163
// by the`requestHandler`)
153164
client.initSessionFlusher();
@@ -161,7 +172,8 @@ describe('NodeClient', () => {
161172
});
162173

163174
test('When captureEvent is called with an exception but requestHandler is not used, then requestSession status should not be set', () => {
164-
client = new NodeClient({ dsn: PUBLIC_DSN, autoSessionTracking: true, release: '1.3' });
175+
const options = { dsn: PUBLIC_DSN, autoSessionTracking: true, release: '1.3' };
176+
client = new NodeClient(options, setupNodeTransport(options).transport);
165177

166178
const scope = new Scope();
167179
scope.setRequestSession({ status: 'ok' });
@@ -180,11 +192,12 @@ describe('NodeClient', () => {
180192
describe('flush/close', () => {
181193
test('client close function disables _sessionFlusher', async () => {
182194
jest.useRealTimers();
183-
const client = new NodeClient({
195+
const options = {
184196
dsn: PUBLIC_DSN,
185197
autoSessionTracking: true,
186198
release: '1.1',
187-
});
199+
};
200+
const client = new NodeClient(options, setupNodeTransport(options).transport);
188201
client.initSessionFlusher();
189202
// Clearing interval is important here to ensure that the flush function later on is called by the `client.close()`
190203
// not due to the interval running every 60s

0 commit comments

Comments
 (0)