-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Expand file tree
/
Copy pathtest.ts
More file actions
53 lines (46 loc) · 1.88 KB
/
test.ts
File metadata and controls
53 lines (46 loc) · 1.88 KB
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
import { afterAll, describe, expect } from 'vitest';
import { cleanupChildProcesses, createEsmAndCjsTests } from '../../utils/runner';
describe('vercel xxx', () => {
afterAll(() => {
cleanupChildProcesses();
});
createEsmAndCjsTests(__dirname, 'scenario.mjs', 'instrument.mjs', (createRunner, test) => {
test('should flush events correctly on Vercel', async () => {
const runner = createRunner()
.expect({
transaction: {
transaction: 'GET /test/express',
},
})
.start();
runner.makeRequest('get', '/test/express');
await runner.completed();
const actualLogs = runner.getLogs();
// We want to test that the following logs are present in this order
// other logs may be in between
const expectedLogs = [
'Sentry Logger [log]: @sentry/instrumentation-http Patching server.emit',
'Sentry Logger [log]: @sentry/instrumentation-http Handling incoming request',
'Sentry Logger [log]: @sentry/instrumentation-http Patching request.on',
'Sentry Logger [debug]: @opentelemetry_sentry-patched/instrumentation-http http instrumentation incomingRequest',
'Sentry Logger [log]: [Tracing] Starting sampled root span',
// later...
'Sentry Logger [log]: Patching response to flush on Vercel',
'Sentry Logger [log]: Patching res.end()',
// later...
'Sentry Logger [log]: Flushing events before Vercel Lambda freeze',
'Sentry Logger [log]: SpanExporter exported 4 spans, 0 spans are waiting for their parent spans to finish',
];
// Test that the order of logs is correct
for (const log of actualLogs) {
if (expectedLogs.length === 0) {
break;
}
if (log === expectedLogs[0]) {
expectedLogs.shift();
}
}
expect(expectedLogs).toEqual([]);
});
});
});