diff --git a/test/smoke/agent/agent-restart-listener.tap.js b/test/smoke/agent/agent-restart-listener.test.js similarity index 81% rename from test/smoke/agent/agent-restart-listener.tap.js rename to test/smoke/agent/agent-restart-listener.test.js index 7957c0eaad..d796737cde 100644 --- a/test/smoke/agent/agent-restart-listener.tap.js +++ b/test/smoke/agent/agent-restart-listener.test.js @@ -5,13 +5,14 @@ 'use strict' -const tap = require('tap') +const test = require('node:test') +const assert = require('node:assert') const configurator = require('../../../lib/config') const Agent = require('../../../lib/agent') const { getTestSecret } = require('../../helpers/secrets') const license = getTestSecret('TEST_LICENSE') -tap.test('Collector API should connect to staging-collector.newrelic.com', (t) => { +test('Collector API should connect to staging-collector.newrelic.com', (t, end) => { const config = configurator.initialize({ app_name: 'node.js Tests', license_key: license, @@ -31,9 +32,9 @@ tap.test('Collector API should connect to staging-collector.newrelic.com', (t) = const agent = new Agent(config) agent.start((error, returned) => { - t.notOk(error, 'connected without error') - t.ok(returned, 'got boot configuration') - t.ok(returned.agent_run_id, 'got run ID') + assert.ok(!error, 'connected without error') + assert.ok(returned, 'got boot configuration') + assert.ok(returned.agent_run_id, 'got run ID') const initialStoppedListeners = agent.listenerCount('stopped') const initialErroredListeners = agent.listenerCount('errored') @@ -43,24 +44,24 @@ tap.test('Collector API should connect to staging-collector.newrelic.com', (t) = const currentStoppedListeners = agent.listenerCount('stopped') const currentErroredListeners = agent.listenerCount('errored') const currentDisconnectedListeners = agent.listenerCount('disconnected') - t.equal( + assert.equal( currentStoppedListeners, initialStoppedListeners, 'should not have extra stopped listeners' ) - t.equal( + assert.equal( currentErroredListeners, initialErroredListeners, 'should not have extra errored listeners' ) - t.equal( + assert.equal( currentDisconnectedListeners, initialDisconnectedListeners, 'should not have extra disconnected listeners' ) agent.stop(() => { - t.end() + end() }) }) }) diff --git a/test/smoke/agent/lasp-send-trace.tap.js b/test/smoke/agent/lasp-send-trace.test.js similarity index 60% rename from test/smoke/agent/lasp-send-trace.tap.js rename to test/smoke/agent/lasp-send-trace.test.js index 8aebf63b1a..c28a23e669 100644 --- a/test/smoke/agent/lasp-send-trace.tap.js +++ b/test/smoke/agent/lasp-send-trace.test.js @@ -5,20 +5,17 @@ 'use strict' -const tap = require('tap') +const test = require('node:test') +const assert = require('node:assert') const configurator = require('../../../lib/config') const Agent = require('../../../lib/agent') const API = require('../../../api') const { getTestSecret } = require('../../helpers/secrets') const license = getTestSecret('LASP_LICENSE') -tap.test('LASP-enabled agent', (t) => { - let agent = null - let api = null - let config = null - - t.beforeEach(function () { - config = configurator.initialize({ +test('LASP-enabled agent', async (t) => { + t.beforeEach(function (ctx) { + const config = configurator.initialize({ app_name: 'node.js Tests', license_key: license, security_policies_token: 'ffff-ffff-ffff-ffff', @@ -36,14 +33,19 @@ tap.test('LASP-enabled agent', (t) => { } }) - agent = new Agent(config) - api = new API(agent) + const agent = new Agent(config) + const api = new API(agent) // Agent cannot create transactions from initial 'stopped' state agent.setState('started') + ctx.nr = { + agent, + api + } }) - t.test('drops full trace if custom attributes are disabled by LASP', function (t) { + await t.test('drops full trace if custom attributes are disabled by LASP', function (t, end) { + const { agent, api } = t.nr let transaction const proxy = agent.tracer.transactionProxy(function () { transaction = agent.getTransaction() @@ -53,26 +55,31 @@ tap.test('LASP-enabled agent', (t) => { api.addCustomAttribute('foo', 'bar') api.addCustomAttribute('fizz', 'buzz') const attributes = transaction.trace.custom.attributes - t.same(Object.keys(attributes), ['foo', 'fizz'], 'transaction trace has custom attributes') + assert.deepEqual( + Object.keys(attributes), + ['foo', 'fizz'], + 'transaction trace has custom attributes' + ) }) proxy() transaction.end() - t.ok(agent.traces.trace, 'should have a trace before connect') + assert.ok(agent.traces.trace, 'should have a trace before connect') agent.start(function (error) { - t.error(error, 'connected without error') - t.notOk(agent.traces.trace, 'should no longer have a trace') + assert.ok(!error, 'connected without error') + assert.ok(!agent.traces.trace, 'should no longer have a trace') agent.stop(function (error) { - t.error(error, 'stopped without error') + assert.ok(!error, 'stopped without error') - t.end() + end() }) }) }) - t.test('drops full trace if attributes.include is disabled by LASP', function (t) { + await t.test('drops full trace if attributes.include is disabled by LASP', function (t, end) { + const { agent, api } = t.nr agent.config.attributes.include = ['f*'] agent.config.emit('attributes.include') let transaction @@ -84,24 +91,26 @@ tap.test('LASP-enabled agent', (t) => { api.addCustomAttribute('foo', 'bar') api.addCustomAttribute('fizz', 'buzz') const attributes = transaction.trace.custom.attributes - t.same(Object.keys(attributes), ['foo', 'fizz'], 'transaction trace has custom attributes') + assert.deepEqual( + Object.keys(attributes), + ['foo', 'fizz'], + 'transaction trace has custom attributes' + ) }) proxy() transaction.end() - t.ok(agent.traces.trace, 'should have a trace before connect') + assert.ok(agent.traces.trace, 'should have a trace before connect') agent.start(function (error) { - t.error(error, 'connected without error') - t.notOk(agent.traces.trace, 'should no longer have a trace') + assert.ok(!error, 'connected without error') + assert.ok(!agent.traces.trace, 'should no longer have a trace') agent.stop(function (error) { - t.error(error, 'stopped without error') + assert.ok(!error, 'stopped without error') - t.end() + end() }) }) }) - - t.autoend() }) diff --git a/test/smoke/agent/start-stop.tap.js b/test/smoke/agent/start-stop.test.js similarity index 59% rename from test/smoke/agent/start-stop.tap.js rename to test/smoke/agent/start-stop.test.js index 1af6c11a2f..ef73aeb438 100644 --- a/test/smoke/agent/start-stop.tap.js +++ b/test/smoke/agent/start-stop.test.js @@ -4,14 +4,14 @@ */ 'use strict' - -const tap = require('tap') +const test = require('node:test') +const assert = require('node:assert') const configurator = require('../../../lib/config') const Agent = require('../../../lib/agent') const { getTestSecret } = require('../../helpers/secrets') const license = getTestSecret('TEST_LICENSE') -tap.test('Collector API should connect to staging-collector.newrelic.com', (t) => { +test('Collector API should connect to staging-collector.newrelic.com', (t, end) => { const config = configurator.initialize({ app_name: 'node.js Tests', license_key: license, @@ -31,16 +31,16 @@ tap.test('Collector API should connect to staging-collector.newrelic.com', (t) = const agent = new Agent(config) agent.start((error, returned) => { - t.notOk(error, 'connected without error') - t.ok(returned, 'got boot configuration') - t.ok(returned.agent_run_id, 'got run ID') - t.ok(agent.config.run_id, 'run ID set in configuration') + assert.ok(!error, 'connected without error') + assert.ok(returned, 'got boot configuration') + assert.ok(returned.agent_run_id, 'got run ID') + assert.ok(agent.config.run_id, 'run ID set in configuration') agent.stop((error) => { - t.notOk(error, 'should have shut down without issue') - t.notOk(agent.config.run_id, 'run ID should have been cleared by shutdown') + assert.ok(!error, 'should have shut down without issue') + assert.ok(!agent.config.run_id, 'run ID should have been cleared by shutdown') - t.end() + end() }) }) }) diff --git a/test/smoke/e2e/express.tap.js b/test/smoke/e2e/express.test.js similarity index 85% rename from test/smoke/e2e/express.tap.js rename to test/smoke/e2e/express.test.js index 6383e854fe..18c2bb4ca9 100644 --- a/test/smoke/e2e/express.tap.js +++ b/test/smoke/e2e/express.test.js @@ -4,17 +4,17 @@ */ 'use strict' - const cp = require('child_process') const http = require('http') const path = require('path') const util = require('util') -const tap = require('tap') +const test = require('node:test') +const assert = require('node:assert') const EXIT_TYPES = ['error', 'exit', 'disconnect', 'close'] const exitHandlers = {} -tap.test('Express e2e request smoke test', (t) => { +test('Express e2e request smoke test', (t, end) => { const server = cp.fork(path.join(__dirname, 'express-server')) // Bind to the various ways failure could happen @@ -40,13 +40,13 @@ tap.test('Express e2e request smoke test', (t) => { }) res.on('end', function onEnd() { - t.equal(data, 'hello world!', 'should return appropriate response data') + assert.equal(data, 'hello world!', 'should return appropriate response data') // unbind from the exit conditions EXIT_TYPES.forEach((type) => { server.removeListener(type, exitHandlers[type]) }) server.kill() - t.end() + end() }) }) }) diff --git a/test/smoke/index/index-bad-version.tap.js b/test/smoke/index/index-bad-version.test.js similarity index 69% rename from test/smoke/index/index-bad-version.tap.js rename to test/smoke/index/index-bad-version.test.js index 3571ef6041..b1b40a6df5 100644 --- a/test/smoke/index/index-bad-version.tap.js +++ b/test/smoke/index/index-bad-version.test.js @@ -4,14 +4,14 @@ */ 'use strict' - -const tap = require('tap') +const test = require('node:test') +const assert = require('node:assert') const { getTestSecret } = require('../../helpers/secrets') const StubApi = require('../../../stub_api') const license = getTestSecret('TEST_LICENSE') const VERSIONS = ['garbage', '4.0.0'] -tap.test('load agent with bad versions should load stub agent', (t) => { +test('load agent with bad versions should load stub agent', async (t) => { process.env.NEW_RELIC_HOME = __dirname + '/..' process.env.NEW_RELIC_HOST = 'staging-collector.newrelic.com' process.env.NEW_RELIC_LICENSE_KEY = license @@ -23,21 +23,19 @@ tap.test('load agent with bad versions should load stub agent', (t) => { delete require.cache[require.resolve('../../../index.js')] }) - VERSIONS.forEach((version) => { - t.test(`agent version: ${version}`, (t) => { - t.doesNotThrow(function () { + for (const version of VERSIONS) { + await t.test(`agent version: ${version}`, (t, end) => { + assert.doesNotThrow(function () { const _version = process.version Object.defineProperty(process, 'version', { value: version, writable: true }) - t.equal(process.version, version, 'should have set bad version') + assert.equal(process.version, version, 'should have set bad version') const api = require('../../../index.js') - t.ok(api instanceof StubApi) + assert.ok(api instanceof StubApi) process.version = _version }, "malformed process.version doesn't blow up the process") - t.end() + end() }) - }) - - t.end() + } }) diff --git a/test/smoke/index/index.tap.js b/test/smoke/index/index.test.js similarity index 55% rename from test/smoke/index/index.tap.js rename to test/smoke/index/index.test.js index ee79e7ab42..9f1b8f360b 100644 --- a/test/smoke/index/index.tap.js +++ b/test/smoke/index/index.test.js @@ -4,40 +4,40 @@ */ 'use strict' - -const { test } = require('tap') +const test = require('node:test') +const assert = require('node:assert') const { getTestSecret } = require('../../helpers/secrets') const license = getTestSecret('TEST_LICENSE') -test('loading the application via index.js', { timeout: 15000 }, (t) => { +test('loading the application via index.js', { timeout: 15000 }, (t, end) => { let agent = null process.env.NEW_RELIC_HOME = __dirname + '/..' process.env.NEW_RELIC_HOST = 'staging-collector.newrelic.com' process.env.NEW_RELIC_LICENSE_KEY = license - t.doesNotThrow(function () { + assert.doesNotThrow(function () { const api = require('../../../index.js') agent = api.agent - t.equal(agent._state, 'connecting', 'agent is booting') + assert.equal(agent._state, 'connecting', 'agent is booting') }, "just loading the agent doesn't throw") let metric = agent.metrics.getMetric('Supportability/Nodejs/FeatureFlag/await_support/enabled') - t.notOk(metric, 'should not create metric for unchanged feature flags') + assert.ok(!metric, 'should not create metric for unchanged feature flags') metric = agent.metrics.getMetric('Supportability/Nodejs/FeatureFlag/internal_test_only/enabled') - t.ok(metric, 'should create metric for changed feature flags') + assert.ok(metric, 'should create metric for changed feature flags') function shutdown() { - t.equal(agent._state, 'started', "agent didn't error connecting to staging") - t.same(agent.config.applications(), ['My Application'], 'app name is valid') - t.equal(agent.config.agent_enabled, true, 'the agent is still enabled') + assert.equal(agent._state, 'started', "agent didn't error connecting to staging") + assert.deepEqual(agent.config.applications(), ['My Application'], 'app name is valid') + assert.equal(agent.config.agent_enabled, true, 'the agent is still enabled') agent.stop(function cbStop(err) { - t.notOk(err, 'should not error when stopping') - t.equal(agent._state, 'stopped', "agent didn't error shutting down") + assert.ok(!err, 'should not error when stopping') + assert.equal(agent._state, 'stopped', "agent didn't error shutting down") - t.end() + end() }) }