Skip to content

Commit 398976c

Browse files
authored
test(node): Add configureScope integration tests (#4786)
1 parent 5375de8 commit 398976c

File tree

4 files changed

+64
-0
lines changed

4 files changed

+64
-0
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
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.configureScope(scope => {
9+
scope.setTag('foo', 'bar');
10+
scope.setUser({ id: 'baz' });
11+
scope.setExtra('qux', 'quux');
12+
scope.clear();
13+
});
14+
15+
Sentry.captureMessage('cleared_scope');
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { Event } from '@sentry/node';
2+
3+
import { assertSentryEvent, getEventRequest, runServer } from '../../../../utils';
4+
5+
test('should clear previously set properties of a scope', async () => {
6+
const url = await runServer(__dirname);
7+
const requestBody = await getEventRequest(url);
8+
9+
assertSentryEvent(requestBody, {
10+
message: 'cleared_scope',
11+
tags: {},
12+
extra: {},
13+
});
14+
15+
expect((requestBody as Event).user).not.toBeDefined();
16+
});
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.configureScope(scope => {
9+
scope.setTag('foo', 'bar');
10+
scope.setUser({ id: 'baz' });
11+
scope.setExtra('qux', 'quux');
12+
});
13+
14+
Sentry.captureMessage('configured_scope');
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { assertSentryEvent, getEventRequest, runServer } from '../../../../utils';
2+
3+
test('should set different properties of a scope', async () => {
4+
const url = await runServer(__dirname);
5+
const requestBody = await getEventRequest(url);
6+
7+
assertSentryEvent(requestBody, {
8+
message: 'configured_scope',
9+
tags: {
10+
foo: 'bar',
11+
},
12+
extra: {
13+
qux: 'quux',
14+
},
15+
user: {
16+
id: 'baz',
17+
},
18+
});
19+
});

0 commit comments

Comments
 (0)