-
Notifications
You must be signed in to change notification settings - Fork 323
/
Copy pathclient.spec.js
61 lines (52 loc) · 1.93 KB
/
client.spec.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
55
56
57
58
59
60
61
'use strict'
const {
FakeAgent,
createSandbox,
curlAndAssertMessage,
checkSpansForServiceName,
spawnPluginIntegrationTestProc
} = require('../../../../integration-tests/helpers')
// eslint-disable-next-line import/no-extraneous-dependencies
const { assert } = require('chai')
const { NODE_MAJOR } = require('../../../../version')
const hookFile = 'dd-trace/loader-hook.mjs'
const BUILD_COMMAND = NODE_MAJOR < 18
? 'yarn exec next build' : 'NODE_OPTIONS=--openssl-legacy-provider yarn exec next build'
const NODE_OPTIONS = NODE_MAJOR < 18 ? `--loader=${hookFile} --require dd-trace/init`
: `--loader=${hookFile} --require dd-trace/init --openssl-legacy-provider`
const VERSIONS_TO_TEST = NODE_MAJOR < 18 ? '>=11.1 <13.2' : '>=11.1'
describe('esm', () => {
let agent
let proc
let sandbox
// match versions tested with unit tests
withVersions('next', 'next', VERSIONS_TO_TEST, version => {
before(async function () {
// next builds slower in the CI, match timeout with unit tests
this.timeout(120 * 1000)
sandbox = await createSandbox([`'next@${version}'`, 'react', 'react-dom'],
false, ['./packages/datadog-plugin-next/test/integration-test/*'],
BUILD_COMMAND)
})
after(async () => {
await sandbox.remove()
})
beforeEach(async () => {
agent = await new FakeAgent().start()
})
afterEach(async () => {
proc && proc.kill()
await agent.stop()
})
it('is instrumented', async () => {
proc = await spawnPluginIntegrationTestProc(sandbox.folder, 'server.mjs', agent.port, undefined, {
NODE_OPTIONS
})
return curlAndAssertMessage(agent, proc, ({ headers, payload }) => {
assert.propertyVal(headers, 'host', `127.0.0.1:${agent.port}`)
assert.isArray(payload)
assert.strictEqual(checkSpansForServiceName(payload, 'next.request'), true)
}, undefined, undefined, true)
}).timeout(120 * 1000)
})
})