Skip to content

Commit c252036

Browse files
committed
fix tests
1 parent eb9da37 commit c252036

File tree

6 files changed

+442
-378
lines changed

6 files changed

+442
-378
lines changed

packages/node/test/client.test.ts

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
import { Scope, SessionFlusher } from '@sentry/hub';
2+
import { Event, EventHint } from '@sentry/types';
3+
import * as os from 'os';
24

35
import { NodeClient } from '../src';
46
import { getDefaultNodeClientOptions } from './helper/node-client-options';
@@ -187,6 +189,69 @@ describe('NodeClient', () => {
187189
expect(requestSession!.status).toEqual('ok');
188190
});
189191
});
192+
193+
describe('_prepareEvent', () => {
194+
test('adds platform to event', () => {
195+
const options = getDefaultNodeClientOptions({ dsn: PUBLIC_DSN });
196+
client = new NodeClient(options);
197+
198+
const event: Event = {};
199+
const hint: EventHint = {};
200+
(client as any)._prepareEvent(event, hint);
201+
202+
expect(event.platform).toEqual('node');
203+
});
204+
205+
test('adds runtime context to event', () => {
206+
const options = getDefaultNodeClientOptions({ dsn: PUBLIC_DSN });
207+
client = new NodeClient(options);
208+
209+
const event: Event = {};
210+
const hint: EventHint = {};
211+
(client as any)._prepareEvent(event, hint);
212+
213+
expect(event.contexts?.runtime).toEqual({
214+
name: 'node',
215+
version: process.version,
216+
});
217+
});
218+
219+
test('adds server name to event when value passed in options', () => {
220+
const options = getDefaultNodeClientOptions({ dsn: PUBLIC_DSN, serverName: 'foo' });
221+
client = new NodeClient(options);
222+
223+
const event: Event = {};
224+
const hint: EventHint = {};
225+
(client as any)._prepareEvent(event, hint);
226+
227+
expect(event.server_name).toEqual('foo');
228+
});
229+
230+
test('adds server name to event when value given in env', () => {
231+
const options = getDefaultNodeClientOptions({ dsn: PUBLIC_DSN });
232+
client = new NodeClient(options);
233+
process.env.SENTRY_NAME = 'foo';
234+
235+
const event: Event = {};
236+
const hint: EventHint = {};
237+
(client as any)._prepareEvent(event, hint);
238+
239+
expect(event.server_name).toEqual('foo');
240+
241+
delete process.env.SENTRY_NAME;
242+
});
243+
244+
test('adds hostname as event server name when no value given', () => {
245+
const options = getDefaultNodeClientOptions({ dsn: PUBLIC_DSN });
246+
client = new NodeClient(options);
247+
248+
const event: Event = {};
249+
const hint: EventHint = {};
250+
(client as any)._prepareEvent(event, hint);
251+
252+
expect(event.server_name).toEqual(os.hostname());
253+
});
254+
});
190255
});
191256

192257
describe('flush/close', () => {

0 commit comments

Comments
 (0)