From 2df37deb7eadedfdaa8f6eaf558db8c4e60668e3 Mon Sep 17 00:00:00 2001 From: upx Date: Thu, 18 May 2023 12:56:27 -0700 Subject: [PATCH 1/3] test: migrate message tests to js fixtures squashed test: migrate message tests to js fixtures squashed Add test runners to /parallel dir and fix snapshot Update test/parallel/test-node-output-tick.mjs Co-authored-by: Moshe Atlow Update test/parallel/test-node-output-promise.mjs Co-authored-by: Moshe Atlow Update test/parallel/test-node-output-assertion.mjs Co-authored-by: Moshe Atlow Update test/parallel/test-node-output-map.mjs Co-authored-by: Moshe Atlow fixed snapshot discrepancy with output-errors.mjs Corrected test runner name prefix Removing snapshots that show as 'new' on git diff Restored deleted files Deleted files restored --- BUILDING.md | 8 ++-- .../assertion}/assert_throws_stack.js | 2 +- .../assertion/assert_throws_stack.snapshot} | 13 +++--- .../assertion}/internal_assert.js | 2 +- .../assertion/internal_assert.snapshot} | 10 ++-- .../assertion}/internal_assert_fail.js | 2 +- .../assertion/internal_assert_fail.snapshot} | 10 ++-- .../console}/core_line_numbers.js | 2 +- .../console}/eval_messages.js | 2 +- .../console}/stdin_messages.js | 2 +- .../errors}/if-error-has-good-stack.js | 2 +- .../errors/if-error-has-good-stack.snapshot} | 2 +- .../test-no-extra-info-on-fatal-exception.js | 2 +- .../errors}/throw_error_with_getter_throw.js | 4 +- .../errors}/throw_null.js | 2 +- .../errors}/throw_undefined.js | 2 +- .../errors}/timeout_throw.js | 2 +- .../undefined_reference_in_new_context.js | 2 +- .../errors}/util-inspect-error-cause.js | 2 +- .../errors}/util_inspect_error.js | 2 +- .../errors/util_inspect_error.snapshot} | 10 ++-- .../errors}/v8_warning.js | 2 +- .../map/source_map_enclosing_function.js | 7 +++ .../source_map_enclosing_function.snapshot} | 1 + .../map}/source_map_reference_error_tabs.js | 4 +- .../source_map_sourcemapping_url_string.js | 4 +- .../map}/source_map_throw_catch.js | 4 +- .../map}/source_map_throw_icu.js | 4 +- .../map/source_map_throw_set_immediate.js | 5 ++ .../promise_unhandled_warn_with_error.js | 2 +- .../unhandled_promise_trace_warnings.js | 2 +- .../tick}/max_tick_depth.js | 2 +- .../tick/max_tick_depth.snapshot} | 0 .../tick}/nexttick_throw.js | 2 +- test/parallel/test-node-output-console.mjs | 26 +++++++++-- test/parallel/test-node-output-errors.mjs | 19 ++++++-- test/parallel/test-output-assertion.mjs | 36 +++++++++++++++ test/parallel/test-output-map.mjs | 46 +++++++++++++++++++ test/parallel/test-output-promise.mjs | 35 ++++++++++++++ test/parallel/test-output-tick.mjs | 36 +++++++++++++++ 40 files changed, 262 insertions(+), 60 deletions(-) rename test/{message => fixtures/assertion}/assert_throws_stack.js (82%) rename test/{message/assert_throws_stack.out => fixtures/assertion/assert_throws_stack.snapshot} (62%) rename test/{message => fixtures/assertion}/internal_assert.js (80%) rename test/{message/internal_assert.out => fixtures/assertion/internal_assert.snapshot} (52%) rename test/{message => fixtures/assertion}/internal_assert_fail.js (82%) rename test/{message/internal_assert_fail.out => fixtures/assertion/internal_assert_fail.snapshot} (52%) rename test/{message => fixtures/console}/core_line_numbers.js (95%) rename test/{message => fixtures/console}/eval_messages.js (98%) rename test/{message => fixtures/console}/stdin_messages.js (98%) rename test/{message => fixtures/errors}/if-error-has-good-stack.js (93%) rename test/{message/if-error-has-good-stack.out => fixtures/errors/if-error-has-good-stack.snapshot} (94%) rename test/{message => fixtures/errors}/test-no-extra-info-on-fatal-exception.js (81%) rename test/{message => fixtures/errors}/throw_error_with_getter_throw.js (87%) rename test/{message => fixtures/errors}/throw_null.js (97%) rename test/{message => fixtures/errors}/throw_undefined.js (97%) rename test/{message => fixtures/errors}/timeout_throw.js (98%) rename test/{message => fixtures/errors}/undefined_reference_in_new_context.js (98%) rename test/{message => fixtures/errors}/util-inspect-error-cause.js (98%) rename test/{message => fixtures/errors}/util_inspect_error.js (92%) rename test/{message/util_inspect_error.out => fixtures/errors/util_inspect_error.snapshot} (75%) rename test/{message => fixtures/errors}/v8_warning.js (89%) create mode 100644 test/fixtures/map/source_map_enclosing_function.js rename test/{message/source_map_enclosing_function.out => fixtures/map/source_map_enclosing_function.snapshot} (99%) rename test/{message => fixtures/map}/source_map_reference_error_tabs.js (53%) rename test/{message => fixtures/map}/source_map_sourcemapping_url_string.js (61%) rename test/{message => fixtures/map}/source_map_throw_catch.js (66%) rename test/{message => fixtures/map}/source_map_throw_icu.js (54%) create mode 100644 test/fixtures/map/source_map_throw_set_immediate.js rename test/{message => fixtures/promise}/promise_unhandled_warn_with_error.js (88%) rename test/{message => fixtures/promise}/unhandled_promise_trace_warnings.js (86%) rename test/{message => fixtures/tick}/max_tick_depth.js (98%) rename test/{message/max_tick_depth.out => fixtures/tick/max_tick_depth.snapshot} (100%) rename test/{message => fixtures/tick}/nexttick_throw.js (98%) create mode 100644 test/parallel/test-output-assertion.mjs create mode 100644 test/parallel/test-output-map.mjs create mode 100644 test/parallel/test-output-promise.mjs create mode 100644 test/parallel/test-output-tick.mjs 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 62% rename from test/message/assert_throws_stack.out rename to test/fixtures/assertion/assert_throws_stack.snapshot index 06eaa906442440..f743d8ced635b7 100644 --- a/test/message/assert_throws_stack.out +++ b/test/fixtures/assertion/assert_throws_stack.snapshot @@ -9,7 +9,8 @@ AssertionError [ERR_ASSERTION]: Expected values to be strictly deep-equal: - Comparison { - bar: true - } - at Object. (*assert_throws_stack.js:*:*) + at * + at * at * at * at * @@ -19,16 +20,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..719ce3ebccfd41 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..643cff076e3453 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/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/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/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/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/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/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/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/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/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/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/map/source_map_enclosing_function.js b/test/fixtures/map/source_map_enclosing_function.js new file mode 100644 index 00000000000000..cf67a62d505fa1 --- /dev/null +++ b/test/fixtures/map/source_map_enclosing_function.js @@ -0,0 +1,7 @@ +// Flags: --enable-source-maps + +'use strict'; +require('../../common'); +Error.stackTraceLimit = 5; + +require('../source-map/enclosing-call-site-min.js'); diff --git a/test/message/source_map_enclosing_function.out b/test/fixtures/map/source_map_enclosing_function.snapshot similarity index 99% rename from test/message/source_map_enclosing_function.out rename to test/fixtures/map/source_map_enclosing_function.snapshot index 5bb920e7eba42a..976cd4fdbbc6e9 100644 --- a/test/message/source_map_enclosing_function.out +++ b/test/fixtures/map/source_map_enclosing_function.snapshot @@ -2,6 +2,7 @@ throw err ^ + Error: an error! at functionD (*enclosing-call-site.js:16:17) at functionC (*enclosing-call-site.js:10:3) 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/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/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/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_set_immediate.js b/test/fixtures/map/source_map_throw_set_immediate.js new file mode 100644 index 00000000000000..44c8591366f245 --- /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('../source-map/uglify-throw'); 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/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/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/parallel/test-node-output-console.mjs b/test/parallel/test-node-output-console.mjs index 5a1b9feb6c8bed..b3b8fd23b12598 100644 --- a/test/parallel/test-node-output-console.mjs +++ b/test/parallel/test-node-output-console.mjs @@ -13,25 +13,45 @@ function replaceStackTrace(str) { 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, '*').replaceAll('[*m', ''); } const tests = [ { name: 'console/2100bytes.js' }, { name: 'console/console_low_stack_space.js' }, { name: 'console/console.js' }, + { name: 'console/core_line_numbers.js', + transform: snapshot + .transform(snapshot.replaceWindowsLineEndings, snapshot.replaceWindowsPaths, normalize), + tty: true + }, + { name: 'console/eval_messages.js', + transform: snapshot + .transform(snapshot.replaceWindowsLineEndings, snapshot.replaceWindowsPaths, normalize), + tty: true + }, { name: 'console/hello_world.js' }, { name: 'console/stack_overflow.js', transform: snapshot .transform(snapshot.replaceWindowsLineEndings, snapshot.replaceWindowsPaths, normalize) }, + { name: 'console/stdin_messages.js', + transform: snapshot + .transform(snapshot.replaceWindowsLineEndings, snapshot.replaceWindowsPaths, normalize), + tty: true + }, + { name: 'console/stdin_messages.js', + transform: snapshot + .transform(snapshot.replaceWindowsLineEndings, snapshot.replaceWindowsPaths, replaceNodeVersion, stackTrace), + tty: true + }, !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..5ea05ce0fd80e3 100644 --- a/test/parallel/test-node-output-errors.mjs +++ b/test/parallel/test-node-output-errors.mjs @@ -22,15 +22,18 @@ 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:*/'); } - function normalizeNoNumbers(str) { return normalize(str).replaceAll(/\d+:\d+/g, '*:*').replaceAll(/:\d+/g, ':*').replaceAll('*fixtures*message*', '*'); } + function normalizeCustom(str) { + return normalizeNoNumbers(str).replaceAll(/\d+/g, '*').replaceAll('[*m', ''); + } 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 customTransform = snapshot.transform(common, replaceStackTrace, normalizeCustom); const tests = [ { name: 'errors/async_error_eval_cjs.js' }, @@ -50,11 +53,21 @@ describe('errors output', { concurrency: true }, () => { { 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/if-error-has-good-stack.js', transform: errTransform, tty: false }, + { name: 'errors/test-no-extra-info-on-fatal-exception.js', transform: errTransform, tty: false }, + { name: 'errors/throw_error_with_getter_throw.js', transform: errTransform, tty: true }, + { name: 'errors/throw_null.js', transform: errTransform, tty: true }, + { name: 'errors/throw_undefined.js', transform: errTransform, tty: true }, + { name: 'errors/timeout_throw.js', transform: errTransform, tty: false }, + { name: 'errors/undefined_reference_in_new_context.js', transform: errTransform, tty: false }, + { name: 'errors/util_inspect_error.js', transform: customTransform, tty: true }, + { name: 'errors/util-inspect-error-cause.js', transform: customTransform, tty: true }, + { name: 'errors/v8_warning.js', transform: errTransform, tty: true }, !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..78613be516e6e1 --- /dev/null +++ b/test/parallel/test-output-assertion.mjs @@ -0,0 +1,36 @@ +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 replaceNodeVersion(str) { + return str.replaceAll(process.version, '*'); +} + +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(/\/(\w)/g, '*$1').replaceAll('*test*', '*').replaceAll('*fixtures*assertion*', '*').replaceAll('file:**', 'file:*/'); + } + + function normalizeNoNumbers(str) { + return normalize(str).replaceAll(/\d+:\d+/g, '*:*').replaceAll(/:\d+/g, ':*').replaceAll('*fixtures*message*', '*'); + } + const common = snapshot + .transform(snapshot.replaceWindowsLineEndings, snapshot.replaceWindowsPaths, replaceNodeVersion); + const defaultTransform = snapshot.transform(common, normalize); + const customTransform = snapshot.transform(common, replaceStackTrace, normalizeNoNumbers); + const tests = [ + { name: 'assertion/assert_throws_stack.js', transform: customTransform }, + { name: 'assertion/internal_assert_fail.js', transform: customTransform }, + { name: 'assertion/internal_assert.js', transform: customTransform }, + ]; + for (const { name, transform } of tests) { + it(name, async () => { + await snapshot.spawnAndAssert(fixtures.path(name), transform ?? defaultTransform, { tty: true }); + }); + } +}); diff --git a/test/parallel/test-output-map.mjs b/test/parallel/test-output-map.mjs new file mode 100644 index 00000000000000..16aa354aefe100 --- /dev/null +++ b/test/parallel/test-output-map.mjs @@ -0,0 +1,46 @@ +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 replaceNodeVersion(str) { + return str.replaceAll(process.version, '*'); +} + +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('//', '*').replaceAll(/\/(\w)/g, '*$1').replaceAll('*test*', '*').replaceAll('*fixtures*source-map*', '*').replaceAll('file:**', 'file:*/'); + } + + function normalizeNoNumbers(str) { + return normalize(str).replaceAll(/\d+:\d+/g, '*:*').replaceAll(/:\d+/g, ':*').replaceAll('*fixtures*source-map*', '*'); + } + function normalizeSpecialCharacters(str) { + const replacement = (match) => match.replace(/./g, '*').replace(/\s\*/g, ''); + return normalizeNoNumbers(str).replace(/(?<=\(")[^"]+/, replacement); + } + const common = snapshot + .transform(snapshot.replaceWindowsLineEndings, snapshot.replaceWindowsPaths, replaceNodeVersion); + const defaultTransform = snapshot.transform(common, normalize); + const noNumTransform = snapshot.transform(common, normalizeNoNumbers); + const customTransform = snapshot.transform(common, replaceStackTrace, normalizeNoNumbers); + const specialTransform = snapshot.transform(common, replaceStackTrace, normalizeSpecialCharacters); + + const tests = [ + { name: 'map/source_map_enclosing_function.js' }, + { name: 'map/source_map_reference_error_tabs.js' }, + { name: 'map/source_map_sourcemapping_url_string.js', transform: noNumTransform }, + { name: 'map/source_map_throw_catch.js', transform: customTransform }, + { name: 'map/source_map_throw_icu.js', transform: specialTransform }, + { name: 'map/source_map_throw_set_immediate.js', transform: customTransform }, + ]; + for (const { name, transform } of tests) { + it(name, async () => { + await snapshot.spawnAndAssert(fixtures.path(name), transform ?? defaultTransform, { tty: true }); + }); + } +}); diff --git a/test/parallel/test-output-promise.mjs b/test/parallel/test-output-promise.mjs new file mode 100644 index 00000000000000..a93776594dfbfd --- /dev/null +++ b/test/parallel/test-output-promise.mjs @@ -0,0 +1,35 @@ +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 replaceNodeVersion(str) { + return str.replaceAll(process.version, '*'); +} + +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('//', '*').replaceAll(/\/(\w)/g, '*$1').replaceAll('*test*', '*').replaceAll('*fixtures*source-map*', '*').replaceAll('file:**', 'file:*/'); + } + + function normalizeNoNumbers(str) { + return normalize(str).replaceAll(/\d+:\d+/g, '*:*').replaceAll(/:\d+/g, ':*').replaceAll('*fixtures*source-map*', '*'); + } + const common = snapshot + .transform(snapshot.replaceWindowsLineEndings, snapshot.replaceWindowsPaths, replaceNodeVersion); + const defaultTransform = snapshot.transform(common, replaceStackTrace, normalizeNoNumbers); + + const tests = [ + { name: 'promise/promise_unhandled_warn_with_error.js' }, + { name: 'promise/unhandled_promise_trace_warnings.js' }, + ]; + for (const { name, transform } of tests) { + it(name, async () => { + await snapshot.spawnAndAssert(fixtures.path(name), transform ?? defaultTransform, { tty: true }); + }); + } +}); diff --git a/test/parallel/test-output-tick.mjs b/test/parallel/test-output-tick.mjs new file mode 100644 index 00000000000000..c9672923101626 --- /dev/null +++ b/test/parallel/test-output-tick.mjs @@ -0,0 +1,36 @@ +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 replaceNodeVersion(str) { + return str.replaceAll(process.version, '*'); +} + +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('//', '*').replaceAll(/\/(\w)/g, '*$1').replaceAll('*test*', '*').replaceAll('*fixtures*source-map*', '*').replaceAll('file:**', 'file:*/'); + } + + function normalizeNoNumbers(str) { + return normalize(str).replaceAll(/\d+:\d+/g, '*:*').replaceAll(/:\d+/g, ':*').replaceAll('*fixtures*source-map*', '*'); + } + const common = snapshot + .transform(snapshot.replaceWindowsLineEndings, snapshot.replaceWindowsPaths, replaceNodeVersion); + const defaultTransform = snapshot.transform(common); + const customTransform = snapshot.transform(common, replaceStackTrace, normalizeNoNumbers); + + const tests = [ + { name: 'tick/max_tick_depth.js' }, + { name: 'tick/nexttick_throw.js', transform: customTransform }, + ]; + for (const { name, transform } of tests) { + it(name, async () => { + await snapshot.spawnAndAssert(fixtures.path(name), transform ?? defaultTransform, { tty: true }); + }); + } +}); From b91a25782ca0d4f3e256d24823aadb4464209796 Mon Sep 17 00:00:00 2001 From: upx Date: Tue, 23 May 2023 18:17:51 -0700 Subject: [PATCH 2/3] Fix to tests and missing snapshots --- .../assertion/assert_throws_stack.snapshot | 5 +- .../assertion/internal_assert.snapshot | 4 +- .../assertion/internal_assert_fail.snapshot | 4 +- .../console/core_line_numbers.snapshot | 10 + test/fixtures/console/eval_messages.snapshot | 81 ++++++++ test/fixtures/console/force_colors.snapshot | 2 +- test/fixtures/console/stack_overflow.snapshot | 2 +- test/fixtures/console/stdin_messages.snapshot | 89 +++++++++ test/fixtures/errors/force_colors.snapshot | 14 +- ...-no-extra-info-on-fatal-exception.snapshot | 6 + .../throw_error_with_getter_throw.snapshot | 8 + test/fixtures/errors/throw_null.snapshot | 8 + test/fixtures/errors/throw_undefined.snapshot | 8 + test/fixtures/errors/timeout_throw.snapshot | 10 + ...ndefined_reference_in_new_context.snapshot | 13 ++ .../errors/util-inspect-error-cause.snapshot | 181 ++++++++++++++++++ test/fixtures/errors/v8_warning.snapshot | 2 + .../map/source_map_enclosing_function.js | 7 - .../source_map_reference_error_tabs.snapshot | 10 + ...urce_map_sourcemapping_url_string.snapshot | 3 + .../map/source_map_throw_catch.snapshot | 4 + .../map/source_map_throw_icu.snapshot | 10 + .../source_map_throw_set_immediate.snapshot | 10 + ...promise_unhandled_warn_with_error.snapshot | 10 + .../unhandled_promise_trace_warnings.snapshot | 26 +++ test/fixtures/tick/nexttick_throw.snapshot | 9 + .../source_map_enclosing_function.out} | 1 - test/parallel/test-node-output-console.mjs | 44 ++--- test/parallel/test-node-output-errors.mjs | 72 +++---- test/parallel/test-output-assertion.mjs | 28 ++- test/parallel/test-output-map.mjs | 40 ++-- test/parallel/test-output-promise.mjs | 20 +- test/parallel/test-output-tick.mjs | 21 +- 33 files changed, 617 insertions(+), 145 deletions(-) create mode 100644 test/fixtures/console/core_line_numbers.snapshot create mode 100644 test/fixtures/console/eval_messages.snapshot create mode 100644 test/fixtures/console/stdin_messages.snapshot create mode 100644 test/fixtures/errors/test-no-extra-info-on-fatal-exception.snapshot create mode 100644 test/fixtures/errors/throw_error_with_getter_throw.snapshot create mode 100644 test/fixtures/errors/throw_null.snapshot create mode 100644 test/fixtures/errors/throw_undefined.snapshot create mode 100644 test/fixtures/errors/timeout_throw.snapshot create mode 100644 test/fixtures/errors/undefined_reference_in_new_context.snapshot create mode 100644 test/fixtures/errors/util-inspect-error-cause.snapshot create mode 100644 test/fixtures/errors/v8_warning.snapshot delete mode 100644 test/fixtures/map/source_map_enclosing_function.js create mode 100644 test/fixtures/map/source_map_reference_error_tabs.snapshot create mode 100644 test/fixtures/map/source_map_sourcemapping_url_string.snapshot create mode 100644 test/fixtures/map/source_map_throw_catch.snapshot create mode 100644 test/fixtures/map/source_map_throw_icu.snapshot create mode 100644 test/fixtures/map/source_map_throw_set_immediate.snapshot create mode 100644 test/fixtures/promise/promise_unhandled_warn_with_error.snapshot create mode 100644 test/fixtures/promise/unhandled_promise_trace_warnings.snapshot create mode 100644 test/fixtures/tick/nexttick_throw.snapshot rename test/{fixtures/map/source_map_enclosing_function.snapshot => message/source_map_enclosing_function.out} (99%) diff --git a/test/fixtures/assertion/assert_throws_stack.snapshot b/test/fixtures/assertion/assert_throws_stack.snapshot index f743d8ced635b7..ebd3517dd74a48 100644 --- a/test/fixtures/assertion/assert_throws_stack.snapshot +++ b/test/fixtures/assertion/assert_throws_stack.snapshot @@ -1,4 +1,4 @@ -node:assert:* +node:assert* throw err; ^ @@ -15,7 +15,6 @@ AssertionError [ERR_ASSERTION]: Expected values to be strictly deep-equal: at * at * at * - at * at * { generatedMessage: true, code: 'ERR_ASSERTION', @@ -29,7 +28,7 @@ AssertionError [ERR_ASSERTION]: Expected values to be strictly deep-equal: at * at * at * - at node:internal*main*run_main_module:*:*, + at node:internal*main*run_main_module**, expected: { bar: true }, operator: 'throws' } diff --git a/test/fixtures/assertion/internal_assert.snapshot b/test/fixtures/assertion/internal_assert.snapshot index 719ce3ebccfd41..3b60a41ffc4f0c 100644 --- a/test/fixtures/assertion/internal_assert.snapshot +++ b/test/fixtures/assertion/internal_assert.snapshot @@ -1,9 +1,9 @@ -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 * at * diff --git a/test/fixtures/assertion/internal_assert_fail.snapshot b/test/fixtures/assertion/internal_assert_fail.snapshot index 643cff076e3453..6821e0007dac80 100644 --- a/test/fixtures/assertion/internal_assert_fail.snapshot +++ b/test/fixtures/assertion/internal_assert_fail.snapshot @@ -1,10 +1,10 @@ -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 * at * diff --git a/test/fixtures/console/core_line_numbers.snapshot b/test/fixtures/console/core_line_numbers.snapshot new file mode 100644 index 00000000000000..899c9e00302256 --- /dev/null +++ b/test/fixtures/console/core_line_numbers.snapshot @@ -0,0 +1,10 @@ +node:punycode:* + throw new RangeError(errors[type]); + ^ + +RangeError: Invalid input + at * + at * + at * + +Node.js * diff --git a/test/fixtures/console/eval_messages.snapshot b/test/fixtures/console/eval_messages.snapshot new file mode 100644 index 00000000000000..0d12777cb5aac4 --- /dev/null +++ b/test/fixtures/console/eval_messages.snapshot @@ -0,0 +1,81 @@ +[eval] +at * +with(this){__filename} +^^^^ + +SyntaxError: Strict mode code may not include a with statement + at * + at * + at * + at * + at * + at * + at * + at * + +Node.js * +* +* +at * +throw new Error("hello") +^ + +Error: hello + at * + at * + at * + at * + at * + at * + at * + at * + +Node.js * +at * +throw new Error("hello") +^ + +Error: hello + at * + at * + at * + at * + at * + at * + at * + at * + +Node.js * +* +at * +var x = *; y = x; + ^ + +ReferenceError: y is not defined + at * + at * + at * + at * + at * + at * + at * + at * + +Node.js * + +at * +var ______________________________________________; throw * + ^ +* +(Use `node --trace-uncaught ...` to show where the exception was thrown) + +Node.js * + +at * +var ______________________________________________; throw * + ^ +* +(Use `node --trace-uncaught ...` to show where the exception was thrown) + +Node.js * +done 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/fixtures/console/stdin_messages.snapshot b/test/fixtures/console/stdin_messages.snapshot new file mode 100644 index 00000000000000..1d896c3abc6ffc --- /dev/null +++ b/test/fixtures/console/stdin_messages.snapshot @@ -0,0 +1,89 @@ +[stdin] +at * +with(this){__filename} +^^^^ + +SyntaxError: Strict mode code may not include a with statement + at * + at * + at * + at * + at * + at * + at * + at * + at * + at * + +Node.js * +* +* +at * +throw new Error("hello") +^ + +Error: hello + at * + at * + at * + at * + at * + at * + at * + at * + at * + at * + +Node.js * +at * +throw new Error("hello") +^ + +Error: hello + at * + at * + at * + at * + at * + at * + at * + at * + at * + at * + +Node.js * +* +at * +let x = *; y = x; + ^ + +ReferenceError: y is not defined + at * + at * + at * + at * + at * + at * + at * + at * + at * + at * + +Node.js * + +at * +let ______________________________________________; throw * + ^ +* +(Use `node --trace-uncaught ...` to show where the exception was thrown) + +Node.js * + +at * +let ______________________________________________; throw * + ^ +* +(Use `node --trace-uncaught ...` to show where the exception was thrown) + +Node.js * +done 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/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..a6a251ff95d770 --- /dev/null +++ b/test/fixtures/errors/test-no-extra-info-on-fatal-exception.snapshot @@ -0,0 +1,6 @@ +*test-no-extra-info-on-fatal-exception.js:* +throw new Error('foo'); +^ + +Error: foo + at * 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..b933657bfe677e --- /dev/null +++ b/test/fixtures/errors/throw_error_with_getter_throw.snapshot @@ -0,0 +1,8 @@ + +at * +throw { * eslint-disable-line no-throw-literal +^ +[object Object] +(Use `node --trace-uncaught ...` to show where the exception was thrown) + +Node.js * diff --git a/test/fixtures/errors/throw_null.snapshot b/test/fixtures/errors/throw_null.snapshot new file mode 100644 index 00000000000000..3e9499ef959334 --- /dev/null +++ b/test/fixtures/errors/throw_null.snapshot @@ -0,0 +1,8 @@ + +at * +throw null; +^ +null +(Use `node --trace-uncaught ...` to show where the exception was thrown) + +Node.js * diff --git a/test/fixtures/errors/throw_undefined.snapshot b/test/fixtures/errors/throw_undefined.snapshot new file mode 100644 index 00000000000000..5bb1b424dfcd01 --- /dev/null +++ b/test/fixtures/errors/throw_undefined.snapshot @@ -0,0 +1,8 @@ + +at * +throw undefined; +^ +undefined +(Use `node --trace-uncaught ...` to show where the exception was thrown) + +Node.js * diff --git a/test/fixtures/errors/timeout_throw.snapshot b/test/fixtures/errors/timeout_throw.snapshot new file mode 100644 index 00000000000000..866b020ae298c0 --- /dev/null +++ b/test/fixtures/errors/timeout_throw.snapshot @@ -0,0 +1,10 @@ +*timeout_throw.js:* + undefined_reference_error_maker; + ^ + +ReferenceError: undefined_reference_error_maker is not defined + at * + at * + at * + +Node.js * 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..f9321748511d8d --- /dev/null +++ b/test/fixtures/errors/undefined_reference_in_new_context.snapshot @@ -0,0 +1,13 @@ +before +at * +Error.stackTraceLimit = 5; foo.bar = 5; + ^ + +ReferenceError: foo is not defined + at * + at * + at * + at * + at * + +Node.js * 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..ab5cdfdc94ccf1 --- /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:*:*)' + } +} +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 * + at process.processTicksAndRejections (node:internal*process*task_queues:*:*) { + [cause]: FoobarError: Individual message + at Object. (/test*util-inspect-error-cause.js:*:*) +  at Module._compile (node:internal*modules*cjs*loader:*:*) +  ... 4 lines matching cause stack trace ... +  at node:internal*main*run_main_module:*:* { + status: 'Feeling good', + extraProperties: 'Yes!', + [cause]: TypeError: Inner error + at Object. (/test*util-inspect-error-cause.js:*:*) +  at Module._compile (node:internal*modules*cjs*loader:*:*) +  at Module._extensions..js (node:internal*modules*cjs*loader:*:*) +  at Module.load (node:internal*modules*cjs*loader:*:*) +  at Module._load (node:internal*modules*cjs*loader:*:*) +  at Function.executeUserEntryPoint [as runMain] (node:internal*modules*run_main:*:*) +  at node:internal*main*run_main_module:*:* + } +} +Error: Stack causes + at Object. (/test*util-inspect-error-cause.js:*:*) + at Module._compile (node:internal*modules*cjs*loader:*:*) + ... 4 lines matching cause stack trace ... + at node:internal*main*run_main_module:*:* { + [cause]: FoobarError: Individual message + at Object. (/test*util-inspect-error-cause.js:*:*) +  at Module._compile (node:internal*modules*cjs*loader:*:*) +  ... 4 lines matching cause stack trace ... +  at node:internal*main*run_main_module:*:* { + status: 'Feeling good', + extraProperties: 'Yes!', + [cause]: TypeError: Inner error + at Object. (/test*util-inspect-error-cause.js:*:*) +  at Module._compile (node:internal*modules*cjs*loader:*:*) +  at Module._extensions..js (node:internal*modules*cjs*loader:*:*) +  at Module.load (node:internal*modules*cjs*loader:*:*) +  at Module._load (node:internal*modules*cjs*loader:*:*) +  at Function.executeUserEntryPoint [as runMain] (node:internal*modules*run_main:*:*) +  at node:internal*main*run_main_module:*:* + } +} +RangeError: New Stack Frames + at * + at process.processTicksAndRejections (node:internal*process*task_queues:*:*) { + [cause]: Error: Stack causes + at Object. (/test*util-inspect-error-cause.js:*:*) +  at Module._compile (node:internal*modules*cjs*loader:*:*) +  ... 4 lines matching cause stack trace ... +  at node:internal*main*run_main_module:*:* { + [cause]: FoobarError: Individual message + at Object. (/test*util-inspect-error-cause.js:*:*) +  at Module._compile (node:internal*modules*cjs*loader:*:*) +  ... 4 lines matching cause stack trace ... +  at node:internal*main*run_main_module:*:* { + status: 'Feeling good', + extraProperties: 'Yes!', + [cause]: TypeError: Inner error + at Object. (/test*util-inspect-error-cause.js:*:*) +  at Module._compile (node:internal*modules*cjs*loader:*:*) +  at Module._extensions..js (node:internal*modules*cjs*loader:*:*) +  at Module.load (node:internal*modules*cjs*loader:*:*) +  at Module._load (node:internal*modules*cjs*loader:*:*) +  at Function.executeUserEntryPoint [as runMain] (node:internal*modules*run_main:*:*) +  at node:internal*main*run_main_module:*:* + } + } +} +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/fixtures/errors/v8_warning.snapshot b/test/fixtures/errors/v8_warning.snapshot new file mode 100644 index 00000000000000..b006af0518f0f4 --- /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 `node --trace-warnings ...` to show where the warning was created) diff --git a/test/fixtures/map/source_map_enclosing_function.js b/test/fixtures/map/source_map_enclosing_function.js deleted file mode 100644 index cf67a62d505fa1..00000000000000 --- a/test/fixtures/map/source_map_enclosing_function.js +++ /dev/null @@ -1,7 +0,0 @@ -// Flags: --enable-source-maps - -'use strict'; -require('../../common'); -Error.stackTraceLimit = 5; - -require('../source-map/enclosing-call-site-min.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..469caae323048f --- /dev/null +++ b/test/fixtures/map/source_map_reference_error_tabs.snapshot @@ -0,0 +1,10 @@ +*tabs.coffee:* + alert "I knew it!" + ^ + + +ReferenceError: alert is not defined + at * + at * + +Node.js * 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..b24d4b512207a9 --- /dev/null +++ b/test/fixtures/map/source_map_sourcemapping_url_string.snapshot @@ -0,0 +1,3 @@ +Error: an exception. + at * + at * 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/fixtures/map/source_map_throw_icu.snapshot b/test/fixtures/map/source_map_throw_icu.snapshot new file mode 100644 index 00000000000000..26185e7d15735d --- /dev/null +++ b/test/fixtures/map/source_map_throw_icu.snapshot @@ -0,0 +1,10 @@ +*icu.jsx:* + ("*******", throw Error("an error")); + ^ + + +Error: an error + at * + at * + +Node.js * 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/fixtures/promise/promise_unhandled_warn_with_error.snapshot b/test/fixtures/promise/promise_unhandled_warn_with_error.snapshot new file mode 100644 index 00000000000000..d37c9cdac48d85 --- /dev/null +++ b/test/fixtures/promise/promise_unhandled_warn_with_error.snapshot @@ -0,0 +1,10 @@ +(node*) UnhandledPromiseRejectionWarning: Error: alas + at * + at * + at * + at * + at * + at * + at * +(Use `node --trace-warnings ...` to show where the warning was created) +(node*) 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/fixtures/promise/unhandled_promise_trace_warnings.snapshot b/test/fixtures/promise/unhandled_promise_trace_warnings.snapshot new file mode 100644 index 00000000000000..fce4af0e495766 --- /dev/null +++ b/test/fixtures/promise/unhandled_promise_trace_warnings.snapshot @@ -0,0 +1,26 @@ +(node*) UnhandledPromiseRejectionWarning: Error: This was rejected + at * + at * + at * + at * + at * + at * + at * + at * + at * + at * +(node*) Error: This was rejected + at * + at * + at * + at * + at * + at * + at * +(node*) PromiseRejectionHandledWarning: Promise rejection was handled asynchronously (rejection id: 1) + at * + at * + at Promise.then () + at Promise.catch () + at * + at * diff --git a/test/fixtures/tick/nexttick_throw.snapshot b/test/fixtures/tick/nexttick_throw.snapshot new file mode 100644 index 00000000000000..07f5ad5e26522f --- /dev/null +++ b/test/fixtures/tick/nexttick_throw.snapshot @@ -0,0 +1,9 @@ +*nexttick_throw.js* + undefined_reference_error_maker; + ^ + +ReferenceError: undefined_reference_error_maker is not defined + at * + at * + +Node.js * diff --git a/test/fixtures/map/source_map_enclosing_function.snapshot b/test/message/source_map_enclosing_function.out similarity index 99% rename from test/fixtures/map/source_map_enclosing_function.snapshot rename to test/message/source_map_enclosing_function.out index 976cd4fdbbc6e9..5bb920e7eba42a 100644 --- a/test/fixtures/map/source_map_enclosing_function.snapshot +++ b/test/message/source_map_enclosing_function.out @@ -2,7 +2,6 @@ throw err ^ - Error: an error! at functionD (*enclosing-call-site.js:16:17) at functionC (*enclosing-call-site.js:10:3) diff --git a/test/parallel/test-node-output-console.mjs b/test/parallel/test-node-output-console.mjs index b3b8fd23b12598..2439934646461a 100644 --- a/test/parallel/test-node-output-console.mjs +++ b/test/parallel/test-node-output-console.mjs @@ -13,42 +13,30 @@ function replaceStackTrace(str) { describe('console output', { concurrency: true }, () => { function normalize(str) { - return str.replaceAll(snapshot.replaceWindowsPaths(process.cwd()), '').replaceAll('/', '*').replaceAll(process.version, '*').replaceAll(/\d+/g, '*').replaceAll('[*m', ''); + 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 tests = [ { name: 'console/2100bytes.js' }, { name: 'console/console_low_stack_space.js' }, { name: 'console/console.js' }, - { name: 'console/core_line_numbers.js', - transform: snapshot - .transform(snapshot.replaceWindowsLineEndings, snapshot.replaceWindowsPaths, normalize), - tty: true - }, - { name: 'console/eval_messages.js', - transform: snapshot - .transform(snapshot.replaceWindowsLineEndings, snapshot.replaceWindowsPaths, normalize), - tty: true - }, + { name: 'console/core_line_numbers.js', transform: normalizedTransform }, + { name: 'console/eval_messages.js', transform: normalizedTransform }, { name: 'console/hello_world.js' }, - { - name: 'console/stack_overflow.js', - transform: snapshot - .transform(snapshot.replaceWindowsLineEndings, snapshot.replaceWindowsPaths, normalize) - }, - { name: 'console/stdin_messages.js', - transform: snapshot - .transform(snapshot.replaceWindowsLineEndings, snapshot.replaceWindowsPaths, normalize), - tty: true - }, - { name: 'console/stdin_messages.js', - transform: snapshot - .transform(snapshot.replaceWindowsLineEndings, snapshot.replaceWindowsPaths, replaceNodeVersion, stackTrace), - tty: true - }, + { name: 'console/stack_overflow.js', transform: normalizedTransform }, + { name: 'console/stdin_messages.js', transform: normalizedTransform }, !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, tty = false, env } of tests) { it(name, async () => { 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 5ea05ce0fd80e3..f597e292c105b3 100644 --- a/test/parallel/test-node-output-errors.mjs +++ b/test/parallel/test-node-output-errors.mjs @@ -9,31 +9,32 @@ 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 replaceStackTrace(str) { return snapshot.replaceStackTrace(str, '$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('//', '*') + .replaceAll(process.version, '*') + .replaceAll(/\/(\w)/g, '*$1') + .replaceAll('*test*', '*') + .replaceAll('*fixtures*errors*', '*') + .replaceAll('file:**', 'file:*/'); } + function normalizeNoNumbers(str) { - return normalize(str).replaceAll(/\d+:\d+/g, '*:*').replaceAll(/:\d+/g, ':*').replaceAll('*fixtures*message*', '*'); - } - function normalizeCustom(str) { - return normalizeNoNumbers(str).replaceAll(/\d+/g, '*').replaceAll('[*m', ''); + 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 customTransform = snapshot.transform(common, replaceStackTrace, normalizeCustom); + const defaultTransform = snapshot.transform(common, normalize); + const noNumberTransform = snapshot.transform(common, normalizeNoNumbers); + const noStackTraceTransform = snapshot.transform(common, replaceStackTrace, normalizeNoNumbers); const tests = [ { name: 'errors/async_error_eval_cjs.js' }, @@ -42,29 +43,30 @@ 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/if-error-has-good-stack.js', transform: errTransform, tty: false }, - { name: 'errors/test-no-extra-info-on-fatal-exception.js', transform: errTransform, tty: false }, - { name: 'errors/throw_error_with_getter_throw.js', transform: errTransform, tty: true }, - { name: 'errors/throw_null.js', transform: errTransform, tty: true }, - { name: 'errors/throw_undefined.js', transform: errTransform, tty: true }, - { name: 'errors/timeout_throw.js', transform: errTransform, tty: false }, - { name: 'errors/undefined_reference_in_new_context.js', transform: errTransform, tty: false }, - { name: 'errors/util_inspect_error.js', transform: customTransform, tty: true }, - { name: 'errors/util-inspect-error-cause.js', transform: customTransform, tty: true }, - { name: 'errors/v8_warning.js', transform: errTransform, tty: true }, + { 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: noStackTraceTransform }, + { name: 'errors/throw_error_with_getter_throw.js', transform: noStackTraceTransform }, + { name: 'errors/throw_null.js', transform: noStackTraceTransform }, + { name: 'errors/throw_undefined.js', transform: noStackTraceTransform }, + { name: 'errors/timeout_throw.js', transform: noStackTraceTransform }, + { name: 'errors/undefined_reference_in_new_context.js', transform: noStackTraceTransform }, + { name: 'errors/util_inspect_error.js', transform: noStackTraceTransform }, + { name: 'errors/util-inspect-error-cause.js', transform: noStackTraceTransform }, + { name: 'errors/v8_warning.js', transform: noStackTraceTransform }, !skipForceColors ? { name: 'errors/force_colors.js', env: { FORCE_COLOR: 1 } } : null, ].filter(Boolean); + for (const { name, transform, tty = false, env } of tests) { it(name, async () => { 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 index 78613be516e6e1..723533a80627bc 100644 --- a/test/parallel/test-output-assertion.mjs +++ b/test/parallel/test-output-assertion.mjs @@ -3,34 +3,32 @@ import * as fixtures from '../common/fixtures.mjs'; import * as snapshot from '../common/assertSnapshot.js'; import { describe, it } from 'node:test'; -function replaceNodeVersion(str) { - return str.replaceAll(process.version, '*'); -} - 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(/\/(\w)/g, '*$1').replaceAll('*test*', '*').replaceAll('*fixtures*assertion*', '*').replaceAll('file:**', 'file:*/'); + return str + .replaceAll(snapshot.replaceWindowsPaths(process.cwd()), '') + .replaceAll('/', '*') + .replaceAll(process.version, '*') + .replaceAll(/:\d+/g, '*'); } - function normalizeNoNumbers(str) { - return normalize(str).replaceAll(/\d+:\d+/g, '*:*').replaceAll(/:\d+/g, ':*').replaceAll('*fixtures*message*', '*'); - } const common = snapshot - .transform(snapshot.replaceWindowsLineEndings, snapshot.replaceWindowsPaths, replaceNodeVersion); - const defaultTransform = snapshot.transform(common, normalize); - const customTransform = snapshot.transform(common, replaceStackTrace, normalizeNoNumbers); + .transform(snapshot.replaceWindowsLineEndings, snapshot.replaceWindowsPaths); + const defaultTransform = snapshot.transform(common, replaceStackTrace, normalize); + const tests = [ - { name: 'assertion/assert_throws_stack.js', transform: customTransform }, - { name: 'assertion/internal_assert_fail.js', transform: customTransform }, - { name: 'assertion/internal_assert.js', transform: customTransform }, + { 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, { tty: true }); + await snapshot.spawnAndAssert(fixtures.path(name), transform ?? defaultTransform); }); } }); diff --git a/test/parallel/test-output-map.mjs b/test/parallel/test-output-map.mjs index 16aa354aefe100..7f7a4d9ea04d99 100644 --- a/test/parallel/test-output-map.mjs +++ b/test/parallel/test-output-map.mjs @@ -3,44 +3,42 @@ import * as fixtures from '../common/fixtures.mjs'; import * as snapshot from '../common/assertSnapshot.js'; import { describe, it } from 'node:test'; -function replaceNodeVersion(str) { - return str.replaceAll(process.version, '*'); -} - 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('//', '*').replaceAll(/\/(\w)/g, '*$1').replaceAll('*test*', '*').replaceAll('*fixtures*source-map*', '*').replaceAll('file:**', 'file:*/'); + return str + .replaceAll(snapshot.replaceWindowsPaths(process.cwd()), '') + .replaceAll('//', '*') + .replaceAll(process.version, '*') + .replaceAll(/\/(\w)/g, '*$1') + .replaceAll('*test*', '*') + .replaceAll('*fixtures*source-map*', '*') + .replaceAll(/:\d+/g, ':*'); } - function normalizeNoNumbers(str) { - return normalize(str).replaceAll(/\d+:\d+/g, '*:*').replaceAll(/:\d+/g, ':*').replaceAll('*fixtures*source-map*', '*'); - } function normalizeSpecialCharacters(str) { - const replacement = (match) => match.replace(/./g, '*').replace(/\s\*/g, ''); - return normalizeNoNumbers(str).replace(/(?<=\(")[^"]+/, replacement); + const replacement = (match) => match.replace(/[^(\n|\r)]/g, '*').replace(/\s\*/g, ''); + return normalize(str).replace(/(?<=\(")[^"]+/, replacement); } + const common = snapshot - .transform(snapshot.replaceWindowsLineEndings, snapshot.replaceWindowsPaths, replaceNodeVersion); + .transform(snapshot.replaceWindowsLineEndings, snapshot.replaceWindowsPaths); const defaultTransform = snapshot.transform(common, normalize); - const noNumTransform = snapshot.transform(common, normalizeNoNumbers); - const customTransform = snapshot.transform(common, replaceStackTrace, normalizeNoNumbers); - const specialTransform = snapshot.transform(common, replaceStackTrace, normalizeSpecialCharacters); + const noStackTraceTransform = snapshot.transform(common, replaceStackTrace, normalize); + const noSpecialCharacterTransform = snapshot.transform(common, replaceStackTrace, normalizeSpecialCharacters); const tests = [ - { name: 'map/source_map_enclosing_function.js' }, - { name: 'map/source_map_reference_error_tabs.js' }, - { name: 'map/source_map_sourcemapping_url_string.js', transform: noNumTransform }, - { name: 'map/source_map_throw_catch.js', transform: customTransform }, - { name: 'map/source_map_throw_icu.js', transform: specialTransform }, - { name: 'map/source_map_throw_set_immediate.js', transform: customTransform }, + { name: 'map/source_map_reference_error_tabs.js', transform: noStackTraceTransform }, + { name: 'map/source_map_sourcemapping_url_string.js', transform: noStackTraceTransform }, + { name: 'map/source_map_throw_catch.js', transform: noStackTraceTransform }, + { name: 'map/source_map_throw_icu.js', transform: noSpecialCharacterTransform } ]; for (const { name, transform } of tests) { it(name, async () => { - await snapshot.spawnAndAssert(fixtures.path(name), transform ?? defaultTransform, { tty: true }); + await snapshot.spawnAndAssert(fixtures.path(name), transform ?? defaultTransform); }); } }); diff --git a/test/parallel/test-output-promise.mjs b/test/parallel/test-output-promise.mjs index a93776594dfbfd..8b74f80fd28a2b 100644 --- a/test/parallel/test-output-promise.mjs +++ b/test/parallel/test-output-promise.mjs @@ -3,33 +3,31 @@ import * as fixtures from '../common/fixtures.mjs'; import * as snapshot from '../common/assertSnapshot.js'; import { describe, it } from 'node:test'; -function replaceNodeVersion(str) { - return str.replaceAll(process.version, '*'); -} - 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('//', '*').replaceAll(/\/(\w)/g, '*$1').replaceAll('*test*', '*').replaceAll('*fixtures*source-map*', '*').replaceAll('file:**', 'file:*/'); + return str + .replaceAll(snapshot.replaceWindowsPaths(process.cwd()), '') + .replaceAll('/', '*') + .replaceAll(process.version, '*') + .replaceAll(/:\d+/g, '*'); } - function normalizeNoNumbers(str) { - return normalize(str).replaceAll(/\d+:\d+/g, '*:*').replaceAll(/:\d+/g, ':*').replaceAll('*fixtures*source-map*', '*'); - } const common = snapshot - .transform(snapshot.replaceWindowsLineEndings, snapshot.replaceWindowsPaths, replaceNodeVersion); - const defaultTransform = snapshot.transform(common, replaceStackTrace, normalizeNoNumbers); + .transform(snapshot.replaceWindowsLineEndings, snapshot.replaceWindowsPaths); + const defaultTransform = snapshot.transform(common, replaceStackTrace, normalize); const tests = [ { name: 'promise/promise_unhandled_warn_with_error.js' }, { name: 'promise/unhandled_promise_trace_warnings.js' }, ]; + for (const { name, transform } of tests) { it(name, async () => { - await snapshot.spawnAndAssert(fixtures.path(name), transform ?? defaultTransform, { tty: true }); + await snapshot.spawnAndAssert(fixtures.path(name), transform ?? defaultTransform); }); } }); diff --git a/test/parallel/test-output-tick.mjs b/test/parallel/test-output-tick.mjs index c9672923101626..6cdc5505fa6741 100644 --- a/test/parallel/test-output-tick.mjs +++ b/test/parallel/test-output-tick.mjs @@ -3,34 +3,33 @@ import * as fixtures from '../common/fixtures.mjs'; import * as snapshot from '../common/assertSnapshot.js'; import { describe, it } from 'node:test'; -function replaceNodeVersion(str) { - return str.replaceAll(process.version, '*'); -} - 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('//', '*').replaceAll(/\/(\w)/g, '*$1').replaceAll('*test*', '*').replaceAll('*fixtures*source-map*', '*').replaceAll('file:**', 'file:*/'); + return str + .replaceAll(snapshot.replaceWindowsPaths(process.cwd()), '') + .replaceAll('/', '*') + .replaceAll(process.version, '*') + .replaceAll('*test*fixtures*tick*', '*') + .replaceAll(/:\d+/g, '*'); } - function normalizeNoNumbers(str) { - return normalize(str).replaceAll(/\d+:\d+/g, '*:*').replaceAll(/:\d+/g, ':*').replaceAll('*fixtures*source-map*', '*'); - } const common = snapshot - .transform(snapshot.replaceWindowsLineEndings, snapshot.replaceWindowsPaths, replaceNodeVersion); + .transform(snapshot.replaceWindowsLineEndings, snapshot.replaceWindowsPaths); const defaultTransform = snapshot.transform(common); - const customTransform = snapshot.transform(common, replaceStackTrace, normalizeNoNumbers); + const customTransform = snapshot.transform(common, replaceStackTrace, normalize); const tests = [ { name: 'tick/max_tick_depth.js' }, { name: 'tick/nexttick_throw.js', transform: customTransform }, ]; + for (const { name, transform } of tests) { it(name, async () => { - await snapshot.spawnAndAssert(fixtures.path(name), transform ?? defaultTransform, { tty: true }); + await snapshot.spawnAndAssert(fixtures.path(name), transform ?? defaultTransform); }); } }); From 665067028854bf86fe81806681ddb2b6afcacde7 Mon Sep 17 00:00:00 2001 From: upx Date: Tue, 11 Jul 2023 21:31:38 -0700 Subject: [PATCH 3/3] Restored snapshots to original .out content --- .../console/core_line_numbers.snapshot | 10 +- test/fixtures/console/eval_messages.snapshot | 100 +++++++-------- test/fixtures/console/stdin_messages.snapshot | 114 +++++++++--------- ...-no-extra-info-on-fatal-exception.snapshot | 4 +- .../throw_error_with_getter_throw.snapshot | 10 +- test/fixtures/errors/throw_null.snapshot | 4 +- test/fixtures/errors/throw_undefined.snapshot | 4 +- test/fixtures/errors/timeout_throw.snapshot | 9 +- ...ndefined_reference_in_new_context.snapshot | 12 +- .../errors/util-inspect-error-cause.snapshot | 104 ++++++++-------- test/fixtures/errors/v8_warning.snapshot | 2 +- .../source_map_reference_error_tabs.snapshot | 7 +- ...urce_map_sourcemapping_url_string.snapshot | 4 +- .../map/source_map_throw_icu.snapshot | 7 +- .../map/source_map_throw_set_immediate.js | 4 +- ...promise_unhandled_warn_with_error.snapshot | 8 +- .../unhandled_promise_trace_warnings.snapshot | 20 +-- test/fixtures/tick/nexttick_throw.snapshot | 6 +- test/parallel/test-node-output-console.mjs | 37 +++++- test/parallel/test-node-output-errors.mjs | 105 +++++++++++++--- test/parallel/test-output-map.mjs | 48 +++++--- test/parallel/test-output-promise.mjs | 26 +++- test/parallel/test-output-tick.mjs | 17 +-- 23 files changed, 389 insertions(+), 273 deletions(-) diff --git a/test/fixtures/console/core_line_numbers.snapshot b/test/fixtures/console/core_line_numbers.snapshot index 899c9e00302256..40a7863e03fe2f 100644 --- a/test/fixtures/console/core_line_numbers.snapshot +++ b/test/fixtures/console/core_line_numbers.snapshot @@ -1,10 +1,10 @@ -node:punycode:* +node:punycode:49 throw new RangeError(errors[type]); ^ RangeError: Invalid input - at * - at * - at * + at error (node:punycode:49:8) + at Object.decode (node:punycode:*:*) + at Object. (*test*message*core_line_numbers.js:*:*) -Node.js * +Node.js * \ No newline at end of file diff --git a/test/fixtures/console/eval_messages.snapshot b/test/fixtures/console/eval_messages.snapshot index 0d12777cb5aac4..53f0a25c72a387 100644 --- a/test/fixtures/console/eval_messages.snapshot +++ b/test/fixtures/console/eval_messages.snapshot @@ -1,81 +1,81 @@ [eval] -at * +[eval]:1 with(this){__filename} ^^^^ - SyntaxError: Strict mode code may not include a with statement - at * - at * - at * - at * - at * - at * - at * - at * + 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 * -* -* -at * +42 +42 +[eval]:1 throw new Error("hello") ^ Error: hello - at * - at * - at * - at * - at * - at * - at * - at * + 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 * -at * + +[eval]:1 throw new Error("hello") ^ Error: hello - at * - at * - at * - at * - at * - at * - at * - at * + 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 * -* -at * -var x = *; y = x; +100 +[eval]:1 +var x = 100; y = x; ^ ReferenceError: y is not defined - at * - at * - at * - at * - at * - at * - at * - at * + 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 * -at * -var ______________________________________________; throw * +[eval]:1 +var ______________________________________________; throw 10 ^ -* -(Use `node --trace-uncaught ...` to show where the exception was thrown) +10 +(Use `* --trace-uncaught ...` to show where the exception was thrown) Node.js * -at * -var ______________________________________________; throw * +[eval]:1 +var ______________________________________________; throw 10 ^ -* -(Use `node --trace-uncaught ...` to show where the exception was thrown) +10 +(Use `* --trace-uncaught ...` to show where the exception was thrown) Node.js * -done +done \ No newline at end of file diff --git a/test/fixtures/console/stdin_messages.snapshot b/test/fixtures/console/stdin_messages.snapshot index 1d896c3abc6ffc..2ebbf22ece0d60 100644 --- a/test/fixtures/console/stdin_messages.snapshot +++ b/test/fixtures/console/stdin_messages.snapshot @@ -1,89 +1,89 @@ [stdin] -at * +[stdin]:1 with(this){__filename} ^^^^ SyntaxError: Strict mode code may not include a with statement - at * - at * - at * - at * - at * - at * - at * - at * - at * - at * + 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 * -* -* -at * +42 +42 +[stdin]:1 throw new Error("hello") ^ Error: hello - at * - at * - at * - at * - at * - at * - at * - at * - at * - at * + 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 * -at * +[stdin]:1 throw new Error("hello") ^ Error: hello - at * - at * - at * - at * - at * - at * - at * - at * - at * - at * + 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 * -* -at * -let x = *; y = x; +100 +[stdin]:1 +let x = 100; y = x; ^ ReferenceError: y is not defined - at * - at * - at * - at * - at * - at * - at * - at * - at * - at * + 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 * -at * -let ______________________________________________; throw * +[stdin]:1 +let ______________________________________________; throw 10 ^ -* -(Use `node --trace-uncaught ...` to show where the exception was thrown) +10 +(Use `* --trace-uncaught ...` to show where the exception was thrown) Node.js * -at * -let ______________________________________________; throw * +[stdin]:1 +let ______________________________________________; throw 10 ^ -* -(Use `node --trace-uncaught ...` to show where the exception was thrown) +10 +(Use `* --trace-uncaught ...` to show where the exception was thrown) Node.js * -done +done \ No newline at end of file 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 index a6a251ff95d770..a7d93b82e70738 100644 --- a/test/fixtures/errors/test-no-extra-info-on-fatal-exception.snapshot +++ b/test/fixtures/errors/test-no-extra-info-on-fatal-exception.snapshot @@ -1,6 +1,6 @@ -*test-no-extra-info-on-fatal-exception.js:* +*:7 throw new Error('foo'); ^ Error: foo - at * + at Object. (*:7:7) \ No newline at end of file diff --git a/test/fixtures/errors/throw_error_with_getter_throw.snapshot b/test/fixtures/errors/throw_error_with_getter_throw.snapshot index b933657bfe677e..d277a8c8ae4482 100644 --- a/test/fixtures/errors/throw_error_with_getter_throw.snapshot +++ b/test/fixtures/errors/throw_error_with_getter_throw.snapshot @@ -1,8 +1,8 @@ -at * -throw { * eslint-disable-line no-throw-literal +*test*message*throw_null.js:* +throw null; ^ -[object Object] -(Use `node --trace-uncaught ...` to show where the exception was thrown) +null +(Use `* --trace-uncaught ...` to show where the exception was thrown) -Node.js * +Node.js * \ No newline at end of file diff --git a/test/fixtures/errors/throw_null.snapshot b/test/fixtures/errors/throw_null.snapshot index 3e9499ef959334..0fe2a49d050b18 100644 --- a/test/fixtures/errors/throw_null.snapshot +++ b/test/fixtures/errors/throw_null.snapshot @@ -1,8 +1,8 @@ -at * +*test*message*throw_null.js:* throw null; ^ null -(Use `node --trace-uncaught ...` to show where the exception was thrown) +(Use `* --trace-uncaught ...` to show where the exception was thrown) Node.js * diff --git a/test/fixtures/errors/throw_undefined.snapshot b/test/fixtures/errors/throw_undefined.snapshot index 5bb1b424dfcd01..56b0cac4259d6d 100644 --- a/test/fixtures/errors/throw_undefined.snapshot +++ b/test/fixtures/errors/throw_undefined.snapshot @@ -1,8 +1,8 @@ -at * +*test*message*throw_undefined.js:* throw undefined; ^ undefined -(Use `node --trace-uncaught ...` to show where the exception was thrown) +(Use `* --trace-uncaught ...` to show where the exception was thrown) Node.js * diff --git a/test/fixtures/errors/timeout_throw.snapshot b/test/fixtures/errors/timeout_throw.snapshot index 866b020ae298c0..83b861caa7ca29 100644 --- a/test/fixtures/errors/timeout_throw.snapshot +++ b/test/fixtures/errors/timeout_throw.snapshot @@ -1,10 +1,9 @@ -*timeout_throw.js:* +*test*message*timeout_throw.js:* undefined_reference_error_maker; ^ - ReferenceError: undefined_reference_error_maker is not defined - at * - at * - at * + 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/fixtures/errors/undefined_reference_in_new_context.snapshot b/test/fixtures/errors/undefined_reference_in_new_context.snapshot index f9321748511d8d..8d8228bd902950 100644 --- a/test/fixtures/errors/undefined_reference_in_new_context.snapshot +++ b/test/fixtures/errors/undefined_reference_in_new_context.snapshot @@ -1,13 +1,13 @@ before -at * +evalmachine.:1 Error.stackTraceLimit = 5; foo.bar = 5; ^ ReferenceError: foo is not defined - at * - at * - at * - at * - at * + 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/fixtures/errors/util-inspect-error-cause.snapshot b/test/fixtures/errors/util-inspect-error-cause.snapshot index ab5cdfdc94ccf1..73f0a673d76e1f 100644 --- a/test/fixtures/errors/util-inspect-error-cause.snapshot +++ b/test/fixtures/errors/util-inspect-error-cause.snapshot @@ -19,8 +19,8 @@ Error: Object cause [cause]: { message: 'Unique', name: 'Error', - stack: 'Error: Unique*n' + - ' at Module._compile (node:internal*modules*cjs*loader:*:*)' + stack: 'Error: Unique\n' + + ' at Module._compile (node:internal/modules/cjs/loader:827:30)' } } Error: undefined cause @@ -45,69 +45,69 @@ Error: cause that throws } RangeError: New Stack Frames at * - at process.processTicksAndRejections (node:internal*process*task_queues:*:*) { +*[90m at *[39m { [cause]: FoobarError: Individual message - at Object. (/test*util-inspect-error-cause.js:*:*) -  at Module._compile (node:internal*modules*cjs*loader:*:*) -  ... 4 lines matching cause stack trace ... -  at node:internal*main*run_main_module:*:* { - status: 'Feeling good', - extraProperties: 'Yes!', + 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 Object. (/test*util-inspect-error-cause.js:*:*) -  at Module._compile (node:internal*modules*cjs*loader:*:*) -  at Module._extensions..js (node:internal*modules*cjs*loader:*:*) -  at Module.load (node:internal*modules*cjs*loader:*:*) -  at Module._load (node:internal*modules*cjs*loader:*:*) -  at Function.executeUserEntryPoint [as runMain] (node:internal*modules*run_main:*:*) -  at node:internal*main*run_main_module:*:* + at * + *[90m at *[39m + *[90m at *[39m + *[90m at *[39m + *[90m at *[39m + *[90m at *[39m + *[90m at *[39m } } Error: Stack causes - at Object. (/test*util-inspect-error-cause.js:*:*) - at Module._compile (node:internal*modules*cjs*loader:*:*) - ... 4 lines matching cause stack trace ... - at node:internal*main*run_main_module:*:* { + at * +*[90m at *[39m +*[90m ... 4 lines matching cause stack trace ...*[39m +*[90m at *[39m { [cause]: FoobarError: Individual message - at Object. (/test*util-inspect-error-cause.js:*:*) -  at Module._compile (node:internal*modules*cjs*loader:*:*) -  ... 4 lines matching cause stack trace ... -  at node:internal*main*run_main_module:*:* { - status: 'Feeling good', - extraProperties: 'Yes!', + 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 Object. (/test*util-inspect-error-cause.js:*:*) -  at Module._compile (node:internal*modules*cjs*loader:*:*) -  at Module._extensions..js (node:internal*modules*cjs*loader:*:*) -  at Module.load (node:internal*modules*cjs*loader:*:*) -  at Module._load (node:internal*modules*cjs*loader:*:*) -  at Function.executeUserEntryPoint [as runMain] (node:internal*modules*run_main:*:*) -  at node:internal*main*run_main_module:*:* + 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 process.processTicksAndRejections (node:internal*process*task_queues:*:*) { +*[90m at *[39m { [cause]: Error: Stack causes - at Object. (/test*util-inspect-error-cause.js:*:*) -  at Module._compile (node:internal*modules*cjs*loader:*:*) -  ... 4 lines matching cause stack trace ... -  at node:internal*main*run_main_module:*:* { + at * + *[90m at *[39m + *[90m ... 4 lines matching cause stack trace ...*[39m + *[90m at *[39m { [cause]: FoobarError: Individual message - at Object. (/test*util-inspect-error-cause.js:*:*) -  at Module._compile (node:internal*modules*cjs*loader:*:*) -  ... 4 lines matching cause stack trace ... -  at node:internal*main*run_main_module:*:* { - status: 'Feeling good', - extraProperties: 'Yes!', + 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 Object. (/test*util-inspect-error-cause.js:*:*) -  at Module._compile (node:internal*modules*cjs*loader:*:*) -  at Module._extensions..js (node:internal*modules*cjs*loader:*:*) -  at Module.load (node:internal*modules*cjs*loader:*:*) -  at Module._load (node:internal*modules*cjs*loader:*:*) -  at Function.executeUserEntryPoint [as runMain] (node:internal*modules*run_main:*:*) -  at node:internal*main*run_main_module:*:* + at * + *[90m at *[39m + *[90m at *[39m + *[90m at *[39m + *[90m at *[39m + *[90m at *[39m + *[90m at *[39m } } } @@ -140,7 +140,7 @@ Error: Stack causes at * at * ... 4 lines matching cause stack trace ... - at * { + at * status: 'Feeling good', extraProperties: 'Yes!', [cause]: TypeError: Inner error diff --git a/test/fixtures/errors/v8_warning.snapshot b/test/fixtures/errors/v8_warning.snapshot index b006af0518f0f4..6c419c83cddf28 100644 --- a/test/fixtures/errors/v8_warning.snapshot +++ b/test/fixtures/errors/v8_warning.snapshot @@ -1,2 +1,2 @@ (node:*) V8: *v8_warning.js:* Invalid asm.js: Invalid return type -(Use `node --trace-warnings ...` to show where the warning was created) +(Use `* --trace-warnings ...` to show where the warning was created) diff --git a/test/fixtures/map/source_map_reference_error_tabs.snapshot b/test/fixtures/map/source_map_reference_error_tabs.snapshot index 469caae323048f..7bf2d13305ef12 100644 --- a/test/fixtures/map/source_map_reference_error_tabs.snapshot +++ b/test/fixtures/map/source_map_reference_error_tabs.snapshot @@ -1,10 +1,9 @@ -*tabs.coffee:* +*tabs.coffee:26 alert "I knew it!" ^ - ReferenceError: alert is not defined - at * - at * + at *tabs.coffee:26:2* + at *tabs.coffee:1:14* Node.js * diff --git a/test/fixtures/map/source_map_sourcemapping_url_string.snapshot b/test/fixtures/map/source_map_sourcemapping_url_string.snapshot index b24d4b512207a9..3d0b6e15eb6c7a 100644 --- a/test/fixtures/map/source_map_sourcemapping_url_string.snapshot +++ b/test/fixtures/map/source_map_sourcemapping_url_string.snapshot @@ -1,3 +1,3 @@ Error: an exception. - at * - at * + at *typescript-sourcemapping_url_string.ts:3:7* + at Module._compile (node:internal/modules/cjs/loader:*) diff --git a/test/fixtures/map/source_map_throw_icu.snapshot b/test/fixtures/map/source_map_throw_icu.snapshot index 26185e7d15735d..6c658fcff88952 100644 --- a/test/fixtures/map/source_map_throw_icu.snapshot +++ b/test/fixtures/map/source_map_throw_icu.snapshot @@ -1,10 +1,9 @@ -*icu.jsx:* +*icu.jsx:3 ("*******", throw Error("an error")); ^ - Error: an error - at * - at * + 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 index 44c8591366f245..bf7a65925d1ffc 100644 --- a/test/fixtures/map/source_map_throw_set_immediate.js +++ b/test/fixtures/map/source_map_throw_set_immediate.js @@ -1,5 +1,5 @@ // Flags: --enable-source-maps 'use strict'; -require('../../common'); -require('../source-map/uglify-throw'); +require('../common'); +require('../fixtures/source-map/uglify-throw'); \ No newline at end of file diff --git a/test/fixtures/promise/promise_unhandled_warn_with_error.snapshot b/test/fixtures/promise/promise_unhandled_warn_with_error.snapshot index d37c9cdac48d85..1a278646ac7462 100644 --- a/test/fixtures/promise/promise_unhandled_warn_with_error.snapshot +++ b/test/fixtures/promise/promise_unhandled_warn_with_error.snapshot @@ -1,10 +1,10 @@ -(node*) UnhandledPromiseRejectionWarning: Error: alas +*UnhandledPromiseRejectionWarning: Error: alas + at *promise_unhandled_warn_with_error.js:*:* at * at * at * at * at * at * - at * -(Use `node --trace-warnings ...` to show where the warning was created) -(node*) 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) +(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/fixtures/promise/unhandled_promise_trace_warnings.snapshot b/test/fixtures/promise/unhandled_promise_trace_warnings.snapshot index fce4af0e495766..a8717d0e13d1e4 100644 --- a/test/fixtures/promise/unhandled_promise_trace_warnings.snapshot +++ b/test/fixtures/promise/unhandled_promise_trace_warnings.snapshot @@ -1,4 +1,5 @@ -(node*) UnhandledPromiseRejectionWarning: Error: This was rejected +(node:*) UnhandledPromiseRejectionWarning: Error: This was rejected + at * (*test*message*unhandled_promise_trace_warnings.js:*) at * at * at * @@ -8,19 +9,18 @@ at * at * at * +(node:*) Error: This was rejected + at * (*test*message*unhandled_promise_trace_warnings.js:*) at * -(node*) Error: This was rejected at * at * at * at * at * - at * - at * -(node*) PromiseRejectionHandledWarning: Promise rejection was handled asynchronously (rejection id: 1) - at * - at * - at Promise.then () - at Promise.catch () - 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/fixtures/tick/nexttick_throw.snapshot b/test/fixtures/tick/nexttick_throw.snapshot index 07f5ad5e26522f..929a4e2a89a00a 100644 --- a/test/fixtures/tick/nexttick_throw.snapshot +++ b/test/fixtures/tick/nexttick_throw.snapshot @@ -1,9 +1,9 @@ -*nexttick_throw.js* +*test*message*nexttick_throw.js:* undefined_reference_error_maker; ^ ReferenceError: undefined_reference_error_maker is not defined - at * - at * + 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 2439934646461a..87d18789bfe46e 100644 --- a/test/parallel/test-node-output-console.mjs +++ b/test/parallel/test-node-output-console.mjs @@ -11,29 +11,56 @@ 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('/', '*') .replaceAll(process.version, '*') .replaceAll(/\d+/g, '*'); } - const common = snapshot - .transform(snapshot.replaceWindowsLineEndings, snapshot.replaceWindowsPaths); + 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: normalizedTransform }, + { name: 'console/eval_messages.js', transform: noEvalMessagesTransform }, { name: 'console/hello_world.js' }, { name: 'console/stack_overflow.js', transform: normalizedTransform }, - { name: 'console/stdin_messages.js', transform: normalizedTransform }, + { name: 'console/stdin_messages.js', transform: noMessagesTransform }, !skipForceColors ? { name: 'console/force_colors.js', env: { FORCE_COLOR: 1 } } : null, ].filter(Boolean); diff --git a/test/parallel/test-node-output-errors.mjs b/test/parallel/test-node-output-errors.mjs index f597e292c105b3..41a37ef9889d7b 100644 --- a/test/parallel/test-node-output-errors.mjs +++ b/test/parallel/test-node-output-errors.mjs @@ -9,20 +9,33 @@ 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 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('/test/fixtures/errors/', '*') .replaceAll(process.version, '*') - .replaceAll(/\/(\w)/g, '*$1') - .replaceAll('*test*', '*') - .replaceAll('*fixtures*errors*', '*') - .replaceAll('file:**', 'file:*/'); + .replaceAll('/', '*') + .replace(/\(node:\d+\)/g, '(node:*)') + .replaceAll(' ** ', ' * ') + .replaceAll('*test*fixtures*', '*fixtures*') + .replaceAll('file:***', 'file:*/'); } function normalizeNoNumbers(str) { @@ -30,12 +43,72 @@ describe('errors output', { concurrency: true }, () => { .replaceAll(/:\d+/g, ':*'); } - const common = snapshot - .transform(snapshot.replaceWindowsLineEndings, snapshot.replaceWindowsPaths); + 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' }, { name: 'errors/async_error_eval_esm.js' }, @@ -55,15 +128,15 @@ describe('errors output', { concurrency: true }, () => { { 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: noStackTraceTransform }, - { name: 'errors/throw_error_with_getter_throw.js', transform: noStackTraceTransform }, - { name: 'errors/throw_null.js', transform: noStackTraceTransform }, - { name: 'errors/throw_undefined.js', transform: noStackTraceTransform }, - { name: 'errors/timeout_throw.js', transform: noStackTraceTransform }, - { name: 'errors/undefined_reference_in_new_context.js', transform: noStackTraceTransform }, + { 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: noStackTraceTransform }, - { name: 'errors/v8_warning.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); diff --git a/test/parallel/test-output-map.mjs b/test/parallel/test-output-map.mjs index 7f7a4d9ea04d99..4bc7cadc683298 100644 --- a/test/parallel/test-output-map.mjs +++ b/test/parallel/test-output-map.mjs @@ -7,34 +7,44 @@ 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('//', '*') - .replaceAll(process.version, '*') - .replaceAll(/\/(\w)/g, '*$1') - .replaceAll('*test*', '*') - .replaceAll('*fixtures*source-map*', '*') - .replaceAll(/:\d+/g, ':*'); - } - - function normalizeSpecialCharacters(str) { - const replacement = (match) => match.replace(/[^(\n|\r)]/g, '*').replace(/\s\*/g, ''); - return normalize(str).replace(/(?<=\(")[^"]+/, replacement); + .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 common = snapshot.transform(snapshot.replaceWindowsLineEndings, snapshot.replaceWindowsPaths); + const defaultTransform = snapshot.transform(common, normalize); - const noStackTraceTransform = snapshot.transform(common, replaceStackTrace, normalize); - const noSpecialCharacterTransform = snapshot.transform(common, replaceStackTrace, normalizeSpecialCharacters); + + 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: noStackTraceTransform }, - { name: 'map/source_map_sourcemapping_url_string.js', transform: noStackTraceTransform }, - { name: 'map/source_map_throw_catch.js', transform: noStackTraceTransform }, - { name: 'map/source_map_throw_icu.js', transform: noSpecialCharacterTransform } + { 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 () => { diff --git a/test/parallel/test-output-promise.mjs b/test/parallel/test-output-promise.mjs index 8b74f80fd28a2b..266463d2c729e6 100644 --- a/test/parallel/test-output-promise.mjs +++ b/test/parallel/test-output-promise.mjs @@ -11,18 +11,32 @@ describe('map output', { concurrency: true }, () => { function normalize(str) { return str .replaceAll(snapshot.replaceWindowsPaths(process.cwd()), '') - .replaceAll('/', '*') .replaceAll(process.version, '*') - .replaceAll(/:\d+/g, '*'); + .replace(/\(node:\d+\)/g, '(node:*)'); } - const common = snapshot - .transform(snapshot.replaceWindowsLineEndings, snapshot.replaceWindowsPaths); + 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' }, - { name: 'promise/unhandled_promise_trace_warnings.js' }, + { 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) { diff --git a/test/parallel/test-output-tick.mjs b/test/parallel/test-output-tick.mjs index 6cdc5505fa6741..d9850da8fe6fea 100644 --- a/test/parallel/test-output-tick.mjs +++ b/test/parallel/test-output-tick.mjs @@ -3,28 +3,23 @@ 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('/', '*') + .replaceAll('/test/fixtures/tick/', '*test*message*') .replaceAll(process.version, '*') - .replaceAll('*test*fixtures*tick*', '*') - .replaceAll(/:\d+/g, '*'); + .replaceAll(/\d+/g, '*'); } - const common = snapshot - .transform(snapshot.replaceWindowsLineEndings, snapshot.replaceWindowsPaths); + const common = snapshot.transform(snapshot.replaceWindowsLineEndings, snapshot.replaceWindowsPaths); + const defaultTransform = snapshot.transform(common); - const customTransform = snapshot.transform(common, replaceStackTrace, normalize); + const noNextTickThrowTransform = snapshot.transform(common, normalize); const tests = [ { name: 'tick/max_tick_depth.js' }, - { name: 'tick/nexttick_throw.js', transform: customTransform }, + { name: 'tick/nexttick_throw.js', transform: noNextTickThrowTransform }, ]; for (const { name, transform } of tests) {