Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -546,15 +546,10 @@ export default [
rules: {
'mocha/consistent-spacing-between-blocks': 'off',
'mocha/max-top-level-suites': ['error', { limit: 1 }],
'mocha/no-exports': 'off',
'mocha/no-global-tests': 'off',
'mocha/no-identical-title': 'off',
'mocha/no-mocha-arrows': 'off',
'mocha/no-setup-in-describe': 'off',
'mocha/no-sibling-hooks': 'off',
'mocha/no-skipped-tests': 'off',
'mocha/no-top-level-hooks': 'off',
'mocha/prefer-arrow-callback': 'off',
'n/handle-callback-err': 'off',
'n/no-missing-require': 'off',
'require-await': 'off'
Expand Down
10 changes: 4 additions & 6 deletions integration-tests/appsec/multer.spec.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
'use strict'

const { assert } = require('chai')
const path = require('path')
const axios = require('axios')
const { assert } = require('chai')
const { describe, it, beforeEach, afterEach, before, after } = require('mocha')

const path = require('node:path')

const {
createSandbox,
FakeAgent,
spawnProc
} = require('../helpers')

const { NODE_MAJOR } = require('../../version')

const describe = NODE_MAJOR <= 16 ? globalThis.describe.skip : globalThis.describe

describe('multer', () => {
let sandbox, cwd, startupTestFile, agent, proc, env

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const sum = require('./dependency')
const { expect } = require('chai')

let count = 0

describe('dynamic-instrumentation', () => {
it('retries with DI', function () {
if (process.env.TEST_SHOULD_PASS_AFTER_RETRY && count++ === 1) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const sum = require('./dependency')
const { expect } = require('chai')

let count = 0

describe('dynamic-instrumentation', () => {
it('retries with DI', function () {
const willFail = count++ === 0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ describe('ci visibility', () => {
if (typeof jest !== 'undefined') {
it.todo('todo will not be retried')
}

it.skip('skip will not be retried', () => {
expect(1 + 2).to.equal(4)
})
Expand Down
8 changes: 6 additions & 2 deletions integration-tests/cucumber/cucumber.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ versions.forEach(version => {
reportMethods.forEach((reportMethod) => {
context(`reporting via ${reportMethod}`, () => {
let envVars, isAgentless, logsEndpoint

beforeEach(() => {
isAgentless = reportMethod === 'agentless'
envVars = isAgentless ? getCiVisAgentlessConfig(receiver.port) : getCiVisEvpProxyConfig(receiver.port)
Expand Down Expand Up @@ -269,6 +270,7 @@ versions.forEach(version => {
})
})
})

context('intelligent test runner', () => {
it('can report git metadata', (done) => {
const searchCommitsRequestPromise = receiver.payloadReceived(
Expand Down Expand Up @@ -1240,7 +1242,8 @@ versions.forEach(version => {
})
})

if (version !== '7.0.0') { // EFD in parallel mode only supported from cucumber>=11
if (version !== '7.0.0') {
// EFD in parallel mode only supported from cucumber>=11
context('parallel mode', () => {
it('retries new tests', (done) => {
const NUM_RETRIES_EFD = 3
Expand Down Expand Up @@ -1530,7 +1533,8 @@ versions.forEach(version => {
}
})

if (version === 'latest') { // flaky test retries only supported from >=8.0.0
if (version === 'latest') {
// flaky test retries only supported from >=8.0.0
context('flaky test retries', () => {
it('can retry failed tests', (done) => {
receiver.setSettings({
Expand Down
3 changes: 3 additions & 0 deletions integration-tests/helpers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -463,6 +463,7 @@ function useEnv (env) {
before(() => {
Object.assign(process.env, env)
})

after(() => {
for (const key of Object.keys(env)) {
delete process.env[key]
Expand All @@ -474,6 +475,7 @@ function useSandbox (...args) {
before(async () => {
sandbox = await createSandbox(...args)
})

after(() => {
const oldSandbox = sandbox
sandbox = undefined
Expand All @@ -489,6 +491,7 @@ function setShouldKill (value) {
before(() => {
shouldKill = value
})

after(() => {
shouldKill = true
})
Expand Down
24 changes: 22 additions & 2 deletions integration-tests/init.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ delete process.env.DD_INJECT_FORCE
function testInjectionScenarios (arg, filename, esmWorks = false) {
if (!currentVersionIsSupported) return
const doTest = (file, ...args) => testFile(file, ...args)

context('preferring app-dir dd-trace', () => {
context('when dd-trace is not in the app dir', () => {
const NODE_OPTIONS = `--no-warnings --${arg} ${path.join(__dirname, '..', filename)}`
Expand All @@ -39,34 +40,45 @@ function testInjectionScenarios (arg, filename, esmWorks = false) {
if (currentVersionIsSupported) {
context('without DD_INJECTION_ENABLED', () => {
it('should initialize the tracer', () => doTest('init/trace.js', 'true\n', [], 'manual'))

it('should initialize instrumentation', () => doTest('init/instrument.js', 'true\n', [], 'manual'))

it(`should ${esmWorks ? '' : 'not '}initialize ESM instrumentation`, () =>
doTest('init/instrument.mjs', `${esmWorks}\n`, [], 'manual'))
})
}

context('with DD_INJECTION_ENABLED', () => {
useEnv({ DD_INJECTION_ENABLED })

it('should not initialize the tracer', () => doTest('init/trace.js', 'false\n', []))

it('should not initialize instrumentation', () => doTest('init/instrument.js', 'false\n', []))

it('should not initialize ESM instrumentation', () => doTest('init/instrument.mjs', 'false\n', []))
})
})

context('when dd-trace in the app dir', () => {
const NODE_OPTIONS = `--no-warnings --${arg} dd-trace/${filename}`
useEnv({ NODE_OPTIONS })

context('without DD_INJECTION_ENABLED', () => {
it('should initialize the tracer', () => doTest('init/trace.js', 'true\n', [], 'manual'))

it('should initialize instrumentation', () => doTest('init/instrument.js', 'true\n', [], 'manual'))

it(`should ${esmWorks ? '' : 'not '}initialize ESM instrumentation`, () =>
doTest('init/instrument.mjs', `${esmWorks}\n`, [], 'manual'))
})

context('with DD_INJECTION_ENABLED', () => {
useEnv({ DD_INJECTION_ENABLED, DD_TRACE_DEBUG })

it('should initialize the tracer', () => doTest('init/trace.js', 'true\n', telemetryGood, 'ssi'))

it('should initialize instrumentation', () => doTest('init/instrument.js', 'true\n', telemetryGood, 'ssi'))

it(`should ${esmWorks ? '' : 'not '}initialize ESM instrumentation`, () =>
doTest('init/instrument.mjs', `${esmWorks}\n`, telemetryGood, 'ssi'))
})
Expand All @@ -91,15 +103,17 @@ function testRuntimeVersionChecks (arg, filename) {
context('when node version is less than engines field', () => {
useEnv({ NODE_OPTIONS })

it('should not initialize the tracer', () =>
doTest('false\n', []))
it('should not initialize the tracer', () => doTest('false\n', []))

context('with DD_INJECTION_ENABLED', () => {
useEnv({ DD_INJECTION_ENABLED })

context('without debug', () => {
it('should not initialize the tracer', () => doTest('false\n', telemetryAbort))

it('should initialize the tracer, if DD_INJECT_FORCE', () => doTestForced('true\n', telemetryForced))
})

context('with debug', () => {
useEnv({ DD_TRACE_DEBUG })

Expand All @@ -109,6 +123,7 @@ Found incompatible runtime Node.js ${process.versions.node}, Supported runtimes:
>=18.
false
`, telemetryAbort))

it('should initialize the tracer, if DD_INJECT_FORCE', () =>
doTestForced(`Aborting application instrumentation due to incompatible_runtime.
Found incompatible runtime Node.js ${process.versions.node}, Supported runtimes: Node.js \
Expand All @@ -125,19 +140,23 @@ true
useEnv({ NODE_OPTIONS })

it('should initialize the tracer, if no DD_INJECTION_ENABLED', () => doTest('true\n', [], 'manual'))

context('with DD_INJECTION_ENABLED', () => {
useEnv({ DD_INJECTION_ENABLED })

context('without debug', () => {
it('should initialize the tracer', () => doTest('true\n', telemetryGood, 'ssi'))

it('should initialize the tracer, if DD_INJECT_FORCE', () =>
doTestForced('true\n', telemetryGood, 'ssi'))
})

context('with debug', () => {
useEnv({ DD_TRACE_DEBUG })

it('should initialize the tracer', () =>
doTest('Application instrumentation bootstrapping complete\ntrue\n', telemetryGood, 'ssi'))

it('should initialize the tracer, if DD_INJECT_FORCE', () =>
doTestForced('Application instrumentation bootstrapping complete\ntrue\n', telemetryGood, 'ssi'))
})
Expand Down Expand Up @@ -183,6 +202,7 @@ if (semver.satisfies(process.versions.node, '>=14.13.1')) {
process.versions.node !== '18.0.0')
testRuntimeVersionChecks('loader', 'initialize.mjs')
})

if (semver.satisfies(process.versions.node, '>=20.6.0')) {
context('as --import', () => {
testInjectionScenarios('import', 'initialize.mjs', true)
Expand Down
1 change: 1 addition & 0 deletions integration-tests/jest/jest.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -950,6 +950,7 @@ describe('jest CommonJS', () => {
})
})
})

it('can report code coverage', (done) => {
const libraryConfigRequestPromise = receiver.payloadReceived(
({ url }) => url === '/api/v2/libraries/tests/services/setting'
Expand Down
2 changes: 2 additions & 0 deletions integration-tests/mocha/mocha.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -644,6 +644,7 @@ describe('mocha CommonJS', function () {
})
})
})

it('can report code coverage', (done) => {
let testOutput
const libraryConfigRequestPromise = receiver.payloadReceived(
Expand Down Expand Up @@ -3504,6 +3505,7 @@ describe('mocha CommonJS', function () {
}
)
})

context('test is new', () => {
it('should be retried and marked both as new and modified', (done) => {
receiver.setKnownTests({
Expand Down
14 changes: 14 additions & 0 deletions integration-tests/package-guardrails.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,20 +27,25 @@ describe('package guardrails', () => {

context('when package is out of range', () => {
useSandbox(['[email protected]'])

context('with DD_INJECTION_ENABLED', () => {
useEnv({ DD_INJECTION_ENABLED })

it('should not instrument the package, and send telemetry', () =>
runTest('false\n',
['complete', 'injection_forced:false',
'abort.integration', 'integration:bluebird,integration_version:1.0.0'
]
))
})

context('with logging disabled', () => {
it('should not instrument the package', () => runTest('false\n', []))
})

context('with logging enabled', () => {
useEnv({ DD_TRACE_DEBUG })

it('should not instrument the package', () =>
runTest(`Application instrumentation bootstrapping complete
Found incompatible integration version: [email protected]
Expand All @@ -52,29 +57,36 @@ false
context('when package is in range', () => {
context('when bluebird is 2.9.0', () => {
useSandbox(['[email protected]'])

it('should instrument the package', () => runTest('true\n', [], 'manual'))
})

context('when bluebird is 3.7.2', () => {
useSandbox(['[email protected]'])

it('should instrument the package', () => runTest('true\n', [], 'manual'))
})
})

context('when package is in range (fastify)', () => {
context('when fastify is latest', () => {
useSandbox(['fastify'])

it('should instrument the package', () => runTest('true\n', [], 'manual'))
})

context('when fastify is latest and logging enabled', () => {
useSandbox(['fastify'])
useEnv({ DD_TRACE_DEBUG })

it('should instrument the package', () =>
runTest('Application instrumentation bootstrapping complete\ntrue\n', [], 'manual'))
})
})

context('when package errors out', () => {
useSandbox(['bluebird'])

before(() => {
const file = path.join(sandboxCwd(), 'node_modules/dd-trace/packages/datadog-instrumentations/src/bluebird.js')
fs.writeFileSync(file, `
Expand All @@ -89,6 +101,7 @@ addHook({ name: 'bluebird', versions: ['*'] }, Promise => {

context('with DD_INJECTION_ENABLED', () => {
useEnv({ DD_INJECTION_ENABLED })

it('should not instrument the package, and send telemetry', () =>
runTest('false\n',
['complete', 'injection_forced:false',
Expand All @@ -102,6 +115,7 @@ addHook({ name: 'bluebird', versions: ['*'] }, Promise => {

context('with logging enabled', () => {
useEnv({ DD_TRACE_DEBUG, DD_LOG_LEVEL })

it('should not instrument the package', () =>
runTest(
log => {
Expand Down
1 change: 1 addition & 0 deletions integration-tests/pino.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ describe('pino test', () => {
}
})
})

it('Log injection enabled', async () => {
proc = await spawnProc(startupTestFile, {
cwd,
Expand Down
1 change: 1 addition & 0 deletions integration-tests/playwright/playwright.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ versions.forEach((version) => {
context(...args)
}
}

describe(`playwright@${version}`, () => {
let sandbox, cwd, receiver, childProcess, webAppPort, webPortWithRedirect

Expand Down
1 change: 1 addition & 0 deletions integration-tests/selenium/selenium.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ versionRange.forEach(version => {
]
testFrameworks.forEach(({ name, command }) => {
if ((NODE_MAJOR === 18 || NODE_MAJOR === 23) && name === 'cucumber') return

context(`with ${name}`, () => {
it('identifies tests using selenium as browser tests', (done) => {
const assertionPromise = receiver
Expand Down
1 change: 1 addition & 0 deletions integration-tests/vitest/vitest.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2089,6 +2089,7 @@ versions.forEach((version) => {
)
})
})

context('test is new', () => {
it('should be retried and marked both as new and modified', (done) => {
receiver.setKnownTests({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ describe('esm', () => {
proc && proc.kill()
await agent.stop()
})

it('is instrumented', async () => {
const res = agent.assertMessageReceived(({ headers, payload }) => {
assert.propertyVal(headers, 'host', `127.0.0.1:${agent.port}`)
Expand Down
3 changes: 3 additions & 0 deletions packages/datadog-plugin-cypress/test/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ describe('Plugin', function () {
beforeEach(() => {
return agent.load()
})

beforeEach(function (done) {
// This test does not check test optimization agentless protocol,
// so we'll make the tracer default to reporting to v0.4/traces
Expand All @@ -46,7 +47,9 @@ describe('Plugin', function () {
done()
})
})

afterEach(() => agent.close({ ritmReset: false }))

afterEach(done => {
appServer.close(done)
})
Expand Down
Loading
Loading