From b1f584df9b21db6328438bb86c33db2bcc774837 Mon Sep 17 00:00:00 2001 From: James Sumners Date: Mon, 25 Nov 2024 12:54:17 -0500 Subject: [PATCH] chore: Updated index, issue-2155, and metric integration tests to node:test --- ...disabled.tap.js => index-disabled.test.js} | 11 +++-- test/integration/index/index-no-config.tap.js | 25 ----------- .../integration/index/index-no-config.test.js | 35 +++++++++++++++ .../{test.tap.mjs => test.test.mjs} | 27 ++++++----- test/integration/metric/normalization.tap.js | 45 ------------------- test/integration/metric/normalization.test.js | 41 +++++++++++++++++ 6 files changed, 96 insertions(+), 88 deletions(-) rename test/integration/index/{index-disabled.tap.js => index-disabled.test.js} (62%) delete mode 100644 test/integration/index/index-no-config.tap.js create mode 100644 test/integration/index/index-no-config.test.js rename test/integration/issue-2155/{test.tap.mjs => test.test.mjs} (75%) delete mode 100644 test/integration/metric/normalization.tap.js create mode 100644 test/integration/metric/normalization.test.js diff --git a/test/integration/index/index-disabled.tap.js b/test/integration/index/index-disabled.test.js similarity index 62% rename from test/integration/index/index-disabled.tap.js rename to test/integration/index/index-disabled.test.js index 9b14175683..f743784922 100644 --- a/test/integration/index/index-disabled.tap.js +++ b/test/integration/index/index-disabled.test.js @@ -5,15 +5,14 @@ 'use strict' -const test = require('tap').test - -test('loading the application via index.js with agent disabled', function (t) { - t.plan(2) +const test = require('node:test') +const assert = require('node:assert') +test('loading the application via index.js with agent disabled', () => { process.env.NEW_RELIC_HOME = __dirname + '/..' process.env.NEW_RELIC_ENABLED = 'false' const api = require('../../../index.js') - t.ok(api, 'should have an API') - t.notOk(api.agent, 'should not have an associated agent') + assert.ok(api, 'should have an API') + assert.equal(api.agent, undefined, 'should not have an associated agent') }) diff --git a/test/integration/index/index-no-config.tap.js b/test/integration/index/index-no-config.tap.js deleted file mode 100644 index f0fc81589d..0000000000 --- a/test/integration/index/index-no-config.tap.js +++ /dev/null @@ -1,25 +0,0 @@ -/* - * Copyright 2020 New Relic Corporation. All rights reserved. - * SPDX-License-Identifier: Apache-2.0 - */ - -'use strict' - -const test = require('tap').test - -test('loading the application via index.js with no config', function (t) { - t.plan(3) - - process.env.NEW_RELIC_HOME = '/this/is/not/a/real/path' - process.env.HOME = '/this/is/also/not/a/real/path' - process.cwd = function () { - return __dirname - } - let api - t.doesNotThrow(function () { - api = require('../../../') - }, 'should not die when the config file is not found') - - t.ok(api, 'should have an API') - t.notOk(api.agent, 'should not have an associated agent') -}) diff --git a/test/integration/index/index-no-config.test.js b/test/integration/index/index-no-config.test.js new file mode 100644 index 0000000000..44523ebde3 --- /dev/null +++ b/test/integration/index/index-no-config.test.js @@ -0,0 +1,35 @@ +/* + * Copyright 2020 New Relic Corporation. All rights reserved. + * SPDX-License-Identifier: Apache-2.0 + */ + +'use strict' + +const test = require('node:test') +const assert = require('node:assert') + +test('loading the application via index.js with no config', (t) => { + process.env.NEW_RELIC_HOME = '/this/is/not/a/real/path' + process.env.HOME = '/this/is/also/not/a/real/path' + process.cwd = function () { + return __dirname + } + + /* eslint-disable no-console */ + const logs = [] + const logError = console.error + t.after(() => { + console.error = logError + }) + console.error = (...args) => logs.push(args) + /* eslint-enable no-console */ + + let api + assert.doesNotThrow(function () { + api = require('../../../') + }, 'should not die when the config file is not found') + + assert.ok(api, 'should have an API') + assert.equal(api.agent, undefined, 'should not have an associated agent') + assert.equal(logs.length, 2) +}) diff --git a/test/integration/issue-2155/test.tap.mjs b/test/integration/issue-2155/test.test.mjs similarity index 75% rename from test/integration/issue-2155/test.tap.mjs rename to test/integration/issue-2155/test.test.mjs index efdc94a9a8..decc5c0d26 100644 --- a/test/integration/issue-2155/test.tap.mjs +++ b/test/integration/issue-2155/test.test.mjs @@ -3,10 +3,12 @@ * SPDX-License-Identifier: Apache-2.0 */ -import tap from 'tap' -import crypto from 'crypto' -import path from 'path' -import url from 'url' +import test from 'node:test' +import assert from 'node:assert' +import crypto from 'node:crypto' +import path from 'node:path' +import url from 'node:url' + import helper from '../../lib/agent_helper.js' import shimmer from '../../../lib/shimmer.js' import InstrumentationDescriptor from '../../../lib/instrumentation-descriptor.js' @@ -35,7 +37,8 @@ function instrumentation(shim, resolvedModule) { }) } -tap.beforeEach(async (t) => { +test.beforeEach(async (ctx) => { + ctx.nr = {} shimmer.registerInstrumentation({ type: InstrumentationDescriptor.TYPE_GENERIC, moduleName: 'foo', @@ -44,18 +47,18 @@ tap.beforeEach(async (t) => { }) const agent = helper.instrumentMockedAgent() - t.context.agent = agent + ctx.nr.agent = agent const { default: foo } = await import('./foo.cjs?v=' + crypto.randomBytes(16).toString('hex')) - t.context.mod = foo + ctx.nr.mod = foo }) -tap.afterEach((t) => { - helper.unloadAgent(t.context.agent) +test.afterEach((ctx) => { + helper.unloadAgent(ctx.nr.agent) }) -tap.test('CJS imported as ESM gets wrapped correctly', async (t) => { - const { mod } = t.context +test('CJS imported as ESM gets wrapped correctly', async (t) => { + const { mod } = t.nr const instance = mod() - t.equal(instance.name(), 'wrapped: foo') + assert.equal(instance.name(), 'wrapped: foo') }) diff --git a/test/integration/metric/normalization.tap.js b/test/integration/metric/normalization.tap.js deleted file mode 100644 index a0124e9d8e..0000000000 --- a/test/integration/metric/normalization.tap.js +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Copyright 2020 New Relic Corporation. All rights reserved. - * SPDX-License-Identifier: Apache-2.0 - */ - -'use strict' - -const test = require('tap').test -const ruleTests = require('../../lib/cross_agent_tests/rules') -const Config = require('../../../lib/config') -const Normalizer = require('../../../lib/metrics/normalizer') - -test('metric normalization', function (t) { - t.plan(1) - - t.test('cross agent tests', function (t) { - t.plan(ruleTests.length) - const config = new Config({}) - - ruleTests.forEach(function (rulesTest) { - t.test(rulesTest.testname, function (t) { - t.plan(rulesTest.tests.length * 2) - - const normalizer = new Normalizer(config, 'Url') - normalizer.load(rulesTest.rules) - - rulesTest.tests.forEach(function (io) { - const normalized = normalizer.normalize(io.input) - - if (io.expected === null) { - t.pass('ignored, not checking name') - t.ok(normalized.ignore, 'should ignore ' + io.input) - } else { - t.equal( - normalized.value, - io.expected, - 'should normalize ' + io.input + ' to ' + io.expected - ) - t.notOk(normalized.ignore, 'should not ignore ' + io.input) - } - }) - }) - }) - }) -}) diff --git a/test/integration/metric/normalization.test.js b/test/integration/metric/normalization.test.js new file mode 100644 index 0000000000..bdfda465ca --- /dev/null +++ b/test/integration/metric/normalization.test.js @@ -0,0 +1,41 @@ +/* + * Copyright 2020 New Relic Corporation. All rights reserved. + * SPDX-License-Identifier: Apache-2.0 + */ + +'use strict' + +const test = require('node:test') +const tspl = require('@matteo.collina/tspl') + +const ruleTests = require('../../lib/cross_agent_tests/rules') +const Config = require('../../../lib/config') +const Normalizer = require('../../../lib/metrics/normalizer') + +test('cross agent tests', async (t) => { + for (const ruleTest of ruleTests) { + await t.test(ruleTest.testname, async (t) => { + const plan = tspl(t, { plan: ruleTest.tests.length * 2 }) + const config = new Config({}) + + const normalizer = new Normalizer(config, 'Url') + normalizer.load(ruleTest.rules) + + ruleTest.tests.forEach(function (io) { + const normalized = normalizer.normalize(io.input) + + if (io.expected === null) { + plan.ok('ignored, not checking name') + plan.ok(normalized.ignore, 'should ignore ' + io.input) + } else { + plan.equal( + normalized.value, + io.expected, + 'should normalize ' + io.input + ' to ' + io.expected + ) + plan.equal(normalized.ignore, false, 'should not ignore ' + io.input) + } + }) + }) + } +})