Skip to content

Commit e22999d

Browse files
authored
test(node): Add setExtra integration tests (#4788)
1 parent 37b14bf commit e22999d

File tree

6 files changed

+91
-0
lines changed

6 files changed

+91
-0
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import * as Sentry from '@sentry/node';
2+
3+
Sentry.init({
4+
dsn: 'https://[email protected]/1337',
5+
release: '1.0',
6+
});
7+
8+
Sentry.setExtra('extra_1', {
9+
foo: 'bar',
10+
baz: {
11+
qux: 'quux',
12+
},
13+
});
14+
15+
Sentry.setExtra('extra_2', false);
16+
17+
Sentry.captureMessage('multiple_extras');
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { assertSentryEvent, getEventRequest, runServer } from '../../../../utils';
2+
3+
test('should record multiple extras of different types', async () => {
4+
const url = await runServer(__dirname);
5+
const requestBody = await getEventRequest(url);
6+
7+
assertSentryEvent(requestBody, {
8+
message: 'multiple_extras',
9+
extra: {
10+
extra_1: { foo: 'bar', baz: { qux: 'quux' } },
11+
extra_2: false,
12+
},
13+
});
14+
});
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import * as Sentry from '@sentry/node';
2+
3+
Sentry.init({
4+
dsn: 'https://[email protected]/1337',
5+
release: '1.0',
6+
});
7+
8+
type Circular = {
9+
self?: Circular;
10+
};
11+
12+
const objCircular: Circular = {};
13+
objCircular.self = objCircular;
14+
15+
Sentry.setExtra('non_serializable', objCircular);
16+
17+
Sentry.captureMessage('non_serializable');
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { assertSentryEvent, getEventRequest, runServer } from '../../../../utils';
2+
3+
test('should normalize non-serializable extra', async () => {
4+
const url = await runServer(__dirname);
5+
const requestBody = await getEventRequest(url);
6+
7+
assertSentryEvent(requestBody, {
8+
message: 'non_serializable',
9+
extra: {},
10+
});
11+
});
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import * as Sentry from '@sentry/node';
2+
3+
Sentry.init({
4+
dsn: 'https://[email protected]/1337',
5+
release: '1.0',
6+
});
7+
8+
Sentry.setExtra('foo', {
9+
foo: 'bar',
10+
baz: {
11+
qux: 'quux',
12+
},
13+
});
14+
Sentry.captureMessage('simple_extra');
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { assertSentryEvent, getEventRequest, runServer } from '../../../../utils';
2+
3+
test('should set a simple extra', async () => {
4+
const url = await runServer(__dirname);
5+
const requestBody = await getEventRequest(url);
6+
7+
assertSentryEvent(requestBody, {
8+
message: 'simple_extra',
9+
extra: {
10+
foo: {
11+
foo: 'bar',
12+
baz: {
13+
qux: 'quux',
14+
},
15+
},
16+
},
17+
});
18+
});

0 commit comments

Comments
 (0)