Skip to content

Commit

Permalink
address feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
jsumners-nr committed Jul 23, 2024
1 parent d656c25 commit 6bd0072
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 3 deletions.
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -161,8 +161,8 @@
"bench": "node ./bin/run-bench.js",
"docker-env": "./bin/docker-env-vars.sh",
"docs": "rm -rf ./out && jsdoc -c ./jsdoc-conf.jsonc --private -r .",
"integration": "npm run prepare-test && npm run sub-install && time c8 -o ./coverage/integration node --test test/integration/**/*.tap.js",
"integration:esm": "time c8 -o ./coverage/integration-esm node --test --loader=./esm-loader.mjs test/integration/**/*.tap.mjs",
"integration": "npm run prepare-test && npm run sub-install && time c8 -o ./coverage/integration node --test-reporter ./test/lib/test-reporter.js --test test/integration/*.tap.js test/integration/**/*.tap.js",
"integration:esm": "time c8 -o ./coverage/integration-esm node --loader=./esm-loader.mjs --test-reporter ./test/lib/test-reporter.js --test test/integration/**/*.tap.mjs",
"prepare-test": "npm run ssl && npm run docker-env",
"lint": "eslint ./*.{js,mjs} lib test bin examples",
"lint:fix": "eslint --fix, ./*.{js,mjs} lib test bin examples",
Expand All @@ -175,7 +175,7 @@
"sub-install": "node test/bin/install_sub_deps",
"test": "npm run integration && npm run unit",
"third-party-updates": "oss third-party manifest --includeOptDeps && oss third-party notices --includeOptDeps && git add THIRD_PARTY_NOTICES.md third_party_manifest.json",
"unit": "rm -f newrelic_agent.log && time c8 -o ./coverage/unit node --test test/unit/**/*.test.js",
"unit": "rm -f newrelic_agent.log && time c8 -o ./coverage/unit node --test-reporter ./test/lib/test-reporter.js --test test/unit/*.test.js test/unit/**/*.test.js",
"unit:scripts": "time c8 -o ./coverage/scripts-unit node --test bin/test/*.test.js",
"update-cross-agent-tests": "./bin/update-cats.sh",
"versioned-tests": "./bin/run-versioned-tests.sh",
Expand Down
41 changes: 41 additions & 0 deletions test/lib/test-reporter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* Copyright 2024 New Relic Corporation. All rights reserved.
* SPDX-License-Identifier: Apache-2.0
*/

// This file provides a custom test reporter for the native test runner
// included in Node.js >=18. The default `spec` reporter writes too much
// information to be usable in CI, and the `dot` reporter hides which tests
// failed. This custom reporter outputs nothing for successful tests, and
// outputs the failing test file when any failing test has occurred.
//
// See https://nodejs.org/api/test.html#custom-reporters.
'use strict'

const { Transform } = require('node:stream')
const testReporter = new Transform({
writableObjectMode: true,
transform(event, encoding, callback) {
if (event.type !== 'test:fail') {
// We don't want to write out anything for any cases other than the
// failure case.
return callback(null, null)
}

// Once v18 has been dropped, we might want to revisit the output of
// failure cases. The `event` object is supposed to provide things like
// the failing line number and column, along with the failing test name.
// But on v18, we seem to only get `1` for both line and column, and the
// 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.
callback(null, `failed: ${event.data.file}`)
}
})

module.exports = testReporter

0 comments on commit 6bd0072

Please sign in to comment.