Skip to content

Commit bfb8f4c

Browse files
committed
cleanup
1 parent 99bca74 commit bfb8f4c

File tree

3 files changed

+36
-13
lines changed
  • dev-packages
    • browser-integration-tests/suites/public-api/withScope/throwError
    • node-integration-tests/suites/express/handle-error-withScope

3 files changed

+36
-13
lines changed

dev-packages/browser-integration-tests/suites/public-api/withScope/throwError/test.ts

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,30 @@ import type { Event } from '@sentry/types';
44
import { sentryTest } from '../../../../utils/fixtures';
55
import { getFirstSentryEnvelopeRequest } from '../../../../utils/helpers';
66

7-
sentryTest('scope is applied to thrown error', async ({ getLocalTestPath, page }) => {
8-
const url = await getLocalTestPath({ testDir: __dirname });
7+
/**
8+
* Why does this test exist?
9+
*
10+
* We recently discovered that errors caught by global handlers will potentially loose scope data from the active scope
11+
* where the error was thrown in. The simple example in this test (see subject.ts) demonstrates this behavior (in a
12+
* browser environment but the same behavior applies to the server; see the test there).
13+
*
14+
* This test nevertheless covers the behavior so that we're aware.
15+
*/
16+
sentryTest(
17+
'withScope scope is NOT applied to thrown error caught by global handler',
18+
async ({ getLocalTestPath, page }) => {
19+
const url = await getLocalTestPath({ testDir: __dirname });
920

10-
const eventData = await getFirstSentryEnvelopeRequest<Event>(page, url);
21+
const eventData = await getFirstSentryEnvelopeRequest<Event>(page, url);
1122

12-
const ex = eventData.exception?.values ? eventData.exception.values[0] : undefined;
23+
const ex = eventData.exception?.values ? eventData.exception.values[0] : undefined;
1324

14-
expect(eventData.tags).toMatchObject({
15-
global: 'tag',
16-
local: 'tag', // this tag is missing :(
17-
});
18-
expect(ex?.value).toBe('test error');
19-
});
25+
// This tag is missing :(
26+
expect(eventData.tags?.local).toBeUndefined();
27+
28+
expect(eventData.tags).toMatchObject({
29+
global: 'tag',
30+
});
31+
expect(ex?.value).toBe('test error');
32+
},
33+
);

dev-packages/node-integration-tests/suites/express/handle-error-withScope/server.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ app.use(Sentry.Handlers.requestHandler());
1414

1515
Sentry.setTag('global', 'tag');
1616

17-
app.get('/test/express', () => {
17+
app.get('/test/withScope', () => {
1818
Sentry.withScope(scope => {
1919
scope.setTag('local', 'tag');
2020
throw new Error('test_error');

dev-packages/node-integration-tests/suites/express/handle-error-withScope/test.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,15 @@ afterAll(() => {
44
cleanupChildProcesses();
55
});
66

7+
/**
8+
* Why does this test exist?
9+
*
10+
* We recently discovered that errors caught by global handlers will potentially loose scope data from the active scope
11+
* where the error was originally thrown in. The simple example in this test (see subject.ts) demonstrates this behavior
12+
* (in a Node environment but the same behavior applies to the browser; see the test there).
13+
*
14+
* This test nevertheless covers the behavior so that we're aware.
15+
*/
716
test('applies withScope scope to thrown error', done => {
817
const runner = createRunner(__dirname, 'server.ts')
918
.ignore('session', 'sessions')
@@ -32,11 +41,11 @@ test('applies withScope scope to thrown error', done => {
3241
},
3342
tags: {
3443
global: 'tag',
35-
local: 'tag', // This tag is missing :(
44+
local: undefined, // This tag is missing :(
3645
},
3746
},
3847
})
3948
.start(done);
4049

41-
expect(() => runner.makeRequest('get', '/test/express')).rejects.toThrow();
50+
expect(() => runner.makeRequest('get', '/test/withScope')).rejects.toThrow();
4251
});

0 commit comments

Comments
 (0)