Skip to content

Commit

Permalink
test_runner: expose spec reporter as newable function
Browse files Browse the repository at this point in the history
Fixes: #48112
Ref: #48208
PR-URL: #49184
Refs: #48208
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Moshe Atlow <moshe@atlow.co.il>
  • Loading branch information
atlowChemi authored and UlisesGascon committed Sep 10, 2023
1 parent af6dc17 commit 283f280
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 12 deletions.
6 changes: 3 additions & 3 deletions lib/test/reporters.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';

const { ObjectDefineProperties } = primordials;
const { ObjectDefineProperties, ReflectConstruct } = primordials;

let dot;
let spec;
Expand All @@ -21,9 +21,9 @@ ObjectDefineProperties(module.exports, {
__proto__: null,
configurable: true,
enumerable: true,
get() {
value: function value() {
spec ??= require('internal/test_runner/reporter/spec');
return spec;
return ReflectConstruct(spec, arguments);
},
},
tap: {
Expand Down
31 changes: 22 additions & 9 deletions test/parallel/test-runner-run.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -82,15 +82,28 @@ describe('require(\'node:test\').run', { concurrency: true }, () => {
]);
});

it('should be piped with spec', async () => {
const specReporter = new spec();
const result = await run({
files: [join(testFixtures, 'default-behavior/test/random.cjs')]
}).compose(specReporter).toArray();
const stringResults = result.map((bfr) => bfr.toString());
assert.match(stringResults[0], /this should pass/);
assert.match(stringResults[1], /tests 1/);
assert.match(stringResults[1], /pass 1/);
describe('should be piped with spec reporter', () => {
it('new spec', async () => {
const specReporter = new spec();
const result = await run({
files: [join(testFixtures, 'default-behavior/test/random.cjs')]
}).compose(specReporter).toArray();
const stringResults = result.map((bfr) => bfr.toString());
assert.match(stringResults[0], /this should pass/);
assert.match(stringResults[1], /tests 1/);
assert.match(stringResults[1], /pass 1/);
});

it('spec()', async () => {
const specReporter = spec();
const result = await run({
files: [join(testFixtures, 'default-behavior/test/random.cjs')]
}).compose(specReporter).toArray();
const stringResults = result.map((bfr) => bfr.toString());
assert.match(stringResults[0], /this should pass/);
assert.match(stringResults[1], /tests 1/);
assert.match(stringResults[1], /pass 1/);
});
});

it('should be piped with tap', async () => {
Expand Down

0 comments on commit 283f280

Please sign in to comment.