diff --git a/packages/datadog-plugin-ai/test/integration-test/client.spec.js b/packages/datadog-plugin-ai/test/integration-test/client.spec.js index b1874a9c077..58fd7b2cd38 100644 --- a/packages/datadog-plugin-ai/test/integration-test/client.spec.js +++ b/packages/datadog-plugin-ai/test/integration-test/client.spec.js @@ -63,7 +63,7 @@ describe('esm', () => { assert.fail('No ai spans found') }) - proc = await spawnPluginIntegrationTestProc(sandbox.folder, 'server.mjs', agent.port, null, { + proc = await spawnPluginIntegrationTestProc(sandbox.folder, 'server.mjs', agent.port, { NODE_OPTIONS: '--import dd-trace/initialize.mjs' }) diff --git a/packages/datadog-plugin-anthropic/test/integration-test/client.spec.js b/packages/datadog-plugin-anthropic/test/integration-test/client.spec.js index 6f06527336f..d45b35a39da 100644 --- a/packages/datadog-plugin-anthropic/test/integration-test/client.spec.js +++ b/packages/datadog-plugin-anthropic/test/integration-test/client.spec.js @@ -45,7 +45,7 @@ describe('esm', () => { assert.strictEqual(checkSpansForServiceName(payload, 'anthropic.request'), true) }) - proc = await spawnPluginIntegrationTestProc(sandbox.folder, 'server.mjs', agent.port, null, { + proc = await spawnPluginIntegrationTestProc(sandbox.folder, 'server.mjs', agent.port, { NODE_OPTIONS: '--import dd-trace/initialize.mjs', ANTHROPIC_API_KEY: '' }) diff --git a/packages/datadog-plugin-aws-sdk/test/integration-test/client.spec.js b/packages/datadog-plugin-aws-sdk/test/integration-test/client.spec.js index 4e93c23fa77..b1a8c656c88 100644 --- a/packages/datadog-plugin-aws-sdk/test/integration-test/client.spec.js +++ b/packages/datadog-plugin-aws-sdk/test/integration-test/client.spec.js @@ -41,7 +41,7 @@ describe('esm', () => { assert.strictEqual(checkSpansForServiceName(payload, 'aws.request'), true) }) - proc = await spawnPluginIntegrationTestProc(sandbox.folder, 'server.mjs', agent.port, undefined, + proc = await spawnPluginIntegrationTestProc(sandbox.folder, 'server.mjs', agent.port, { AWS_SECRET_ACCESS_KEY: '0000000000/00000000000000000000000000000', AWS_ACCESS_KEY_ID: '00000000000000000000' diff --git a/packages/datadog-plugin-axios/test/integration-test/client.spec.js b/packages/datadog-plugin-axios/test/integration-test/client.spec.js index 13f0bb0978b..37c5be73af5 100644 --- a/packages/datadog-plugin-axios/test/integration-test/client.spec.js +++ b/packages/datadog-plugin-axios/test/integration-test/client.spec.js @@ -1,27 +1,24 @@ 'use strict' +const { join } = require('node:path') + +const { assert } = require('chai') + const { FakeAgent, - createSandbox, checkSpansForServiceName, spawnPluginIntegrationTestProc } = require('../../../../integration-tests/helpers') -const { assert } = require('chai') +const { insertVersionDep } = require('../../../dd-trace/test/setup/mocha') describe('esm', () => { let agent let proc - let sandbox + const env = { + NODE_OPTIONS: `--loader=${join(__dirname, '..', '..', '..', '..', 'initialize.mjs')}` + } - before(async function () { - this.timeout(60000) - sandbox = await createSandbox(['axios'], false, [ - './packages/datadog-plugin-axios/test/integration-test/*']) - }) - - after(async () => { - await sandbox.remove() - }) + insertVersionDep(__dirname, 'axios', '*') beforeEach(async () => { agent = await new FakeAgent().start() @@ -40,7 +37,7 @@ describe('esm', () => { assert.strictEqual(checkSpansForServiceName(payload, 'http.request'), true) }) - proc = await spawnPluginIntegrationTestProc(sandbox.folder, 'server.mjs', agent.port) + proc = await spawnPluginIntegrationTestProc(__dirname, 'server.mjs', agent.port, env) await res }).timeout(20000) diff --git a/packages/datadog-plugin-azure-functions/test/integration-test/http-test/client.spec.js b/packages/datadog-plugin-azure-functions/test/integration-test/http-test/client.spec.js index ff9b3d20246..01db87ea93a 100644 --- a/packages/datadog-plugin-azure-functions/test/integration-test/http-test/client.spec.js +++ b/packages/datadog-plugin-azure-functions/test/integration-test/http-test/client.spec.js @@ -78,6 +78,7 @@ describe('esm', () => { }) }) +// TODO(BridgeAR): Unify with other helper of the same name. async function spawnPluginIntegrationTestProc (cwd, command, args, agentPort, stdioHandler, additionalEnvArgs = {}) { let env = { NODE_OPTIONS: `--loader=${hookFile} func start`, diff --git a/packages/datadog-plugin-couchbase/test/integration-test/client.spec.js b/packages/datadog-plugin-couchbase/test/integration-test/client.spec.js index 0edf5fda001..99a8eca68d7 100644 --- a/packages/datadog-plugin-couchbase/test/integration-test/client.spec.js +++ b/packages/datadog-plugin-couchbase/test/integration-test/client.spec.js @@ -1,30 +1,26 @@ 'use strict' +const { join } = require('node:path') + +const { assert } = require('chai') + const { FakeAgent, - createSandbox, checkSpansForServiceName, spawnPluginIntegrationTestProc } = require('../../../../integration-tests/helpers') -const { withVersions } = require('../../../dd-trace/test/setup/mocha') -const { assert } = require('chai') +const { withVersions, insertVersionDep } = require('../../../dd-trace/test/setup/mocha') describe('esm', () => { let agent let proc - let sandbox + const env = { + NODE_OPTIONS: `--loader=${join(__dirname, '..', '..', '..', '..', 'initialize.mjs')}` + } // test against later versions because server.mjs uses newer package syntax withVersions('couchbase', 'couchbase', '>=4.0.0', version => { - before(async function () { - this.timeout(60000) - sandbox = await createSandbox([`'couchbase@${version}'`], false, [ - './packages/datadog-plugin-couchbase/test/integration-test/*']) - }) - - after(async () => { - await sandbox.remove() - }) + insertVersionDep(__dirname, 'couchbase', version) beforeEach(async () => { agent = await new FakeAgent().start() @@ -42,7 +38,7 @@ describe('esm', () => { assert.strictEqual(checkSpansForServiceName(payload, 'couchbase.upsert'), true) }) - proc = await spawnPluginIntegrationTestProc(sandbox.folder, 'server.mjs', agent.port) + proc = await spawnPluginIntegrationTestProc(__dirname, 'server.mjs', agent.port, env) await res }).timeout(20000) }) diff --git a/packages/datadog-plugin-couchbase/test/integration-test/server.mjs b/packages/datadog-plugin-couchbase/test/integration-test/server.mjs index 452b2d6ce47..a26ed947d4d 100644 --- a/packages/datadog-plugin-couchbase/test/integration-test/server.mjs +++ b/packages/datadog-plugin-couchbase/test/integration-test/server.mjs @@ -1,4 +1,3 @@ -import 'dd-trace/init.js' import { connect } from 'couchbase' const cluster = await connect( diff --git a/packages/datadog-plugin-fastify/test/integration-test/client.spec.js b/packages/datadog-plugin-fastify/test/integration-test/client.spec.js index 46ca79bc837..06a868ff9cc 100644 --- a/packages/datadog-plugin-fastify/test/integration-test/client.spec.js +++ b/packages/datadog-plugin-fastify/test/integration-test/client.spec.js @@ -1,5 +1,9 @@ 'use strict' +const { join } = require('node:path') + +const { assert } = require('chai') + const { FakeAgent, curlAndAssertMessage, @@ -7,8 +11,6 @@ const { spawnPluginIntegrationTestProc } = require('../../../../integration-tests/helpers') const { withVersions, insertVersionDep } = require('../../../dd-trace/test/setup/mocha') -const { assert } = require('chai') -const { join } = require('path') describe('esm', () => { let agent diff --git a/packages/datadog-plugin-google-cloud-pubsub/test/integration-test/client.spec.js b/packages/datadog-plugin-google-cloud-pubsub/test/integration-test/client.spec.js index d84b0b69e99..9bbc0a1bcc6 100644 --- a/packages/datadog-plugin-google-cloud-pubsub/test/integration-test/client.spec.js +++ b/packages/datadog-plugin-google-cloud-pubsub/test/integration-test/client.spec.js @@ -41,7 +41,7 @@ describe('esm', () => { assert.strictEqual(checkSpansForServiceName(payload, 'pubsub.request'), true) }) - proc = await spawnPluginIntegrationTestProc(sandbox.folder, 'server.mjs', agent.port, undefined, + proc = await spawnPluginIntegrationTestProc(sandbox.folder, 'server.mjs', agent.port, { PUBSUB_EMULATOR_HOST: 'localhost:8081' }) await res diff --git a/packages/datadog-plugin-hapi/test/integration-test/client.spec.js b/packages/datadog-plugin-hapi/test/integration-test/client.spec.js index a6e38641fc0..da8c1cd37c1 100644 --- a/packages/datadog-plugin-hapi/test/integration-test/client.spec.js +++ b/packages/datadog-plugin-hapi/test/integration-test/client.spec.js @@ -1,30 +1,26 @@ 'use strict' +const { join } = require('node:path') + +const { assert } = require('chai') + const { FakeAgent, - createSandbox, curlAndAssertMessage, checkSpansForServiceName, spawnPluginIntegrationTestProc } = require('../../../../integration-tests/helpers') -const { withVersions } = require('../../../dd-trace/test/setup/mocha') -const { assert } = require('chai') +const { withVersions, insertVersionDep } = require('../../../dd-trace/test/setup/mocha') describe('esm', () => { let agent let proc - let sandbox + const env = { + NODE_OPTIONS: `--loader=${join(__dirname, '..', '..', '..', '..', 'initialize.mjs')}` + } withVersions('hapi', '@hapi/hapi', version => { - before(async function () { - this.timeout(60000) - sandbox = await createSandbox([`'@hapi/hapi@${version}'`], false, [ - './packages/datadog-plugin-hapi/test/integration-test/*']) - }) - - after(async () => { - await sandbox.remove() - }) + insertVersionDep(__dirname, '@hapi/hapi', version) beforeEach(async () => { agent = await new FakeAgent().start() @@ -36,7 +32,7 @@ describe('esm', () => { }) it('is instrumented', async () => { - proc = await spawnPluginIntegrationTestProc(sandbox.folder, 'server.mjs', agent.port) + proc = await spawnPluginIntegrationTestProc(__dirname, 'server.mjs', agent.port, env) return curlAndAssertMessage(agent, proc, ({ headers, payload }) => { assert.propertyVal(headers, 'host', `127.0.0.1:${agent.port}`) diff --git a/packages/datadog-plugin-hapi/test/integration-test/server.mjs b/packages/datadog-plugin-hapi/test/integration-test/server.mjs index 32f7373ad1e..7a7884c027c 100644 --- a/packages/datadog-plugin-hapi/test/integration-test/server.mjs +++ b/packages/datadog-plugin-hapi/test/integration-test/server.mjs @@ -1,4 +1,3 @@ -import 'dd-trace/init.js' import Hapi from '@hapi/hapi' const server = Hapi.server({ port: 0, host: 'localhost' }) diff --git a/packages/datadog-plugin-hono/test/integration-test/client.spec.js b/packages/datadog-plugin-hono/test/integration-test/client.spec.js index b9d71d7cbe4..f792541d4c4 100644 --- a/packages/datadog-plugin-hono/test/integration-test/client.spec.js +++ b/packages/datadog-plugin-hono/test/integration-test/client.spec.js @@ -36,7 +36,7 @@ describe('esm integration test', () => { }) it('is instrumented', async () => { - proc = await spawnPluginIntegrationTestProc(sandbox.folder, 'server.mjs', agent.port, undefined, { + proc = await spawnPluginIntegrationTestProc(sandbox.folder, 'server.mjs', agent.port, { VERSION: version }) proc.url += '/hello' @@ -48,7 +48,7 @@ describe('esm integration test', () => { }).timeout(50000) it('receives missing route trace', async () => { - proc = await spawnPluginIntegrationTestProc(sandbox.folder, 'server.mjs', agent.port, undefined, { + proc = await spawnPluginIntegrationTestProc(sandbox.folder, 'server.mjs', agent.port, { VERSION: version }) proc.url += '/missing' diff --git a/packages/datadog-plugin-http/test/integration-test/client.spec.js b/packages/datadog-plugin-http/test/integration-test/client.spec.js index 6c4b07ba3d1..b672bb88beb 100644 --- a/packages/datadog-plugin-http/test/integration-test/client.spec.js +++ b/packages/datadog-plugin-http/test/integration-test/client.spec.js @@ -1,27 +1,21 @@ 'use strict' +const { join } = require('node:path') + +const { assert } = require('chai') + const { FakeAgent, - createSandbox, curlAndAssertMessage, spawnPluginIntegrationTestProc } = require('../../../../integration-tests/helpers') -const { assert } = require('chai') describe('esm', () => { let agent let proc - let sandbox - - before(async function () { - this.timeout(60000) - sandbox = await createSandbox([], false, [ - './packages/datadog-plugin-http/test/integration-test/*']) - }) - - after(async () => { - await sandbox.remove() - }) + const env = { + NODE_OPTIONS: `--loader=${join(__dirname, '..', '..', '..', '..', 'initialize.mjs')}` + } beforeEach(async () => { agent = await new FakeAgent().start() @@ -34,7 +28,7 @@ describe('esm', () => { context('http', () => { it('is instrumented', async () => { - proc = await spawnPluginIntegrationTestProc(sandbox.folder, 'server.mjs', agent.port) + proc = await spawnPluginIntegrationTestProc(__dirname, 'server.mjs', agent.port, env) return curlAndAssertMessage(agent, proc, ({ headers, payload }) => { assert.propertyVal(headers, 'host', `127.0.0.1:${agent.port}`) diff --git a/packages/datadog-plugin-http/test/integration-test/server.mjs b/packages/datadog-plugin-http/test/integration-test/server.mjs index 762cb7e9c84..8b617b34c91 100644 --- a/packages/datadog-plugin-http/test/integration-test/server.mjs +++ b/packages/datadog-plugin-http/test/integration-test/server.mjs @@ -1,4 +1,3 @@ -import 'dd-trace/init.js' import http from 'http' const server = http.createServer(async (req, res) => { diff --git a/packages/datadog-plugin-iovalkey/test/integration-test/client.spec.js b/packages/datadog-plugin-iovalkey/test/integration-test/client.spec.js index 57da3d2f2a5..2edd330c4a2 100644 --- a/packages/datadog-plugin-iovalkey/test/integration-test/client.spec.js +++ b/packages/datadog-plugin-iovalkey/test/integration-test/client.spec.js @@ -1,28 +1,25 @@ 'use strict' +const { join } = require('node:path') + +const { assert } = require('chai') + const { FakeAgent, - createSandbox, checkSpansForServiceName, spawnPluginIntegrationTestProc } = require('../../../../integration-tests/helpers') -const { withVersions } = require('../../../dd-trace/test/setup/mocha') -const { assert } = require('chai') +const { withVersions, insertVersionDep } = require('../../../dd-trace/test/setup/mocha') describe('esm', () => { let agent let proc - let sandbox - withVersions('iovalkey', 'iovalkey', version => { - before(async function () { - this.timeout(60000) - sandbox = await createSandbox([`'iovalkey@${version}'`], false, [ - './packages/datadog-plugin-iovalkey/test/integration-test/*']) - }) + const env = { + NODE_OPTIONS: `--loader=${join(__dirname, '..', '..', '..', '..', 'initialize.mjs')}` + } - after(async () => { - await sandbox.remove() - }) + withVersions('iovalkey', 'iovalkey', version => { + insertVersionDep(__dirname, 'iovalkey', version) beforeEach(async () => { agent = await new FakeAgent().start() @@ -40,7 +37,7 @@ describe('esm', () => { assert.strictEqual(checkSpansForServiceName(payload, 'valkey.command'), true) }) - proc = await spawnPluginIntegrationTestProc(sandbox.folder, 'server.mjs', agent.port) + proc = await spawnPluginIntegrationTestProc(__dirname, 'server.mjs', agent.port, env) await res }).timeout(20000) diff --git a/packages/datadog-plugin-iovalkey/test/integration-test/server.mjs b/packages/datadog-plugin-iovalkey/test/integration-test/server.mjs index f333ae859d4..5d2350e41c4 100644 --- a/packages/datadog-plugin-iovalkey/test/integration-test/server.mjs +++ b/packages/datadog-plugin-iovalkey/test/integration-test/server.mjs @@ -1,4 +1,3 @@ -import 'dd-trace/init.js' import Valkey from 'iovalkey' const client = new Valkey({ connectionName: 'test' }) diff --git a/packages/datadog-plugin-kafkajs/test/integration-test/client.spec.js b/packages/datadog-plugin-kafkajs/test/integration-test/client.spec.js index b778a36e3b7..c5777605718 100644 --- a/packages/datadog-plugin-kafkajs/test/integration-test/client.spec.js +++ b/packages/datadog-plugin-kafkajs/test/integration-test/client.spec.js @@ -1,28 +1,25 @@ 'use strict' +const { join } = require('node:path') + +const { assert } = require('chai') + const { FakeAgent, - createSandbox, checkSpansForServiceName, spawnPluginIntegrationTestProc } = require('../../../../integration-tests/helpers') -const { withVersions } = require('../../../dd-trace/test/setup/mocha') -const { assert } = require('chai') +const { withVersions, insertVersionDep } = require('../../../dd-trace/test/setup/mocha') describe('esm', () => { let agent let proc - let sandbox - withVersions('kafkajs', 'kafkajs', version => { - before(async function () { - this.timeout(60000) - sandbox = await createSandbox([`'kafkajs@${version}'`], false, [ - './packages/datadog-plugin-kafkajs/test/integration-test/*']) - }) + const env = { + NODE_OPTIONS: `--loader=${join(__dirname, '..', '..', '..', '..', 'initialize.mjs')}` + } - after(async () => { - await sandbox.remove() - }) + withVersions('kafkajs', 'kafkajs', version => { + insertVersionDep(__dirname, 'kafkajs', version) beforeEach(async () => { agent = await new FakeAgent().start() @@ -40,7 +37,7 @@ describe('esm', () => { assert.strictEqual(checkSpansForServiceName(payload, 'kafka.produce'), true) }) - proc = await spawnPluginIntegrationTestProc(sandbox.folder, 'server.mjs', agent.port) + proc = await spawnPluginIntegrationTestProc(__dirname, 'server.mjs', agent.port, env) await res }).timeout(20000) diff --git a/packages/datadog-plugin-kafkajs/test/integration-test/server.mjs b/packages/datadog-plugin-kafkajs/test/integration-test/server.mjs index 342d98b909b..ed9e3d60f20 100644 --- a/packages/datadog-plugin-kafkajs/test/integration-test/server.mjs +++ b/packages/datadog-plugin-kafkajs/test/integration-test/server.mjs @@ -1,4 +1,3 @@ -import 'dd-trace/init.js' import { Kafka } from 'kafkajs' const kafka = new Kafka({ diff --git a/packages/datadog-plugin-langchain/test/integration-test/client.spec.js b/packages/datadog-plugin-langchain/test/integration-test/client.spec.js index 3dcf3fbfe78..34b67e2f1b9 100644 --- a/packages/datadog-plugin-langchain/test/integration-test/client.spec.js +++ b/packages/datadog-plugin-langchain/test/integration-test/client.spec.js @@ -46,7 +46,7 @@ describe('esm', () => { assert.strictEqual(checkSpansForServiceName(payload, 'langchain.request'), true) }) - proc = await spawnPluginIntegrationTestProc(sandbox.folder, 'server.mjs', agent.port, null, { + proc = await spawnPluginIntegrationTestProc(sandbox.folder, 'server.mjs', agent.port, { NODE_OPTIONS: '--import dd-trace/initialize.mjs' }) diff --git a/packages/datadog-plugin-mariadb/test/integration-test/client.spec.js b/packages/datadog-plugin-mariadb/test/integration-test/client.spec.js index 387b41d6866..2025d7daba8 100644 --- a/packages/datadog-plugin-mariadb/test/integration-test/client.spec.js +++ b/packages/datadog-plugin-mariadb/test/integration-test/client.spec.js @@ -1,30 +1,26 @@ 'use strict' +const { join } = require('node:path') + +const { assert } = require('chai') + const { FakeAgent, - createSandbox, checkSpansForServiceName, spawnPluginIntegrationTestProc } = require('../../../../integration-tests/helpers') -const { withVersions } = require('../../../dd-trace/test/setup/mocha') -const { assert } = require('chai') +const { withVersions, insertVersionDep } = require('../../../dd-trace/test/setup/mocha') describe('esm', () => { let agent let proc - let sandbox + const env = { + NODE_OPTIONS: `--loader=${join(__dirname, '..', '..', '..', '..', 'initialize.mjs')}` + } // test against later versions because server.mjs uses newer package syntax withVersions('mariadb', 'mariadb', '>=3.0.0', version => { - before(async function () { - this.timeout(60000) - sandbox = await createSandbox([`'mariadb@${version}'`], false, [ - './packages/datadog-plugin-mariadb/test/integration-test/*']) - }) - - after(async () => { - await sandbox.remove() - }) + insertVersionDep(__dirname, 'mariadb', version) beforeEach(async () => { agent = await new FakeAgent().start() @@ -42,7 +38,7 @@ describe('esm', () => { assert.strictEqual(checkSpansForServiceName(payload, 'mariadb.query'), true) }) - proc = await spawnPluginIntegrationTestProc(sandbox.folder, 'server.mjs', agent.port) + proc = await spawnPluginIntegrationTestProc(__dirname, 'server.mjs', agent.port, env) await res }).timeout(20000) diff --git a/packages/datadog-plugin-mariadb/test/integration-test/server.mjs b/packages/datadog-plugin-mariadb/test/integration-test/server.mjs index 30d0bcc0ae3..f4c60a04a00 100644 --- a/packages/datadog-plugin-mariadb/test/integration-test/server.mjs +++ b/packages/datadog-plugin-mariadb/test/integration-test/server.mjs @@ -1,4 +1,3 @@ -import 'dd-trace/init.js' import mariadb from 'mariadb' const pool = mariadb.createPool({ diff --git a/packages/datadog-plugin-mysql2/test/integration-test/client.spec.js b/packages/datadog-plugin-mysql2/test/integration-test/client.spec.js index 8997d50f168..618c8a9c4e8 100644 --- a/packages/datadog-plugin-mysql2/test/integration-test/client.spec.js +++ b/packages/datadog-plugin-mysql2/test/integration-test/client.spec.js @@ -1,5 +1,9 @@ 'use strict' +const { join } = require('node:path') + +const { assert } = require('chai') + const { FakeAgent, createSandbox, diff --git a/packages/datadog-plugin-next/test/integration-test/client.spec.js b/packages/datadog-plugin-next/test/integration-test/client.spec.js index 798115fe239..ce82e4a0766 100644 --- a/packages/datadog-plugin-next/test/integration-test/client.spec.js +++ b/packages/datadog-plugin-next/test/integration-test/client.spec.js @@ -44,7 +44,7 @@ describe('esm', () => { for (const variant of varySandbox.VARIANTS) { it(`is instrumented loaded with ${variant}`, async () => { - proc = await spawnPluginIntegrationTestProc(sandbox.folder, variants[variant], agent.port, undefined, { + proc = await spawnPluginIntegrationTestProc(sandbox.folder, variants[variant], agent.port, { NODE_OPTIONS: `--loader=${hookFile} --require dd-trace/init --openssl-legacy-provider` }) return curlAndAssertMessage(agent, proc, ({ headers, payload }) => { diff --git a/packages/datadog-plugin-oracledb/test/integration-test/client.spec.js b/packages/datadog-plugin-oracledb/test/integration-test/client.spec.js index 5fb44e0d0db..9961295b459 100644 --- a/packages/datadog-plugin-oracledb/test/integration-test/client.spec.js +++ b/packages/datadog-plugin-oracledb/test/integration-test/client.spec.js @@ -1,29 +1,25 @@ 'use strict' +const { join } = require('node:path') + +const { assert } = require('chai') + const { FakeAgent, - createSandbox, checkSpansForServiceName, spawnPluginIntegrationTestProc } = require('../../../../integration-tests/helpers') -const { withVersions } = require('../../../dd-trace/test/setup/mocha') -const { assert } = require('chai') +const { withVersions, insertVersionDep } = require('../../../dd-trace/test/setup/mocha') describe('esm', () => { let agent let proc - let sandbox + const env = { + NODE_OPTIONS: `--loader=${join(__dirname, '..', '..', '..', '..', 'initialize.mjs')}` + } withVersions('oracledb', 'oracledb', version => { - before(async function () { - this.timeout(60000) - sandbox = await createSandbox([`'oracledb@${version}'`], false, [ - './packages/datadog-plugin-oracledb/test/integration-test/*']) - }) - - after(async () => { - await sandbox.remove() - }) + insertVersionDep(__dirname, 'oracledb', version) beforeEach(async () => { agent = await new FakeAgent().start() @@ -41,7 +37,7 @@ describe('esm', () => { assert.strictEqual(checkSpansForServiceName(payload, 'oracle.query'), true) }) - proc = await spawnPluginIntegrationTestProc(sandbox.folder, 'server.mjs', agent.port) + proc = await spawnPluginIntegrationTestProc(__dirname, 'server.mjs', agent.port, env) await res }).timeout(20000) diff --git a/packages/datadog-plugin-oracledb/test/integration-test/server.mjs b/packages/datadog-plugin-oracledb/test/integration-test/server.mjs index 5c01b4e58c9..67f8bbd2cbc 100644 --- a/packages/datadog-plugin-oracledb/test/integration-test/server.mjs +++ b/packages/datadog-plugin-oracledb/test/integration-test/server.mjs @@ -1,4 +1,3 @@ -import 'dd-trace/init.js' import oracledb from 'oracledb' const hostname = 'localhost' diff --git a/packages/datadog-plugin-redis/test/integration-test/client.spec.js b/packages/datadog-plugin-redis/test/integration-test/client.spec.js index 6017ad3966c..803c8588d58 100644 --- a/packages/datadog-plugin-redis/test/integration-test/client.spec.js +++ b/packages/datadog-plugin-redis/test/integration-test/client.spec.js @@ -1,29 +1,26 @@ 'use strict' +const { join } = require('node:path') + +const { assert } = require('chai') + const { FakeAgent, - createSandbox, checkSpansForServiceName, spawnPluginIntegrationTestProc } = require('../../../../integration-tests/helpers') -const { withVersions } = require('../../../dd-trace/test/setup/mocha') -const { assert } = require('chai') +const { withVersions, insertVersionDep } = require('../../../dd-trace/test/setup/mocha') describe('esm', () => { let agent let proc - let sandbox + const env = { + NODE_OPTIONS: `--loader=${join(__dirname, '..', '..', '..', '..', 'initialize.mjs')}` + } + // test against later versions because server.mjs uses newer package syntax withVersions('redis', 'redis', '>=4', version => { - before(async function () { - this.timeout(60000) - sandbox = await createSandbox([`'redis@${version}'`], false, [ - './packages/datadog-plugin-redis/test/integration-test/*']) - }) - - after(async () => { - await sandbox.remove() - }) + insertVersionDep(__dirname, 'redis', version) beforeEach(async () => { agent = await new FakeAgent().start() @@ -41,7 +38,7 @@ describe('esm', () => { assert.strictEqual(checkSpansForServiceName(payload, 'redis.command'), true) }) - proc = await spawnPluginIntegrationTestProc(sandbox.folder, 'server.mjs', agent.port) + proc = await spawnPluginIntegrationTestProc(__dirname, 'server.mjs', agent.port, env) await res }).timeout(20000) diff --git a/packages/datadog-plugin-redis/test/integration-test/server.mjs b/packages/datadog-plugin-redis/test/integration-test/server.mjs index 7bedf14c5c4..ec90adab844 100644 --- a/packages/datadog-plugin-redis/test/integration-test/server.mjs +++ b/packages/datadog-plugin-redis/test/integration-test/server.mjs @@ -1,4 +1,3 @@ -import 'dd-trace/init.js' import redis from 'redis' const client = redis.createClient() diff --git a/packages/datadog-plugin-restify/test/integration-test/client.spec.js b/packages/datadog-plugin-restify/test/integration-test/client.spec.js index aded6631aba..7ab7747ec3c 100644 --- a/packages/datadog-plugin-restify/test/integration-test/client.spec.js +++ b/packages/datadog-plugin-restify/test/integration-test/client.spec.js @@ -1,31 +1,27 @@ 'use strict' +const { join } = require('node:path') + +const { assert } = require('chai') + const { FakeAgent, - createSandbox, curlAndAssertMessage, checkSpansForServiceName, spawnPluginIntegrationTestProc } = require('../../../../integration-tests/helpers') -const { withVersions } = require('../../../dd-trace/test/setup/mocha') -const { assert } = require('chai') +const { withVersions, insertVersionDep } = require('../../../dd-trace/test/setup/mocha') describe('esm', () => { let agent let proc - let sandbox + const env = { + NODE_OPTIONS: `--loader=${join(__dirname, '..', '..', '..', '..', 'initialize.mjs')}` + } // test against later versions because server.mjs uses newer package syntax withVersions('restify', 'restify', '>3', version => { - before(async function () { - this.timeout(60000) - sandbox = await createSandbox([`'restify@${version}'`], - false, ['./packages/datadog-plugin-restify/test/integration-test/*']) - }) - - after(async () => { - await sandbox.remove() - }) + insertVersionDep(__dirname, 'restify', version) beforeEach(async () => { agent = await new FakeAgent().start() @@ -37,7 +33,7 @@ describe('esm', () => { }) it('is instrumented', async () => { - proc = await spawnPluginIntegrationTestProc(sandbox.folder, 'server.mjs', agent.port) + proc = await spawnPluginIntegrationTestProc(__dirname, 'server.mjs', agent.port, env) return curlAndAssertMessage(agent, proc, ({ headers, payload }) => { assert.propertyVal(headers, 'host', `127.0.0.1:${agent.port}`) diff --git a/packages/datadog-plugin-restify/test/integration-test/server.mjs b/packages/datadog-plugin-restify/test/integration-test/server.mjs index cfd5597a32b..8055b016e38 100644 --- a/packages/datadog-plugin-restify/test/integration-test/server.mjs +++ b/packages/datadog-plugin-restify/test/integration-test/server.mjs @@ -1,4 +1,3 @@ -import 'dd-trace/init.js' import restify from 'restify' const server = restify.createServer() diff --git a/packages/datadog-plugin-rhea/test/integration-test/client.spec.js b/packages/datadog-plugin-rhea/test/integration-test/client.spec.js index d90b1afba7b..4da953d471c 100644 --- a/packages/datadog-plugin-rhea/test/integration-test/client.spec.js +++ b/packages/datadog-plugin-rhea/test/integration-test/client.spec.js @@ -1,29 +1,25 @@ 'use strict' +const { join } = require('node:path') + +const { assert } = require('chai') + const { FakeAgent, - createSandbox, checkSpansForServiceName, spawnPluginIntegrationTestProc } = require('../../../../integration-tests/helpers') -const { withVersions } = require('../../../dd-trace/test/setup/mocha') -const { assert } = require('chai') +const { withVersions, insertVersionDep } = require('../../../dd-trace/test/setup/mocha') describe('esm', () => { let agent let proc - let sandbox + const env = { + NODE_OPTIONS: `--loader=${join(__dirname, '..', '..', '..', '..', 'initialize.mjs')}` + } withVersions('rhea', 'rhea', version => { - before(async function () { - this.timeout(60000) - sandbox = await createSandbox([`'rhea@${version}'`], false, [ - './packages/datadog-plugin-rhea/test/integration-test/*']) - }) - - after(async () => { - await sandbox.remove() - }) + insertVersionDep(__dirname, 'rhea', version) beforeEach(async () => { agent = await new FakeAgent().start() @@ -41,7 +37,7 @@ describe('esm', () => { assert.strictEqual(checkSpansForServiceName(payload, 'amqp.send'), true) }) - proc = await spawnPluginIntegrationTestProc(sandbox.folder, 'server.mjs', agent.port) + proc = await spawnPluginIntegrationTestProc(__dirname, 'server.mjs', agent.port, env) await res }).timeout(20000) diff --git a/packages/datadog-plugin-rhea/test/integration-test/server.mjs b/packages/datadog-plugin-rhea/test/integration-test/server.mjs index 9ea577d1821..6d4107fc20b 100644 --- a/packages/datadog-plugin-rhea/test/integration-test/server.mjs +++ b/packages/datadog-plugin-rhea/test/integration-test/server.mjs @@ -1,4 +1,3 @@ -import 'dd-trace/init.js' import container from 'rhea' container.on('connection_open', function (context) { diff --git a/packages/datadog-plugin-router/test/integration-test/client.spec.js b/packages/datadog-plugin-router/test/integration-test/client.spec.js index d412c529153..f3b5ba2e74b 100644 --- a/packages/datadog-plugin-router/test/integration-test/client.spec.js +++ b/packages/datadog-plugin-router/test/integration-test/client.spec.js @@ -1,30 +1,26 @@ 'use strict' +const { join } = require('node:path') + +const { assert } = require('chai') + const { FakeAgent, - createSandbox, curlAndAssertMessage, checkSpansForServiceName, spawnPluginIntegrationTestProc } = require('../../../../integration-tests/helpers') -const { withVersions } = require('../../../dd-trace/test/setup/mocha') -const { assert } = require('chai') +const { withVersions, insertVersionDep } = require('../../../dd-trace/test/setup/mocha') describe('esm', () => { let agent let proc - let sandbox + const env = { + NODE_OPTIONS: `--loader=${join(__dirname, '..', '..', '..', '..', 'initialize.mjs')}` + } withVersions('router', 'router', version => { - before(async function () { - this.timeout(60000) - sandbox = await createSandbox([`'router@${version}'`] - , false, ['./packages/datadog-plugin-router/test/integration-test/*']) - }) - - after(async () => { - await sandbox.remove() - }) + insertVersionDep(__dirname, 'router', version) beforeEach(async () => { agent = await new FakeAgent().start() @@ -36,7 +32,7 @@ describe('esm', () => { }) it('is instrumented', async () => { - proc = await spawnPluginIntegrationTestProc(sandbox.folder, 'server.mjs', agent.port) + proc = await spawnPluginIntegrationTestProc(__dirname, 'server.mjs', agent.port, env) return curlAndAssertMessage(agent, proc, ({ headers, payload }) => { assert.propertyVal(headers, 'host', `127.0.0.1:${agent.port}`) diff --git a/packages/datadog-plugin-router/test/integration-test/server.mjs b/packages/datadog-plugin-router/test/integration-test/server.mjs index 205a71db047..7ac75b6b0f1 100644 --- a/packages/datadog-plugin-router/test/integration-test/server.mjs +++ b/packages/datadog-plugin-router/test/integration-test/server.mjs @@ -1,4 +1,3 @@ -import 'dd-trace/init.js' import router from 'router' import http from 'http' diff --git a/packages/datadog-plugin-sharedb/test/integration-test/client.spec.js b/packages/datadog-plugin-sharedb/test/integration-test/client.spec.js index 98c97cd61a9..a9d01204b0c 100644 --- a/packages/datadog-plugin-sharedb/test/integration-test/client.spec.js +++ b/packages/datadog-plugin-sharedb/test/integration-test/client.spec.js @@ -1,30 +1,26 @@ 'use strict' +const { join } = require('node:path') + +const { assert } = require('chai') + const { FakeAgent, - createSandbox, checkSpansForServiceName, spawnPluginIntegrationTestProc } = require('../../../../integration-tests/helpers') -const { withVersions } = require('../../../dd-trace/test/setup/mocha') -const { assert } = require('chai') +const { withVersions, insertVersionDep } = require('../../../dd-trace/test/setup/mocha') describe('esm', () => { let agent let proc - let sandbox + const env = { + NODE_OPTIONS: `--loader=${join(__dirname, '..', '..', '..', '..', 'initialize.mjs')}` + } // test against later versions because server.mjs uses newer package syntax withVersions('sharedb', 'sharedb', '>=3', version => { - before(async function () { - this.timeout(60000) - sandbox = await createSandbox([`'sharedb@${version}'`], false, [ - './packages/datadog-plugin-sharedb/test/integration-test/*']) - }) - - after(async () => { - await sandbox.remove() - }) + insertVersionDep(__dirname, 'sharedb', version) beforeEach(async () => { agent = await new FakeAgent().start() @@ -42,7 +38,7 @@ describe('esm', () => { assert.strictEqual(checkSpansForServiceName(payload, 'sharedb.request'), true) }) - proc = await spawnPluginIntegrationTestProc(sandbox.folder, 'server.mjs', agent.port) + proc = await spawnPluginIntegrationTestProc(__dirname, 'server.mjs', agent.port, env) await res }).timeout(20000) diff --git a/packages/datadog-plugin-sharedb/test/integration-test/server.mjs b/packages/datadog-plugin-sharedb/test/integration-test/server.mjs index 8b593029fc9..21d3dc5e8e3 100644 --- a/packages/datadog-plugin-sharedb/test/integration-test/server.mjs +++ b/packages/datadog-plugin-sharedb/test/integration-test/server.mjs @@ -1,4 +1,3 @@ -import 'dd-trace/init.js' import ShareDB from 'sharedb' const backend = new ShareDB({ presence: true }) diff --git a/packages/datadog-plugin-tedious/test/integration-test/client.spec.js b/packages/datadog-plugin-tedious/test/integration-test/client.spec.js index 19b19a93a03..8c892a88743 100644 --- a/packages/datadog-plugin-tedious/test/integration-test/client.spec.js +++ b/packages/datadog-plugin-tedious/test/integration-test/client.spec.js @@ -1,14 +1,16 @@ 'use strict' +const { join } = require('node:path') + +const { assert } = require('chai') + const { FakeAgent, - createSandbox, checkSpansForServiceName, spawnPluginIntegrationTestProc } = require('../../../../integration-tests/helpers') -const { assert } = require('chai') const version = require('../../../../version.js') -const { withVersions } = require('../../../dd-trace/test/setup/mocha') +const { withVersions, insertVersionDep } = require('../../../dd-trace/test/setup/mocha') // tedious does not support node 20 const describe = version.NODE_MAJOR >= 20 @@ -18,19 +20,13 @@ const describe = version.NODE_MAJOR >= 20 describe('esm', () => { let agent let proc - let sandbox + const env = { + NODE_OPTIONS: `--loader=${join(__dirname, '..', '..', '..', '..', 'initialize.mjs')}` + } // test against later versions because server.mjs uses newer package syntax withVersions('tedious', 'tedious', '>=16.0.0', version => { - before(async function () { - this.timeout(60000) - sandbox = await createSandbox([`'tedious@${version}'`], false, [ - './packages/datadog-plugin-tedious/test/integration-test/*']) - }) - - after(async () => { - await sandbox.remove() - }) + insertVersionDep(__dirname, 'tedious', version) beforeEach(async () => { agent = await new FakeAgent().start() @@ -48,7 +44,7 @@ describe('esm', () => { assert.strictEqual(checkSpansForServiceName(payload, 'tedious.request'), true) }) - proc = await spawnPluginIntegrationTestProc(sandbox.folder, 'server.mjs', agent.port) + proc = await spawnPluginIntegrationTestProc(__dirname, 'server.mjs', agent.port, env) await res }).timeout(20000) diff --git a/packages/datadog-plugin-tedious/test/integration-test/server.mjs b/packages/datadog-plugin-tedious/test/integration-test/server.mjs index faf74b86a6f..382e784b127 100644 --- a/packages/datadog-plugin-tedious/test/integration-test/server.mjs +++ b/packages/datadog-plugin-tedious/test/integration-test/server.mjs @@ -1,4 +1,3 @@ -import 'dd-trace/init.js' import tds from 'tedious' const config = { diff --git a/packages/dd-trace/test/setup/mocha.js b/packages/dd-trace/test/setup/mocha.js index aae297266b2..f09e13d90b4 100644 --- a/packages/dd-trace/test/setup/mocha.js +++ b/packages/dd-trace/test/setup/mocha.js @@ -337,18 +337,25 @@ function getModulePath (moduleName, version) { * @param {string} version - The "version" string, as used with `withVersions` */ function insertVersionDep (dir, pkgName, version) { - const nmDir = path.join(dir, 'node_modules') + const moduleNameParts = pkgName.split(/[/\\]/) + const modulePath = getModulePath(pkgName, version) + let pathToCreate = 'node_modules' + if (moduleNameParts.length > 1) { + pathToCreate += '/' + moduleNameParts[0] + pkgName = '/' + moduleNameParts[1] + } + const nmDir = path.join(dir, pathToCreate) const pkgDir = path.join(nmDir, pkgName) before(() => { - const pkgPath = path.dirname(require(getModulePath(pkgName, version)).pkgJsonPath()) - fs.mkdirSync(nmDir) + const pkgPath = path.dirname(require(modulePath).pkgJsonPath()) + fs.mkdirSync(nmDir, { recursive: true }) fs.symlinkSync(pkgPath, pkgDir) }) after(() => { fs.unlinkSync(pkgDir) - fs.rmdirSync(nmDir) + fs.rmSync(path.join(dir, 'node_modules'), { recursive: true, force: true }) }) }