Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 5d12932

Browse files
GeoffreyBoothMoLow
authored andcommittedFeb 7, 2023
fix: move test reporter loading
Move the logic for handling --test-reporter out of the general module loader and into the test_runner subsystem. PR-URL: nodejs/node#45923 Reviewed-By: Moshe Atlow <moshe@atlow.co.il> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Jacob Smith <jacob@frende.me> Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com> (cherry picked from commit 12c0571c8fece32d274eaf0ae197c0eb1948fe11)
1 parent 61cf2c2 commit 5d12932

File tree

4 files changed

+21
-8
lines changed

4 files changed

+21
-8
lines changed
 

‎README.md

+4-1
Original file line numberDiff line numberDiff line change
@@ -447,7 +447,7 @@ The following built-reporters are supported:
447447
The `spec` reporter outputs the test results in a human-readable format.
448448

449449
* `dot`
450-
The `dot` reporter outputs the test results in a comact format,
450+
The `dot` reporter outputs the test results in a compact format,
451451
where each passing test is represented by a `.`,
452452
and each failing test is represented by a `X`.
453453

@@ -564,6 +564,9 @@ module.exports = async function * customReporter(source) {
564564
};
565565
```
566566

567+
The value provided to `--test-reporter` should be a string like one used in an
568+
`import()` in JavaScript code, or a value provided for [`--import`][].
569+
567570
### Multiple reporters
568571

569572
The [`--test-reporter`][] flag can be specified multiple times to report test

‎lib/internal/test_runner/utils.js

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// https://github.com/nodejs/node/blob/a1b27b25bb01aadd3fd2714e4b136db11b7eb85a/lib/internal/test_runner/utils.js
1+
// https://github.com/nodejs/node/blob/12c0571c8fece32d274eaf0ae197c0eb1948fe11/lib/internal/test_runner/utils.js
22
'use strict'
33
const {
44
ArrayPrototypePush,
@@ -103,7 +103,10 @@ const kDefaultDestination = 'stdout'
103103
async function getReportersMap (reporters, destinations) {
104104
return SafePromiseAllReturnArrayLike(reporters, async (name, i) => {
105105
const destination = kBuiltinDestinations.get(destinations[i]) ?? createWriteStream(destinations[i])
106-
let reporter = await import(kBuiltinReporters.get(name) ?? name)
106+
107+
// Load the test reporter passed to --test-reporter
108+
const reporterSpecifier = kBuiltinReporters.get(name) ?? name
109+
let reporter = await import(reporterSpecifier)
107110

108111
if (reporter?.default) {
109112
reporter = reporter.default

‎test/common/fixtures.js

+7-2
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,19 @@
1-
// https://github.com/nodejs/node/blob/1aab13cad9c800f4121c1d35b554b78c1b17bdbd/test/common/fixtures.js
1+
// https://github.com/nodejs/node/blob/12c0571c8fece32d274eaf0ae197c0eb1948fe11/test/common/fixtures.js
22
'use strict'
33

44
const path = require('path')
5+
const { pathToFileURL } = require('url')
56

67
const fixturesDir = path.join(__dirname, '..', 'fixtures')
78

89
function fixturesPath (...args) {
910
return path.join(fixturesDir, ...args)
1011
}
12+
function fixturesFileURL (...args) {
13+
return pathToFileURL(fixturesPath(...args))
14+
}
1115

1216
module.exports = {
13-
path: fixturesPath
17+
path: fixturesPath,
18+
fileURL: fixturesFileURL
1419
}

‎test/parallel/test-runner-reporters.js

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// https://github.com/nodejs/node/blob/a1b27b25bb01aadd3fd2714e4b136db11b7eb85a/test/parallel/test-runner-reporters.js
1+
// https://github.com/nodejs/node/blob/12c0571c8fece32d274eaf0ae197c0eb1948fe11/test/parallel/test-runner-reporters.js
22
'use strict'
33

44
require('../common')
@@ -91,10 +91,12 @@ describe('node:test reporters', { concurrency: true }, () => {
9191
it(`should support a '${ext}' file as a custom reporter`, async () => {
9292
const filename = `custom.${ext}`
9393
const child = spawnSync(process.execPath,
94-
['--test', '--test-reporter', fixtures.path('test-runner/custom_reporters/', filename),
94+
['--test', '--test-reporter', fixtures.fileURL('test-runner/custom_reporters/', filename),
9595
testFile])
9696
assert.strictEqual(child.stderr.toString(), '')
97-
assert.strictEqual(child.stdout.toString(), `${filename} {"test:start":5,"test:pass":2,"test:fail":3,"test:plan":3,"test:diagnostic":7}`)
97+
const stdout = child.stdout.toString()
98+
assert.match(stdout, /{"test:start":5,"test:pass":2,"test:fail":3,"test:plan":3,"test:diagnostic":\d+}$/)
99+
assert.strictEqual(stdout.slice(0, filename.length + 2), `${filename} {`)
98100
})
99101
})
100102
})

0 commit comments

Comments
 (0)
Please sign in to comment.