-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
/
Copy pathtest.ts
85 lines (82 loc) · 2.54 KB
/
test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
import { cleanupChildProcesses, createRunner } from '../../../utils/runner';
afterAll(() => {
cleanupChildProcesses();
});
/**
* Why does this test exist?
*
* We recently discovered that errors caught by global handlers will potentially loose scope data from the active scope
* where the error was originally thrown in. The simple example in this test (see subject.ts) demonstrates this behavior
* (in a Node environment but the same behavior applies to the browser; see the test there).
*
* This test nevertheless covers the behavior so that we're aware.
*/
test('withScope scope is NOT applied to thrown error caught by global handler', done => {
createRunner(__dirname, 'server.ts')
.expect({
event: {
exception: {
values: [
{
mechanism: {
type: 'middleware',
handled: false,
},
type: 'Error',
value: 'test_error',
stacktrace: {
frames: expect.arrayContaining([
expect.objectContaining({
function: expect.any(String),
lineno: expect.any(Number),
colno: expect.any(Number),
}),
]),
},
},
],
},
// 'local' tag is not applied to the event
tags: expect.not.objectContaining({ local: expect.anything() }),
},
})
.start(done)
.makeRequest('get', '/test/withScope', { expectError: true });
});
/**
* This test shows that the isolation scope set tags are applied correctly to the error.
*/
test('isolation scope is applied to thrown error caught by global handler', done => {
createRunner(__dirname, 'server.ts')
.expect({
event: {
exception: {
values: [
{
mechanism: {
type: 'middleware',
handled: false,
},
type: 'Error',
value: 'isolation_test_error',
stacktrace: {
frames: expect.arrayContaining([
expect.objectContaining({
function: expect.any(String),
lineno: expect.any(Number),
colno: expect.any(Number),
}),
]),
},
},
],
},
tags: {
global: 'tag',
'isolation-scope': 'tag',
},
},
})
.start(done)
.makeRequest('get', '/test/isolationScope', { expectError: true });
});