Skip to content

Commit

Permalink
[test optimization] Remove node 16 checks in tests (#5149)
Browse files Browse the repository at this point in the history
  • Loading branch information
juan-fernandez authored Jan 27, 2025
1 parent 29c26b0 commit bf28ddd
Show file tree
Hide file tree
Showing 9 changed files with 13 additions and 54 deletions.
5 changes: 1 addition & 4 deletions integration-tests/automatic-log-submission.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,6 @@ const {
} = require('./helpers')
const { FakeCiVisIntake } = require('./ci-visibility-intake')
const webAppServer = require('./ci-visibility/web-app-server')
const { NODE_MAJOR } = require('../version')

const cucumberVersion = NODE_MAJOR <= 16 ? '9' : 'latest'

describe('test visibility automatic log submission', () => {
let sandbox, cwd, receiver, childProcess, webAppPort
Expand All @@ -23,7 +20,7 @@ describe('test visibility automatic log submission', () => {
before(async () => {
sandbox = await createSandbox([
'mocha',
`@cucumber/cucumber@${cucumberVersion}`,
'@cucumber/cucumber',
'jest',
'winston',
'chai@4'
Expand Down
4 changes: 1 addition & 3 deletions integration-tests/cucumber/cucumber.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
const { exec } = require('child_process')

const getPort = require('get-port')
const semver = require('semver')
const { assert } = require('chai')

const {
Expand Down Expand Up @@ -47,8 +46,7 @@ const {
} = require('../../packages/dd-trace/src/plugins/util/test')
const { DD_HOST_CPU_COUNT } = require('../../packages/dd-trace/src/plugins/util/env')

const isOldNode = semver.satisfies(process.version, '<=16')
const versions = ['7.0.0', isOldNode ? '9' : 'latest']
const versions = ['7.0.0', 'latest']

const runTestsCommand = './node_modules/.bin/cucumber-js ci-visibility/features/*.feature'
const runTestsWithCoverageCommand = './node_modules/nyc/bin/nyc.js -r=text-summary ' +
Expand Down
5 changes: 2 additions & 3 deletions integration-tests/init.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ const {
} = require('./helpers')
const path = require('path')
const fs = require('fs')
const { DD_MAJOR } = require('../version')

const DD_INJECTION_ENABLED = 'tracing'
const DD_INJECT_FORCE = 'true'
Expand Down Expand Up @@ -104,13 +103,13 @@ function testRuntimeVersionChecks (arg, filename) {
it('should not initialize the tracer', () =>
doTest(`Aborting application instrumentation due to incompatible_runtime.
Found incompatible runtime nodejs ${process.versions.node}, Supported runtimes: nodejs \
>=${DD_MAJOR === 4 ? '16' : '18'}.
>=18.
false
`, ...telemetryAbort))
it('should initialize the tracer, if DD_INJECT_FORCE', () =>
doTestForced(`Aborting application instrumentation due to incompatible_runtime.
Found incompatible runtime nodejs ${process.versions.node}, Supported runtimes: nodejs \
>=${DD_MAJOR === 4 ? '16' : '18'}.
>=18.
DD_INJECT_FORCE enabled, allowing unsupported runtimes and continuing.
Application instrumentation bootstrapping complete
true
Expand Down
5 changes: 1 addition & 4 deletions integration-tests/selenium/selenium.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,6 @@ const {
TEST_IS_RUM_ACTIVE,
TEST_TYPE
} = require('../../packages/dd-trace/src/plugins/util/test')
const { NODE_MAJOR } = require('../../version')

const cucumberVersion = NODE_MAJOR <= 16 ? '9' : 'latest'

const webAppServer = require('../ci-visibility/web-app-server')

Expand All @@ -36,7 +33,7 @@ versionRange.forEach(version => {
sandbox = await createSandbox([
'mocha',
'jest',
`@cucumber/cucumber@${cucumberVersion}`,
'@cucumber/cucumber',
'chai@v4',
`selenium-webdriver@${version}`
])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,14 @@ const {
spawnPluginIntegrationTestProc
} = require('../../../../integration-tests/helpers')
const { assert } = require('chai')
const { NODE_MAJOR } = require('../../../../version')

// newer packages are not supported on older node versions
const range = NODE_MAJOR < 16 ? '<3' : '>=4.4.0'

describe('esm', () => {
let agent
let proc
let sandbox

// test against later versions because server.mjs uses newer package syntax
withVersions('cassandra-driver', 'cassandra-driver', range, version => {
withVersions('cassandra-driver', 'cassandra-driver', '>=4.4.0', version => {
before(async function () {
this.timeout(20000)
sandbox = await createSandbox([`'cassandra-driver@${version}'`], false, [
Expand Down
4 changes: 0 additions & 4 deletions packages/datadog-plugin-cucumber/test/index.spec.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
'use strict'
const path = require('path')
const { PassThrough } = require('stream')
const semver = require('semver')

const proxyquire = require('proxyquire').noPreserveCache()
const nock = require('nock')
Expand All @@ -24,7 +23,6 @@ const {
TEST_SOURCE_START
} = require('../../dd-trace/src/plugins/util/test')

const { NODE_MAJOR } = require('../../../version')
const { version: ddTraceVersion } = require('../../../package.json')

const runCucumber = (version, Cucumber, requireName, featureName, testName) => {
Expand Down Expand Up @@ -56,8 +54,6 @@ describe('Plugin', function () {
let Cucumber
this.timeout(10000)
withVersions('cucumber', '@cucumber/cucumber', (version, _, specificVersion) => {
if (NODE_MAJOR <= 16 && semver.satisfies(specificVersion, '>=10')) return

afterEach(() => {
// > If you want to run tests multiple times, you may need to clear Node's require cache
// before subsequent calls in whichever manner best suits your needs.
Expand Down
11 changes: 2 additions & 9 deletions packages/datadog-plugin-next/test/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,8 @@ const { execSync, spawn } = require('child_process')
const agent = require('../../dd-trace/test/plugins/agent')
const { writeFileSync, readdirSync } = require('fs')
const { satisfies } = require('semver')
const { DD_MAJOR, NODE_MAJOR } = require('../../../version')
const { rawExpectedSchema } = require('./naming')

const BUILD_COMMAND = NODE_MAJOR < 18
? 'yarn exec next build'
: 'NODE_OPTIONS=--openssl-legacy-provider yarn exec next build'
let VERSIONS_TO_TEST = NODE_MAJOR < 18 ? '>=11.1 <13.2' : '>=11.1'
VERSIONS_TO_TEST = DD_MAJOR >= 4 ? VERSIONS_TO_TEST : '>=9.5 <11.1'

describe('Plugin', function () {
let server
let port
Expand All @@ -26,7 +19,7 @@ describe('Plugin', function () {
const satisfiesStandalone = version => satisfies(version, '>=12.0.0')

// TODO: Figure out why 10.x tests are failing.
withVersions('next', 'next', VERSIONS_TO_TEST, version => {
withVersions('next', 'next', '>=11.1', version => {
const pkg = require(`../../../versions/next@${version}/node_modules/next/package.json`)

const startServer = ({ withConfig, standalone }, schemaVersion = 'v0', defaultToGlobalService = false) => {
Expand Down Expand Up @@ -110,7 +103,7 @@ describe('Plugin', function () {
}

// building in-process makes tests fail for an unknown reason
execSync(BUILD_COMMAND, {
execSync('NODE_OPTIONS=--openssl-legacy-provider yarn exec next build', {
cwd,
env: {
...process.env,
Expand Down
16 changes: 3 additions & 13 deletions packages/datadog-plugin-next/test/integration-test/client.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,31 +8,21 @@ const {
spawnPluginIntegrationTestProc
} = require('../../../../integration-tests/helpers')
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 => {
withVersions('next', 'next', '>=11.1', 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@^18.2.0', 'react-dom@^18.2.0'],
false, ['./packages/datadog-plugin-next/test/integration-test/*'],
BUILD_COMMAND)
'NODE_OPTIONS=--openssl-legacy-provider yarn exec next build')
})

after(async () => {
Expand All @@ -50,7 +40,7 @@ describe('esm', () => {

it('is instrumented', async () => {
proc = await spawnPluginIntegrationTestProc(sandbox.folder, 'server.mjs', agent.port, undefined, {
NODE_OPTIONS
NODE_OPTIONS: `--loader=${hookFile} --require dd-trace/init --openssl-legacy-provider`
})
return curlAndAssertMessage(agent, proc, ({ headers, payload }) => {
assert.propertyVal(headers, 'host', `127.0.0.1:${agent.port}`)
Expand Down
11 changes: 2 additions & 9 deletions packages/dd-trace/test/appsec/index.next.plugin.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,15 @@ const { writeFileSync } = require('fs')
const { satisfies } = require('semver')
const path = require('path')

const { DD_MAJOR, NODE_MAJOR } = require('../../../../version')
const agent = require('../plugins/agent')

const BUILD_COMMAND = NODE_MAJOR < 18
? 'yarn exec next build'
: 'NODE_OPTIONS=--openssl-legacy-provider yarn exec next build'
let VERSIONS_TO_TEST = NODE_MAJOR < 18 ? '>=11.1 <13.2' : '>=11.1'
VERSIONS_TO_TEST = DD_MAJOR >= 4 ? VERSIONS_TO_TEST : '>=9.5 <11.1'

describe('test suite', () => {
let server
let port

const satisfiesStandalone = version => satisfies(version, '>=12.0.0')

withVersions('next', 'next', VERSIONS_TO_TEST, version => {
withVersions('next', 'next', '>=11.1', version => {
const realVersion = require(`../../../../versions/next@${version}`).version()

function initApp (appName) {
Expand Down Expand Up @@ -58,7 +51,7 @@ describe('test suite', () => {
}

// building in-process makes tests fail for an unknown reason
execSync(BUILD_COMMAND, {
execSync('NODE_OPTIONS=--openssl-legacy-provider yarn exec next build', {
cwd,
env: {
...process.env,
Expand Down

0 comments on commit bf28ddd

Please sign in to comment.