-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
/
Copy pathtest.ts
118 lines (104 loc) · 3.46 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
import * as childProcess from 'child_process';
import * as path from 'path';
import { conditionalTest } from '../../../utils';
import { cleanupChildProcesses, createRunner } from '../../../utils/runner';
const EXPECTED_LOCAL_VARIABLES_EVENT = {
exception: {
values: [
{
stacktrace: {
frames: expect.arrayContaining([
expect.objectContaining({
function: 'one',
vars: {
name: 'some name',
arr: [1, '2', null],
obj: { name: 'some name', num: 5 },
ty: '<Some>',
bool: false,
num: 0,
str: '',
something: '<undefined>',
somethingElse: '<null>',
},
}),
expect.objectContaining({
function: 'Some.two',
vars: { name: 'some name' },
}),
]),
},
},
],
},
};
conditionalTest({ min: 18 })('LocalVariables integration', () => {
afterAll(() => {
cleanupChildProcesses();
});
test('Should not include local variables by default', done => {
createRunner(__dirname, 'no-local-variables.js')
.ignore('session')
.expect({
event: event => {
for (const frame of event.exception?.values?.[0].stacktrace?.frames || []) {
expect(frame.vars).toBeUndefined();
}
},
})
.start(done);
});
test('Should include local variables when enabled', done => {
createRunner(__dirname, 'local-variables.js')
.ignore('session')
.expect({ event: EXPECTED_LOCAL_VARIABLES_EVENT })
.start(done);
});
test('Should include local variables when instrumenting via --require', done => {
const requirePath = path.resolve(__dirname, 'local-variables-instrument.js');
createRunner(__dirname, 'local-variables-no-sentry.js')
.withFlags(`--require=${requirePath}`)
.ignore('session')
.expect({ event: EXPECTED_LOCAL_VARIABLES_EVENT })
.start(done);
});
test('Should include local variables with ESM', done => {
createRunner(__dirname, 'local-variables-caught.mjs')
.ignore('session')
.expect({ event: EXPECTED_LOCAL_VARIABLES_EVENT })
.start(done);
});
test('Should not import inspector when not in use', done => {
createRunner(__dirname, 'deny-inspector.mjs')
.withFlags('--import=@sentry/node/import')
.ensureNoErrorOutput()
.ignore('session')
.start(done);
});
test('Includes local variables for caught exceptions when enabled', done => {
createRunner(__dirname, 'local-variables-caught.js')
.ignore('session')
.expect({ event: EXPECTED_LOCAL_VARIABLES_EVENT })
.start(done);
});
test('Should not leak memory', done => {
const testScriptPath = path.resolve(__dirname, 'local-variables-memory-test.js');
const child = childProcess.spawn('node', [testScriptPath], {
stdio: ['inherit', 'inherit', 'inherit', 'ipc'],
});
let reportedCount = 0;
child.on('message', msg => {
reportedCount++;
const rssMb = (msg as { memUsage: { rss: number } }).memUsage.rss / 1024 / 1024;
// We shouldn't use more than 120MB of memory
expect(rssMb).toBeLessThan(120);
});
// Wait for 20 seconds
setTimeout(() => {
// Ensure we've had memory usage reported at least 15 times
expect(reportedCount).toBeGreaterThan(15);
child.kill();
done();
}, 20000);
});
});