diff --git a/test/lib/temp-remove-listeners.js b/test/lib/temp-remove-listeners.js index 58e7010d9..add84af82 100644 --- a/test/lib/temp-remove-listeners.js +++ b/test/lib/temp-remove-listeners.js @@ -20,7 +20,6 @@ module.exports = function tempRemoveListeners({ t, emitter, event }) { return } - t.diagnostic(`Removing listeners for ${event}`) const listeners = emitter.listeners(event) emitter.removeAllListeners(event) @@ -28,7 +27,6 @@ module.exports = function tempRemoveListeners({ t, emitter, event }) { // be one `t.after` handler per test, and putting in here obscures the fact // that it has been added. t.after(() => { - t.diagnostic(`Re-adding listeners for ${event}`) for (const l of listeners) { emitter.on(event, l) } diff --git a/test/unit/load-externals.test.js b/test/unit/load-externals.test.js index bec9c45a8..27a379ef4 100644 --- a/test/unit/load-externals.test.js +++ b/test/unit/load-externals.test.js @@ -5,23 +5,28 @@ 'use strict' -const tap = require('tap') +const test = require('node:test') +const assert = require('node:assert') + const loadExternals = require('../../load-externals') -tap.test('should load libs to webpack externals', async (t) => { +test('should load libs to webpack externals', async () => { const config = { target: 'node-20.x', externals: ['next'] } loadExternals(config) - t.ok(config.externals.length > 1, 'should add all libraries agent supports to the externals list') + assert.ok( + config.externals.length > 1, + 'should add all libraries agent supports to the externals list' + ) }) -tap.test('should not add externals when target is not node', async (t) => { +test('should not add externals when target is not node', async () => { const config = { target: 'web', externals: ['next'] } loadExternals(config) - t.ok(config.externals.length === 1, 'should not agent libraries when target is not node') + assert.ok(config.externals.length === 1, 'should not agent libraries when target is not node') }) diff --git a/test/unit/logger.test.js b/test/unit/logger.test.js index 4216539e8..9fbcb337f 100644 --- a/test/unit/logger.test.js +++ b/test/unit/logger.test.js @@ -5,154 +5,155 @@ 'use strict' -const tap = require('tap') -const cp = require('child_process') +const test = require('node:test') +const assert = require('node:assert') +const path = require('node:path') +const cp = require('node:child_process') + +const tempRemoveListeners = require('../lib/temp-remove-listeners') + const Logger = require('../../lib/util/logger') -const path = require('path') - -tap.test('Logger', function (t) { - t.autoend() - let logger = null - - t.beforeEach(function () { - logger = new Logger({ - name: 'newrelic', - level: 'trace', - enabled: true, - configured: true - }) - }) - t.afterEach(function () { - logger = null +test.beforeEach((ctx) => { + ctx.nr = {} + ctx.nr.logger = new Logger({ + name: 'newrelic', + level: 'trace', + enabled: true, + configured: true }) +}) - t.test('should not throw when passed-in log level is 0', function (t) { - t.doesNotThrow(function () { - logger.level(0) - }) - t.end() +test('should not throw when passed-in log level is 0', (t) => { + const { logger } = t.nr + assert.doesNotThrow(() => { + logger.level(0) }) +}) - t.test('should not throw when passed-in log level is ONE MILLION', function (t) { - t.doesNotThrow(function () { - logger.level(1000000) - }) - t.end() +test('should not throw when passed-in log level is ONE MILLION', (t) => { + const { logger } = t.nr + assert.doesNotThrow(function () { + logger.level(1000000) }) +}) - t.test('should not throw when passed-in log level is "verbose"', function (t) { - t.doesNotThrow(function () { - logger.level('verbose') - }) - t.end() +test('should not throw when passed-in log level is "verbose"', (t) => { + const { logger } = t.nr + assert.doesNotThrow(function () { + logger.level('verbose') }) +}) - t.test('should enqueue logs until configured', function (t) { - logger.options.configured = false - logger.trace('trace') - logger.debug('debug') - logger.info('info') - logger.warn('warn') - logger.error('error') - logger.fatal('fatal') - t.ok(logger.logQueue.length === 6, 'should have 6 logs in the queue') - t.end() - }) +test('should enqueue logs until configured', (t) => { + const { logger } = t.nr + logger.options.configured = false + logger.trace('trace') + logger.debug('debug') + logger.info('info') + logger.warn('warn') + logger.error('error') + logger.fatal('fatal') + assert.ok(logger.logQueue.length === 6, 'should have 6 logs in the queue') +}) - t.test('should not enqueue logs when disabled', function (t) { - logger.trace('trace') - logger.debug('debug') - logger.info('info') - logger.warn('warn') - logger.error('error') - logger.fatal('fatal') - t.ok(logger.logQueue.length === 0, 'should have 0 logs in the queue') - t.end() - }) +test('should not enqueue logs when disabled', (t) => { + const { logger } = t.nr + logger.trace('trace') + logger.debug('debug') + logger.info('info') + logger.warn('warn') + logger.error('error') + logger.fatal('fatal') + assert.ok(logger.logQueue.length === 0, 'should have 0 logs in the queue') +}) - t.test('should flush logs when configured', function (t) { - logger.options.configured = false - logger.trace('trace') - logger.debug('debug') - logger.info('info') - logger.warn('warn') - logger.error('error') - logger.fatal('fatal') - - t.ok(logger.logQueue.length === 6, 'should have 6 logs in the queue') - - logger.configure({ - level: 'trace', - enabled: true, - name: 'test-logger' - }) +test('should flush logs when configured', (t) => { + const { logger } = t.nr + logger.options.configured = false + logger.trace('trace') + logger.debug('debug') + logger.info('info') + logger.warn('warn') + logger.error('error') + logger.fatal('fatal') - t.ok(logger.logQueue.length === 0, 'should have 0 logs in the queue') - t.end() + assert.ok(logger.logQueue.length === 6, 'should have 6 logs in the queue') + + logger.configure({ + level: 'trace', + enabled: true, + name: 'test-logger' }) - t.test('should fallback to default logging config when config is invalid', function (t) { - runTestFile('disabled-with-invalid-config/disabled.js', function (error, message) { - t.notOk(error) + assert.ok(logger.logQueue.length === 0, 'should have 0 logs in the queue') +}) + +test('should fallback to default logging config when config is invalid', (t, end) => { + runTestFile('disabled-with-invalid-config/disabled.js', function (error, message) { + assert.equal(error, undefined) - // should pipe logs to stdout if config is invalid, even if logging is disabled - t.ok(message) - t.end() - }) + // should pipe logs to stdout if config is invalid, even if logging is disabled + assert.ok(message) + end() }) +}) - t.test('should not cause crash if unwritable', function (t) { - runTestFile('unwritable-log/unwritable.js', t.end) - }) +test('should not cause crash if unwritable', (t, end) => { + runTestFile('unwritable-log/unwritable.js', end) +}) - t.test('should not be created if logger is disabled', function (t) { - runTestFile('disabled-log/disabled.js', t.end) - }) +test('should not be created if logger is disabled', (t, end) => { + runTestFile('disabled-log/disabled.js', end) +}) - t.test('should not log bootstrapping logs when logs disabled', function (t) { - runTestFile('disabled-with-log-queue/disabled.js', function (error, message) { - t.notOk(error) - t.notOk(message) - t.end() - }) +test('should not log bootstrapping logs when logs disabled', (t, end) => { + runTestFile('disabled-with-log-queue/disabled.js', function (error, message) { + assert.equal(error, undefined) + assert.equal(message, undefined) + end() }) +}) - t.test('should log bootstrapping logs at specified level when logs enabled', function (t) { - runTestFile('enabled-with-log-queue/enabled.js', function (error, message) { - t.notOk(error) - t.ok(message) +test('should log bootstrapping logs at specified level when logs enabled', (t, end) => { + runTestFile('enabled-with-log-queue/enabled.js', function (error, message) { + assert.equal(error, undefined) + assert.ok(message) - let logs = [] - t.doesNotThrow(function () { - logs = message.split('\n').filter(Boolean).map(JSON.parse) - }) + let logs = [] + assert.doesNotThrow(function () { + logs = message.split('\n').filter(Boolean).map(JSON.parse) + }) - t.ok(logs.length >= 1) - t.ok(logs.every((log) => log.level >= 30)) + assert.ok(logs.length >= 1) + assert.ok(logs.every((log) => log.level >= 30)) - t.end() - }) + end() }) +}) - t.test('should not throw for huge messages', function (t) { - process.once('warning', (warning) => { - t.equal(warning.name, 'NewRelicWarning') - t.ok(warning.message) - t.end() - }) +test('should not throw for huge messages', (t, end) => { + const { logger } = t.nr - let huge = 'a' - while (huge.length < Logger.MAX_LOG_BUFFER / 2) { - huge += huge - } - - t.doesNotThrow(() => { - logger.fatal('some message to start the buffer off') - logger.fatal(huge) - logger.fatal(huge) - }) + tempRemoveListeners({ t, emitter: process, event: 'warning' }) + process.once('warning', (warning) => { + assert.equal(warning.name, 'NewRelicWarning') + assert.ok(warning.message) + end() }) + + let huge = 'a' + while (huge.length < Logger.MAX_LOG_BUFFER / 2) { + huge += huge + } + + try { + logger.fatal('some message to start the buffer off') + logger.fatal(huge) + logger.fatal(huge) + } catch (error) { + assert.ifError(error) + } }) /** diff --git a/test/unit/metrics-mapper.test.js b/test/unit/metrics-mapper.test.js index 52f86dc38..7f1b81c12 100644 --- a/test/unit/metrics-mapper.test.js +++ b/test/unit/metrics-mapper.test.js @@ -4,92 +4,102 @@ */ 'use strict' -const tap = require('tap') + +const test = require('node:test') +const assert = require('node:assert') + +const { match } = require('../lib/custom-assertions') + const MetricMapper = require('../../lib/metrics/mapper.js') -tap.test('MetricMapper', function (t) { - t.test("shouldn't throw if passed null", function (t) { - t.doesNotThrow(function () { - new MetricMapper().load(null) - }) - t.end() +test("shouldn't throw if passed null", () => { + try { + new MetricMapper().load(null) + } catch (error) { + assert.ifError(error) + } +}) + +test("shouldn't throw if passed undefined", () => { + try { + new MetricMapper().load(undefined) + } catch (error) { + assert.ifError(error) + } +}) + +test("shouldn't throw if passed an empty list", () => { + try { + new MetricMapper().load([]) + } catch (error) { + assert.ifError(error) + } +}) + +test("shouldn't throw if passed garbage input", () => { + try { + new MetricMapper().load({ name: 'garbage' }, 1001) + } catch (error) { + assert.ifError(error) + } +}) + +test('when loading mappings at creation', async (t) => { + t.beforeEach((ctx) => { + ctx.nr = {} + ctx.nr.mapper = new MetricMapper([ + [{ name: 'Test/RenameMe1' }, 1001], + [{ name: 'Test/RenameMe2', scope: 'TEST' }, 1002] + ]) + }) + + await t.test('should have loaded all the mappings', (t) => { + const { mapper } = t.nr + assert.equal(mapper.length, 2) + }) + + await t.test('should apply mappings', (t) => { + const { mapper } = t.nr + assert.equal(mapper.map('Test/RenameMe1'), 1001) + assert.equal(mapper.map('Test/RenameMe2', 'TEST'), 1002) }) - t.test("shouldn't throw if passed undefined", function (t) { - t.doesNotThrow(function () { - new MetricMapper().load(undefined) - }) - t.end() + await t.test('should turn non-mapped metrics into specs', (t) => { + const { mapper } = t.nr + assert.equal(match(mapper.map('Test/Metric1'), { name: 'Test/Metric1' }), true) + assert.equal( + match(mapper.map('Test/Metric2', 'TEST'), { name: 'Test/Metric2', scope: 'TEST' }), + true + ) }) +}) - t.test("shouldn't throw if passed an empty list", function (t) { - t.doesNotThrow(function () { - new MetricMapper().load([]) - }) - t.end() +test('when adding mappings after creation', async (t) => { + t.beforeEach((ctx) => { + ctx.nr = { + mapper: new MetricMapper() + } + ctx.nr.mapper.load([[{ name: 'Test/RenameMe1' }, 1001]]) + ctx.nr.mapper.load([[{ name: 'Test/RenameMe2', scope: 'TEST' }, 1002]]) }) - t.test("shouldn't throw if passed garbage input", function (t) { - t.doesNotThrow(function () { - new MetricMapper().load({ name: 'garbage' }, 1001) - }) - t.end() + await t.test('should have loaded all the mappings', (t) => { + const { mapper } = t.nr + assert.equal(mapper.length, 2) }) - t.test('when loading mappings at creation', function (t) { - let mapper - - t.before(function () { - mapper = new MetricMapper([ - [{ name: 'Test/RenameMe1' }, 1001], - [{ name: 'Test/RenameMe2', scope: 'TEST' }, 1002] - ]) - }) - - t.test('should have loaded all the mappings', function (t) { - t.equal(mapper.length, 2) - t.end() - }) - - t.test('should apply mappings', function (t) { - t.equal(mapper.map('Test/RenameMe1'), 1001) - t.equal(mapper.map('Test/RenameMe2', 'TEST'), 1002) - t.end() - }) - - t.test('should turn non-mapped metrics into specs', function (t) { - t.same(mapper.map('Test/Metric1'), { name: 'Test/Metric1' }) - t.same(mapper.map('Test/Metric2', 'TEST'), { name: 'Test/Metric2', scope: 'TEST' }) - t.end() - }) - t.end() + await t.test('should apply mappings', (t) => { + const { mapper } = t.nr + assert.equal(mapper.map('Test/RenameMe1'), 1001) + assert.equal(mapper.map('Test/RenameMe2', 'TEST'), 1002) }) - t.test('when adding mappings after creation', function (t) { - const mapper = new MetricMapper() - - t.before(function () { - mapper.load([[{ name: 'Test/RenameMe1' }, 1001]]) - mapper.load([[{ name: 'Test/RenameMe2', scope: 'TEST' }, 1002]]) - }) - - t.test('should have loaded all the mappings', function (t) { - t.equal(mapper.length, 2) - t.end() - }) - - t.test('should apply mappings', function (t) { - t.equal(mapper.map('Test/RenameMe1'), 1001) - t.equal(mapper.map('Test/RenameMe2', 'TEST'), 1002) - t.end() - }) - - t.test('should turn non-mapped metrics into specs', function (t) { - t.same(mapper.map('Test/Metric1'), { name: 'Test/Metric1' }) - t.same(mapper.map('Test/Metric2', 'TEST'), { name: 'Test/Metric2', scope: 'TEST' }) - t.end() - }) - t.end() + await t.test('should turn non-mapped metrics into specs', (t) => { + const { mapper } = t.nr + assert.equal(match(mapper.map('Test/Metric1'), { name: 'Test/Metric1' }), true) + assert.equal( + match(mapper.map('Test/Metric2', 'TEST'), { name: 'Test/Metric2', scope: 'TEST' }), + true + ) }) - t.end() }) diff --git a/test/unit/name-state.test.js b/test/unit/name-state.test.js index e0837d1bd..896a7f8a0 100644 --- a/test/unit/name-state.test.js +++ b/test/unit/name-state.test.js @@ -4,97 +4,89 @@ */ 'use strict' -const tap = require('tap') + +const test = require('node:test') +const assert = require('node:assert') + const NameState = require('../../lib/transaction/name-state.js') -tap.test('NameState', function (t) { - t.autoend() - t.test('should handle basic naming', function (t) { - const state = new NameState('Nodejs', 'GET', '/', 'path1') - state.appendPath('path2') - t.equal(state.getName(), 'Nodejs/GET//path1/path2') - t.end() - }) - - t.test('should handle piece-wise naming', function (t) { - const state = new NameState(null, null, null, null) - state.setPrefix('Nodejs') - state.setVerb('GET') - state.setDelimiter('/') - state.appendPath('path1') - state.appendPath('path2') - state.appendPath('path3') - t.equal(state.getName(), 'Nodejs/GET//path1/path2/path3') - t.end() - }) - - t.test('should handle missing components', function (t) { - let state = new NameState('Nodejs', null, null, 'path1') - t.equal(state.getName(), 'Nodejs/path1') - - state = new NameState('Nodejs', null, '/', 'path1') - t.equal(state.getName(), 'Nodejs//path1') - - state = new NameState(null, null, null, 'path1') - t.equal(state.getName(), '/path1') - - state = new NameState('Nodejs', null, null, null) - t.equal(state.getName(), null) - t.end() - }) - - t.test('should delete the name when reset', function (t) { - const state = new NameState('Nodejs', 'GET', '/', 'path1') - t.equal(state.getName(), 'Nodejs/GET//path1') - - state.reset() - t.equal(state.getName(), null) - t.end() - }) - - t.test('should handle regex paths', function (t) { - const state = new NameState('Nodejs', 'GET', '/', []) - state.appendPath(new RegExp('regex1')) - state.appendPath('path1') - state.appendPath(/regex2/) - state.appendPath('path2') - - t.equal(state.getPath(), '/regex1/path1/regex2/path2') - t.equal(state.getName(), 'Nodejs/GET//regex1/path1/regex2/path2') - t.end() - }) - - t.test('should pick the current stack name over marked paths', function (t) { - const state = new NameState('Nodejs', 'GET', '/') - state.appendPath('path1') - state.markPath() - state.appendPath('path2') - - t.equal(state.getPath(), '/path1/path2') - t.equal(state.getName(), 'Nodejs/GET//path1/path2') - t.end() - }) - - t.test('should pick marked paths if the path stack is empty', function (t) { - const state = new NameState('Nodejs', 'GET', '/') - state.appendPath('path1') - state.markPath() - state.popPath() - - t.equal(state.getPath(), '/path1') - t.equal(state.getName(), 'Nodejs/GET//path1') - t.end() - }) - - t.test('should not report as empty if a path has been marked', function (t) { - const state = new NameState('Nodejs', 'GET', '/') - t.equal(state.isEmpty(), true) - - state.appendPath('path1') - state.markPath() - state.popPath() - - t.equal(state.isEmpty(), false) - t.end() - }) +test('should handle basic naming', () => { + const state = new NameState('Nodejs', 'GET', '/', 'path1') + state.appendPath('path2') + assert.equal(state.getName(), 'Nodejs/GET//path1/path2') +}) + +test('should handle piece-wise naming', () => { + const state = new NameState(null, null, null, null) + state.setPrefix('Nodejs') + state.setVerb('GET') + state.setDelimiter('/') + state.appendPath('path1') + state.appendPath('path2') + state.appendPath('path3') + assert.equal(state.getName(), 'Nodejs/GET//path1/path2/path3') +}) + +test('should handle missing components', () => { + let state = new NameState('Nodejs', null, null, 'path1') + assert.equal(state.getName(), 'Nodejs/path1') + + state = new NameState('Nodejs', null, '/', 'path1') + assert.equal(state.getName(), 'Nodejs//path1') + + state = new NameState(null, null, null, 'path1') + assert.equal(state.getName(), '/path1') + + state = new NameState('Nodejs', null, null, null) + assert.equal(state.getName(), null) +}) + +test('should delete the name when reset', () => { + const state = new NameState('Nodejs', 'GET', '/', 'path1') + assert.equal(state.getName(), 'Nodejs/GET//path1') + + state.reset() + assert.equal(state.getName(), null) +}) + +test('should handle regex paths', () => { + const state = new NameState('Nodejs', 'GET', '/', []) + state.appendPath(new RegExp('regex1')) + state.appendPath('path1') + state.appendPath(/regex2/) + state.appendPath('path2') + + assert.equal(state.getPath(), '/regex1/path1/regex2/path2') + assert.equal(state.getName(), 'Nodejs/GET//regex1/path1/regex2/path2') +}) + +test('should pick the current stack name over marked paths', () => { + const state = new NameState('Nodejs', 'GET', '/') + state.appendPath('path1') + state.markPath() + state.appendPath('path2') + + assert.equal(state.getPath(), '/path1/path2') + assert.equal(state.getName(), 'Nodejs/GET//path1/path2') +}) + +test('should pick marked paths if the path stack is empty', () => { + const state = new NameState('Nodejs', 'GET', '/') + state.appendPath('path1') + state.markPath() + state.popPath() + + assert.equal(state.getPath(), '/path1') + assert.equal(state.getName(), 'Nodejs/GET//path1') +}) + +test('should not report as empty if a path has been marked', () => { + const state = new NameState('Nodejs', 'GET', '/') + assert.equal(state.isEmpty(), true) + + state.appendPath('path1') + state.markPath() + state.popPath() + + assert.equal(state.isEmpty(), false) }) diff --git a/test/unit/parse-proc-cpuinfo.test.js b/test/unit/parse-proc-cpuinfo.test.js index 71b3f0fef..6826a4975 100644 --- a/test/unit/parse-proc-cpuinfo.test.js +++ b/test/unit/parse-proc-cpuinfo.test.js @@ -5,16 +5,17 @@ 'use strict' -const { test } = require('tap') +const test = require('node:test') +const assert = require('node:assert') + +const { match } = require('../lib/custom-assertions') const parseCpuInfo = require('../../lib/parse-proc-cpuinfo') -/** - * Most functionality is covered in-depth via cross-agent tests in - * test/integration/pricing/proc_cpuinfo.tap.js - */ +// Most functionality is covered in-depth via cross-agent tests in +// test/integration/pricing/proc_cpuinfo.tap.js -test('Should return object with null processor stats when data is null', (t) => { +test('Should return object with null processor stats when data is null', () => { const expectedStats = { logical: null, cores: null, @@ -23,12 +24,10 @@ test('Should return object with null processor stats when data is null', (t) => const result = parseCpuInfo(null) - t.same(result, expectedStats) - - t.end() + assert.equal(match(result, expectedStats), true) }) -test('Should return object with null processor stats when data is undefined', (t) => { +test('Should return object with null processor stats when data is undefined', () => { const expectedStats = { logical: null, cores: null, @@ -37,7 +36,5 @@ test('Should return object with null processor stats when data is undefined', (t const result = parseCpuInfo(undefined) - t.same(result, expectedStats) - - t.end() + assert.equal(match(result, expectedStats), true) }) diff --git a/test/unit/parse-proc-meminfo.test.js b/test/unit/parse-proc-meminfo.test.js index 51eb7aded..8172fc3b0 100644 --- a/test/unit/parse-proc-meminfo.test.js +++ b/test/unit/parse-proc-meminfo.test.js @@ -5,27 +5,22 @@ 'use strict' -const { test } = require('tap') +const test = require('node:test') +const assert = require('node:assert') + +const { match } = require('../lib/custom-assertions') const parseMemInfo = require('../../lib/parse-proc-meminfo') -/** - * Most functionality is covered in-depth via cross-agent tests in - * test/integration/pricing/proc_meminfo.tap.js - */ +// Most functionality is covered in-depth via cross-agent tests in +// test/integration/pricing/proc_meminfo.tap.js -test('Should return `null` when data is null', (t) => { +test('Should return `null` when data is null', () => { const result = parseMemInfo(null) - - t.same(result, null) - - t.end() + assert.equal(match(result, null), true) }) -test('Should return `null` when data is undefined', (t) => { +test('Should return `null` when data is undefined', () => { const result = parseMemInfo(undefined) - - t.same(result, undefined) - - t.end() + assert.equal(match(result, undefined), true) }) diff --git a/test/unit/parsed-statement.test.js b/test/unit/parsed-statement.test.js index 5f6c1e3a7..9a86be8d5 100644 --- a/test/unit/parsed-statement.test.js +++ b/test/unit/parsed-statement.test.js @@ -5,30 +5,27 @@ 'use strict' -const tap = require('tap') +const test = require('node:test') +const assert = require('node:assert') const helper = require('../lib/agent_helper') +const { match } = require('../lib/custom-assertions') + const Transaction = require('../../lib/transaction') const ParsedStatement = require('../../lib/db/parsed-statement') -function checkMetric(t, metrics, name, scope) { - t.match(metrics.getMetric(name, scope), { total: 0.333 }) +function checkMetric(metrics, name, scope) { + assert.equal(match(metrics.getMetric(name, scope), { total: 0.333 }), true) } -tap.test('recording database metrics', (t) => { - t.autoend() - - let agent = null - let metrics = null - - t.test('setup', (t) => { - agent = helper.loadMockedAgent() - t.end() - }) +test('recording database metrics', async (t) => { + await t.test('on scoped transactions with parsed statements - with collection', async (t) => { + await t.test('with collection', async (t) => { + t.beforeEach((ctx) => { + ctx.nr = {} + const agent = helper.loadMockedAgent() + ctx.nr.agent = agent - t.test('on scoped transactions with parsed statements - with collection', (t) => { - t.test('with collection', (t) => { - t.beforeEach(() => { const ps = new ParsedStatement('NoSQL', 'select', 'test_collection') const transaction = new Transaction(agent) const segment = transaction.trace.add('test') @@ -38,59 +35,65 @@ tap.test('recording database metrics', (t) => { ps.recordMetrics(segment, 'TEST') transaction.end() - metrics = transaction.metrics + ctx.nr.metrics = transaction.metrics }) - t.test('should find 1 scoped metric', (t) => { - t.equal(metrics._toScopedData().length, 1) - t.end() + t.afterEach((ctx) => { + helper.unloadAgent(ctx.nr.agent) }) - t.test('should find 6 unscoped metrics', (t) => { - t.equal(metrics._toUnscopedData().length, 6) - t.end() + await t.test('should find 1 scoped metric', (t) => { + const { metrics } = t.nr + assert.equal(metrics._toScopedData().length, 1) }) - t.test('should find a scoped metric on the table and operation', (t) => { - checkMetric(t, metrics, 'Datastore/statement/NoSQL/test_collection/select', 'TEST') - t.end() + await t.test('should find 6 unscoped metrics', (t) => { + const { metrics } = t.nr + assert.equal(metrics._toUnscopedData().length, 6) }) - t.test('should find an unscoped metric on the table and operation', (t) => { - checkMetric(t, metrics, 'Datastore/statement/NoSQL/test_collection/select') - t.end() + await t.test('should find a scoped metric on the table and operation', (t) => { + const { metrics } = t.nr + checkMetric(metrics, 'Datastore/statement/NoSQL/test_collection/select', 'TEST') }) - t.test('should find an unscoped rollup metric on the operation', (t) => { - checkMetric(t, metrics, 'Datastore/operation/NoSQL/select') - t.end() + await t.test('should find an unscoped metric on the table and operation', (t) => { + const { metrics } = t.nr + checkMetric(metrics, 'Datastore/statement/NoSQL/test_collection/select') }) - t.test('should find a database rollup metric', (t) => { - checkMetric(t, metrics, 'Datastore/all') - t.end() + await t.test('should find an unscoped rollup metric on the operation', (t) => { + const { metrics } = t.nr + checkMetric(metrics, 'Datastore/operation/NoSQL/select') }) - t.test('should find a database rollup metric of type `Other`', (t) => { - checkMetric(t, metrics, 'Datastore/allOther') - t.end() + await t.test('should find a database rollup metric', (t) => { + const { metrics } = t.nr + checkMetric(metrics, 'Datastore/all') }) - t.test('should find a database type rollup metric of type `All`', (t) => { - checkMetric(t, metrics, 'Datastore/NoSQL/all') - t.end() + await t.test('should find a database rollup metric of type `Other`', (t) => { + const { metrics } = t.nr + checkMetric(metrics, 'Datastore/allOther') }) - t.test('should find a database type rollup metric of type `Other`', (t) => { - checkMetric(t, metrics, 'Datastore/NoSQL/allOther') - t.end() + await t.test('should find a database type rollup metric of type `All`', (t) => { + const { metrics } = t.nr + checkMetric(metrics, 'Datastore/NoSQL/all') }) - t.end() + await t.test('should find a database type rollup metric of type `Other`', (t) => { + const { metrics } = t.nr + checkMetric(metrics, 'Datastore/NoSQL/allOther') + }) }) - t.test('without collection', (t) => { - t.beforeEach(() => { + await t.test('without collection', async (t) => { + t.beforeEach((ctx) => { + ctx.nr = {} + const agent = helper.loadMockedAgent() + ctx.nr.agent = agent + const ps = new ParsedStatement('NoSQL', 'select') const transaction = new Transaction(agent) const segment = transaction.trace.add('test') @@ -100,64 +103,62 @@ tap.test('recording database metrics', (t) => { ps.recordMetrics(segment, 'TEST') transaction.end() - metrics = transaction.metrics + ctx.nr.metrics = transaction.metrics }) - t.test('should find 1 scoped metric', (t) => { - t.equal(metrics._toScopedData().length, 1) - t.end() + t.afterEach((ctx) => { + helper.unloadAgent(ctx.nr.agent) }) - t.test('should find 5 unscoped metrics', (t) => { - t.equal(metrics._toUnscopedData().length, 5) - t.end() + await t.test('should find 1 scoped metric', (t) => { + const { metrics } = t.nr + assert.equal(metrics._toScopedData().length, 1) }) - t.test('should find a scoped metric on the operation', (t) => { - checkMetric(t, metrics, 'Datastore/operation/NoSQL/select', 'TEST') - t.end() + await t.test('should find 5 unscoped metrics', (t) => { + const { metrics } = t.nr + assert.equal(metrics._toUnscopedData().length, 5) }) - t.test('should find an unscoped metric on the operation', (t) => { - checkMetric(t, metrics, 'Datastore/operation/NoSQL/select') - t.end() + await t.test('should find a scoped metric on the operation', (t) => { + const { metrics } = t.nr + checkMetric(metrics, 'Datastore/operation/NoSQL/select', 'TEST') }) - t.test('should find a database rollup metric', (t) => { - checkMetric(t, metrics, 'Datastore/all') - t.end() + await t.test('should find an unscoped metric on the operation', (t) => { + const { metrics } = t.nr + checkMetric(metrics, 'Datastore/operation/NoSQL/select') }) - t.test('should find a database rollup metric of type `Other`', (t) => { - checkMetric(t, metrics, 'Datastore/allOther') - t.end() + await t.test('should find a database rollup metric', (t) => { + const { metrics } = t.nr + checkMetric(metrics, 'Datastore/all') }) - t.test('should find a database type rollup metric of type `All`', (t) => { - checkMetric(t, metrics, 'Datastore/NoSQL/all') - t.end() + await t.test('should find a database rollup metric of type `Other`', (t) => { + const { metrics } = t.nr + checkMetric(metrics, 'Datastore/allOther') }) - t.test('should find a database type rollup metric of type `Other`', (t) => { - checkMetric(t, metrics, 'Datastore/NoSQL/allOther') - t.end() + await t.test('should find a database type rollup metric of type `All`', (t) => { + const { metrics } = t.nr + checkMetric(metrics, 'Datastore/NoSQL/all') }) - t.end() + await t.test('should find a database type rollup metric of type `Other`', (t) => { + const { metrics } = t.nr + checkMetric(metrics, 'Datastore/NoSQL/allOther') + }) }) - - t.end() }) - t.test('reset', (t) => { - helper.unloadAgent(agent) - agent = helper.loadMockedAgent() - t.end() - }) + await t.test('on unscoped transactions with parsed statements', async (t) => { + await t.test('with collection', async (t) => { + t.beforeEach((ctx) => { + ctx.nr = {} + const agent = helper.loadMockedAgent() + ctx.nr.agent = agent - t.test('on unscoped transactions with parsed statements', (t) => { - t.test('with collection', (t) => { - t.beforeEach(() => { const ps = new ParsedStatement('NoSQL', 'select', 'test_collection') const transaction = new Transaction(agent) const segment = transaction.trace.add('test') @@ -167,54 +168,60 @@ tap.test('recording database metrics', (t) => { ps.recordMetrics(segment, null) transaction.end() - metrics = transaction.metrics + ctx.nr.metrics = transaction.metrics }) - t.test('should find 0 unscoped metrics', (t) => { - t.equal(metrics._toScopedData().length, 0) - t.end() + t.afterEach((ctx) => { + helper.unloadAgent(ctx.nr.agent) }) - t.test('should find 6 unscoped metrics', (t) => { - t.equal(metrics._toUnscopedData().length, 6) - t.end() + await t.test('should find 0 unscoped metrics', (t) => { + const { metrics } = t.nr + assert.equal(metrics._toScopedData().length, 0) }) - t.test('should find an unscoped metric on the table and operation', (t) => { - checkMetric(t, metrics, 'Datastore/statement/NoSQL/test_collection/select') - t.end() + await t.test('should find 6 unscoped metrics', (t) => { + const { metrics } = t.nr + assert.equal(metrics._toUnscopedData().length, 6) }) - t.test('should find an unscoped rollup metric on the operation', (t) => { - checkMetric(t, metrics, 'Datastore/operation/NoSQL/select') - t.end() + await t.test('should find an unscoped metric on the table and operation', (t) => { + const { metrics } = t.nr + checkMetric(metrics, 'Datastore/statement/NoSQL/test_collection/select') }) - t.test('should find an unscoped rollup DB metric', (t) => { - checkMetric(t, metrics, 'Datastore/all') - t.end() + await t.test('should find an unscoped rollup metric on the operation', (t) => { + const { metrics } = t.nr + checkMetric(metrics, 'Datastore/operation/NoSQL/select') }) - t.test('should find an unscoped rollup DB metric of type `Other`', (t) => { - checkMetric(t, metrics, 'Datastore/allOther') - t.end() + await t.test('should find an unscoped rollup DB metric', (t) => { + const { metrics } = t.nr + checkMetric(metrics, 'Datastore/all') }) - t.test('should find a database type rollup metric of type `All`', (t) => { - checkMetric(t, metrics, 'Datastore/NoSQL/all') - t.end() + await test('should find an unscoped rollup DB metric of type `Other`', (t) => { + const { metrics } = t.nr + checkMetric(metrics, 'Datastore/allOther') }) - t.test('should find a database type rollup metric of type `Other`', (t) => { - checkMetric(t, metrics, 'Datastore/NoSQL/allOther') - t.end() + await test('should find a database type rollup metric of type `All`', (t) => { + const { metrics } = t.nr + checkMetric(metrics, 'Datastore/NoSQL/all') }) - t.end() + await test('should find a database type rollup metric of type `Other`', (t) => { + const { metrics } = t.nr + checkMetric(metrics, 'Datastore/NoSQL/allOther') + }) }) - t.test('without collection', (t) => { - t.beforeEach(() => { + await t.test('without collection', async (t) => { + t.beforeEach((ctx) => { + ctx.nr = {} + const agent = helper.loadMockedAgent() + ctx.nr.agent = agent + const ps = new ParsedStatement('NoSQL', 'select') const transaction = new Transaction(agent) const segment = transaction.trace.add('test') @@ -224,77 +231,70 @@ tap.test('recording database metrics', (t) => { ps.recordMetrics(segment, null) transaction.end() - metrics = transaction.metrics + ctx.nr.metrics = transaction.metrics }) - t.test('should find 0 unscoped metrics', (t) => { - t.equal(metrics._toScopedData().length, 0) - t.end() + t.afterEach((ctx) => { + helper.unloadAgent(ctx.nr.agent) }) - t.test('should find 5 unscoped metrics', (t) => { - t.equal(metrics._toUnscopedData().length, 5) - t.end() + await t.test('should find 0 unscoped metrics', (t) => { + const { metrics } = t.nr + assert.equal(metrics._toScopedData().length, 0) }) - t.test('should find an unscoped metric on the operation', (t) => { - checkMetric(t, metrics, 'Datastore/operation/NoSQL/select') - t.end() + await t.test('should find 5 unscoped metrics', (t) => { + const { metrics } = t.nr + assert.equal(metrics._toUnscopedData().length, 5) }) - t.test('should find an unscoped rollup DB metric', (t) => { - checkMetric(t, metrics, 'Datastore/all') - t.end() + await t.test('should find an unscoped metric on the operation', (t) => { + const { metrics } = t.nr + checkMetric(metrics, 'Datastore/operation/NoSQL/select') }) - t.test('should find an unscoped rollup DB metric of type `Other`', (t) => { - checkMetric(t, metrics, 'Datastore/allOther') - t.end() + await t.test('should find an unscoped rollup DB metric', (t) => { + const { metrics } = t.nr + checkMetric(metrics, 'Datastore/all') }) - t.test('should find a database type rollup metric of type `All`', (t) => { - checkMetric(t, metrics, 'Datastore/NoSQL/all') - t.end() + await t.test('should find an unscoped rollup DB metric of type `Other`', (t) => { + const { metrics } = t.nr + checkMetric(metrics, 'Datastore/allOther') }) - t.test('should find a database type rollup metric of type `Other`', (t) => { - checkMetric(t, metrics, 'Datastore/NoSQL/allOther') - t.end() + await t.test('should find a database type rollup metric of type `All`', (t) => { + const { metrics } = t.nr + checkMetric(metrics, 'Datastore/NoSQL/all') }) - t.end() + await t.test('should find a database type rollup metric of type `Other`', (t) => { + const { metrics } = t.nr + checkMetric(metrics, 'Datastore/NoSQL/allOther') + }) }) - - t.end() - }) - - t.test('teardown', (t) => { - helper.unloadAgent(agent) - t.end() }) }) -tap.test('recording slow queries', (t) => { - t.autoend() - - t.test('with collection', (t) => { - let transaction - let segment - let agent - - t.beforeEach(() => { - agent = helper.loadMockedAgent({ +test('recording slow queries', async (t) => { + await t.test('with collection', async (t) => { + t.beforeEach((ctx) => { + ctx.nr = {} + const agent = helper.loadMockedAgent({ slow_sql: { enabled: true }, transaction_tracer: { record_sql: 'obfuscated' } }) + ctx.nr.agent = agent const ps = new ParsedStatement('MySql', 'select', 'foo', 'select * from foo where b=1') - transaction = new Transaction(agent) + const transaction = new Transaction(agent) + ctx.nr.transaction = transaction transaction.type = Transaction.TYPES.BG - segment = transaction.trace.add('test') + const segment = transaction.trace.add('test') + ctx.nr.segment = segment segment.setDurationInMillis(503) ps.recordMetrics(segment, 'TEST') @@ -308,57 +308,54 @@ tap.test('recording slow queries', (t) => { transaction.end() }) - t.afterEach(() => { - helper.unloadAgent(agent) + t.afterEach((ctx) => { + helper.unloadAgent(ctx.nr.agent) }) - t.test('should update segment names', (t) => { - t.equal(segment.name, 'Datastore/statement/MySql/foo/select') - t.end() + await t.test('should update segment names', (t) => { + const { segment } = t.nr + assert.equal(segment.name, 'Datastore/statement/MySql/foo/select') }) - t.test('should capture queries', (t) => { - t.equal(agent.queries.samples.size, 1) + await t.test('should capture queries', (t) => { + const { agent } = t.nr + assert.equal(agent.queries.samples.size, 1) const sample = agent.queries.samples.values().next().value const trace = sample.trace - t.equal(sample.total, 1004) - t.equal(sample.totalExclusive, 1004) - t.equal(sample.min, 501) - t.equal(sample.max, 503) - t.equal(sample.sumOfSquares, 504010) - t.equal(sample.callCount, 2) - t.equal(trace.obfuscated, 'select * from foo where b=?') - t.equal(trace.normalized, 'select*fromfoowhereb=?') - t.equal(trace.id, 75330402683074160) - t.equal(trace.query, 'select * from foo where b=1') - t.equal(trace.metric, 'Datastore/statement/MySql/foo/select') - t.equal(typeof trace.trace, 'string') - - t.end() + assert.equal(sample.total, 1004) + assert.equal(sample.totalExclusive, 1004) + assert.equal(sample.min, 501) + assert.equal(sample.max, 503) + assert.equal(sample.sumOfSquares, 504010) + assert.equal(sample.callCount, 2) + assert.equal(trace.obfuscated, 'select * from foo where b=?') + assert.equal(trace.normalized, 'select*fromfoowhereb=?') + assert.equal(trace.id, 75330402683074160) + assert.equal(trace.query, 'select * from foo where b=1') + assert.equal(trace.metric, 'Datastore/statement/MySql/foo/select') + assert.equal(typeof trace.trace, 'string') }) - - t.end() }) - t.test('without collection', (t) => { - let transaction - let segment - let agent - - t.beforeEach(() => { - agent = helper.loadMockedAgent({ + await t.test('without collection', async (t) => { + t.beforeEach((ctx) => { + ctx.nr = {} + const agent = helper.loadMockedAgent({ slow_sql: { enabled: true }, transaction_tracer: { record_sql: 'obfuscated' } }) + ctx.nr.agent = agent const ps = new ParsedStatement('MySql', 'select', null, 'select * from foo where b=1') - transaction = new Transaction(agent) - segment = transaction.trace.add('test') + const transaction = new Transaction(agent) + const segment = transaction.trace.add('test') + ctx.nr.transaction = transaction + ctx.nr.segment = segment segment.setDurationInMillis(503) ps.recordMetrics(segment, 'TEST') @@ -372,67 +369,62 @@ tap.test('recording slow queries', (t) => { transaction.end() }) - t.afterEach(() => { - helper.unloadAgent(agent) - agent = null + t.afterEach((ctx) => { + helper.unloadAgent(ctx.nr.agent) }) - t.test('should update segment names', (t) => { - t.equal(segment.name, 'Datastore/operation/MySql/select') - t.end() + await t.test('should update segment names', (t) => { + const { segment } = t.nr + assert.equal(segment.name, 'Datastore/operation/MySql/select') }) - t.test('should have IDs that fit a signed long', (t) => { + await t.test('should have IDs that fit a signed long', (t) => { + const { agent } = t.nr const sample = agent.queries.samples.values().next().value const trace = sample.trace - t.ok(trace.id <= 2 ** 63 - 1) - - t.end() + assert.ok(trace.id <= 2 ** 63 - 1) }) - t.test('should capture queries', (t) => { - t.equal(agent.queries.samples.size, 1) + await t.test('should capture queries', (t) => { + const { agent } = t.nr + assert.equal(agent.queries.samples.size, 1) const sample = agent.queries.samples.values().next().value const trace = sample.trace - t.equal(sample.total, 1004) - t.equal(sample.totalExclusive, 1004) - t.equal(sample.min, 501) - t.equal(sample.max, 503) - t.equal(sample.sumOfSquares, 504010) - t.equal(sample.callCount, 2) - t.equal(trace.obfuscated, 'select * from foo where b=?') - t.equal(trace.normalized, 'select*fromfoowhereb=?') - t.equal(trace.id, 75330402683074160) - t.equal(trace.query, 'select * from foo where b=1') - t.equal(trace.metric, 'Datastore/operation/MySql/select') - t.equal(typeof trace.trace, 'string') - - t.end() + assert.equal(sample.total, 1004) + assert.equal(sample.totalExclusive, 1004) + assert.equal(sample.min, 501) + assert.equal(sample.max, 503) + assert.equal(sample.sumOfSquares, 504010) + assert.equal(sample.callCount, 2) + assert.equal(trace.obfuscated, 'select * from foo where b=?') + assert.equal(trace.normalized, 'select*fromfoowhereb=?') + assert.equal(trace.id, 75330402683074160) + assert.equal(trace.query, 'select * from foo where b=1') + assert.equal(trace.metric, 'Datastore/operation/MySql/select') + assert.equal(typeof trace.trace, 'string') }) - - t.end() }) - t.test('without query', (t) => { - let transaction - let segment - let agent - - t.beforeEach(() => { - agent = helper.loadMockedAgent({ + await t.test('without query', async (t) => { + t.beforeEach((ctx) => { + ctx.nr = {} + const agent = helper.loadMockedAgent({ slow_sql: { enabled: true }, transaction_tracer: { record_sql: 'obfuscated' } }) + ctx.nr.agent = agent const ps = new ParsedStatement('MySql', 'select', null, null) - transaction = new Transaction(agent) - segment = transaction.trace.add('test') + const transaction = new Transaction(agent) + const segment = transaction.trace.add('test') + ctx.nr.transaction = transaction + ctx.nr.segment = segment segment.setDurationInMillis(503) ps.recordMetrics(segment, 'TEST') @@ -446,20 +438,18 @@ tap.test('recording slow queries', (t) => { transaction.end() }) - t.afterEach(() => { - helper.unloadAgent(agent) + t.afterEach((ctx) => { + helper.unloadAgent(ctx.nr.agent) }) - t.test('should update segment names', (t) => { - t.equal(segment.name, 'Datastore/operation/MySql/select') - t.end() + await t.test('should update segment names', (t) => { + const { segment } = t.nr + assert.equal(segment.name, 'Datastore/operation/MySql/select') }) - t.test('should not capture queries', (t) => { - t.match(agent.queries.samples.size, 0) - t.end() + await t.test('should not capture queries', (t) => { + const { agent } = t.nr + assert.equal(match(agent.queries.samples.size, 0), true) }) - - t.end() }) }) diff --git a/test/unit/prioritized-attributes.test.js b/test/unit/prioritized-attributes.test.js index b0058052a..30ffa1f86 100644 --- a/test/unit/prioritized-attributes.test.js +++ b/test/unit/prioritized-attributes.test.js @@ -1,43 +1,40 @@ /* - * Copyright 2020 New Relic Corporation. All rights reserved. + * Copyright 2024 New Relic Corporation. All rights reserved. * SPDX-License-Identifier: Apache-2.0 */ 'use strict' -const tap = require('tap') +const test = require('node:test') +const assert = require('node:assert') const helper = require('../lib/agent_helper') + const { PrioritizedAttributes, ATTRIBUTE_PRIORITY } = require('../../lib/prioritized-attributes') const AttributeFilter = require('../../lib/config/attribute-filter') const DESTINATIONS = AttributeFilter.DESTINATIONS const TRANSACTION_SCOPE = 'transaction' -tap.test('#addAttribute', (t) => { - t.autoend() - - let agent = null - - t.beforeEach(() => { - agent = helper.loadMockedAgent() +test('#addAttribute', async (t) => { + t.beforeEach((ctx) => { + ctx.nr = {} + ctx.nr.agent = helper.loadMockedAgent() }) - t.afterEach(() => { - helper.unloadAgent(agent) + t.afterEach((ctx) => { + helper.unloadAgent(ctx.nr.agent) }) - t.test('adds an attribute to instance', (t) => { + await t.test('adds an attribute to instance', () => { const inst = new PrioritizedAttributes(TRANSACTION_SCOPE) inst.addAttribute(DESTINATIONS.TRANS_SCOPE, 'test', 'success') const attributes = inst.get(DESTINATIONS.TRANS_SCOPE) - t.equal(attributes.test, 'success') - - t.end() + assert.equal(attributes.test, 'success') }) - t.test('does not add attribute if key length limit is exceeded', (t) => { + await t.test('does not add attribute if key length limit is exceeded', () => { const tooLong = [ 'Lorem ipsum dolor sit amet, consectetur adipiscing elit.', 'Cras id lacinia erat. Suspendisse mi nisl, sodales vel est eu,', @@ -48,26 +45,12 @@ tap.test('#addAttribute', (t) => { const inst = new PrioritizedAttributes(TRANSACTION_SCOPE) inst.addAttribute(DESTINATIONS.TRANS_SCOPE, tooLong, 'will fail') - t.notOk(inst.has(tooLong)) - - t.end() + assert.equal(inst.has(tooLong), undefined) }) }) -tap.test('#addAttribute - high priority', (t) => { - t.autoend() - - let agent = null - - t.beforeEach(() => { - agent = helper.loadMockedAgent() - }) - - t.afterEach(() => { - helper.unloadAgent(agent) - }) - - t.test('should overwrite existing high priority attribute', (t) => { +test('#addAttribute - high priority', async (t) => { + await t.test('should overwrite existing high priority attribute', () => { const inst = new PrioritizedAttributes(TRANSACTION_SCOPE, 2) inst.addAttribute(0x01, 'Roboto', 1, false, ATTRIBUTE_PRIORITY.HIGH) @@ -75,13 +58,11 @@ tap.test('#addAttribute - high priority', (t) => { const res = inst.get(0x01) - t.equal(Object.keys(res).length, 1) - t.equal(res.Roboto, 99) - - t.end() + assert.equal(Object.keys(res).length, 1) + assert.equal(res.Roboto, 99) }) - t.test('should overwrite existing low priority attribute', (t) => { + await t.test('should overwrite existing low priority attribute', () => { const inst = new PrioritizedAttributes(TRANSACTION_SCOPE, 2) inst.addAttribute(0x01, 'Roboto', 1, false, ATTRIBUTE_PRIORITY.LOW) @@ -89,13 +70,11 @@ tap.test('#addAttribute - high priority', (t) => { const res = inst.get(0x01) - t.equal(Object.keys(res).length, 1) - t.equal(res.Roboto, 99) - - t.end() + assert.equal(Object.keys(res).length, 1) + assert.equal(res.Roboto, 99) }) - t.test('should overwrite existing attribute even when at maximum', (t) => { + await t.test('should overwrite existing attribute even when at maximum', () => { const maxAttributeCount = 1 const inst = new PrioritizedAttributes(TRANSACTION_SCOPE, maxAttributeCount) inst.addAttribute(0x01, 'Roboto', 1, false, ATTRIBUTE_PRIORITY.LOW) @@ -104,81 +83,82 @@ tap.test('#addAttribute - high priority', (t) => { const res = inst.get(0x01) - t.equal(Object.keys(res).length, 1) - t.equal(res.Roboto, 99) - - t.end() + assert.equal(Object.keys(res).length, 1) + assert.equal(res.Roboto, 99) }) - t.test('should not add new attribute past maximum when no lower priority attributes', (t) => { - const maxAttributeCount = 1 - const inst = new PrioritizedAttributes(TRANSACTION_SCOPE, maxAttributeCount) - inst.addAttribute(0x01, 'old', 1, false, ATTRIBUTE_PRIORITY.HIGH) - - inst.addAttribute(0x01, 'new', 99, false, ATTRIBUTE_PRIORITY.HIGH) - - const res = inst.get(0x01) - const hasAttribute = Object.hasOwnProperty.bind(res) + await t.test( + 'should not add new attribute past maximum when no lower priority attributes', + () => { + const maxAttributeCount = 1 + const inst = new PrioritizedAttributes(TRANSACTION_SCOPE, maxAttributeCount) + inst.addAttribute(0x01, 'old', 1, false, ATTRIBUTE_PRIORITY.HIGH) - t.equal(Object.keys(res).length, maxAttributeCount) - t.equal(res.old, 1) - t.notOk(hasAttribute('new')) + inst.addAttribute(0x01, 'new', 99, false, ATTRIBUTE_PRIORITY.HIGH) - t.end() - }) + const res = inst.get(0x01) + const hasAttribute = Object.hasOwnProperty.bind(res) - t.test('should add new attribute, drop newest low priority attribute, when at maximum', (t) => { - const maxAttributeCount = 4 - const inst = new PrioritizedAttributes(TRANSACTION_SCOPE, maxAttributeCount) - inst.addAttribute(0x01, 'old-low', 1, false, ATTRIBUTE_PRIORITY.LOW) - inst.addAttribute(0x01, 'old-high', 1, false, ATTRIBUTE_PRIORITY.HIGH) - inst.addAttribute(0x01, 'new-low', 99, false, ATTRIBUTE_PRIORITY.LOW) - inst.addAttribute(0x01, 'newish-high', 50, false, ATTRIBUTE_PRIORITY.HIGH) + assert.equal(Object.keys(res).length, maxAttributeCount) + assert.equal(res.old, 1) + assert.equal(hasAttribute('new'), false) + } + ) - inst.addAttribute(0x01, 'new-high', 99, false, ATTRIBUTE_PRIORITY.HIGH) + await t.test( + 'should add new attribute, drop newest low priority attribute, when at maximum', + () => { + const maxAttributeCount = 4 + const inst = new PrioritizedAttributes(TRANSACTION_SCOPE, maxAttributeCount) + inst.addAttribute(0x01, 'old-low', 1, false, ATTRIBUTE_PRIORITY.LOW) + inst.addAttribute(0x01, 'old-high', 1, false, ATTRIBUTE_PRIORITY.HIGH) + inst.addAttribute(0x01, 'new-low', 99, false, ATTRIBUTE_PRIORITY.LOW) + inst.addAttribute(0x01, 'newish-high', 50, false, ATTRIBUTE_PRIORITY.HIGH) - const res = inst.get(0x01) - const hasAttribute = Object.hasOwnProperty.bind(res) + inst.addAttribute(0x01, 'new-high', 99, false, ATTRIBUTE_PRIORITY.HIGH) - t.equal(Object.keys(res).length, maxAttributeCount) - t.equal(res['old-low'], 1) - t.equal(res['old-high'], 1) - t.equal(res['newish-high'], 50) - t.equal(res['new-high'], 99) - t.notOk(hasAttribute('new-low')) + const res = inst.get(0x01) + const hasAttribute = Object.hasOwnProperty.bind(res) - t.end() - }) + assert.equal(Object.keys(res).length, maxAttributeCount) + assert.equal(res['old-low'], 1) + assert.equal(res['old-high'], 1) + assert.equal(res['newish-high'], 50) + assert.equal(res['new-high'], 99) + assert.equal(hasAttribute('new-low'), false) + } + ) - t.test('should stop adding attributes after all low priority dropped, when at maximum', (t) => { - const maxAttributeCount = 3 - const inst = new PrioritizedAttributes(TRANSACTION_SCOPE, maxAttributeCount) - inst.addAttribute(0x01, 'old-low', 1, false, ATTRIBUTE_PRIORITY.LOW) - inst.addAttribute(0x01, 'oldest-high', 1, false, ATTRIBUTE_PRIORITY.HIGH) - inst.addAttribute(0x01, 'new-low', 99, false, ATTRIBUTE_PRIORITY.LOW) - inst.addAttribute(0x01, 'older-high', 50, false, ATTRIBUTE_PRIORITY.HIGH) - inst.addAttribute(0x01, 'newish-high', 99, false, ATTRIBUTE_PRIORITY.HIGH) + await t.test( + 'should stop adding attributes after all low priority dropped, when at maximum', + () => { + const maxAttributeCount = 3 + const inst = new PrioritizedAttributes(TRANSACTION_SCOPE, maxAttributeCount) + inst.addAttribute(0x01, 'old-low', 1, false, ATTRIBUTE_PRIORITY.LOW) + inst.addAttribute(0x01, 'oldest-high', 1, false, ATTRIBUTE_PRIORITY.HIGH) + inst.addAttribute(0x01, 'new-low', 99, false, ATTRIBUTE_PRIORITY.LOW) + inst.addAttribute(0x01, 'older-high', 50, false, ATTRIBUTE_PRIORITY.HIGH) + inst.addAttribute(0x01, 'newish-high', 99, false, ATTRIBUTE_PRIORITY.HIGH) - inst.addAttribute(0x01, 'failed-new-high', 999, false, ATTRIBUTE_PRIORITY.HIGH) + inst.addAttribute(0x01, 'failed-new-high', 999, false, ATTRIBUTE_PRIORITY.HIGH) - const res = inst.get(0x01) - const hasAttribute = Object.hasOwnProperty.bind(res) - - t.equal(Object.keys(res).length, maxAttributeCount) - t.equal(res['oldest-high'], 1) - t.equal(res['older-high'], 50) - t.equal(res['newish-high'], 99) + const res = inst.get(0x01) + const hasAttribute = Object.hasOwnProperty.bind(res) - t.notOk(hasAttribute('old-low')) - t.notOk(hasAttribute('new-low')) - t.notOk(hasAttribute('failed-new-high')) + assert.equal(Object.keys(res).length, maxAttributeCount) + assert.equal(res['oldest-high'], 1) + assert.equal(res['older-high'], 50) + assert.equal(res['newish-high'], 99) - t.end() - }) + assert.equal(hasAttribute('old-low'), false) + assert.equal(hasAttribute('new-low'), false) + assert.equal(hasAttribute('failed-new-high'), false) + } + ) - t.test( + await t.test( 'should not drop low priority attribute overwritten by high priority, when at maximum', - (t) => { + () => { const maxAttributeCount = 4 const inst = new PrioritizedAttributes(TRANSACTION_SCOPE, maxAttributeCount) inst.addAttribute(0x01, 'old-low', 1, false, ATTRIBUTE_PRIORITY.LOW) @@ -198,33 +178,19 @@ tap.test('#addAttribute - high priority', (t) => { const res = inst.get(0x01) const hasAttribute = Object.hasOwnProperty.bind(res) - t.equal(Object.keys(res).length, maxAttributeCount) - t.equal(res['old-high'], 1) - t.equal(res['newish-high'], 50) - t.equal(res['new-high'], 99) - - t.equal(res.overwritten, 'high') - t.notOk(hasAttribute('old-low')) + assert.equal(Object.keys(res).length, maxAttributeCount) + assert.equal(res['old-high'], 1) + assert.equal(res['newish-high'], 50) + assert.equal(res['new-high'], 99) - t.end() + assert.equal(res.overwritten, 'high') + assert.equal(hasAttribute('old-low'), false) } ) }) -tap.test('#addAttribute - low priority', (t) => { - t.autoend() - - let agent = null - - t.beforeEach(() => { - agent = helper.loadMockedAgent() - }) - - t.afterEach(() => { - helper.unloadAgent(agent) - }) - - t.test('should overwrite existing low priority attribute', (t) => { +test('#addAttribute - low priority', async (t) => { + await t.test('should overwrite existing low priority attribute', () => { const inst = new PrioritizedAttributes(TRANSACTION_SCOPE, 2) inst.addAttribute(0x01, 'Roboto', 1, false, ATTRIBUTE_PRIORITY.LOW) @@ -232,13 +198,11 @@ tap.test('#addAttribute - low priority', (t) => { const res = inst.get(0x01) - t.equal(Object.keys(res).length, 1) - t.equal(res.Roboto, 99) - - t.end() + assert.equal(Object.keys(res).length, 1) + assert.equal(res.Roboto, 99) }) - t.test('should overwrite existing low priority attribute even when at maximum', (t) => { + await t.test('should overwrite existing low priority attribute even when at maximum', () => { const inst = new PrioritizedAttributes(TRANSACTION_SCOPE, 1) inst.addAttribute(0x01, 'Roboto', 1, false, ATTRIBUTE_PRIORITY.LOW) @@ -246,13 +210,11 @@ tap.test('#addAttribute - low priority', (t) => { const res = inst.get(0x01) - t.equal(Object.keys(res).length, 1) - t.equal(res.Roboto, 99) - - t.end() + assert.equal(Object.keys(res).length, 1) + assert.equal(res.Roboto, 99) }) - t.test('should not overwrite existing high priority attribute', (t) => { + await t.test('should not overwrite existing high priority attribute', () => { const inst = new PrioritizedAttributes(TRANSACTION_SCOPE, 1) inst.addAttribute(0x01, 'Roboto', 1, false, ATTRIBUTE_PRIORITY.HIGH) @@ -260,13 +222,11 @@ tap.test('#addAttribute - low priority', (t) => { const res = inst.get(0x01) - t.equal(Object.keys(res).length, 1) - t.equal(res.Roboto, 1) - - t.end() + assert.equal(Object.keys(res).length, 1) + assert.equal(res.Roboto, 1) }) - t.test('should not add new attribute past maximum', (t) => { + await t.test('should not add new attribute past maximum', () => { const maxAttributeCount = 2 const inst = new PrioritizedAttributes(TRANSACTION_SCOPE, maxAttributeCount) inst.addAttribute(0x01, 'old-high', 1, false, ATTRIBUTE_PRIORITY.HIGH) @@ -277,40 +237,24 @@ tap.test('#addAttribute - low priority', (t) => { const res = inst.get(0x01) const hasAttribute = Object.hasOwnProperty.bind(res) - t.equal(Object.keys(res).length, maxAttributeCount) - t.equal(res['old-high'], 1) - t.equal(res['old-low'], 99) - t.notOk(hasAttribute('failed-new-low')) - - t.end() + assert.equal(Object.keys(res).length, maxAttributeCount) + assert.equal(res['old-high'], 1) + assert.equal(res['old-low'], 99) + assert.equal(hasAttribute('failed-new-low'), false) }) }) -tap.test('#addAttributes', (t) => { - t.autoend() - - let agent = null - - t.beforeEach(() => { - agent = helper.loadMockedAgent() - }) - - t.afterEach(() => { - helper.unloadAgent(agent) - }) - - t.test('adds multiple attributes to instance', (t) => { +test('#addAttributes', async (t) => { + await t.test('adds multiple attributes to instance', () => { const inst = new PrioritizedAttributes(TRANSACTION_SCOPE) inst.addAttributes(DESTINATIONS.TRANS_SCOPE, { one: '1', two: '2' }) const attributes = inst.get(DESTINATIONS.TRANS_SCOPE) - t.equal(attributes.one, '1') - t.equal(attributes.two, '2') - - t.end() + assert.equal(attributes.one, '1') + assert.equal(attributes.two, '2') }) - t.test('only allows non-null-type primitive attribute values', (t) => { + await t.test('only allows non-null-type primitive attribute values', () => { const inst = new PrioritizedAttributes(TRANSACTION_SCOPE, 10) const attributes = { first: 'first', @@ -327,20 +271,18 @@ tap.test('#addAttributes', (t) => { inst.addAttributes(DESTINATIONS.TRANS_SCOPE, attributes) const res = inst.get(DESTINATIONS.TRANS_SCOPE) - t.equal(Object.keys(res).length, 3) + assert.equal(Object.keys(res).length, 3) const hasAttribute = Object.hasOwnProperty.bind(res) - t.notOk(hasAttribute('second')) - t.notOk(hasAttribute('third')) - t.notOk(hasAttribute('sixth')) - t.notOk(hasAttribute('seventh')) - t.notOk(hasAttribute('eighth')) - t.notOk(hasAttribute('ninth')) - - t.end() + assert.equal(hasAttribute('second'), false) + assert.equal(hasAttribute('third'), false) + assert.equal(hasAttribute('sixth'), false) + assert.equal(hasAttribute('seventh'), false) + assert.equal(hasAttribute('eighth'), false) + assert.equal(hasAttribute('ninth'), false) }) - t.test('disallows adding more than maximum allowed attributes', (t) => { + await t.test('disallows adding more than maximum allowed attributes', () => { const inst = new PrioritizedAttributes(TRANSACTION_SCOPE, 3) const attributes = { first: 1, @@ -352,39 +294,23 @@ tap.test('#addAttributes', (t) => { inst.addAttributes(DESTINATIONS.TRANS_SCOPE, attributes) const res = inst.get(DESTINATIONS.TRANS_SCOPE) - t.equal(Object.keys(res).length, 3) - - t.end() + assert.equal(Object.keys(res).length, 3) }) - t.test('Overwrites value of added attribute with same key', (t) => { + await t.test('Overwrites value of added attribute with same key', () => { const inst = new PrioritizedAttributes(TRANSACTION_SCOPE, 2) inst.addAttribute(0x01, 'Roboto', 1) inst.addAttribute(0x01, 'Roboto', 99) const res = inst.get(0x01) - t.equal(Object.keys(res).length, 1) - t.equal(res.Roboto, 99) - - t.end() + assert.equal(Object.keys(res).length, 1) + assert.equal(res.Roboto, 99) }) }) -tap.test('#get', (t) => { - t.autoend() - - let agent = null - - t.beforeEach(() => { - agent = helper.loadMockedAgent() - }) - - t.afterEach(() => { - helper.unloadAgent(agent) - }) - - t.test('gets attributes by destination, truncating values if necessary', (t) => { +test('#get', async (t) => { + await t.test('gets attributes by destination, truncating values if necessary', () => { const longVal = [ 'Lorem ipsum dolor sit amet, consectetur adipiscing elit.', 'Cras id lacinia erat. Suspendisse mi nisl, sodales vel est eu,', @@ -398,17 +324,15 @@ tap.test('#get', (t) => { inst.addAttribute(0x01, 'tooLong', longVal) inst.addAttribute(0x08, 'wrongDest', 'hello') - t.ok(Buffer.byteLength(longVal) > 255) + assert.ok(Buffer.byteLength(longVal) > 255) const res = inst.get(0x01) - t.equal(res.valid, 50) + assert.equal(res.valid, 50) - t.equal(Buffer.byteLength(res.tooLong), 255) - - t.end() + assert.equal(Buffer.byteLength(res.tooLong), 255) }) - t.test('only returns attributes up to specified limit', (t) => { + await t.test('only returns attributes up to specified limit', () => { const inst = new PrioritizedAttributes(TRANSACTION_SCOPE, 2) inst.addAttribute(0x01, 'first', 'first') inst.addAttribute(0x01, 'second', 'second') @@ -417,44 +341,38 @@ tap.test('#get', (t) => { const res = inst.get(0x01) const hasAttribute = Object.hasOwnProperty.bind(res) - t.equal(Object.keys(res).length, 2) - t.notOk(hasAttribute('third')) - - t.end() + assert.equal(Object.keys(res).length, 2) + assert.equal(hasAttribute('third'), false) }) }) -tap.test('#hasValidDestination', (t) => { - t.autoend() - - let agent = null - - t.beforeEach(() => { - agent = helper.loadMockedAgent() +test('#hasValidDestination', async (t) => { + t.beforeEach((ctx) => { + ctx.nr = {} + ctx.nr.agent = helper.loadMockedAgent() }) - t.afterEach(() => { - helper.unloadAgent(agent) + t.afterEach((ctx) => { + helper.unloadAgent(ctx.nr.agent) }) - t.test('should return true if single destination valid', (t) => { + await t.test('should return true if single destination valid', () => { const attributes = new PrioritizedAttributes(TRANSACTION_SCOPE) const hasDestination = attributes.hasValidDestination(DESTINATIONS.TRANS_EVENT, 'testAttr') - t.equal(hasDestination, true) - t.end() + assert.equal(hasDestination, true) }) - t.test('should return true if all destinations valid', (t) => { + await t.test('should return true if all destinations valid', () => { const attributes = new PrioritizedAttributes(TRANSACTION_SCOPE) const destinations = DESTINATIONS.TRANS_EVENT | DESTINATIONS.TRANS_TRACE const hasDestination = attributes.hasValidDestination(destinations, 'testAttr') - t.equal(hasDestination, true) - t.end() + assert.equal(hasDestination, true) }) - t.test('should return true if only one destination valid', (t) => { + await t.test('should return true if only one destination valid', (t) => { + const { agent } = t.nr const attributeName = 'testAttr' agent.config.transaction_events.attributes.exclude = [attributeName] agent.config.emit('transaction_events.attributes.exclude') @@ -463,11 +381,11 @@ tap.test('#hasValidDestination', (t) => { const destinations = DESTINATIONS.TRANS_EVENT | DESTINATIONS.TRANS_TRACE const hasDestination = attributes.hasValidDestination(destinations, attributeName) - t.equal(hasDestination, true) - t.end() + assert.equal(hasDestination, true) }) - t.test('should return false if no valid destinations', (t) => { + await t.test('should return false if no valid destinations', (t) => { + const { agent } = t.nr const attributeName = 'testAttr' agent.config.attributes.exclude = [attributeName] agent.config.emit('attributes.exclude') @@ -476,25 +394,12 @@ tap.test('#hasValidDestination', (t) => { const destinations = DESTINATIONS.TRANS_EVENT | DESTINATIONS.TRANS_TRACE const hasDestination = attributes.hasValidDestination(destinations, attributeName) - t.equal(hasDestination, false) - t.end() + assert.equal(hasDestination, false) }) }) -tap.test('#reset', (t) => { - t.autoend() - - let agent = null - - t.beforeEach(() => { - agent = helper.loadMockedAgent() - }) - - t.afterEach(() => { - helper.unloadAgent(agent) - }) - - t.test('resets instance attributes', (t) => { +test('#reset', async (t) => { + await t.test('resets instance attributes', () => { const inst = new PrioritizedAttributes(TRANSACTION_SCOPE) inst.addAttribute(0x01, 'first', 'first') inst.addAttribute(0x01, 'second', 'second') @@ -502,10 +407,8 @@ tap.test('#reset', (t) => { inst.reset() - t.notOk(inst.has('first')) - t.notOk(inst.has('second')) - t.notOk(inst.has('third')) - - t.end() + assert.equal(inst.has('first'), undefined) + assert.equal(inst.has('second'), undefined) + assert.equal(inst.has('third'), undefined) }) }) diff --git a/test/unit/priority-queue.test.js b/test/unit/priority-queue.test.js index bed8059b9..ed99e679c 100644 --- a/test/unit/priority-queue.test.js +++ b/test/unit/priority-queue.test.js @@ -5,91 +5,88 @@ 'use strict' -const tap = require('tap') -const PriorityQueue = require('../../lib/priority-queue') - -tap.test('PriorityQueue', function (t) { - t.autoend() - let queue = null +const test = require('node:test') +const assert = require('node:assert') - t.test('#add', function (t) { - t.autoend() +const { match } = require('../lib/custom-assertions') - t.test('structures the data as a min heap', function (t) { - queue = new PriorityQueue() +const PriorityQueue = require('../../lib/priority-queue') - queue.add('left grandchild', 10) - queue.add('parent', 1) - queue.add('right child', 5) - queue.add('left child', 8) +test('#add', async (t) => { + await t.test('structures the data as a min heap', () => { + const queue = new PriorityQueue() - t.same(queue.toArray(), ['parent', 'left child', 'right child', 'left grandchild']) - t.end() - }) + queue.add('left grandchild', 10) + queue.add('parent', 1) + queue.add('right child', 5) + queue.add('left child', 8) - t.test('replaces lowest priority item if limit is met', function (t) { - queue = new PriorityQueue(4) + assert.equal( + match(queue.toArray(), ['parent', 'left child', 'right child', 'left grandchild']), + true + ) + }) - queue.add('left grandchild', 10) - queue.add('parent', 1) - queue.add('right child', 5) - queue.add('left child', 8) + await t.test('replaces lowest priority item if limit is met', () => { + const queue = new PriorityQueue(4) - t.same(queue.toArray(), ['parent', 'left child', 'right child', 'left grandchild']) + queue.add('left grandchild', 10) + queue.add('parent', 1) + queue.add('right child', 5) + queue.add('left child', 8) - queue.add('new parent', 2) + assert.equal( + match(queue.toArray(), ['parent', 'left child', 'right child', 'left grandchild']), + true + ) - t.same(queue.toArray(), ['new parent', 'right child', 'left grandchild', 'left child']) - t.end() - }) + queue.add('new parent', 2) - t.test('does not insert events in the case the limit is 0', function (t) { - queue = new PriorityQueue(0) - t.equal(queue.add('test', 1), false) - t.equal(queue.length, 0) - t.end() - }) + assert.equal( + match(queue.toArray(), ['new parent', 'right child', 'left grandchild', 'left child']), + true + ) }) - t.test('#merge', function (t) { - t.autoend() + await t.test('does not insert events in the case the limit is 0', () => { + const queue = new PriorityQueue(0) + assert.equal(queue.add('test', 1), false) + assert.equal(queue.length, 0) + }) +}) - t.test('merges two sources and maintains the limit', function (t) { - const queueLimit = 4 - const queue1 = new PriorityQueue(queueLimit) - const queue2 = new PriorityQueue(queueLimit) +test('#merge', async (t) => { + await t.test('merges two sources and maintains the limit', () => { + const queueLimit = 4 + const queue1 = new PriorityQueue(queueLimit) + const queue2 = new PriorityQueue(queueLimit) - for (let pri = 0; pri < queueLimit; ++pri) { - queue1.add('test', pri) - queue2.add('test', pri) - } + for (let pri = 0; pri < queueLimit; ++pri) { + queue1.add('test', pri) + queue2.add('test', pri) + } - queue1.merge(queue2) - t.equal(queue1.length, queueLimit) - t.end() - }) + queue1.merge(queue2) + assert.equal(queue1.length, queueLimit) }) +}) - t.test('#setLimit', function (t) { - t.autoend() - - t.test('resets the limit property and slices the data if necessary', function (t) { - queue = new PriorityQueue(5) +test('#setLimit', async (t) => { + await t.test('resets the limit property and slices the data if necessary', () => { + const queue = new PriorityQueue(5) - t.equal(queue.limit, 5) - queue.setLimit(10) - t.equal(queue.limit, 10) + assert.equal(queue.limit, 5) + queue.setLimit(10) + assert.equal(queue.limit, 10) - for (let i = 0; i < 6; i++) { - queue.add(i, i) - } + for (let i = 0; i < 6; i++) { + queue.add(i, i) + } - t.equal(queue.length, 6) - t.same(queue.toArray(), [0, 5, 4, 3, 2, 1]) - queue.setLimit(5) - t.same(queue.toArray(), [1, 2, 3, 4, 5]) - t.equal(queue.length, 5) - t.end() - }) + assert.equal(queue.length, 6) + assert.equal(match(queue.toArray(), [0, 5, 4, 3, 2, 1]), true) + queue.setLimit(5) + assert.equal(match(queue.toArray(), [1, 2, 3, 4, 5]), true) + assert.equal(queue.length, 5) }) }) diff --git a/test/unit/protocols.test.js b/test/unit/protocols.test.js index cd094f8dc..20fb73792 100644 --- a/test/unit/protocols.test.js +++ b/test/unit/protocols.test.js @@ -5,42 +5,48 @@ 'use strict' -const tap = require('tap') +const test = require('node:test') +const assert = require('node:assert') +const { match } = require('../lib/custom-assertions') const helper = require('../lib/agent_helper') -const RemoteMethod = require('../../lib/collector/remote-method') -tap.test('errors', (t) => { - let agent +const RemoteMethod = require('../../lib/collector/remote-method') - t.beforeEach(() => { - agent = helper.loadMockedAgent() +test('errors', async (t) => { + t.beforeEach((ctx) => { + ctx.nr = {} + const agent = helper.loadMockedAgent() agent.config.attributes.enabled = true agent.config.run_id = 1 agent.errors.traceAggregator.reconfigure(agent.config) + + ctx.nr.agent = agent }) - t.afterEach(() => { - helper.unloadAgent(agent) + t.afterEach((ctx) => { + helper.unloadAgent(ctx.nr.agent) }) - t.test('should serialize down to match the protocol', (t) => { + await t.test('should serialize down to match the protocol', (t, end) => { + const { agent } = t.nr const error = new Error('test') error.stack = 'test stack' agent.errors.add(null, error) const payload = agent.errors.traceAggregator._toPayloadSync() RemoteMethod.prototype.serialize(payload, (err, errors) => { - t.equal(err, null) - t.same( - errors, - '[1,[[0,"Unknown","test","Error",{"userAttributes":{},"agentAttributes":{},' + - '"intrinsics":{"error.expected":false},"stack_trace":["test stack"]},null]]]' + assert.equal(err, null) + assert.equal( + match( + errors, + '[1,[[0,"Unknown","test","Error",{"userAttributes":{},"agentAttributes":{},' + + '"intrinsics":{"error.expected":false},"stack_trace":["test stack"]},null]]]' + ), + true ) - t.end() + end() }) }) - - t.end() })