|
1 | 1 | import { afterAll, describe, expect, test } from 'vitest'; |
2 | | -import { cleanupChildProcesses, createRunner } from '../../../utils/runner'; |
| 2 | +import { cleanupChildProcesses, createEsmAndCjsTests, createRunner } from '../../../utils/runner'; |
3 | 3 | import { createTestServer } from '../../../utils/server'; |
4 | 4 |
|
5 | 5 | describe('httpIntegration', () => { |
6 | 6 | afterAll(() => { |
7 | 7 | cleanupChildProcesses(); |
8 | 8 | }); |
9 | 9 |
|
10 | | - test('allows to pass instrumentation options to integration', async () => { |
11 | | - // response shape seems different on Node 14, so we skip this there |
12 | | - const nodeMajorVersion = Number(process.versions.node.split('.')[0]); |
13 | | - if (nodeMajorVersion <= 14) { |
14 | | - return; |
15 | | - } |
16 | | - |
17 | | - const runner = createRunner(__dirname, 'server.js') |
18 | | - .expect({ |
19 | | - transaction: { |
20 | | - contexts: { |
21 | | - trace: { |
22 | | - span_id: expect.stringMatching(/[a-f0-9]{16}/), |
23 | | - trace_id: expect.stringMatching(/[a-f0-9]{32}/), |
24 | | - data: { |
25 | | - url: expect.stringMatching(/\/test$/), |
26 | | - 'http.response.status_code': 200, |
27 | | - attr1: 'yes', |
28 | | - attr2: 'yes', |
29 | | - attr3: 'yes', |
| 10 | + createEsmAndCjsTests(__dirname, 'server.mjs', 'instrument.mjs', (createRunner, test) => { |
| 11 | + test('allows to pass instrumentation options to integration', async () => { |
| 12 | + const runner = createRunner() |
| 13 | + .expect({ |
| 14 | + transaction: { |
| 15 | + contexts: { |
| 16 | + trace: { |
| 17 | + span_id: expect.stringMatching(/[a-f0-9]{16}/), |
| 18 | + trace_id: expect.stringMatching(/[a-f0-9]{32}/), |
| 19 | + data: { |
| 20 | + url: expect.stringMatching(/\/test$/), |
| 21 | + 'http.response.status_code': 200, |
| 22 | + attr1: 'yes', |
| 23 | + attr2: 'yes', |
| 24 | + attr3: 'yes', |
| 25 | + }, |
| 26 | + op: 'http.server', |
| 27 | + status: 'ok', |
30 | 28 | }, |
31 | | - op: 'http.server', |
32 | | - status: 'ok', |
33 | | - }, |
34 | | - }, |
35 | | - extra: { |
36 | | - requestHookCalled: { |
37 | | - url: expect.stringMatching(/\/test$/), |
38 | | - method: 'GET', |
39 | | - }, |
40 | | - responseHookCalled: { |
41 | | - url: expect.stringMatching(/\/test$/), |
42 | | - method: 'GET', |
43 | 29 | }, |
44 | | - applyCustomAttributesOnSpanCalled: { |
45 | | - reqUrl: expect.stringMatching(/\/test$/), |
46 | | - reqMethod: 'GET', |
47 | | - resUrl: expect.stringMatching(/\/test$/), |
48 | | - resMethod: 'GET', |
| 30 | + extra: { |
| 31 | + requestHookCalled: { |
| 32 | + url: expect.stringMatching(/\/test$/), |
| 33 | + method: 'GET', |
| 34 | + }, |
| 35 | + responseHookCalled: { |
| 36 | + url: expect.stringMatching(/\/test$/), |
| 37 | + method: 'GET', |
| 38 | + }, |
| 39 | + applyCustomAttributesOnSpanCalled: { |
| 40 | + reqUrl: expect.stringMatching(/\/test$/), |
| 41 | + reqMethod: 'GET', |
| 42 | + resUrl: expect.stringMatching(/\/test$/), |
| 43 | + resMethod: 'GET', |
| 44 | + }, |
49 | 45 | }, |
50 | 46 | }, |
51 | | - }, |
52 | | - }) |
53 | | - .start(); |
54 | | - runner.makeRequest('get', '/test'); |
55 | | - await runner.completed(); |
| 47 | + }) |
| 48 | + .start(); |
| 49 | + runner.makeRequest('get', '/test'); |
| 50 | + await runner.completed(); |
| 51 | + }); |
56 | 52 | }); |
57 | 53 |
|
58 | 54 | test('allows to pass experimental config through to integration', async () => { |
@@ -155,7 +151,7 @@ describe('httpIntegration', () => { |
155 | 151 | expect(breadcrumbs![0]?.data?.url).toEqual(`${SERVER_URL}/pass`); |
156 | 152 | }, |
157 | 153 | }) |
158 | | - .start(closeTestServer); |
| 154 | + .start(); |
159 | 155 | runner.makeRequest('get', '/testUrl'); |
160 | 156 | await runner.completed(); |
161 | 157 | closeTestServer(); |
|
0 commit comments