Skip to content

Commit 7a2f61e

Browse files
committed
test_runner: expose test_runner as newable function
Fixes: #48112 Ref: #48208
1 parent 9a2e6bc commit 7a2f61e

File tree

2 files changed

+25
-12
lines changed

2 files changed

+25
-12
lines changed

lib/test/reporters.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
'use strict';
22

3-
const { ObjectDefineProperties } = primordials;
3+
const { ObjectDefineProperties, ReflectConstruct } = primordials;
44

55
let dot;
66
let spec;
@@ -21,9 +21,9 @@ ObjectDefineProperties(module.exports, {
2121
__proto__: null,
2222
configurable: true,
2323
enumerable: true,
24-
get() {
24+
value: function SpecReporter() {
2525
spec ??= require('internal/test_runner/reporter/spec');
26-
return spec;
26+
return ReflectConstruct(spec, arguments);
2727
},
2828
},
2929
tap: {

test/parallel/test-runner-run.mjs

+22-9
Original file line numberDiff line numberDiff line change
@@ -82,15 +82,28 @@ describe('require(\'node:test\').run', { concurrency: true }, () => {
8282
]);
8383
});
8484

85-
it('should be piped with spec', async () => {
86-
const specReporter = new spec();
87-
const result = await run({
88-
files: [join(testFixtures, 'default-behavior/test/random.cjs')]
89-
}).compose(specReporter).toArray();
90-
const stringResults = result.map((bfr) => bfr.toString());
91-
assert.match(stringResults[0], /this should pass/);
92-
assert.match(stringResults[1], /tests 1/);
93-
assert.match(stringResults[1], /pass 1/);
85+
describe('should be piped with spec reporter', () => {
86+
it('new spec', async () => {
87+
const specReporter = new spec();
88+
const result = await run({
89+
files: [join(testFixtures, 'default-behavior/test/random.cjs')]
90+
}).compose(specReporter).toArray();
91+
const stringResults = result.map((bfr) => bfr.toString());
92+
assert.match(stringResults[0], /this should pass/);
93+
assert.match(stringResults[1], /tests 1/);
94+
assert.match(stringResults[1], /pass 1/);
95+
});
96+
97+
it('spec()', async () => {
98+
const specReporter = spec();
99+
const result = await run({
100+
files: [join(testFixtures, 'default-behavior/test/random.cjs')]
101+
}).compose(specReporter).toArray();
102+
const stringResults = result.map((bfr) => bfr.toString());
103+
assert.match(stringResults[0], /this should pass/);
104+
assert.match(stringResults[1], /tests 1/);
105+
assert.match(stringResults[1], /pass 1/);
106+
});
94107
});
95108

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

0 commit comments

Comments
 (0)