Skip to content

Commit 7c91b7b

Browse files
committed
add test demonstrating correct isolationScope behavior
1 parent bfb8f4c commit 7c91b7b

File tree

2 files changed

+43
-1
lines changed
  • dev-packages/node-integration-tests/suites/express/handle-error-scope-data-loss

2 files changed

+43
-1
lines changed

dev-packages/node-integration-tests/suites/express/handle-error-withScope/server.ts renamed to dev-packages/node-integration-tests/suites/express/handle-error-scope-data-loss/server.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,11 @@ app.get('/test/withScope', () => {
2121
});
2222
});
2323

24+
app.get('/test/isolationScope', () => {
25+
Sentry.getIsolationScope().setTag('isolation-scope', 'tag');
26+
throw new Error('isolation_test_error');
27+
});
28+
2429
app.use(Sentry.Handlers.errorHandler());
2530

2631
startExpressServerAndSendPortToRunner(app);

dev-packages/node-integration-tests/suites/express/handle-error-withScope/test.ts renamed to dev-packages/node-integration-tests/suites/express/handle-error-scope-data-loss/test.ts

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ afterAll(() => {
1313
*
1414
* This test nevertheless covers the behavior so that we're aware.
1515
*/
16-
test('applies withScope scope to thrown error', done => {
16+
test('withScope scope is NOT applied to thrown error caught by global handler', done => {
1717
const runner = createRunner(__dirname, 'server.ts')
1818
.ignore('session', 'sessions')
1919
.expect({
@@ -49,3 +49,40 @@ test('applies withScope scope to thrown error', done => {
4949

5050
expect(() => runner.makeRequest('get', '/test/withScope')).rejects.toThrow();
5151
});
52+
53+
test('isolation scope is applied to thrown error caught by global handler', done => {
54+
const runner = createRunner(__dirname, 'server.ts')
55+
.ignore('session', 'sessions')
56+
.expect({
57+
event: {
58+
exception: {
59+
values: [
60+
{
61+
mechanism: {
62+
type: 'middleware',
63+
handled: false,
64+
},
65+
type: 'Error',
66+
value: 'isolation_test_error',
67+
stacktrace: {
68+
frames: expect.arrayContaining([
69+
expect.objectContaining({
70+
function: expect.any(String),
71+
lineno: expect.any(Number),
72+
colno: expect.any(Number),
73+
}),
74+
]),
75+
},
76+
},
77+
],
78+
},
79+
tags: {
80+
global: 'tag',
81+
'isolation-scope': 'tag',
82+
},
83+
},
84+
})
85+
.start(done);
86+
87+
expect(() => runner.makeRequest('get', '/test/isolationScope')).rejects.toThrow();
88+
});

0 commit comments

Comments
 (0)