-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
/
Copy pathtracingWithSentryAPI.js
54 lines (46 loc) · 1.86 KB
/
tracingWithSentryAPI.js
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
const assert = require('assert');
const { sleep } = require('../utils/common');
const { getAsync, interceptTracingRequest } = require('../utils/server');
module.exports = async ({ url: urlBase, argv }) => {
const urls = {
// testName: [url, route]
unwrappedNoParamURL: [`/api/withSentryAPI/unwrapped/noParams`, '/api/withSentryAPI/unwrapped/noParams'],
unwrappedDynamicURL: [`/api/withSentryAPI/unwrapped/dog`, '/api/withSentryAPI/unwrapped/[animal]'],
unwrappedCatchAllURL: [`/api/withSentryAPI/unwrapped/dog/facts`, '/api/withSentryAPI/unwrapped/[...pathParts]'],
wrappedNoParamURL: [`/api/withSentryAPI/wrapped/noParams`, '/api/withSentryAPI/wrapped/noParams'],
wrappedDynamicURL: [`/api/withSentryAPI/wrapped/dog`, '/api/withSentryAPI/wrapped/[animal]'],
wrappedCatchAllURL: [`/api/withSentryAPI/wrapped/dog/facts`, '/api/withSentryAPI/wrapped/[...pathParts]'],
};
const interceptedRequests = {};
Object.entries(urls).forEach(([testName, [url, route]]) => {
interceptedRequests[testName] = interceptTracingRequest(
{
contexts: {
trace: {
op: 'http.server',
status: 'ok',
tags: { 'http.status_code': '200' },
},
},
transaction: `GET ${route}`,
type: 'transaction',
request: {
url: `${urlBase}${url}`,
},
},
argv,
testName,
);
});
// Wait until all requests have completed
await Promise.all(Object.values(urls).map(([url]) => getAsync(`${urlBase}${url}`)));
await sleep(250);
const failingTests = Object.entries(interceptedRequests).reduce(
(failures, [testName, request]) => (!request.isDone() ? failures.concat(testName) : failures),
[],
);
assert.ok(
failingTests.length === 0,
`Did not intercept transaction request for the following tests: ${failingTests.join(', ')}.`,
);
};