From 46c7cef3e42837bceef7fecc48e2f680cf8ddbb0 Mon Sep 17 00:00:00 2001 From: Vansh Sharma Date: Sun, 12 Apr 2026 17:37:35 +0530 Subject: [PATCH 1/9] test: migrate util message tests from Python to JS --- test/fixtures/util/util_inspect_error.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 test/fixtures/util/util_inspect_error.js diff --git a/test/fixtures/util/util_inspect_error.js b/test/fixtures/util/util_inspect_error.js new file mode 100644 index 00000000000000..ddec5e01a6ed16 --- /dev/null +++ b/test/fixtures/util/util_inspect_error.js @@ -0,0 +1,12 @@ +'use strict'; + +require('../../common'); +const util = require('util'); + +const err = new Error('foo\nbar'); + +console.log(util.inspect({ err, nested: { err } }, { compact: true })); +console.log(util.inspect({ err, nested: { err } }, { compact: false })); + +err.foo = 'bar'; +console.log(util.inspect(err, { compact: true, breakLength: 5 })); From 5fa882b66f1306783c058be226c558a220296578 Mon Sep 17 00:00:00 2001 From: Vansh Sharma Date: Sun, 12 Apr 2026 17:39:18 +0530 Subject: [PATCH 2/9] test: add util_inspect_error snapshot fixture --- .../fixtures/util/util_inspect_error.snapshot | 59 +++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 test/fixtures/util/util_inspect_error.snapshot diff --git a/test/fixtures/util/util_inspect_error.snapshot b/test/fixtures/util/util_inspect_error.snapshot new file mode 100644 index 00000000000000..19bc8c351e04cd --- /dev/null +++ b/test/fixtures/util/util_inspect_error.snapshot @@ -0,0 +1,59 @@ +{ err: + Error: foo + bar + at *util_inspect_error* + at * + at * + at * + at * + at * + at * + at * + nested: + { err: + Error: foo + bar + at *util_inspect_error* + at * + at * + at * + at * + at * + at * + at * } } +{ + err: Error: foo + bar + at *util_inspect_error* + at * + at * + at * + at * + at * + at * + at *, + nested: { + err: Error: foo + bar + at *util_inspect_error* + at * + at * + at * + at * + at * + at * + at * + } +} +Error: foo +bar + at *util_inspect_error* + at * + at * + at * + at * + at * + at * + at * { + foo: 'bar' +} From e00fa412f6970a1a21d03df1dbf47ba01313485f Mon Sep 17 00:00:00 2001 From: Vansh Sharma Date: Sun, 12 Apr 2026 17:40:09 +0530 Subject: [PATCH 3/9] test: add util-inspect-error-cause fixture --- .../fixtures/util/util-inspect-error-cause.js | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 test/fixtures/util/util-inspect-error-cause.js diff --git a/test/fixtures/util/util-inspect-error-cause.js b/test/fixtures/util/util-inspect-error-cause.js new file mode 100644 index 00000000000000..9cbd7d7c8e3734 --- /dev/null +++ b/test/fixtures/util/util-inspect-error-cause.js @@ -0,0 +1,33 @@ +'use strict'; + +require('../../common'); + +const { inspect } = require('util'); + +class FoobarError extends Error { + status = 'Feeling good'; +} + +const cause1 = new TypeError('Inner error'); +const cause2 = new FoobarError('Individual message', { cause: cause1 }); +cause2.extraProperties = 'Yes!'; +const cause3 = new Error('Stack causes', { cause: cause2 }); + +const cause4 = new Error('Number error cause', { cause: 42 }); +const cause5 = new Error('Object cause', { + cause: { + message: 'Unique', + name: 'Error', + stack: 'Error: Unique\n' + + ' at Module._compile (node:internal/modules/cjs/loader:827:30)', + }, +}); +const cause6 = new Error('undefined cause', { + cause: undefined, +}); + +console.log(cause4); +console.log(cause5); +console.log(cause6); +console.log(cause3); +console.log(inspect(cause3, { compact: false, breakLength: Infinity })); From 93f5cef7631dfee04db82bc2c8b3241df272ec59 Mon Sep 17 00:00:00 2001 From: Vansh Sharma Date: Sun, 12 Apr 2026 17:41:00 +0530 Subject: [PATCH 4/9] test: add util-inspect-error-cause snapshot fixture --- .../util/util-inspect-error-cause.snapshot | 69 +++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 test/fixtures/util/util-inspect-error-cause.snapshot diff --git a/test/fixtures/util/util-inspect-error-cause.snapshot b/test/fixtures/util/util-inspect-error-cause.snapshot new file mode 100644 index 00000000000000..1c28008a3affd9 --- /dev/null +++ b/test/fixtures/util/util-inspect-error-cause.snapshot @@ -0,0 +1,69 @@ +Error: Number error cause + at * + at * + at * + at * + at * + at * + at * + at * { + [cause]: 42 +} +Error: Object cause + at * + at * + at * + at * + at * + at * + at * + at * { + [cause]: { + message: 'Unique', + name: 'Error', + stack: 'Error: Unique\n' + + ' at Module._compile (node:internal*modules*cjs*loader:*:*)' + } +} +Error: undefined cause + at * + at * + at * + at * + at * + at * + at * + at * { + [cause]: undefined +} +Error: Stack causes + at * + at * + at * + at * + at * + at * + at * + at * { + [cause]: FoobarError: Individual message + at * + at * + at * + at * + at * + at * + at * + at * { + status: 'Feeling good', + extraProperties: 'Yes!', + [cause]: TypeError: Inner error + at * + at * + at * + at * + at * + at * + at * + at * + } +} From b00070e3696114790913ee343b685363e60605fb Mon Sep 17 00:00:00 2001 From: Vansh Sharma Date: Sun, 12 Apr 2026 17:41:52 +0530 Subject: [PATCH 5/9] test: add test-node-output-util.mjs test runner --- test/parallel/test-node-output-util.mjs | 35 +++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 test/parallel/test-node-output-util.mjs diff --git a/test/parallel/test-node-output-util.mjs b/test/parallel/test-node-output-util.mjs new file mode 100644 index 00000000000000..2318f1087aa313 --- /dev/null +++ b/test/parallel/test-node-output-util.mjs @@ -0,0 +1,35 @@ +import * as common from '../common/index.mjs'; +import * as fixtures from '../common/fixtures.mjs'; +import * as snapshot from '../common/assertSnapshot.js'; +import { describe, it } from 'node:test'; +import { basename } from 'node:path'; +import { pathToFileURL } from 'node:url'; + +describe('util output', { concurrency: !process.env.TEST_PARALLEL }, () => { + function normalize(str) { + const baseName = basename(process.argv0 || 'node', '.exe'); + return str.replaceAll(snapshot.replaceWindowsPaths(process.cwd()), '') + .replaceAll(pathToFileURL(process.cwd()).pathname, '') + .replaceAll('//', '*') + .replaceAll(/\/(\w)/g, '*$1') + .replaceAll('*test*', '*') + .replaceAll('*fixtures*util*', '*') + .replaceAll('file:**', 'file:*/') + .replaceAll(`${baseName} --`, '* --'); + } + + const commonTransform = snapshot + .transform(snapshot.replaceWindowsLineEndings, snapshot.replaceWindowsPaths); + const defaultTransform = snapshot.transform(commonTransform, normalize, snapshot.replaceNodeVersion); + + const tests = [ + { name: 'util/util_inspect_error.js', transform: defaultTransform }, + { name: 'util/util-inspect-error-cause.js', transform: defaultTransform }, + ]; + + for (const { name, transform } of tests) { + it(name, async () => { + await snapshot.spawnAndAssert(fixtures.path(name), transform); + }); + } +}); From e69ca2028f874f67552be6bed435687f0be5b495 Mon Sep 17 00:00:00 2001 From: Vansh Sharma Date: Sun, 12 Apr 2026 17:42:51 +0530 Subject: [PATCH 6/9] Delete test/message/util_inspect_error.js --- test/message/util_inspect_error.js | 12 ------------ 1 file changed, 12 deletions(-) delete mode 100644 test/message/util_inspect_error.js diff --git a/test/message/util_inspect_error.js b/test/message/util_inspect_error.js deleted file mode 100644 index 20affd6c711fd8..00000000000000 --- a/test/message/util_inspect_error.js +++ /dev/null @@ -1,12 +0,0 @@ -'use strict'; - -require('../common'); -const util = require('util'); - -const err = new Error('foo\nbar'); - -console.log(util.inspect({ err, nested: { err } }, { compact: true })); -console.log(util.inspect({ err, nested: { err } }, { compact: false })); - -err.foo = 'bar'; -console.log(util.inspect(err, { compact: true, breakLength: 5 })); From 77d0f6d1ef9a0748b9933b3a41477422672a82fe Mon Sep 17 00:00:00 2001 From: Vansh Sharma Date: Sun, 12 Apr 2026 17:43:54 +0530 Subject: [PATCH 7/9] Delete test/message/util_inspect_error.out --- test/message/util_inspect_error.out | 58 ----------------------------- 1 file changed, 58 deletions(-) delete mode 100644 test/message/util_inspect_error.out diff --git a/test/message/util_inspect_error.out b/test/message/util_inspect_error.out deleted file mode 100644 index 31b65eb2e2bf3c..00000000000000 --- a/test/message/util_inspect_error.out +++ /dev/null @@ -1,58 +0,0 @@ -{ err: - Error: foo - bar - at *util_inspect_error* - at * - at * - at * - at * - at * - at * - at * - nested: - { err: - Error: foo - bar - at *util_inspect_error* - at * - at * - at * - at * - at * - at * - at * -{ - err: Error: foo - bar - at *util_inspect_error* - at * - at * - at * - at * - at * - at * - at * - nested: { - err: Error: foo - bar - at *util_inspect_error* - at * - at * - at * - at * - at * - at * - at * - } -} -{ Error: foo -bar - at *util_inspect_error* - at * - at * - at * - at * - at * - at * - at * - foo: 'bar' } From 199f4cad3b1c0609789e25107fcceafe9501b101 Mon Sep 17 00:00:00 2001 From: Vansh Sharma Date: Sun, 12 Apr 2026 17:44:48 +0530 Subject: [PATCH 8/9] Delete test/message/util-inspect-error-cause.js --- test/message/util-inspect-error-cause.js | 54 ------------------------ 1 file changed, 54 deletions(-) delete mode 100644 test/message/util-inspect-error-cause.js diff --git a/test/message/util-inspect-error-cause.js b/test/message/util-inspect-error-cause.js deleted file mode 100644 index ed9d8230fe0c40..00000000000000 --- a/test/message/util-inspect-error-cause.js +++ /dev/null @@ -1,54 +0,0 @@ -'use strict'; - -require('../common'); - -const { inspect } = require('util'); - -class FoobarError extends Error { - status = 'Feeling good'; -} - -const cause1 = new TypeError('Inner error'); -const cause2 = new FoobarError('Individual message', { cause: cause1 }); -cause2.extraProperties = 'Yes!'; -const cause3 = new Error('Stack causes', { cause: cause2 }); - -const cause4 = new Error('Number error cause', { cause: 42 }); -const cause5 = new Error('Object cause', { - cause: { - message: 'Unique', - name: 'Error', - stack: 'Error: Unique\n' + - ' at Module._compile (node:internal/modules/cjs/loader:827:30)', - }, -}); -const cause6 = new Error('undefined cause', { - cause: undefined, -}); - -console.log(cause4); -console.log(cause5); -console.log(cause6); - -process.nextTick(() => { - const error = new RangeError('New Stack Frames', { cause: cause2 }); - const error2 = new RangeError('New Stack Frames', { cause: cause3 }); - - inspect.defaultOptions.colors = true; - - console.log(inspect(error)); - console.log(inspect(cause3)); - console.log(inspect(error2)); - - inspect.defaultOptions.colors = false; - - console.log(inspect(error)); - console.log(inspect(cause3)); - console.log(inspect(error2)); -}); - -{ - const error = new Error('cause that throws'); - Reflect.defineProperty(error, 'cause', { get() { throw new Error(); } }); - console.log(inspect(error)); -} From 6472988b430bb1f90f18d4148d2fe8df3d245c33 Mon Sep 17 00:00:00 2001 From: Vansh Sharma Date: Sun, 12 Apr 2026 17:45:45 +0530 Subject: [PATCH 9/9] Delete test/message/util-inspect-error-cause.out --- test/message/util-inspect-error-cause.out | 191 ---------------------- 1 file changed, 191 deletions(-) delete mode 100644 test/message/util-inspect-error-cause.out diff --git a/test/message/util-inspect-error-cause.out b/test/message/util-inspect-error-cause.out deleted file mode 100644 index 344ace1bc94074..00000000000000 --- a/test/message/util-inspect-error-cause.out +++ /dev/null @@ -1,191 +0,0 @@ -Error: Number error cause - at * - at * - at * - at * - at * - at * - at * - at * { - [cause]: 42 -} -Error: Object cause - at * - at * - at * - at * - at * - at * - at * - at * { - [cause]: { - message: 'Unique', - name: 'Error', - stack: 'Error: Unique\n' + - ' at Module._compile (node:internal/modules/cjs/loader:827:30)' - } -} -Error: undefined cause - at * - at * - at * - at * - at * - at * - at * - at * { - [cause]: undefined -} -Error: cause that throws - at * - at * - at * - at * - at * - at * - at * - at * { - [cause]: [Getter] -} -RangeError: New Stack Frames - at * -*[90m at *[39m { - [cause]: FoobarError: Individual message - at * - *[90m at *[39m - *[90m ... 5 lines matching cause stack trace ...*[39m - *[90m at *[39m { - status: *[32m'Feeling good'*[39m, - extraProperties: *[32m'Yes!'*[39m, - [cause]: TypeError: Inner error - at * - *[90m at *[39m - *[90m at *[39m - *[90m at *[39m - *[90m at *[39m - *[90m at *[39m - *[90m at *[39m - *[90m at *[39m - } -} -Error: Stack causes - at * -*[90m at *[39m -*[90m ... 5 lines matching cause stack trace ...*[39m -*[90m at *[39m { - [cause]: FoobarError: Individual message - at * - *[90m at *[39m - *[90m ... 5 lines matching cause stack trace ...*[39m - *[90m at *[39m { - status: *[32m'Feeling good'*[39m, - extraProperties: *[32m'Yes!'*[39m, - [cause]: TypeError: Inner error - at * - *[90m at *[39m - *[90m at *[39m - *[90m at *[39m - *[90m at *[39m - *[90m at *[39m - *[90m at *[39m - *[90m at *[39m - } -} -RangeError: New Stack Frames - at * -*[90m at *[39m { - [cause]: Error: Stack causes - at * - *[90m at *[39m - *[90m ... 5 lines matching cause stack trace ...*[39m - *[90m at *[39m { - [cause]: FoobarError: Individual message - at * - *[90m at *[39m - *[90m ... 5 lines matching cause stack trace ...*[39m - *[90m at *[39m { - status: *[32m'Feeling good'*[39m, - extraProperties: *[32m'Yes!'*[39m, - [cause]: TypeError: Inner error - at * - *[90m at *[39m - *[90m at *[39m - *[90m at *[39m - *[90m at *[39m - *[90m at *[39m - *[90m at *[39m - *[90m at *[39m - } - } -} -RangeError: New Stack Frames - at * - at * { - [cause]: FoobarError: Individual message - at * - at * - ... 5 lines matching cause stack trace ... - at * { - status: 'Feeling good', - extraProperties: 'Yes!', - [cause]: TypeError: Inner error - at * - at * - at * - at * - at * - at * - at * - at * - } -} -Error: Stack causes - at * - at * - ... 5 lines matching cause stack trace ... - at * { - [cause]: FoobarError: Individual message - at * - at * - ... 5 lines matching cause stack trace ... - at * - status: 'Feeling good', - extraProperties: 'Yes!', - [cause]: TypeError: Inner error - at * - at * - at * - at * - at * - at * - at * - at * - } -} -RangeError: New Stack Frames - at * - at * { - [cause]: Error: Stack causes - at * - at * - ... 5 lines matching cause stack trace ... - at * { - [cause]: FoobarError: Individual message - at * - at * - ... 5 lines matching cause stack trace ... - at * { - status: 'Feeling good', - extraProperties: 'Yes!', - [cause]: TypeError: Inner error - at * - at * - at * - at * - at * - at * - at * - at * - } - } -}