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

test: Removed tap and cleaned up left over tap helpers #2804

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
24 changes: 0 additions & 24 deletions THIRD_PARTY_NOTICES.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ code, the source code can be found at [https://github.com/newrelic/node-newrelic
* [should](#should)
* [sinon](#sinon)
* [superagent](#superagent)
* [tap](#tap)

**[optionalDependencies](#optionalDependencies)**

Expand Down Expand Up @@ -4108,29 +4107,6 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

```

### tap

This product includes source derived from [tap](https://github.com/tapjs/node-tap) ([v16.3.10](https://github.com/tapjs/node-tap/tree/v16.3.10)), distributed under the [ISC License](https://github.com/tapjs/node-tap/blob/v16.3.10/LICENSE):

```
The ISC License

Copyright (c) 2011-2023 Isaac Z. Schlueter and Contributors

Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.

THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.

```


## optionalDependencies

Expand Down
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -257,8 +257,7 @@
"self-cert": "^2.0.0",
"should": "*",
"sinon": "^5.1.1",
"superagent": "^9.0.1",
"tap": "^16.3.4"
"superagent": "^9.0.1"
},
"repository": {
"type": "git",
Expand Down
44 changes: 0 additions & 44 deletions test/lib/agent_helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@ const cp = require('child_process')
let _agent = null
let _agentApi = null
const tasks = []
// Load custom tap assertions
require('./custom-tap-assertions')

const helper = module.exports

Expand Down Expand Up @@ -461,48 +459,6 @@ helper.makeRequest = (url, options, callback) => {
req.end()
}

helper.temporarilyRemoveListeners = (t, emitter, evnt) => {
if (!emitter) {
t.comment('Not removing %s listeners, emitter does not exist', evnt)
return
}

t.comment('Removing listeners for %s', evnt)
let listeners = emitter.listeners(evnt)
t.teardown(() => {
t.comment('Re-adding listeners for %s', evnt)
listeners.forEach((fn) => {
emitter.on(evnt, fn)
})
listeners = []
})
emitter.removeAllListeners(evnt)
}

/**
* Tap will prevent certain uncaughtException behaviors from occuring
* and adds extra properties. This bypasses that.
* While t.expectUncaughtException seems intended for a similar use case,
* it does not seem to work appropriately for some of our use casese.
*/
helper.temporarilyOverrideTapUncaughtBehavior = (tap, t) => {
const originalThrew = tap.threw
// Prevent tap from failing test and remove extra prop
tap.threw = (err) => {
delete err.tapCaught
}

const originalTestThrew = t.threw
t.threw = (err) => {
delete err.tapCaught
}

t.teardown(() => {
t.threw = originalTestThrew
tap.threw = originalThrew
})
}

/**
* Set up an unref'd loop to execute tasks that are added
* via helper.runOutOfContext
Expand Down
85 changes: 0 additions & 85 deletions test/lib/custom-tap-assertions.js

This file was deleted.

183 changes: 0 additions & 183 deletions test/lib/metrics_helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,193 +5,10 @@

'use strict'

const tap = require('tap')
const urltils = require('../../lib/util/urltils')
const { isSimpleObject } = require('../../lib/util/objects')

exports.findSegment = findSegment
exports.getMetricHostName = getMetricHostName
tap.Test.prototype.addAssert('assertMetrics', 4, assertMetrics)
tap.Test.prototype.addAssert('assertSegments', 3, assertSegments)
tap.Test.prototype.addAssert('assertMetricValues', 3, assertMetricValues)

/**
* @param {Metrics} metrics metrics under test
* @param {Array} expected Array of metric data where metric data is in this form:
* [
* {
* “name”:”name of metric”,
* “scope”:”scope of metric”,
* },
* [count,
* total time,
* exclusive time,
* min time,
* max time,
* sum of squares]
* ]
* @param {boolean} exclusive When true, found and expected metric lengths should match
* @param {boolean} assertValues When true, metric values must match expected
*/
function assertMetrics(metrics, expected, exclusive, assertValues) {
// Assertions about arguments because maybe something returned undefined
// unexpectedly and is passed in, or a return type changed. This will
// hopefully help catch that and make it obvious.
this.ok(isSimpleObject(metrics), 'first argument required to be an Metrics object')
this.ok(Array.isArray(expected), 'second argument required to be an array of metrics')
this.ok(typeof exclusive === 'boolean', 'third argument required to be a boolean if provided')

if (assertValues === undefined) {
assertValues = true
}

for (let i = 0, len = expected.length; i < len; i++) {
const expectedMetric = expected[i]
const metric = metrics.getMetric(expectedMetric[0].name, expectedMetric[0].scope)
this.ok(metric, `should find ${expectedMetric[0].name}`)
if (assertValues) {
this.same(metric.toJSON(), expectedMetric[1])
}
}

if (exclusive) {
const metricsList = metrics.toJSON()
this.equal(metricsList.length, expected.length)
}
}

/**
* @param {Transaction} transaction Nodejs agent transaction
* @param {Array} expected Array of metric data where metric data is in this form:
* [
* {
* “name”:”name of metric”,
* “scope”:”scope of metric”,
* },
* [count,
* total time,
* exclusive time,
* min time,
* max time,
* sum of squares]
* ]
* @param {boolean} exact When true, found and expected metric lengths should match
*/
function assertMetricValues(transaction, expected, exact) {
const metrics = transaction.metrics

for (let i = 0; i < expected.length; ++i) {
let expectedMetric = Object.assign({}, expected[i])
let name = null
let scope = null

if (typeof expectedMetric === 'string') {
name = expectedMetric
expectedMetric = {}
} else {
name = expectedMetric[0].name
scope = expectedMetric[0].scope
}

const metric = metrics.getMetric(name, scope)
this.ok(metric, 'should have expected metric name')

this.strictSame(metric.toJSON(), expectedMetric[1], 'metric values should match')
}

if (exact) {
const metricsJSON = metrics.toJSON()
this.equal(metricsJSON.length, expected.length, 'metrics length should match')
}
}

/**
* @param {TraceSegment} parent Parent segment
* @param {Array} expected Array of strings that represent segment names.
* If an item in the array is another array, it
* represents children of the previous item.
* @param {boolean} options.exact If true, then the expected segments must match
* exactly, including their position and children on all
* levels. When false, then only check that each child
* exists.
* @param {array} options.exclude Array of segment names that should be excluded from
* validation. This is useful, for example, when a
* segment may or may not be created by code that is not
* directly under test. Only used when `exact` is true.
*/
function assertSegments(parent, expected, options) {
let child
let childCount = 0

// rather default to what is more likely to fail than have a false test
let exact = true
if (options && options.exact === false) {
exact = options.exact
} else if (options === false) {
exact = false
}

function getChildren(_parent) {
return _parent.children.filter(function (item) {
if (exact && options && options.exclude) {
return options.exclude.indexOf(item.name) === -1
}
return true
})
}

const children = getChildren(parent)
if (exact) {
for (let i = 0; i < expected.length; ++i) {
const sequenceItem = expected[i]

if (typeof sequenceItem === 'string') {
child = children[childCount++]
this.equal(
child ? child.name : undefined,
sequenceItem,
'segment "' +
parent.name +
'" should have child "' +
sequenceItem +
'" in position ' +
childCount
)

// If the next expected item is not array, then check that the current
// child has no children
if (!Array.isArray(expected[i + 1])) {
this.ok(
getChildren(child).length === 0,
'segment "' + child.name + '" should not have any children'
)
}
} else if (typeof sequenceItem === 'object') {
this.assertSegments(child, sequenceItem, options)
}
}

// check if correct number of children was found
this.equal(children.length, childCount)
} else {
for (let i = 0; i < expected.length; i++) {
const sequenceItem = expected[i]

if (typeof sequenceItem === 'string') {
// find corresponding child in parent
for (let j = 0; j < parent.children.length; j++) {
if (parent.children[j].name === sequenceItem) {
child = parent.children[j]
}
}
this.ok(child, 'segment "' + parent.name + '" should have child "' + sequenceItem + '"')
if (typeof expected[i + 1] === 'object') {
this.assertSegments(child, expected[i + 1], exact)
}
}
}
}
}

function findSegment(root, name) {
if (root.name === name) {
Expand Down
4 changes: 0 additions & 4 deletions test/lib/test-reporter.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -108,10 +108,6 @@ async function* reporter(source) {
// test name gets set to the `file`. So there isn't really any point in
// trying to provide more useful reports here while we need to support v18.
//
// The issue may also stem from the current test suites still being based
// on `tap`. Once we are able to migrate the actual test code to `node:test`
// we should revisit this reporter to determine if we can improve it.
//
// See https://nodejs.org/api/test.html#event-testfail.
switch (event.type) {
case 'test:enqueue': {
Expand Down
Loading
Loading