Skip to content

Commit 689265a

Browse files
authored
test(node): Add withScope integration tests (#4796)
1 parent 509d63a commit 689265a

File tree

2 files changed

+79
-0
lines changed
  • packages/node-integration-tests/suites/public-api/withScope/nested-scopes

2 files changed

+79
-0
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
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.setUser({ id: 'qux' });
9+
Sentry.captureMessage('root_before');
10+
11+
Sentry.withScope(scope => {
12+
scope.setTag('foo', false);
13+
Sentry.captureMessage('outer_before');
14+
15+
Sentry.withScope(scope => {
16+
scope.setTag('bar', 10);
17+
scope.setUser(null);
18+
Sentry.captureMessage('inner');
19+
});
20+
21+
scope.setUser({ id: 'baz' });
22+
Sentry.captureMessage('outer_after');
23+
});
24+
25+
Sentry.captureMessage('root_after');
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
import { Event } from '@sentry/node';
2+
3+
import { assertSentryEvent, getMultipleEventRequests, runServer } from '../../../../utils';
4+
5+
test('should allow nested scoping', async () => {
6+
const url = await runServer(__dirname);
7+
const events = await getMultipleEventRequests(url, 5);
8+
9+
assertSentryEvent(events[0], {
10+
message: 'root_before',
11+
user: {
12+
id: 'qux',
13+
},
14+
tags: {},
15+
});
16+
17+
assertSentryEvent(events[1], {
18+
message: 'outer_before',
19+
user: {
20+
id: 'qux',
21+
},
22+
tags: {
23+
foo: false,
24+
},
25+
});
26+
27+
assertSentryEvent(events[2], {
28+
message: 'inner',
29+
tags: {
30+
foo: false,
31+
bar: 10,
32+
},
33+
});
34+
35+
expect((events[2] as Event).user).toBeUndefined();
36+
37+
assertSentryEvent(events[3], {
38+
message: 'outer_after',
39+
user: {
40+
id: 'baz',
41+
},
42+
tags: {
43+
foo: false,
44+
},
45+
});
46+
47+
assertSentryEvent(events[4], {
48+
message: 'root_after',
49+
user: {
50+
id: 'qux',
51+
},
52+
tags: {},
53+
});
54+
});

0 commit comments

Comments
 (0)