-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
/
Copy pathtest.ts
210 lines (192 loc) · 5.1 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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
import type { Event } from '@sentry/core';
import { conditionalTest } from '../../utils';
import { cleanupChildProcesses, createRunner } from '../../utils/runner';
const ANR_EVENT = {
// Ensure we have context
contexts: {
trace: {
span_id: expect.stringMatching(/[a-f0-9]{16}/),
trace_id: expect.stringMatching(/[a-f0-9]{32}/),
},
device: {
arch: expect.any(String),
},
app: {
app_start_time: expect.any(String),
},
os: {
name: expect.any(String),
},
culture: {
timezone: expect.any(String),
},
},
// and an exception that is our ANR
exception: {
values: [
{
type: 'ApplicationNotResponding',
value: 'Application Not Responding for at least 100 ms',
mechanism: { type: 'ANR' },
stacktrace: {
frames: expect.arrayContaining([
{
colno: expect.any(Number),
lineno: expect.any(Number),
filename: expect.any(String),
function: '?',
in_app: true,
},
{
colno: expect.any(Number),
lineno: expect.any(Number),
filename: expect.any(String),
function: 'longWork',
in_app: true,
},
]),
},
},
],
},
};
const ANR_EVENT_WITHOUT_STACKTRACE = {
// Ensure we have context
contexts: {
device: {
arch: expect.any(String),
},
app: {
app_start_time: expect.any(String),
},
os: {
name: expect.any(String),
},
culture: {
timezone: expect.any(String),
},
},
// and an exception that is our ANR
exception: {
values: [
{
type: 'ApplicationNotResponding',
value: 'Application Not Responding for at least 100 ms',
mechanism: { type: 'ANR' },
stacktrace: {},
},
],
},
};
const ANR_EVENT_WITH_SCOPE = {
...ANR_EVENT,
user: {
email: '[email protected]',
},
breadcrumbs: expect.arrayContaining([
{
timestamp: expect.any(Number),
message: 'important message!',
},
]),
};
const ANR_EVENT_WITH_DEBUG_META: Event = {
...ANR_EVENT_WITH_SCOPE,
debug_meta: {
images: [
{
type: 'sourcemap',
debug_id: 'aaaaaaaa-aaaa-4aaa-aaaa-aaaaaaaaaa',
code_file: expect.stringContaining('basic.'),
},
],
},
};
conditionalTest({ min: 16 })('should report ANR when event loop blocked', () => {
afterAll(() => {
cleanupChildProcesses();
});
test('CJS', done => {
createRunner(__dirname, 'basic.js').withMockSentryServer().expect({ event: ANR_EVENT_WITH_DEBUG_META }).start(done);
});
test('ESM', done => {
createRunner(__dirname, 'basic.mjs')
.withMockSentryServer()
.expect({ event: ANR_EVENT_WITH_DEBUG_META })
.start(done);
});
test('blocked indefinitely', done => {
createRunner(__dirname, 'indefinite.mjs').withMockSentryServer().expect({ event: ANR_EVENT }).start(done);
});
test("With --inspect the debugger isn't used", done => {
createRunner(__dirname, 'basic.mjs')
.withMockSentryServer()
.withFlags('--inspect')
.expect({ event: ANR_EVENT_WITHOUT_STACKTRACE })
.start(done);
});
test('should exit', done => {
const runner = createRunner(__dirname, 'should-exit.js').start();
setTimeout(() => {
expect(runner.childHasExited()).toBe(true);
done();
}, 5_000);
});
test('should exit forced', done => {
const runner = createRunner(__dirname, 'should-exit-forced.js').start();
setTimeout(() => {
expect(runner.childHasExited()).toBe(true);
done();
}, 5_000);
});
test('With session', done => {
createRunner(__dirname, 'basic-session.js')
.withMockSentryServer()
.unignore('session')
.expect({
session: {
status: 'abnormal',
abnormal_mechanism: 'anr_foreground',
},
})
.expect({ event: ANR_EVENT_WITH_SCOPE })
.start(done);
});
test('from forked process', done => {
createRunner(__dirname, 'forker.js').expect({ event: ANR_EVENT_WITH_SCOPE }).start(done);
});
test('worker can be stopped and restarted', done => {
createRunner(__dirname, 'stop-and-start.js').expect({ event: ANR_EVENT_WITH_SCOPE }).start(done);
});
const EXPECTED_ISOLATED_EVENT = {
user: {
id: 5,
},
exception: {
values: [
{
type: 'ApplicationNotResponding',
value: 'Application Not Responding for at least 100 ms',
mechanism: { type: 'ANR' },
stacktrace: {
frames: expect.arrayContaining([
{
colno: expect.any(Number),
lineno: expect.any(Number),
filename: expect.stringMatching(/isolated.mjs$/),
function: 'longWork',
in_app: true,
},
]),
},
},
],
},
};
test('fetches correct isolated scope', done => {
createRunner(__dirname, 'isolated.mjs')
.withMockSentryServer()
.expect({ event: EXPECTED_ISOLATED_EVENT })
.start(done);
});
});