Skip to content

Commit

Permalink
apply suggestion
Browse files Browse the repository at this point in the history
  • Loading branch information
GeoffreyBooth committed Dec 20, 2022
1 parent c3cea01 commit 021ad3d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
16 changes: 11 additions & 5 deletions lib/internal/test_runner/utils.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
'use strict';
const {
ArrayPrototypePush,
ObjectCreate,
ObjectGetOwnPropertyDescriptor,
SafePromiseAllReturnArrayLike,
RegExp,
RegExpPrototypeExec,
SafeMap,
} = primordials;
const { basename, isAbsolute } = require('path');
const { basename } = require('path');
const { createWriteStream } = require('fs');
const { createDeferredPromise } = require('internal/util');
const { getOptionValue } = require('internal/options');
Expand Down Expand Up @@ -104,11 +105,16 @@ async function getReportersMap(reporters, destinations) {
const destination = kBuiltinDestinations.get(destinations[i]) ?? createWriteStream(destinations[i]);

// Load the test reporter passed to --test-reporter
const reporterPath = kBuiltinReporters.get(name) ?? name;
const reporterSpecifier = kBuiltinReporters.get(name) ?? name;
let parentURL;
try {
const { pathToFileURL } = require('internal/url');
parentURL = pathToFileURL(process.cwd() + '/').href;
} catch {
parentURL = 'file:///';
}
const { esmLoader } = require('internal/process/esm_loader');
const { pathToFileURL } = require('internal/url');
const file = isAbsolute(reporterPath) ? pathToFileURL(reporterPath).href : reporterPath;
let reporter = await esmLoader.import(file, undefined, { __proto__: null });
let reporter = await esmLoader.import(reporterSpecifier, parentURL, ObjectCreate(null));

if (reporter?.default) {
reporter = reporter.default;
Expand Down
6 changes: 4 additions & 2 deletions test/parallel/test-runner-reporters.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,8 @@ describe('node:test reporters', { concurrency: true }, () => {
{ cwd: fixtures.path('test-runner') });
assert.strictEqual(child.stderr.toString(), '');
assert.strictEqual(child.stdout.toString(),
'package: reporter-cjs{"test:start":5,"test:pass":2,"test:fail":3,"test:plan":3,"test:diagnostic":7}');
'package: reporter-cjs' +
'{"test:start":5,"test:pass":2,"test:fail":3,"test:plan":3,"test:diagnostic":7}');
});

it('should support a custom ESM reporter from node_modules', async () => {
Expand All @@ -108,6 +109,7 @@ describe('node:test reporters', { concurrency: true }, () => {
{ cwd: fixtures.path('test-runner') });
assert.strictEqual(child.stderr.toString(), '');
assert.strictEqual(child.stdout.toString(),
'package: reporter-esm{"test:start":5,"test:pass":2,"test:fail":3,"test:plan":3,"test:diagnostic":7}');
'package: reporter-esm' +
'{"test:start":5,"test:pass":2,"test:fail":3,"test:plan":3,"test:diagnostic":7}');
});
});

0 comments on commit 021ad3d

Please sign in to comment.