|
1 | 1 | import { Scope, SessionFlusher } from '@sentry/hub';
|
| 2 | +import { Event, EventHint } from '@sentry/types'; |
| 3 | +import * as os from 'os'; |
2 | 4 |
|
3 | 5 | import { NodeClient } from '../src';
|
4 | 6 | import { getDefaultNodeClientOptions } from './helper/node-client-options';
|
@@ -187,6 +189,69 @@ describe('NodeClient', () => {
|
187 | 189 | expect(requestSession!.status).toEqual('ok');
|
188 | 190 | });
|
189 | 191 | });
|
| 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 | + }); |
190 | 255 | });
|
191 | 256 |
|
192 | 257 | describe('flush/close', () => {
|
|
0 commit comments