diff --git a/BUILDING.md b/BUILDING.md index ff101422f7ab32..6bba8f238aeabd 100644 --- a/BUILDING.md +++ b/BUILDING.md @@ -333,10 +333,10 @@ tools/test.py child-process ``` You can also execute the tests in a test suite directory -(such as `test/message`): +(such as `test/report`): -```bash -tools/test.py test/message +```text +$ tools/test.py test/report ``` If you want to check the other options, please refer to the help by using @@ -347,7 +347,7 @@ tools/test.py --help ``` > Note: On Windows you should use `python3` executable. -> Example: `python3 tools/test.py test/message` +> Example: `python3 tools/test.py test/report` You can usually run tests directly with node: diff --git a/test/message/assert_throws_stack.js b/test/fixtures/assertion/assert_throws_stack.js similarity index 82% rename from test/message/assert_throws_stack.js rename to test/fixtures/assertion/assert_throws_stack.js index 36bc5734cae37f..a1fca696c5ac10 100644 --- a/test/message/assert_throws_stack.js +++ b/test/fixtures/assertion/assert_throws_stack.js @@ -1,6 +1,6 @@ 'use strict'; -require('../common'); +require('../../common'); const assert = require('assert').strict; assert.throws(() => { throw new Error('foo'); }, { bar: true }); diff --git a/test/message/assert_throws_stack.out b/test/fixtures/assertion/assert_throws_stack.snapshot similarity index 60% rename from test/message/assert_throws_stack.out rename to test/fixtures/assertion/assert_throws_stack.snapshot index 06eaa906442440..ebd3517dd74a48 100644 --- a/test/message/assert_throws_stack.out +++ b/test/fixtures/assertion/assert_throws_stack.snapshot @@ -1,4 +1,4 @@ -node:assert:* +node:assert* throw err; ^ @@ -9,7 +9,7 @@ AssertionError [ERR_ASSERTION]: Expected values to be strictly deep-equal: - Comparison { - bar: true - } - at Object. (*assert_throws_stack.js:*:*) + at * at * at * at * @@ -19,16 +19,16 @@ AssertionError [ERR_ASSERTION]: Expected values to be strictly deep-equal: generatedMessage: true, code: 'ERR_ASSERTION', actual: Error: foo - at assert.throws.bar (*assert_throws_stack.js:*) - at getActual (node:assert:*) - at Function.throws (node:assert:*) - at Object. (*assert_throws_stack.js:*:*) at * at * at * at * at * - at *, + at * + at * + at * + at * + at node:internal*main*run_main_module**, expected: { bar: true }, operator: 'throws' } diff --git a/test/message/internal_assert.js b/test/fixtures/assertion/internal_assert.js similarity index 80% rename from test/message/internal_assert.js rename to test/fixtures/assertion/internal_assert.js index fdb459b67ca0fa..871504f0925a6f 100644 --- a/test/message/internal_assert.js +++ b/test/fixtures/assertion/internal_assert.js @@ -1,7 +1,7 @@ 'use strict'; // Flags: --expose-internals -require('../common'); +require('../../common'); const assert = require('internal/assert'); assert(false); diff --git a/test/message/internal_assert.out b/test/fixtures/assertion/internal_assert.snapshot similarity index 52% rename from test/message/internal_assert.out rename to test/fixtures/assertion/internal_assert.snapshot index bd25c879478083..3b60a41ffc4f0c 100644 --- a/test/message/internal_assert.out +++ b/test/fixtures/assertion/internal_assert.snapshot @@ -1,13 +1,13 @@ -node:internal/assert:* +node:internal*assert* throw new ERR_INTERNAL_ASSERTION(message); ^ Error [ERR_INTERNAL_ASSERTION]: This is caused by either a bug in Node.js or incorrect usage of Node.js internals. -Please open an issue with this stack trace at https://github.com/nodejs/node/issues +Please open an issue with this stack trace at https:**github.com*nodejs*node*issues - at new NodeError (node:internal/errors:*:*) - at assert (node:internal/assert:*:*) - at * (*test*message*internal_assert.js:7:1) + at * + at * + at * at * at * at * diff --git a/test/message/internal_assert_fail.js b/test/fixtures/assertion/internal_assert_fail.js similarity index 82% rename from test/message/internal_assert_fail.js rename to test/fixtures/assertion/internal_assert_fail.js index 1b2cf13552869b..503a1dcbc7264a 100644 --- a/test/message/internal_assert_fail.js +++ b/test/fixtures/assertion/internal_assert_fail.js @@ -1,7 +1,7 @@ 'use strict'; // Flags: --expose-internals -require('../common'); +require('../../common'); const assert = require('internal/assert'); assert.fail('Unreachable!'); diff --git a/test/message/internal_assert_fail.out b/test/fixtures/assertion/internal_assert_fail.snapshot similarity index 52% rename from test/message/internal_assert_fail.out rename to test/fixtures/assertion/internal_assert_fail.snapshot index 408d6d3364470d..6821e0007dac80 100644 --- a/test/message/internal_assert_fail.out +++ b/test/fixtures/assertion/internal_assert_fail.snapshot @@ -1,14 +1,14 @@ -node:internal/assert:* +node:internal*assert* throw new ERR_INTERNAL_ASSERTION(message); ^ Error [ERR_INTERNAL_ASSERTION]: Unreachable! This is caused by either a bug in Node.js or incorrect usage of Node.js internals. -Please open an issue with this stack trace at https://github.com/nodejs/node/issues +Please open an issue with this stack trace at https:**github.com*nodejs*node*issues - at new NodeError (node:internal/errors:*:*) - at Function.fail (node:internal/assert:*:*) - at * (*test*message*internal_assert_fail.js:7:8) + at * + at * + at * at * at * at * diff --git a/test/message/core_line_numbers.js b/test/fixtures/console/core_line_numbers.js similarity index 95% rename from test/message/core_line_numbers.js rename to test/fixtures/console/core_line_numbers.js index 585a6042652df1..5482a21bae9a1f 100644 --- a/test/message/core_line_numbers.js +++ b/test/fixtures/console/core_line_numbers.js @@ -1,5 +1,5 @@ 'use strict'; -require('../common'); +require('../../common'); Error.stackTraceLimit = 3; const punycode = require('punycode'); diff --git a/test/fixtures/console/core_line_numbers.snapshot b/test/fixtures/console/core_line_numbers.snapshot new file mode 100644 index 00000000000000..40a7863e03fe2f --- /dev/null +++ b/test/fixtures/console/core_line_numbers.snapshot @@ -0,0 +1,10 @@ +node:punycode:49 + throw new RangeError(errors[type]); + ^ + +RangeError: Invalid input + at error (node:punycode:49:8) + at Object.decode (node:punycode:*:*) + at Object. (*test*message*core_line_numbers.js:*:*) + +Node.js * \ No newline at end of file diff --git a/test/message/eval_messages.js b/test/fixtures/console/eval_messages.js similarity index 98% rename from test/message/eval_messages.js rename to test/fixtures/console/eval_messages.js index 69dcbd6efa23a7..171bff06b8d6e9 100644 --- a/test/message/eval_messages.js +++ b/test/fixtures/console/eval_messages.js @@ -21,7 +21,7 @@ 'use strict'; -require('../common'); +require('../../common'); const spawn = require('child_process').spawn; diff --git a/test/fixtures/console/eval_messages.snapshot b/test/fixtures/console/eval_messages.snapshot new file mode 100644 index 00000000000000..53f0a25c72a387 --- /dev/null +++ b/test/fixtures/console/eval_messages.snapshot @@ -0,0 +1,81 @@ +[eval] +[eval]:1 +with(this){__filename} +^^^^ +SyntaxError: Strict mode code may not include a with statement + at new Script (node:vm:*:*) + at createScript (node:vm:*:*) + at Object.runInThisContext (node:vm:*:*) + at node:internal/process/execution:*:* + at [eval]-wrapper:*:* + at runScript (node:internal/process/execution:*:*) + at evalScript (node:internal/process/execution:*:*) + at node:internal/main/eval_string:*:* + +Node.js * +42 +42 +[eval]:1 +throw new Error("hello") +^ + +Error: hello + at [eval]:1:7 + at Script.runInThisContext (node:vm:*:*) + at Object.runInThisContext (node:vm:*:*) + at node:internal/process/execution:*:* + at [eval]-wrapper:*:* + at runScript (node:internal/process/execution:*:*) + at evalScript (node:internal/process/execution:*:*) + at node:internal/main/eval_string:*:* + +Node.js * + +[eval]:1 +throw new Error("hello") +^ + +Error: hello + at [eval]:1:7 + at Script.runInThisContext (node:vm:*:*) + at Object.runInThisContext (node:vm:*:*) + at node:internal/process/execution:*:* + at [eval]-wrapper:*:* + at runScript (node:internal/process/execution:*:*) + at evalScript (node:internal/process/execution:*:*) + at node:internal/main/eval_string:*:* + +Node.js * +100 +[eval]:1 +var x = 100; y = x; + ^ + +ReferenceError: y is not defined + at [eval]:1:16 + at Script.runInThisContext (node:vm:*:*) + at Object.runInThisContext (node:vm:*:*) + at node:internal/process/execution:*:* + at [eval]-wrapper:*:* + at runScript (node:internal/process/execution:*:*) + at evalScript (node:internal/process/execution:*:*) + at node:internal/main/eval_string:*:* + +Node.js * + +[eval]:1 +var ______________________________________________; throw 10 + ^ +10 +(Use `* --trace-uncaught ...` to show where the exception was thrown) + +Node.js * + +[eval]:1 +var ______________________________________________; throw 10 + ^ +10 +(Use `* --trace-uncaught ...` to show where the exception was thrown) + +Node.js * +done \ No newline at end of file diff --git a/test/fixtures/console/force_colors.snapshot b/test/fixtures/console/force_colors.snapshot index 0c754ba4c53554..919c5da1dd7c65 100644 --- a/test/fixtures/console/force_colors.snapshot +++ b/test/fixtures/console/force_colors.snapshot @@ -1 +1 @@ -123 foo { bar: 'baz' } +123 foo { bar: 'baz' } diff --git a/test/fixtures/console/stack_overflow.snapshot b/test/fixtures/console/stack_overflow.snapshot index e723d53adc866e..3bc6f4beceb17d 100644 --- a/test/fixtures/console/stack_overflow.snapshot +++ b/test/fixtures/console/stack_overflow.snapshot @@ -1,5 +1,5 @@ before -*test*fixtures*console*stack_overflow.js:* +at * JSON.stringify(array); ^ diff --git a/test/message/stdin_messages.js b/test/fixtures/console/stdin_messages.js similarity index 98% rename from test/message/stdin_messages.js rename to test/fixtures/console/stdin_messages.js index 79475bd4d217b6..874b473be38e00 100644 --- a/test/message/stdin_messages.js +++ b/test/fixtures/console/stdin_messages.js @@ -21,7 +21,7 @@ 'use strict'; -require('../common'); +require('../../common'); const spawn = require('child_process').spawn; diff --git a/test/fixtures/console/stdin_messages.snapshot b/test/fixtures/console/stdin_messages.snapshot new file mode 100644 index 00000000000000..2ebbf22ece0d60 --- /dev/null +++ b/test/fixtures/console/stdin_messages.snapshot @@ -0,0 +1,89 @@ +[stdin] +[stdin]:1 +with(this){__filename} +^^^^ + +SyntaxError: Strict mode code may not include a with statement + at new Script (node:vm:*) + at createScript (node:vm:*) + at Object.runInThisContext (node:vm:*) + at node:internal/process/execution:*:* + at [stdin]-wrapper:*:* + at runScript (node:internal/process/execution:*:*) + at evalScript (node:internal/process/execution:*:*) + at node:internal/main/eval_stdin:*:* + at Socket. (node:internal/process/execution:*:*) + at Socket.emit (node:events:*:*) + +Node.js * +42 +42 +[stdin]:1 +throw new Error("hello") +^ + +Error: hello + at [stdin]:1:7 + at Script.runInThisContext (node:vm:*) + at Object.runInThisContext (node:vm:*) + at node:internal/process/execution:*:* + at [stdin]-wrapper:*:* + at runScript (node:internal/process/execution:*:*) + at evalScript (node:internal/process/execution:*:*) + at node:internal/main/eval_stdin:*:* + at Socket. (node:internal/process/execution:*:*) + at Socket.emit (node:events:*:*) + +Node.js * +[stdin]:1 +throw new Error("hello") +^ + +Error: hello + at [stdin]:1:* + at Script.runInThisContext (node:vm:*) + at Object.runInThisContext (node:vm:*) + at node:internal/process/execution:*:* + at [stdin]-wrapper:*:* + at runScript (node:internal/process/execution:*:*) + at evalScript (node:internal/process/execution:*:*) + at node:internal/main/eval_stdin:*:* + at Socket. (node:internal/process/execution:*:*) + at Socket.emit (node:events:*:*) + +Node.js * +100 +[stdin]:1 +let x = 100; y = x; + ^ + +ReferenceError: y is not defined + at [stdin]:1:16 + at Script.runInThisContext (node:vm:*) + at Object.runInThisContext (node:vm:*) + at node:internal/process/execution:*:* + at [stdin]-wrapper:*:* + at runScript (node:internal/process/execution:*:*) + at evalScript (node:internal/process/execution:*:*) + at node:internal/main/eval_stdin:*:* + at Socket. (node:internal/process/execution:*:*) + at Socket.emit (node:events:*:*) + +Node.js * + +[stdin]:1 +let ______________________________________________; throw 10 + ^ +10 +(Use `* --trace-uncaught ...` to show where the exception was thrown) + +Node.js * + +[stdin]:1 +let ______________________________________________; throw 10 + ^ +10 +(Use `* --trace-uncaught ...` to show where the exception was thrown) + +Node.js * +done \ No newline at end of file diff --git a/test/fixtures/errors/force_colors.snapshot b/test/fixtures/errors/force_colors.snapshot index a38745e396a8d9..94ad8f2dcfffd4 100644 --- a/test/fixtures/errors/force_colors.snapshot +++ b/test/fixtures/errors/force_colors.snapshot @@ -3,12 +3,12 @@ throw new Error('Should include grayed stack trace') ^ Error: Should include grayed stack trace - at Object. (/test*force_colors.js:1:7) - at Module._compile (node:internal*modules*cjs*loader:1255:14) - at Module._extensions..js (node:internal*modules*cjs*loader:1309:10) - at Module.load (node:internal*modules*cjs*loader:1113:32) - at Module._load (node:internal*modules*cjs*loader:960:12) - at Function.executeUserEntryPoint [as runMain] (node:internal*modules*run_main:83:12) - at node:internal*main*run_main_module:23:47 + at Object. (*force_colors.js:1:7) + at Module._compile (node:internal*modules*cjs*loader:1255:14) + at Module._extensions..js (node:internal*modules*cjs*loader:1309:10) + at Module.load (node:internal*modules*cjs*loader:1113:32) + at Module._load (node:internal*modules*cjs*loader:960:12) + at Function.executeUserEntryPoint [as runMain] (node:internal*modules*run_main:83:12) + at node:internal*main*run_main_module:23:47 Node.js * diff --git a/test/message/if-error-has-good-stack.js b/test/fixtures/errors/if-error-has-good-stack.js similarity index 93% rename from test/message/if-error-has-good-stack.js rename to test/fixtures/errors/if-error-has-good-stack.js index 4f529d3e5d17ff..85c127c4e24c54 100644 --- a/test/message/if-error-has-good-stack.js +++ b/test/fixtures/errors/if-error-has-good-stack.js @@ -1,6 +1,6 @@ 'use strict'; -require('../common'); +require('../../common'); Error.stackTraceLimit = 4; const assert = require('assert'); diff --git a/test/message/if-error-has-good-stack.out b/test/fixtures/errors/if-error-has-good-stack.snapshot similarity index 94% rename from test/message/if-error-has-good-stack.out rename to test/fixtures/errors/if-error-has-good-stack.snapshot index e394127bd4c473..9296b25f10b7c6 100644 --- a/test/message/if-error-has-good-stack.out +++ b/test/fixtures/errors/if-error-has-good-stack.snapshot @@ -3,7 +3,7 @@ node:assert:* ^ AssertionError [ERR_ASSERTION]: ifError got unwanted exception: test error - at z (*if-error-has-good-stack.js:*:* + at z (*if-error-has-good-stack.js:*:*) at y (*if-error-has-good-stack.js:*:*) at x (*if-error-has-good-stack.js:*:*) at Object. (*if-error-has-good-stack.js:*:*) diff --git a/test/message/test-no-extra-info-on-fatal-exception.js b/test/fixtures/errors/test-no-extra-info-on-fatal-exception.js similarity index 81% rename from test/message/test-no-extra-info-on-fatal-exception.js rename to test/fixtures/errors/test-no-extra-info-on-fatal-exception.js index dbc61b0f2382e0..d72a7a22cd727e 100644 --- a/test/message/test-no-extra-info-on-fatal-exception.js +++ b/test/fixtures/errors/test-no-extra-info-on-fatal-exception.js @@ -1,7 +1,7 @@ // Flags: --no-extra-info-on-fatal-exception 'use strict'; -require('../common'); +require('../../common'); Error.stackTraceLimit = 1; throw new Error('foo'); diff --git a/test/fixtures/errors/test-no-extra-info-on-fatal-exception.snapshot b/test/fixtures/errors/test-no-extra-info-on-fatal-exception.snapshot new file mode 100644 index 00000000000000..a7d93b82e70738 --- /dev/null +++ b/test/fixtures/errors/test-no-extra-info-on-fatal-exception.snapshot @@ -0,0 +1,6 @@ +*:7 +throw new Error('foo'); +^ + +Error: foo + at Object. (*:7:7) \ No newline at end of file diff --git a/test/message/throw_error_with_getter_throw.js b/test/fixtures/errors/throw_error_with_getter_throw.js similarity index 87% rename from test/message/throw_error_with_getter_throw.js rename to test/fixtures/errors/throw_error_with_getter_throw.js index a807ff3e2b6504..341397f28c6101 100644 --- a/test/message/throw_error_with_getter_throw.js +++ b/test/fixtures/errors/throw_error_with_getter_throw.js @@ -1,5 +1,7 @@ 'use strict'; -require('../common'); + +require('../../common'); + throw { // eslint-disable-line no-throw-literal get stack() { throw new Error('weird throw but ok'); diff --git a/test/fixtures/errors/throw_error_with_getter_throw.snapshot b/test/fixtures/errors/throw_error_with_getter_throw.snapshot new file mode 100644 index 00000000000000..d277a8c8ae4482 --- /dev/null +++ b/test/fixtures/errors/throw_error_with_getter_throw.snapshot @@ -0,0 +1,8 @@ + +*test*message*throw_null.js:* +throw null; +^ +null +(Use `* --trace-uncaught ...` to show where the exception was thrown) + +Node.js * \ No newline at end of file diff --git a/test/message/throw_null.js b/test/fixtures/errors/throw_null.js similarity index 97% rename from test/message/throw_null.js rename to test/fixtures/errors/throw_null.js index fb233d1db56704..d8fc14ba784488 100644 --- a/test/message/throw_null.js +++ b/test/fixtures/errors/throw_null.js @@ -20,7 +20,7 @@ // USE OR OTHER DEALINGS IN THE SOFTWARE. 'use strict'; -require('../common'); +require('../../common'); // eslint-disable-next-line no-throw-literal throw null; diff --git a/test/fixtures/errors/throw_null.snapshot b/test/fixtures/errors/throw_null.snapshot new file mode 100644 index 00000000000000..0fe2a49d050b18 --- /dev/null +++ b/test/fixtures/errors/throw_null.snapshot @@ -0,0 +1,8 @@ + +*test*message*throw_null.js:* +throw null; +^ +null +(Use `* --trace-uncaught ...` to show where the exception was thrown) + +Node.js * diff --git a/test/message/throw_undefined.js b/test/fixtures/errors/throw_undefined.js similarity index 97% rename from test/message/throw_undefined.js rename to test/fixtures/errors/throw_undefined.js index a89aaf2ee2da59..8c486a7ff4c470 100644 --- a/test/message/throw_undefined.js +++ b/test/fixtures/errors/throw_undefined.js @@ -20,7 +20,7 @@ // USE OR OTHER DEALINGS IN THE SOFTWARE. 'use strict'; -require('../common'); +require('../../common'); // eslint-disable-next-line no-throw-literal throw undefined; diff --git a/test/fixtures/errors/throw_undefined.snapshot b/test/fixtures/errors/throw_undefined.snapshot new file mode 100644 index 00000000000000..56b0cac4259d6d --- /dev/null +++ b/test/fixtures/errors/throw_undefined.snapshot @@ -0,0 +1,8 @@ + +*test*message*throw_undefined.js:* +throw undefined; +^ +undefined +(Use `* --trace-uncaught ...` to show where the exception was thrown) + +Node.js * diff --git a/test/message/timeout_throw.js b/test/fixtures/errors/timeout_throw.js similarity index 98% rename from test/message/timeout_throw.js rename to test/fixtures/errors/timeout_throw.js index 9bcbd85b5036e2..bd4130479b48c6 100644 --- a/test/message/timeout_throw.js +++ b/test/fixtures/errors/timeout_throw.js @@ -20,7 +20,7 @@ // USE OR OTHER DEALINGS IN THE SOFTWARE. 'use strict'; -require('../common'); +require('../../common'); setTimeout(function() { // eslint-disable-next-line no-undef,no-unused-expressions diff --git a/test/fixtures/errors/timeout_throw.snapshot b/test/fixtures/errors/timeout_throw.snapshot new file mode 100644 index 00000000000000..83b861caa7ca29 --- /dev/null +++ b/test/fixtures/errors/timeout_throw.snapshot @@ -0,0 +1,9 @@ +*test*message*timeout_throw.js:* + undefined_reference_error_maker; + ^ +ReferenceError: undefined_reference_error_maker is not defined + at Timeout._onTimeout (*test*message*timeout_throw.js:*:*) + at listOnTimeout (node:internal/timers:*:*) + at process.processTimers (node:internal/timers:*:*) + +Node.js * diff --git a/test/message/undefined_reference_in_new_context.js b/test/fixtures/errors/undefined_reference_in_new_context.js similarity index 98% rename from test/message/undefined_reference_in_new_context.js rename to test/fixtures/errors/undefined_reference_in_new_context.js index 29a67632f8f7dd..baa45de11ecef7 100644 --- a/test/message/undefined_reference_in_new_context.js +++ b/test/fixtures/errors/undefined_reference_in_new_context.js @@ -20,7 +20,7 @@ // USE OR OTHER DEALINGS IN THE SOFTWARE. 'use strict'; -require('../common'); +require('../../common'); const vm = require('vm'); console.error('before'); diff --git a/test/fixtures/errors/undefined_reference_in_new_context.snapshot b/test/fixtures/errors/undefined_reference_in_new_context.snapshot new file mode 100644 index 00000000000000..8d8228bd902950 --- /dev/null +++ b/test/fixtures/errors/undefined_reference_in_new_context.snapshot @@ -0,0 +1,13 @@ +before +evalmachine.:1 +Error.stackTraceLimit = 5; foo.bar = 5; + ^ + +ReferenceError: foo is not defined + at evalmachine.:*:* + at Script.runInContext (node:vm:*) + at Script.runInNewContext (node:vm:*) + at Object.runInNewContext (node:vm:*) + at Object. (*test*message*undefined_reference_in_new_context.js:*) + +Node.js * diff --git a/test/message/util-inspect-error-cause.js b/test/fixtures/errors/util-inspect-error-cause.js similarity index 98% rename from test/message/util-inspect-error-cause.js rename to test/fixtures/errors/util-inspect-error-cause.js index ed9d8230fe0c40..f08c293db9ef95 100644 --- a/test/message/util-inspect-error-cause.js +++ b/test/fixtures/errors/util-inspect-error-cause.js @@ -1,6 +1,6 @@ 'use strict'; -require('../common'); +require('../../common'); const { inspect } = require('util'); diff --git a/test/fixtures/errors/util-inspect-error-cause.snapshot b/test/fixtures/errors/util-inspect-error-cause.snapshot new file mode 100644 index 00000000000000..73f0a673d76e1f --- /dev/null +++ b/test/fixtures/errors/util-inspect-error-cause.snapshot @@ -0,0 +1,181 @@ +Error: Number error cause + at * + at * + at * + at * + at * + at * + at * { + [cause]: 42 +} +Error: Object cause + 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 * { + [cause]: undefined +} +Error: cause that throws + 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 ... 4 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 + } +} +Error: Stack causes + at * +*[90m at *[39m +*[90m ... 4 lines matching cause stack trace ...*[39m +*[90m at *[39m { + [cause]: FoobarError: Individual message + at * + *[90m at *[39m + *[90m ... 4 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 + } +} +RangeError: New Stack Frames + at * +*[90m at *[39m { + [cause]: Error: Stack causes + at * + *[90m at *[39m + *[90m ... 4 lines matching cause stack trace ...*[39m + *[90m at *[39m { + [cause]: FoobarError: Individual message + at * + *[90m at *[39m + *[90m ... 4 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 + } + } +} +RangeError: New Stack Frames + at * + at * { + [cause]: FoobarError: Individual message + at * + at * + ... 4 lines matching cause stack trace ... + at * { + status: 'Feeling good', + extraProperties: 'Yes!', + [cause]: TypeError: Inner error + at * + at * + at * + at * + at * + at * + at * + } +} +Error: Stack causes + at * + at * + ... 4 lines matching cause stack trace ... + at * { + [cause]: FoobarError: Individual message + at * + at * + ... 4 lines matching cause stack trace ... + at * + status: 'Feeling good', + extraProperties: 'Yes!', + [cause]: TypeError: Inner error + at * + at * + at * + at * + at * + at * + at * + } +} +RangeError: New Stack Frames + at * + at * { + [cause]: Error: Stack causes + at * + at * + ... 4 lines matching cause stack trace ... + at * { + [cause]: FoobarError: Individual message + at * + at * + ... 4 lines matching cause stack trace ... + at * { + status: 'Feeling good', + extraProperties: 'Yes!', + [cause]: TypeError: Inner error + at * + at * + at * + at * + at * + at * + at * + } + } +} diff --git a/test/message/util_inspect_error.js b/test/fixtures/errors/util_inspect_error.js similarity index 92% rename from test/message/util_inspect_error.js rename to test/fixtures/errors/util_inspect_error.js index 20affd6c711fd8..ddec5e01a6ed16 100644 --- a/test/message/util_inspect_error.js +++ b/test/fixtures/errors/util_inspect_error.js @@ -1,6 +1,6 @@ 'use strict'; -require('../common'); +require('../../common'); const util = require('util'); const err = new Error('foo\nbar'); diff --git a/test/message/util_inspect_error.out b/test/fixtures/errors/util_inspect_error.snapshot similarity index 75% rename from test/message/util_inspect_error.out rename to test/fixtures/errors/util_inspect_error.snapshot index 644ccd58831ef7..cea1ec5419f2fd 100644 --- a/test/message/util_inspect_error.out +++ b/test/fixtures/errors/util_inspect_error.snapshot @@ -1,38 +1,38 @@ { err: Error: foo bar - at *util_inspect_error* at * at * at * at * at * at * + at node:internal*main*run_main_module:*:*, nested: { err: Error: foo bar - at *util_inspect_error* at * at * at * at * at * at * + at node:internal*main*run_main_module:*:* } } { err: Error: foo bar - at *util_inspect_error* at * at * at * at * at * at * + at node:internal*main*run_main_module:*:*, nested: { err: Error: foo bar - at *util_inspect_error* + at * at * at * at * @@ -43,7 +43,7 @@ } { Error: foo bar - at *util_inspect_error* + at * at * at * at * diff --git a/test/message/v8_warning.js b/test/fixtures/errors/v8_warning.js similarity index 89% rename from test/message/v8_warning.js rename to test/fixtures/errors/v8_warning.js index d7d1c5e7dbdff6..ab4d2bf305823f 100644 --- a/test/message/v8_warning.js +++ b/test/fixtures/errors/v8_warning.js @@ -1,6 +1,6 @@ 'use strict'; -require('../common'); +require('../../common'); function AsmModule() { 'use asm'; diff --git a/test/fixtures/errors/v8_warning.snapshot b/test/fixtures/errors/v8_warning.snapshot new file mode 100644 index 00000000000000..6c419c83cddf28 --- /dev/null +++ b/test/fixtures/errors/v8_warning.snapshot @@ -0,0 +1,2 @@ +(node:*) V8: *v8_warning.js:* Invalid asm.js: Invalid return type +(Use `* --trace-warnings ...` to show where the warning was created) diff --git a/test/message/source_map_reference_error_tabs.js b/test/fixtures/map/source_map_reference_error_tabs.js similarity index 53% rename from test/message/source_map_reference_error_tabs.js rename to test/fixtures/map/source_map_reference_error_tabs.js index fbe058a5f531bf..fbca02979e09fc 100644 --- a/test/message/source_map_reference_error_tabs.js +++ b/test/fixtures/map/source_map_reference_error_tabs.js @@ -1,7 +1,7 @@ // Flags: --enable-source-maps 'use strict'; -require('../common'); +require('../../common'); Error.stackTraceLimit = 2; -require('../fixtures/source-map/tabs.js'); +require('../source-map/tabs.js'); diff --git a/test/fixtures/map/source_map_reference_error_tabs.snapshot b/test/fixtures/map/source_map_reference_error_tabs.snapshot new file mode 100644 index 00000000000000..7bf2d13305ef12 --- /dev/null +++ b/test/fixtures/map/source_map_reference_error_tabs.snapshot @@ -0,0 +1,9 @@ +*tabs.coffee:26 + alert "I knew it!" + ^ + +ReferenceError: alert is not defined + at *tabs.coffee:26:2* + at *tabs.coffee:1:14* + +Node.js * diff --git a/test/message/source_map_sourcemapping_url_string.js b/test/fixtures/map/source_map_sourcemapping_url_string.js similarity index 61% rename from test/message/source_map_sourcemapping_url_string.js rename to test/fixtures/map/source_map_sourcemapping_url_string.js index 254d18bd080e53..a018ba4108aca5 100644 --- a/test/message/source_map_sourcemapping_url_string.js +++ b/test/fixtures/map/source_map_sourcemapping_url_string.js @@ -1,11 +1,11 @@ // Flags: --enable-source-maps 'use strict'; -require('../common'); +require('../../common'); Error.stackTraceLimit = 2; try { - require('../fixtures/source-map/typescript-sourcemapping_url_string'); + require('../source-map/typescript-sourcemapping_url_string'); } catch (err) { setTimeout(() => { console.info(err); diff --git a/test/fixtures/map/source_map_sourcemapping_url_string.snapshot b/test/fixtures/map/source_map_sourcemapping_url_string.snapshot new file mode 100644 index 00000000000000..3d0b6e15eb6c7a --- /dev/null +++ b/test/fixtures/map/source_map_sourcemapping_url_string.snapshot @@ -0,0 +1,3 @@ +Error: an exception. + at *typescript-sourcemapping_url_string.ts:3:7* + at Module._compile (node:internal/modules/cjs/loader:*) diff --git a/test/message/source_map_throw_catch.js b/test/fixtures/map/source_map_throw_catch.js similarity index 66% rename from test/message/source_map_throw_catch.js rename to test/fixtures/map/source_map_throw_catch.js index 603fa81867bcbe..21e1d07bb63eb6 100644 --- a/test/message/source_map_throw_catch.js +++ b/test/fixtures/map/source_map_throw_catch.js @@ -1,11 +1,11 @@ // Flags: --enable-source-maps 'use strict'; -require('../common'); +require('../../common'); Error.stackTraceLimit = 2; try { - require('../fixtures/source-map/typescript-throw'); + require('../source-map/typescript-throw'); } catch (err) { setTimeout(() => { console.info(err); diff --git a/test/fixtures/map/source_map_throw_catch.snapshot b/test/fixtures/map/source_map_throw_catch.snapshot new file mode 100644 index 00000000000000..f92614d1e4c696 --- /dev/null +++ b/test/fixtures/map/source_map_throw_catch.snapshot @@ -0,0 +1,4 @@ +reachable +Error: an exception + at * + at * diff --git a/test/message/source_map_throw_icu.js b/test/fixtures/map/source_map_throw_icu.js similarity index 54% rename from test/message/source_map_throw_icu.js rename to test/fixtures/map/source_map_throw_icu.js index 672c1575c6547a..0527e179d91f3c 100644 --- a/test/message/source_map_throw_icu.js +++ b/test/fixtures/map/source_map_throw_icu.js @@ -1,7 +1,7 @@ // Flags: --enable-source-maps 'use strict'; -require('../common'); +require('../../common'); Error.stackTraceLimit = 2; -require('../fixtures/source-map/icu'); +require('../source-map/icu'); diff --git a/test/fixtures/map/source_map_throw_icu.snapshot b/test/fixtures/map/source_map_throw_icu.snapshot new file mode 100644 index 00000000000000..6c658fcff88952 --- /dev/null +++ b/test/fixtures/map/source_map_throw_icu.snapshot @@ -0,0 +1,9 @@ +*icu.jsx:3 + ("*******", throw Error("an error")); + ^ + +Error: an error + at *icu.jsx:3:23* + at *icu.jsx:9:5* + +Node.js * diff --git a/test/fixtures/map/source_map_throw_set_immediate.js b/test/fixtures/map/source_map_throw_set_immediate.js new file mode 100644 index 00000000000000..bf7a65925d1ffc --- /dev/null +++ b/test/fixtures/map/source_map_throw_set_immediate.js @@ -0,0 +1,5 @@ +// Flags: --enable-source-maps + +'use strict'; +require('../common'); +require('../fixtures/source-map/uglify-throw'); \ No newline at end of file diff --git a/test/fixtures/map/source_map_throw_set_immediate.snapshot b/test/fixtures/map/source_map_throw_set_immediate.snapshot new file mode 100644 index 00000000000000..8ab76caad7bf3a --- /dev/null +++ b/test/fixtures/map/source_map_throw_set_immediate.snapshot @@ -0,0 +1,10 @@ +*uglify-throw-original.js:5 + throw Error('goodbye'); + ^ + +Error: goodbye + at Hello *uglify-throw-original.js:5:9* + at *uglify-throw-original.js:9:3* + at process.processImmediate (node:internal/timers:*) + +Node.js * \ No newline at end of file diff --git a/test/message/promise_unhandled_warn_with_error.js b/test/fixtures/promise/promise_unhandled_warn_with_error.js similarity index 88% rename from test/message/promise_unhandled_warn_with_error.js rename to test/fixtures/promise/promise_unhandled_warn_with_error.js index e07f52039101a3..b71757a259f04a 100644 --- a/test/message/promise_unhandled_warn_with_error.js +++ b/test/fixtures/promise/promise_unhandled_warn_with_error.js @@ -1,7 +1,7 @@ // Flags: --unhandled-rejections=warn-with-error-code 'use strict'; -require('../common'); +require('../../common'); const assert = require('assert'); Promise.reject(new Error('alas')); diff --git a/test/fixtures/promise/promise_unhandled_warn_with_error.snapshot b/test/fixtures/promise/promise_unhandled_warn_with_error.snapshot new file mode 100644 index 00000000000000..1a278646ac7462 --- /dev/null +++ b/test/fixtures/promise/promise_unhandled_warn_with_error.snapshot @@ -0,0 +1,10 @@ +*UnhandledPromiseRejectionWarning: Error: alas + at *promise_unhandled_warn_with_error.js:*:* + at * + at * + at * + at * + at * + at * +(Use `* --trace-warnings ...` to show where the warning was created) +*UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1) diff --git a/test/message/unhandled_promise_trace_warnings.js b/test/fixtures/promise/unhandled_promise_trace_warnings.js similarity index 86% rename from test/message/unhandled_promise_trace_warnings.js rename to test/fixtures/promise/unhandled_promise_trace_warnings.js index 66c1f39e5de091..53c5315a2dabfd 100644 --- a/test/message/unhandled_promise_trace_warnings.js +++ b/test/fixtures/promise/unhandled_promise_trace_warnings.js @@ -1,5 +1,5 @@ // Flags: --trace-warnings --unhandled-rejections=warn 'use strict'; -require('../common'); +require('../../common'); const p = Promise.reject(new Error('This was rejected')); setImmediate(() => p.catch(() => {})); diff --git a/test/fixtures/promise/unhandled_promise_trace_warnings.snapshot b/test/fixtures/promise/unhandled_promise_trace_warnings.snapshot new file mode 100644 index 00000000000000..a8717d0e13d1e4 --- /dev/null +++ b/test/fixtures/promise/unhandled_promise_trace_warnings.snapshot @@ -0,0 +1,26 @@ +(node:*) UnhandledPromiseRejectionWarning: Error: This was rejected + at * (*test*message*unhandled_promise_trace_warnings.js:*) + at * + at * + at * + at * + at * + at * + at * + at * + at * +(node:*) Error: This was rejected + at * (*test*message*unhandled_promise_trace_warnings.js:*) + at * + at * + at * + at * + at * + at * +(node:*) PromiseRejectionHandledWarning: Promise rejection was handled asynchronously (rejection id: 1) + at handledRejection (node:internal/process/promises:*) + at promiseRejectHandler (node:internal/process/promises:*) + at Promise.then * + at Promise.catch * + at Immediate. (*test*message*unhandled_promise_trace_warnings.js:*) + at * diff --git a/test/message/max_tick_depth.js b/test/fixtures/tick/max_tick_depth.js similarity index 98% rename from test/message/max_tick_depth.js rename to test/fixtures/tick/max_tick_depth.js index 15462157d2160d..2370fce0af9420 100644 --- a/test/message/max_tick_depth.js +++ b/test/fixtures/tick/max_tick_depth.js @@ -20,7 +20,7 @@ // USE OR OTHER DEALINGS IN THE SOFTWARE. 'use strict'; -require('../common'); +require('../../common'); process.maxTickDepth = 10; let i = 20; diff --git a/test/message/max_tick_depth.out b/test/fixtures/tick/max_tick_depth.snapshot similarity index 100% rename from test/message/max_tick_depth.out rename to test/fixtures/tick/max_tick_depth.snapshot diff --git a/test/message/nexttick_throw.js b/test/fixtures/tick/nexttick_throw.js similarity index 98% rename from test/message/nexttick_throw.js rename to test/fixtures/tick/nexttick_throw.js index d7e51b411eda64..3aaef64b9bfe7a 100644 --- a/test/message/nexttick_throw.js +++ b/test/fixtures/tick/nexttick_throw.js @@ -20,7 +20,7 @@ // USE OR OTHER DEALINGS IN THE SOFTWARE. 'use strict'; -require('../common'); +require('../../common'); process.nextTick(function() { process.nextTick(function() { diff --git a/test/fixtures/tick/nexttick_throw.snapshot b/test/fixtures/tick/nexttick_throw.snapshot new file mode 100644 index 00000000000000..929a4e2a89a00a --- /dev/null +++ b/test/fixtures/tick/nexttick_throw.snapshot @@ -0,0 +1,9 @@ +*test*message*nexttick_throw.js:* + undefined_reference_error_maker; + ^ + +ReferenceError: undefined_reference_error_maker is not defined + at *test*message*nexttick_throw.js:*:* + at process.processTicksAndRejections (node:internal/process/task_queues:*:*) + +Node.js * diff --git a/test/parallel/test-node-output-console.mjs b/test/parallel/test-node-output-console.mjs index 5a1b9feb6c8bed..87d18789bfe46e 100644 --- a/test/parallel/test-node-output-console.mjs +++ b/test/parallel/test-node-output-console.mjs @@ -11,27 +11,62 @@ function replaceStackTrace(str) { return snapshot.replaceStackTrace(str, '$1at *$7\n'); } +function replaceStackTraceCustom(str) { + return snapshot.replaceStackTrace(str, '$1$3 $4:$5:$6\n'); +} + describe('console output', { concurrency: true }, () => { function normalize(str) { - return str.replaceAll(snapshot.replaceWindowsPaths(process.cwd()), '').replaceAll('/', '*').replaceAll(process.version, '*').replaceAll(/\d+/g, '*'); + return str + .replaceAll(snapshot.replaceWindowsPaths(process.cwd()), '') + // .replaceAll('/', '*') + .replaceAll(process.version, '*') + .replaceAll(/\d+/g, '*'); } + + const common = snapshot.transform(snapshot.replaceWindowsLineEndings, snapshot.replaceWindowsPaths); + + const defaultTransform = snapshot.transform(common, replaceStackTrace); + + const normalizedTransform = snapshot.transform(common, replaceStackTrace, normalize); + + const noEvalMessagesTransform = snapshot.transform(common, replaceStackTraceCustom, (str) => { + return normalize(str) + .replaceAll('at *\n', '') + .replaceAll(' [eval]:*:', '[eval]:1') + .replaceAll(/\s{5}at\s/g, ' at ') + .replaceAll('^\n\n', '^\n') + .replaceAll('Strict mode code may not include a with statement', 'Strict mode code may not include a with statement\n') + .replaceAll(/\snode:vm:\*:\*(\n)?/g, ' (node:vm:*:*)\n') + .replaceAll('* at ', '*\n at ') + .replaceAll(/Script\s(node:internal\/process\/execution:\*:\*)/g, 'Script ($1)') + .replaceAll('Node.js *\n*\n*\n', 'Node.js *\n42\n42\n') + .replaceAll('Error: hello', '\nError: hello'); + }); + + const noMessagesTransform = snapshot.transform(common, replaceStackTraceCustom, (str) => { + return normalize(str) + .replaceAll(/\s\[stdin\]:\*:/g, '[stdin]:1') + .replaceAll(/\s{5}at\s/g, ' at ') + .replaceAll(' at [stdin]:1*\n', ' at [stdin]:1:7\n') + .replaceAll(' node:vm:*:*', ' (node:vm:*)'); + }); + const tests = [ { name: 'console/2100bytes.js' }, { name: 'console/console_low_stack_space.js' }, { name: 'console/console.js' }, + { name: 'console/core_line_numbers.js', transform: normalizedTransform }, + { name: 'console/eval_messages.js', transform: noEvalMessagesTransform }, { name: 'console/hello_world.js' }, - { - name: 'console/stack_overflow.js', - transform: snapshot - .transform(snapshot.replaceWindowsLineEndings, snapshot.replaceWindowsPaths, normalize) - }, + { name: 'console/stack_overflow.js', transform: normalizedTransform }, + { name: 'console/stdin_messages.js', transform: noMessagesTransform }, !skipForceColors ? { name: 'console/force_colors.js', env: { FORCE_COLOR: 1 } } : null, ].filter(Boolean); - const defaultTransform = snapshot - .transform(snapshot.replaceWindowsLineEndings, snapshot.replaceWindowsPaths, replaceStackTrace); - for (const { name, transform, env } of tests) { + + for (const { name, transform, tty = false, env } of tests) { it(name, async () => { - await snapshot.spawnAndAssert(fixtures.path(name), transform ?? defaultTransform, { env }); + await snapshot.spawnAndAssert(fixtures.path(name), transform ?? defaultTransform, { tty: tty }, { env }); }); } }); diff --git a/test/parallel/test-node-output-errors.mjs b/test/parallel/test-node-output-errors.mjs index fca2149fea3212..41a37ef9889d7b 100644 --- a/test/parallel/test-node-output-errors.mjs +++ b/test/parallel/test-node-output-errors.mjs @@ -9,28 +9,105 @@ const skipForceColors = process.config.variables.node_shared_openssl || (common.isWindows && (Number(os.release().split('.')[0]) !== 10 || Number(os.release().split('.')[2]) < 14393)); // See https://github.com/nodejs/node/pull/33132 - -function replaceNodeVersion(str) { - return str.replaceAll(process.version, '*'); +function removeSpecialCharacter(str) { + return str.replaceAll('', ''); } function replaceStackTrace(str) { - return snapshot.replaceStackTrace(str, '$1at *$7\n'); + return snapshot.replaceStackTrace(removeSpecialCharacter(str), '$1at *$7\n'); +} + +function replaceStackTraceCustom(str) { + return snapshot.replaceStackTrace(removeSpecialCharacter(str), '$1$3 $4:$5:$6*\n'); +} + +function replaceStackTrace2(str) { + return removeSpecialCharacter(str).replace(/(\s+)((.+?)\s+\()?(?:\(?(.+?):(\d+)(?::(\d+))?)\)?(\s+\{)?(\[\d+m)?(\n|$)?/g, '$1at *$7\n'); } describe('errors output', { concurrency: true }, () => { function normalize(str) { - return str.replaceAll(snapshot.replaceWindowsPaths(process.cwd()), '').replaceAll('//', '*').replaceAll(/\/(\w)/g, '*$1').replaceAll('*test*', '*').replaceAll('*fixtures*errors*', '*').replaceAll('file:**', 'file:*/'); + return str + .replaceAll(snapshot.replaceWindowsPaths(process.cwd()), '') + .replaceAll('/test/fixtures/errors/', '*') + .replaceAll(process.version, '*') + .replaceAll('/', '*') + .replace(/\(node:\d+\)/g, '(node:*)') + .replaceAll(' ** ', ' * ') + .replaceAll('*test*fixtures*', '*fixtures*') + .replaceAll('file:***', 'file:*/'); } function normalizeNoNumbers(str) { - return normalize(str).replaceAll(/\d+:\d+/g, '*:*').replaceAll(/:\d+/g, ':*').replaceAll('*fixtures*message*', '*'); + return normalize(str) + .replaceAll(/:\d+/g, ':*'); } - const common = snapshot - .transform(snapshot.replaceWindowsLineEndings, snapshot.replaceWindowsPaths); - const defaultTransform = snapshot.transform(common, normalize, replaceNodeVersion); - const errTransform = snapshot.transform(common, normalizeNoNumbers, replaceNodeVersion); - const promiseTransform = snapshot.transform(common, replaceStackTrace, normalizeNoNumbers, replaceNodeVersion); + + const common = snapshot.transform(snapshot.replaceWindowsLineEndings, snapshot.replaceWindowsPaths); + + const defaultTransform = snapshot.transform(common, normalize); + + const noNumberTransform = snapshot.transform(common, normalizeNoNumbers); + const noStackTraceTransform = snapshot.transform(common, replaceStackTrace, normalizeNoNumbers); + + const noFatalExceptionTransform = snapshot.transform(common, replaceStackTraceCustom, (str) => { + return normalize(str) + .replaceAll(/\*test-no-extra-info-on-fatal-exception.js:(\d+)(:\d+)?\*?\n/g, '*:$1$2\n') + .replaceAll(/(\*:\d+:\d+)\n/g, '($1)'); + }); + + const noGetterThrowTransform = snapshot.transform(common, replaceStackTrace, (str) => { + return normalize(str) + .replaceAll('Use `node --trace-uncaught', 'Use `* --trace-uncaught') + .replaceAll('Node.js *\n', 'Node.js *') + .replaceAll('[object Object]\n', 'null\n') + .replaceAll('at *\nthrow { * eslint-disable-line no-throw-literal\n', '*test*message*throw_null.js:*\nthrow null;\n'); + }); + + const noThrowNullTransform = snapshot.transform(common, replaceStackTrace, (str) => { + return normalize(str) + .replaceAll('Use `node --trace-uncaught', 'Use `* --trace-uncaught') + .replaceAll('at *\n', '*test*message*throw_null.js:*\n'); + }); + + const noThrowUndefinedTransform = snapshot.transform(common, replaceStackTrace, (str) => { + return normalize(str) + .replaceAll('Use `node --trace-uncaught', 'Use `* --trace-uncaught') + .replaceAll('at *\n', '*test*message*throw_undefined.js:*\n'); + }); + + const noTimeoutThrowTransform = snapshot.transform(common, replaceStackTraceCustom, (str) => { + return normalize(str) + .replaceAll('^\n\n', '^\n') + .replaceAll(/\*timeout_throw.js:\d+(:\d+)?/g, '*test*message*timeout_throw.js:*') + .replaceAll('_onTimeout *test*message*timeout_throw.js:**\n', '_onTimeout (*test*message*timeout_throw.js:*:*)\n') + .replaceAll(/node:internal\*timers:\d+:\d+\*\n/g, '(node:internal/timers:*:*)\n') + }); + + const noReferenceNewContextTransform = snapshot.transform(common, replaceStackTraceCustom, (str) => { + return normalize(str) + .replaceAll(/node:vm:\d+:\d+\*/g, '(node:vm:*)') + .replaceAll(/\s{5}at\sevalmachine.:\d+:\d+\*\n/g, ' at evalmachine.:*:*\n') + .replaceAll(/\sevalmachine.:(\d+):\*\n/g, 'evalmachine.:$1\n') + .replaceAll(/\*undefined_reference_in_new_context.js:\d+:\d+\*/g, '(*test*message*undefined_reference_in_new_context.js:*)'); + }); + + const noErrorCauseTransform = snapshot.transform(common, replaceStackTrace2, (str) => { + return normalize(str) + // .replaceAll(' at *\n', '') + .replaceAll('Error: Unique/n\' +\n at *\n\'\n', 'Error: Unique\\n\' +\n \' at Module._compile (node:internal/modules/cjs/loader:827:30)\'\n') + .replaceAll('[90m at *\n {\n', '[90m at [39m {\n') + .replaceAll(')[39m\n at *\n', ' [90m at [39m\n') + .replaceAll(/\)\[39m\n(:?\s*at\s\*\n)/g, '') + .replaceAll(/\[(\d+m)/g, '*[$1'); + }); + + const noV8WarningTransform = snapshot.transform(common, replaceStackTrace, (str) => { + return normalize(str) + .replaceAll('/', '*') + .replaceAll(/:\d+/g, ':*') + .replaceAll('`node --trace-warnings ...`', '`* --trace-warnings ...`'); + }); const tests = [ { name: 'errors/async_error_eval_cjs.js' }, @@ -39,22 +116,33 @@ describe('errors output', { concurrency: true }, () => { { name: 'errors/async_error_nexttick_main.js' }, { name: 'errors/async_error_sync_main.js' }, { name: 'errors/async_error_sync_esm.mjs' }, - { name: 'errors/error_aggregateTwoErrors.js', transform: errTransform }, - { name: 'errors/error_exit.js', transform: errTransform }, - { name: 'errors/error_with_nul.js', transform: errTransform }, - { name: 'errors/events_unhandled_error_common_trace.js', transform: errTransform }, - { name: 'errors/events_unhandled_error_nexttick.js', transform: errTransform }, - { name: 'errors/events_unhandled_error_sameline.js', transform: errTransform }, - { name: 'errors/events_unhandled_error_subclass.js', transform: errTransform }, - { name: 'errors/throw_custom_error.js', transform: errTransform }, - { name: 'errors/throw_in_line_with_tabs.js', transform: errTransform }, - { name: 'errors/throw_non_error.js', transform: errTransform }, - { name: 'errors/promise_always_throw_unhandled.js', transform: promiseTransform }, + { name: 'errors/error_aggregateTwoErrors.js', transform: noNumberTransform }, + { name: 'errors/error_exit.js', transform: noNumberTransform }, + { name: 'errors/error_with_nul.js', transform: noNumberTransform }, + { name: 'errors/events_unhandled_error_common_trace.js', transform: noNumberTransform }, + { name: 'errors/events_unhandled_error_nexttick.js', transform: noNumberTransform }, + { name: 'errors/events_unhandled_error_sameline.js', transform: noNumberTransform }, + { name: 'errors/events_unhandled_error_subclass.js', transform: noNumberTransform }, + { name: 'errors/throw_custom_error.js', transform: noNumberTransform }, + { name: 'errors/throw_in_line_with_tabs.js', transform: noNumberTransform }, + { name: 'errors/throw_non_error.js', transform: noNumberTransform }, + { name: 'errors/promise_always_throw_unhandled.js', transform: noStackTraceTransform }, + { name: 'errors/if-error-has-good-stack.js', transform: noNumberTransform }, + { name: 'errors/test-no-extra-info-on-fatal-exception.js', transform: noFatalExceptionTransform }, + { name: 'errors/throw_error_with_getter_throw.js', transform: noGetterThrowTransform }, + { name: 'errors/throw_null.js', transform: noThrowNullTransform }, + { name: 'errors/throw_undefined.js', transform: noThrowUndefinedTransform }, + { name: 'errors/timeout_throw.js', transform: noTimeoutThrowTransform }, + { name: 'errors/undefined_reference_in_new_context.js', transform: noReferenceNewContextTransform }, + { name: 'errors/util_inspect_error.js', transform: noStackTraceTransform }, + { name: 'errors/util-inspect-error-cause.js', transform: noErrorCauseTransform }, + { name: 'errors/v8_warning.js', transform: noV8WarningTransform }, !skipForceColors ? { name: 'errors/force_colors.js', env: { FORCE_COLOR: 1 } } : null, ].filter(Boolean); - for (const { name, transform, env } of tests) { + + for (const { name, transform, tty = false, env } of tests) { it(name, async () => { - await snapshot.spawnAndAssert(fixtures.path(name), transform ?? defaultTransform, { env }); + await snapshot.spawnAndAssert(fixtures.path(name), transform ?? defaultTransform, { tty: tty }, { env }); }); } }); diff --git a/test/parallel/test-output-assertion.mjs b/test/parallel/test-output-assertion.mjs new file mode 100644 index 00000000000000..723533a80627bc --- /dev/null +++ b/test/parallel/test-output-assertion.mjs @@ -0,0 +1,34 @@ +import '../common/index.mjs'; +import * as fixtures from '../common/fixtures.mjs'; +import * as snapshot from '../common/assertSnapshot.js'; +import { describe, it } from 'node:test'; + +function replaceStackTrace(str) { + return snapshot.replaceStackTrace(str, '$1at *$7\n'); +} + +describe('assertion output', { concurrency: true }, () => { + function normalize(str) { + return str + .replaceAll(snapshot.replaceWindowsPaths(process.cwd()), '') + .replaceAll('/', '*') + .replaceAll(process.version, '*') + .replaceAll(/:\d+/g, '*'); + } + + const common = snapshot + .transform(snapshot.replaceWindowsLineEndings, snapshot.replaceWindowsPaths); + const defaultTransform = snapshot.transform(common, replaceStackTrace, normalize); + + const tests = [ + { name: 'assertion/assert_throws_stack.js' }, + { name: 'assertion/internal_assert_fail.js' }, + { name: 'assertion/internal_assert.js' }, + ]; + + for (const { name, transform } of tests) { + it(name, async () => { + await snapshot.spawnAndAssert(fixtures.path(name), transform ?? defaultTransform); + }); + } +}); diff --git a/test/parallel/test-output-map.mjs b/test/parallel/test-output-map.mjs new file mode 100644 index 00000000000000..4bc7cadc683298 --- /dev/null +++ b/test/parallel/test-output-map.mjs @@ -0,0 +1,54 @@ +import '../common/index.mjs'; +import * as fixtures from '../common/fixtures.mjs'; +import * as snapshot from '../common/assertSnapshot.js'; +import { describe, it } from 'node:test'; + +function replaceStackTrace(str) { + return snapshot.replaceStackTrace(str, '$1at *$7\n'); +} + +function replaceStackTraceCustom(str) { + return snapshot.replaceStackTrace(str, '$1at $4:$5:$6*\n'); +} + +describe('map output', { concurrency: true }, () => { + function normalize(str) { + return str + .replaceAll(snapshot.replaceWindowsPaths(process.cwd()), '') + .replaceAll('/test/fixtures/source-map/', '*') + .replaceAll('\n\n', '\n') + .replaceAll('Node.js', '\nNode.js') + .replaceAll(process.version, '*'); + } + + const common = snapshot.transform(snapshot.replaceWindowsLineEndings, snapshot.replaceWindowsPaths); + + const defaultTransform = snapshot.transform(common, normalize); + + const noThrowCatchTransform = snapshot.transform(common, replaceStackTrace, normalize); + const noErrorTabsTransform = snapshot.transform(common, replaceStackTraceCustom, normalize); + + const noUrlStringTransform = snapshot.transform(common, replaceStackTraceCustom, (str) => { + return normalize(str) + .replace(/((node:internal\/modules\/cjs\/loader:)(\d+):(\d+)\*)/, 'Module._compile ($2*)'); + }); + + const noIcuTransform = snapshot.transform(common, replaceStackTraceCustom, (str) => { + const replacement = (match) => match.replace(/[^(\n|\r)]/g, '*'); + + return normalize(str) + .replace(/(?<=\(")[^"]+/, replacement); + }); + + const tests = [ + { name: 'map/source_map_reference_error_tabs.js', transform: noErrorTabsTransform }, + { name: 'map/source_map_sourcemapping_url_string.js', transform: noUrlStringTransform }, + { name: 'map/source_map_throw_catch.js', transform: noThrowCatchTransform }, + { name: 'map/source_map_throw_icu.js', transform: noIcuTransform } + ]; + for (const { name, transform } of tests) { + it(name, async () => { + await snapshot.spawnAndAssert(fixtures.path(name), transform ?? defaultTransform); + }); + } +}); diff --git a/test/parallel/test-output-promise.mjs b/test/parallel/test-output-promise.mjs new file mode 100644 index 00000000000000..266463d2c729e6 --- /dev/null +++ b/test/parallel/test-output-promise.mjs @@ -0,0 +1,47 @@ +import '../common/index.mjs'; +import * as fixtures from '../common/fixtures.mjs'; +import * as snapshot from '../common/assertSnapshot.js'; +import { describe, it } from 'node:test'; + +function replaceStackTrace(str) { + return snapshot.replaceStackTrace(str, '$1at *$7\n'); +} + +describe('map output', { concurrency: true }, () => { + function normalize(str) { + return str + .replaceAll(snapshot.replaceWindowsPaths(process.cwd()), '') + .replaceAll(process.version, '*') + .replace(/\(node:\d+\)/g, '(node:*)'); + } + + const common = snapshot.transform(snapshot.replaceWindowsLineEndings, snapshot.replaceWindowsPaths); + + const defaultTransform = snapshot.transform(common, replaceStackTrace, normalize); + + const noTraceWarnings = snapshot.transform(common, replaceStackTrace, (str) => { + return normalize(str) + .replaceAll( + '(rejection id: 1)\n at *\n at *\n at Promise.then ()\n at Promise.catch ()\n at *\n', + '(rejection id: 1)\n at handledRejection (node:internal/process/promises:*)\n at promiseRejectHandler (node:internal/process/promises:*)\n at Promise.then *\n at Promise.catch *\n at Immediate. (*test*message*unhandled_promise_trace_warnings.js:*)\n') + .replaceAll('This was rejected\n at *\n', 'This was rejected\n at * (*test*message*unhandled_promise_trace_warnings.js:*)\n') + }); + + const noWarnWithError = snapshot.transform(common, replaceStackTrace, (str) => { + return normalize(str) + .replaceAll('(node:*) ', '*') + .replaceAll('Use `node --trace-warnings', 'Use `* --trace-warnings') + .replaceAll('alas\n at *\n', 'alas\n at *promise_unhandled_warn_with_error.js:*:*\n'); + }); + + const tests = [ + { name: 'promise/promise_unhandled_warn_with_error.js', transform: noWarnWithError }, + { name: 'promise/unhandled_promise_trace_warnings.js', transform: noTraceWarnings }, + ]; + + for (const { name, transform } of tests) { + it(name, async () => { + await snapshot.spawnAndAssert(fixtures.path(name), transform ?? defaultTransform); + }); + } +}); diff --git a/test/parallel/test-output-tick.mjs b/test/parallel/test-output-tick.mjs new file mode 100644 index 00000000000000..d9850da8fe6fea --- /dev/null +++ b/test/parallel/test-output-tick.mjs @@ -0,0 +1,30 @@ +import '../common/index.mjs'; +import * as fixtures from '../common/fixtures.mjs'; +import * as snapshot from '../common/assertSnapshot.js'; +import { describe, it } from 'node:test'; + +describe('map output', { concurrency: true }, () => { + function normalize(str) { + return str + .replaceAll(snapshot.replaceWindowsPaths(process.cwd()), '') + .replaceAll('/test/fixtures/tick/', '*test*message*') + .replaceAll(process.version, '*') + .replaceAll(/\d+/g, '*'); + } + + const common = snapshot.transform(snapshot.replaceWindowsLineEndings, snapshot.replaceWindowsPaths); + + const defaultTransform = snapshot.transform(common); + const noNextTickThrowTransform = snapshot.transform(common, normalize); + + const tests = [ + { name: 'tick/max_tick_depth.js' }, + { name: 'tick/nexttick_throw.js', transform: noNextTickThrowTransform }, + ]; + + for (const { name, transform } of tests) { + it(name, async () => { + await snapshot.spawnAndAssert(fixtures.path(name), transform ?? defaultTransform); + }); + } +});