From 193c63ae33c7280d8cf439a48cc5740145f36b7b Mon Sep 17 00:00:00 2001 From: atlowChemi Date: Tue, 15 Aug 2023 21:03:04 +0300 Subject: [PATCH] test_runner: expose spec reporter as newable function Fixes: https://github.com/nodejs/node/issues/48112 Ref: https://github.com/nodejs/node/pull/48208 --- lib/test/reporters.js | 6 +++--- test/parallel/test-runner-run.mjs | 31 ++++++++++++++++++++++--------- 2 files changed, 25 insertions(+), 12 deletions(-) diff --git a/lib/test/reporters.js b/lib/test/reporters.js index 287c07510bc13a..86aea679b52a7a 100644 --- a/lib/test/reporters.js +++ b/lib/test/reporters.js @@ -1,6 +1,6 @@ 'use strict'; -const { ObjectDefineProperties } = primordials; +const { ObjectDefineProperties, ReflectConstruct } = primordials; let dot; let spec; @@ -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: { diff --git a/test/parallel/test-runner-run.mjs b/test/parallel/test-runner-run.mjs index 62fab0af146f4d..be15c42d465fca 100644 --- a/test/parallel/test-runner-run.mjs +++ b/test/parallel/test-runner-run.mjs @@ -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 () => {