Skip to content

Commit 6bd0072

Browse files
committed
address feedback
1 parent d656c25 commit 6bd0072

File tree

2 files changed

+44
-3
lines changed

2 files changed

+44
-3
lines changed

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -161,8 +161,8 @@
161161
"bench": "node ./bin/run-bench.js",
162162
"docker-env": "./bin/docker-env-vars.sh",
163163
"docs": "rm -rf ./out && jsdoc -c ./jsdoc-conf.jsonc --private -r .",
164-
"integration": "npm run prepare-test && npm run sub-install && time c8 -o ./coverage/integration node --test test/integration/**/*.tap.js",
165-
"integration:esm": "time c8 -o ./coverage/integration-esm node --test --loader=./esm-loader.mjs test/integration/**/*.tap.mjs",
164+
"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",
165+
"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",
166166
"prepare-test": "npm run ssl && npm run docker-env",
167167
"lint": "eslint ./*.{js,mjs} lib test bin examples",
168168
"lint:fix": "eslint --fix, ./*.{js,mjs} lib test bin examples",
@@ -175,7 +175,7 @@
175175
"sub-install": "node test/bin/install_sub_deps",
176176
"test": "npm run integration && npm run unit",
177177
"third-party-updates": "oss third-party manifest --includeOptDeps && oss third-party notices --includeOptDeps && git add THIRD_PARTY_NOTICES.md third_party_manifest.json",
178-
"unit": "rm -f newrelic_agent.log && time c8 -o ./coverage/unit node --test test/unit/**/*.test.js",
178+
"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",
179179
"unit:scripts": "time c8 -o ./coverage/scripts-unit node --test bin/test/*.test.js",
180180
"update-cross-agent-tests": "./bin/update-cats.sh",
181181
"versioned-tests": "./bin/run-versioned-tests.sh",

test/lib/test-reporter.js

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/*
2+
* Copyright 2024 New Relic Corporation. All rights reserved.
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
// This file provides a custom test reporter for the native test runner
7+
// included in Node.js >=18. The default `spec` reporter writes too much
8+
// information to be usable in CI, and the `dot` reporter hides which tests
9+
// failed. This custom reporter outputs nothing for successful tests, and
10+
// outputs the failing test file when any failing test has occurred.
11+
//
12+
// See https://nodejs.org/api/test.html#custom-reporters.
13+
'use strict'
14+
15+
const { Transform } = require('node:stream')
16+
const testReporter = new Transform({
17+
writableObjectMode: true,
18+
transform(event, encoding, callback) {
19+
if (event.type !== 'test:fail') {
20+
// We don't want to write out anything for any cases other than the
21+
// failure case.
22+
return callback(null, null)
23+
}
24+
25+
// Once v18 has been dropped, we might want to revisit the output of
26+
// failure cases. The `event` object is supposed to provide things like
27+
// the failing line number and column, along with the failing test name.
28+
// But on v18, we seem to only get `1` for both line and column, and the
29+
// test name gets set to the `file`. So there isn't really any point in
30+
// trying to provide more useful reports here while we need to support v18.
31+
//
32+
// The issue may also stem from the current test suites still being based
33+
// on `tap`. Once we are able to migrate the actual test code to `node:test`
34+
// we should revisit this reporter to determine if we can improve it.
35+
//
36+
// See https://nodejs.org/api/test.html#event-testfail.
37+
callback(null, `failed: ${event.data.file}`)
38+
}
39+
})
40+
41+
module.exports = testReporter

0 commit comments

Comments
 (0)