Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Updated index, issue-2155, and metric integration tests to node:test #2801

Merged
merged 1 commit into from
Nov 26, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -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')
})
25 changes: 0 additions & 25 deletions test/integration/index/index-no-config.tap.js

This file was deleted.

35 changes: 35 additions & 0 deletions test/integration/index/index-no-config.test.js
Original file line number Diff line number Diff line change
@@ -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)
})
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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',
Expand All @@ -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')
})
45 changes: 0 additions & 45 deletions test/integration/metric/normalization.tap.js

This file was deleted.

41 changes: 41 additions & 0 deletions test/integration/metric/normalization.test.js
Original file line number Diff line number Diff line change
@@ -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)
}
})
})
}
})
Loading