From 4ebfc7b8552f397bdc27da5bbf2fb3656831099e Mon Sep 17 00:00:00 2001 From: Sumeet Kaul Date: Sat, 27 May 2023 18:13:36 +0530 Subject: [PATCH 1/3] test_runner: handled change for exposing 'spec' reporter Other reporters (dot, tap) by signature are a function while 'spec' reporter is a ES6 class. This behaviour of api spec is causing difference in semantics while consumption since it has not been addressed anywhere in the document (it has to be instantiated). Instead of making changes in the signature of spec.js, i have proposed changes where the 'spec' reporter gets exposed in reporter.js Fixes: https://github.com/nodejs/node/issues/48112 Refs: https://github.com/nodejs/node/blob/main/lib/internal/test_runner/reporter/spec.js Refs: (@line-no:143) https://github.com/nodejs/node/blob/main/lib/internal/test_runner/utils.js --- lib/test/reporters.js | 4 ++-- test/parallel/test-runner-run.mjs | 3 +-- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/lib/test/reporters.js b/lib/test/reporters.js index 287c07510bc13a..e26039e714c37d 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; @@ -22,7 +22,7 @@ ObjectDefineProperties(module.exports, { configurable: true, enumerable: true, get() { - spec ??= require('internal/test_runner/reporter/spec'); + spec ??= (...args) => ReflectConstruct(require('internal/test_runner/reporter/spec'), args); return spec; }, }, diff --git a/test/parallel/test-runner-run.mjs b/test/parallel/test-runner-run.mjs index 794d55ab1a51d1..107067053881fd 100644 --- a/test/parallel/test-runner-run.mjs +++ b/test/parallel/test-runner-run.mjs @@ -76,8 +76,7 @@ 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, 'test/random.cjs')] }).compose(specReporter).toArray(); + const result = await run({ files: [join(testFixtures, 'test/random.cjs')] }).compose(spec).toArray(); const stringResults = result.map((bfr) => bfr.toString()); assert.match(stringResults[0], /this should pass/); assert.match(stringResults[1], /tests 1/); From 91518eefcd64238cef2d4d0f8d2d195f04623736 Mon Sep 17 00:00:00 2001 From: Sumeet Kaul Date: Sun, 28 May 2023 00:30:42 +0530 Subject: [PATCH 2/3] fixup! test_runner: handled change for exposing 'spec' reporter --- lib/test/reporters.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/test/reporters.js b/lib/test/reporters.js index e26039e714c37d..c9de08612bede4 100644 --- a/lib/test/reporters.js +++ b/lib/test/reporters.js @@ -22,7 +22,7 @@ ObjectDefineProperties(module.exports, { configurable: true, enumerable: true, get() { - spec ??= (...args) => ReflectConstruct(require('internal/test_runner/reporter/spec'), args); + spec ??= function SpecReporter() { return ReflectConstruct(require('internal/test_runner/reporter/spec'), arguments); }; return spec; }, }, From e257f77f446d1a3bf0ee084fbbe9d8318d1c1aa0 Mon Sep 17 00:00:00 2001 From: Sumeet Kaul Date: Sun, 28 May 2023 16:00:51 +0530 Subject: [PATCH 3/3] fixup2! test_runner: handled change for exposing 'spec' reporter --- lib/test/reporters.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/lib/test/reporters.js b/lib/test/reporters.js index c9de08612bede4..33d9991022d1c9 100644 --- a/lib/test/reporters.js +++ b/lib/test/reporters.js @@ -21,9 +21,8 @@ ObjectDefineProperties(module.exports, { __proto__: null, configurable: true, enumerable: true, - get() { - spec ??= function SpecReporter() { return ReflectConstruct(require('internal/test_runner/reporter/spec'), arguments); }; - return spec; + value: spec ?? function SpecReporter() { + return ReflectConstruct(require('internal/test_runner/reporter/spec'), arguments); }, }, tap: {