|
| 1 | +const assert = require('assert'); |
| 2 | + |
| 3 | +const { sleep } = require('../utils/common'); |
| 4 | +const { getAsync, interceptTracingRequest } = require('../utils/server'); |
| 5 | + |
| 6 | +module.exports = async ({ url: urlBase, argv }) => { |
| 7 | + const urls = { |
| 8 | + // testName: [url, route] |
| 9 | + unwrappedNoParamURL: [`/api/withSentryAPI/unwrapped/noParams`, '/api/withSentryAPI/unwrapped/noParams'], |
| 10 | + unwrappedDynamicURL: [`/api/withSentryAPI/unwrapped/dog`, '/api/withSentryAPI/unwrapped/[animal]'], |
| 11 | + unwrappedCatchAllURL: [`/api/withSentryAPI/unwrapped/dog/facts`, '/api/withSentryAPI/unwrapped/[...pathParts]'], |
| 12 | + wrappedNoParamURL: [`/api/withSentryAPI/wrapped/noParams`, '/api/withSentryAPI/wrapped/noParams'], |
| 13 | + wrappedDynamicURL: [`/api/withSentryAPI/wrapped/dog`, '/api/withSentryAPI/wrapped/[animal]'], |
| 14 | + wrappedCatchAllURL: [`/api/withSentryAPI/wrapped/dog/facts`, '/api/withSentryAPI/wrapped/[...pathParts]'], |
| 15 | + }; |
| 16 | + |
| 17 | + const interceptedRequests = {}; |
| 18 | + |
| 19 | + Object.entries(urls).forEach(([testName, [url, route]]) => { |
| 20 | + interceptedRequests[testName] = interceptTracingRequest( |
| 21 | + { |
| 22 | + contexts: { |
| 23 | + trace: { |
| 24 | + op: 'http.server', |
| 25 | + status: 'ok', |
| 26 | + tags: { 'http.status_code': '200' }, |
| 27 | + }, |
| 28 | + }, |
| 29 | + transaction: `GET ${route}`, |
| 30 | + type: 'transaction', |
| 31 | + request: { |
| 32 | + url: `${urlBase}${url}`, |
| 33 | + }, |
| 34 | + }, |
| 35 | + argv, |
| 36 | + testName, |
| 37 | + ); |
| 38 | + }); |
| 39 | + |
| 40 | + // Wait until all requests have completed |
| 41 | + await Promise.all(Object.values(urls).map(([url]) => getAsync(`${urlBase}${url}`))); |
| 42 | + |
| 43 | + await sleep(250); |
| 44 | + |
| 45 | + const failingTests = Object.entries(interceptedRequests).reduce( |
| 46 | + (failures, [testName, request]) => (!request.isDone() ? failures.concat(testName) : failures), |
| 47 | + [], |
| 48 | + ); |
| 49 | + |
| 50 | + assert.ok( |
| 51 | + failingTests.length === 0, |
| 52 | + `Did not intercept transaction request for the following tests: ${failingTests.join(', ')}.`, |
| 53 | + ); |
| 54 | +}; |
0 commit comments