From 853f57239c5baa06c55a40ab8993258e16c6f1d6 Mon Sep 17 00:00:00 2001 From: Yiyun Lei Date: Thu, 21 Sep 2023 18:14:34 -0400 Subject: [PATCH] test: migrate message error tests from Python to JS Migrate the remaining error tests in the `test/message` folder from Python to JS. Fixes: https://github.com/nodejs/node/issues/47707 PR-URL: https://github.com/nodejs/node/pull/49721 Reviewed-By: Moshe Atlow Reviewed-By: Chemi Atlow --- .../errors}/core_line_numbers.js | 2 +- .../errors/core_line_numbers.snapshot} | 4 +-- .../errors}/if-error-has-good-stack.js | 2 +- .../errors/if-error-has-good-stack.snapshot} | 2 +- .../promise_unhandled_warn_with_error.js | 2 +- ...promise_unhandled_warn_with_error.snapshot | 10 +++++++ .../test-no-extra-info-on-fatal-exception.js | 2 +- ...-no-extra-info-on-fatal-exception.snapshot | 6 +++++ .../errors}/throw_error_with_getter_throw.js | 2 +- .../throw_error_with_getter_throw.snapshot | 8 ++++++ .../errors}/throw_null.js | 2 +- test/fixtures/errors/throw_null.snapshot | 8 ++++++ .../errors}/throw_undefined.js | 2 +- test/fixtures/errors/throw_undefined.snapshot | 8 ++++++ .../errors}/timeout_throw.js | 2 +- test/fixtures/errors/timeout_throw.snapshot | 10 +++++++ .../undefined_reference_in_new_context.js | 2 +- ...ndefined_reference_in_new_context.snapshot | 13 ++++++++++ .../unhandled_promise_trace_warnings.js | 2 +- .../unhandled_promise_trace_warnings.snapshot | 26 +++++++++++++++++++ .../promise_unhandled_warn_with_error.out | 10 ------- .../test-no-extra-info-on-fatal-exception.out | 6 ----- .../message/throw_error_with_getter_throw.out | 8 ------ test/message/throw_null.out | 8 ------ test/message/throw_undefined.out | 8 ------ test/message/timeout_throw.out | 9 ------- .../undefined_reference_in_new_context.out | 13 ---------- .../unhandled_promise_trace_warnings.out | 26 ------------------- test/parallel/test-node-output-errors.mjs | 10 +++++++ 29 files changed, 112 insertions(+), 101 deletions(-) rename test/{message => fixtures/errors}/core_line_numbers.js (95%) rename test/{message/core_line_numbers.out => fixtures/errors/core_line_numbers.snapshot} (54%) 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}/promise_unhandled_warn_with_error.js (88%) create mode 100644 test/fixtures/errors/promise_unhandled_warn_with_error.snapshot rename test/{message => fixtures/errors}/test-no-extra-info-on-fatal-exception.js (81%) create mode 100644 test/fixtures/errors/test-no-extra-info-on-fatal-exception.snapshot rename test/{message => fixtures/errors}/throw_error_with_getter_throw.js (88%) create mode 100644 test/fixtures/errors/throw_error_with_getter_throw.snapshot rename test/{message => fixtures/errors}/throw_null.js (97%) create mode 100644 test/fixtures/errors/throw_null.snapshot rename test/{message => fixtures/errors}/throw_undefined.js (97%) create mode 100644 test/fixtures/errors/throw_undefined.snapshot rename test/{message => fixtures/errors}/timeout_throw.js (98%) create mode 100644 test/fixtures/errors/timeout_throw.snapshot rename test/{message => fixtures/errors}/undefined_reference_in_new_context.js (98%) create mode 100644 test/fixtures/errors/undefined_reference_in_new_context.snapshot rename test/{message => fixtures/errors}/unhandled_promise_trace_warnings.js (86%) create mode 100644 test/fixtures/errors/unhandled_promise_trace_warnings.snapshot delete mode 100644 test/message/promise_unhandled_warn_with_error.out delete mode 100644 test/message/test-no-extra-info-on-fatal-exception.out delete mode 100644 test/message/throw_error_with_getter_throw.out delete mode 100644 test/message/throw_null.out delete mode 100644 test/message/throw_undefined.out delete mode 100644 test/message/timeout_throw.out delete mode 100644 test/message/undefined_reference_in_new_context.out delete mode 100644 test/message/unhandled_promise_trace_warnings.out diff --git a/test/message/core_line_numbers.js b/test/fixtures/errors/core_line_numbers.js similarity index 95% rename from test/message/core_line_numbers.js rename to test/fixtures/errors/core_line_numbers.js index 585a6042652df1..5482a21bae9a1f 100644 --- a/test/message/core_line_numbers.js +++ b/test/fixtures/errors/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/core_line_numbers.out b/test/fixtures/errors/core_line_numbers.snapshot similarity index 54% rename from test/message/core_line_numbers.out rename to test/fixtures/errors/core_line_numbers.snapshot index b5f4b6c72010e9..54cdb52744b29e 100644 --- a/test/message/core_line_numbers.out +++ b/test/fixtures/errors/core_line_numbers.snapshot @@ -4,7 +4,7 @@ node:punycode:49 RangeError: Invalid input at error (node:punycode:49:8) - at Object.decode (node:punycode:*:*) - at Object. (*test*message*core_line_numbers.js:*:*) + at Object.decode (node:punycode:242:5) + at Object. (*core_line_numbers.js:13:10) Node.js * diff --git a/test/message/if-error-has-good-stack.js b/test/fixtures/errors/if-error-has-good-stack.js similarity index 93% rename from test/message/if-error-has-good-stack.js rename to test/fixtures/errors/if-error-has-good-stack.js index 4f529d3e5d17ff..85c127c4e24c54 100644 --- a/test/message/if-error-has-good-stack.js +++ b/test/fixtures/errors/if-error-has-good-stack.js @@ -1,6 +1,6 @@ 'use strict'; -require('../common'); +require('../../common'); Error.stackTraceLimit = 4; const assert = require('assert'); diff --git a/test/message/if-error-has-good-stack.out b/test/fixtures/errors/if-error-has-good-stack.snapshot similarity index 94% rename from test/message/if-error-has-good-stack.out rename to test/fixtures/errors/if-error-has-good-stack.snapshot index e394127bd4c473..9296b25f10b7c6 100644 --- a/test/message/if-error-has-good-stack.out +++ b/test/fixtures/errors/if-error-has-good-stack.snapshot @@ -3,7 +3,7 @@ node:assert:* ^ AssertionError [ERR_ASSERTION]: ifError got unwanted exception: test error - at z (*if-error-has-good-stack.js:*:* + at z (*if-error-has-good-stack.js:*:*) at y (*if-error-has-good-stack.js:*:*) at x (*if-error-has-good-stack.js:*:*) at Object. (*if-error-has-good-stack.js:*:*) diff --git a/test/message/promise_unhandled_warn_with_error.js b/test/fixtures/errors/promise_unhandled_warn_with_error.js similarity index 88% rename from test/message/promise_unhandled_warn_with_error.js rename to test/fixtures/errors/promise_unhandled_warn_with_error.js index e07f52039101a3..b71757a259f04a 100644 --- a/test/message/promise_unhandled_warn_with_error.js +++ b/test/fixtures/errors/promise_unhandled_warn_with_error.js @@ -1,7 +1,7 @@ // Flags: --unhandled-rejections=warn-with-error-code 'use strict'; -require('../common'); +require('../../common'); const assert = require('assert'); Promise.reject(new Error('alas')); diff --git a/test/fixtures/errors/promise_unhandled_warn_with_error.snapshot b/test/fixtures/errors/promise_unhandled_warn_with_error.snapshot new file mode 100644 index 00000000000000..d7f1aa2f72007f --- /dev/null +++ b/test/fixtures/errors/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/message/test-no-extra-info-on-fatal-exception.js b/test/fixtures/errors/test-no-extra-info-on-fatal-exception.js similarity index 81% rename from test/message/test-no-extra-info-on-fatal-exception.js rename to test/fixtures/errors/test-no-extra-info-on-fatal-exception.js index dbc61b0f2382e0..d72a7a22cd727e 100644 --- a/test/message/test-no-extra-info-on-fatal-exception.js +++ b/test/fixtures/errors/test-no-extra-info-on-fatal-exception.js @@ -1,7 +1,7 @@ // Flags: --no-extra-info-on-fatal-exception 'use strict'; -require('../common'); +require('../../common'); Error.stackTraceLimit = 1; throw new Error('foo'); diff --git a/test/fixtures/errors/test-no-extra-info-on-fatal-exception.snapshot b/test/fixtures/errors/test-no-extra-info-on-fatal-exception.snapshot new file mode 100644 index 00000000000000..26e096170b3fbd --- /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:7 +throw new Error('foo'); +^ + +Error: foo + at Object. (*test-no-extra-info-on-fatal-exception.js:7:7) diff --git a/test/message/throw_error_with_getter_throw.js b/test/fixtures/errors/throw_error_with_getter_throw.js similarity index 88% rename from test/message/throw_error_with_getter_throw.js rename to test/fixtures/errors/throw_error_with_getter_throw.js index a807ff3e2b6504..0f38a9493dc7c3 100644 --- a/test/message/throw_error_with_getter_throw.js +++ b/test/fixtures/errors/throw_error_with_getter_throw.js @@ -1,5 +1,5 @@ 'use strict'; -require('../common'); +require('../../common'); throw { // eslint-disable-line no-throw-literal get stack() { throw new Error('weird throw but ok'); diff --git a/test/fixtures/errors/throw_error_with_getter_throw.snapshot b/test/fixtures/errors/throw_error_with_getter_throw.snapshot new file mode 100644 index 00000000000000..30bbb336a22aaf --- /dev/null +++ b/test/fixtures/errors/throw_error_with_getter_throw.snapshot @@ -0,0 +1,8 @@ + +*throw_error_with_getter_throw.js:* +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/message/throw_null.js b/test/fixtures/errors/throw_null.js similarity index 97% rename from test/message/throw_null.js rename to test/fixtures/errors/throw_null.js index fb233d1db56704..d8fc14ba784488 100644 --- a/test/message/throw_null.js +++ b/test/fixtures/errors/throw_null.js @@ -20,7 +20,7 @@ // USE OR OTHER DEALINGS IN THE SOFTWARE. 'use strict'; -require('../common'); +require('../../common'); // eslint-disable-next-line no-throw-literal throw null; diff --git a/test/fixtures/errors/throw_null.snapshot b/test/fixtures/errors/throw_null.snapshot new file mode 100644 index 00000000000000..88494ec6832205 --- /dev/null +++ b/test/fixtures/errors/throw_null.snapshot @@ -0,0 +1,8 @@ + +*throw_null.js:* +throw null; +^ +null +(Use `node --trace-uncaught ...` to show where the exception was thrown) + +Node.js * diff --git a/test/message/throw_undefined.js b/test/fixtures/errors/throw_undefined.js similarity index 97% rename from test/message/throw_undefined.js rename to test/fixtures/errors/throw_undefined.js index a89aaf2ee2da59..8c486a7ff4c470 100644 --- a/test/message/throw_undefined.js +++ b/test/fixtures/errors/throw_undefined.js @@ -20,7 +20,7 @@ // USE OR OTHER DEALINGS IN THE SOFTWARE. 'use strict'; -require('../common'); +require('../../common'); // eslint-disable-next-line no-throw-literal throw undefined; diff --git a/test/fixtures/errors/throw_undefined.snapshot b/test/fixtures/errors/throw_undefined.snapshot new file mode 100644 index 00000000000000..baae7384453373 --- /dev/null +++ b/test/fixtures/errors/throw_undefined.snapshot @@ -0,0 +1,8 @@ + +*throw_undefined.js:* +throw undefined; +^ +undefined +(Use `node --trace-uncaught ...` to show where the exception was thrown) + +Node.js * diff --git a/test/message/timeout_throw.js b/test/fixtures/errors/timeout_throw.js similarity index 98% rename from test/message/timeout_throw.js rename to test/fixtures/errors/timeout_throw.js index 9bcbd85b5036e2..bd4130479b48c6 100644 --- a/test/message/timeout_throw.js +++ b/test/fixtures/errors/timeout_throw.js @@ -20,7 +20,7 @@ // USE OR OTHER DEALINGS IN THE SOFTWARE. 'use strict'; -require('../common'); +require('../../common'); setTimeout(function() { // eslint-disable-next-line no-undef,no-unused-expressions diff --git a/test/fixtures/errors/timeout_throw.snapshot b/test/fixtures/errors/timeout_throw.snapshot new file mode 100644 index 00000000000000..ddbb221c27ca3a --- /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 Timeout._onTimeout (*timeout_throw.js:*:*) + at listOnTimeout (node:internal*timers:*:*) + at process.processTimers (node:internal*timers:*:*) + +Node.js * diff --git a/test/message/undefined_reference_in_new_context.js b/test/fixtures/errors/undefined_reference_in_new_context.js similarity index 98% rename from test/message/undefined_reference_in_new_context.js rename to test/fixtures/errors/undefined_reference_in_new_context.js index 29a67632f8f7dd..baa45de11ecef7 100644 --- a/test/message/undefined_reference_in_new_context.js +++ b/test/fixtures/errors/undefined_reference_in_new_context.js @@ -20,7 +20,7 @@ // USE OR OTHER DEALINGS IN THE SOFTWARE. 'use strict'; -require('../common'); +require('../../common'); const vm = require('vm'); console.error('before'); diff --git a/test/fixtures/errors/undefined_reference_in_new_context.snapshot b/test/fixtures/errors/undefined_reference_in_new_context.snapshot new file mode 100644 index 00000000000000..798306c282bfd1 --- /dev/null +++ b/test/fixtures/errors/undefined_reference_in_new_context.snapshot @@ -0,0 +1,13 @@ +before +evalmachine.:* +Error.stackTraceLimit = 5; foo.bar = 5; + ^ + +ReferenceError: foo is not defined + at evalmachine.:*:* + at Script.runInContext (node:vm:*:*) + at Script.runInNewContext (node:vm:*:*) + at Object.runInNewContext (node:vm:*:*) + at Object. (*undefined_reference_in_new_context.js:*:*) + +Node.js * diff --git a/test/message/unhandled_promise_trace_warnings.js b/test/fixtures/errors/unhandled_promise_trace_warnings.js similarity index 86% rename from test/message/unhandled_promise_trace_warnings.js rename to test/fixtures/errors/unhandled_promise_trace_warnings.js index 66c1f39e5de091..53c5315a2dabfd 100644 --- a/test/message/unhandled_promise_trace_warnings.js +++ b/test/fixtures/errors/unhandled_promise_trace_warnings.js @@ -1,5 +1,5 @@ // Flags: --trace-warnings --unhandled-rejections=warn 'use strict'; -require('../common'); +require('../../common'); const p = Promise.reject(new Error('This was rejected')); setImmediate(() => p.catch(() => {})); diff --git a/test/fixtures/errors/unhandled_promise_trace_warnings.snapshot b/test/fixtures/errors/unhandled_promise_trace_warnings.snapshot new file mode 100644 index 00000000000000..1ed082d0736851 --- /dev/null +++ b/test/fixtures/errors/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/message/promise_unhandled_warn_with_error.out b/test/message/promise_unhandled_warn_with_error.out deleted file mode 100644 index 66c98c57f71717..00000000000000 --- a/test/message/promise_unhandled_warn_with_error.out +++ /dev/null @@ -1,10 +0,0 @@ -*UnhandledPromiseRejectionWarning: Error: alas - at *promise_unhandled_warn_with_error.js:*:* - at * - at * - at * - at * - at * - at * -(Use `* --trace-warnings ...` to show where the warning was created) -*UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1) \ No newline at end of file diff --git a/test/message/test-no-extra-info-on-fatal-exception.out b/test/message/test-no-extra-info-on-fatal-exception.out deleted file mode 100644 index d26573344cc41a..00000000000000 --- a/test/message/test-no-extra-info-on-fatal-exception.out +++ /dev/null @@ -1,6 +0,0 @@ -*:7 -throw new Error('foo'); -^ - -Error: foo - at Object. (*:7:7) diff --git a/test/message/throw_error_with_getter_throw.out b/test/message/throw_error_with_getter_throw.out deleted file mode 100644 index 565acfe9e6bf06..00000000000000 --- a/test/message/throw_error_with_getter_throw.out +++ /dev/null @@ -1,8 +0,0 @@ - -*:3 -throw { // eslint-disable-line no-throw-literal -^ -[object Object] -(Use `* --trace-uncaught ...` to show where the exception was thrown) - -Node.js * diff --git a/test/message/throw_null.out b/test/message/throw_null.out deleted file mode 100644 index 0fe2a49d050b18..00000000000000 --- a/test/message/throw_null.out +++ /dev/null @@ -1,8 +0,0 @@ - -*test*message*throw_null.js:* -throw null; -^ -null -(Use `* --trace-uncaught ...` to show where the exception was thrown) - -Node.js * diff --git a/test/message/throw_undefined.out b/test/message/throw_undefined.out deleted file mode 100644 index 56b0cac4259d6d..00000000000000 --- a/test/message/throw_undefined.out +++ /dev/null @@ -1,8 +0,0 @@ - -*test*message*throw_undefined.js:* -throw undefined; -^ -undefined -(Use `* --trace-uncaught ...` to show where the exception was thrown) - -Node.js * diff --git a/test/message/timeout_throw.out b/test/message/timeout_throw.out deleted file mode 100644 index 83b861caa7ca29..00000000000000 --- a/test/message/timeout_throw.out +++ /dev/null @@ -1,9 +0,0 @@ -*test*message*timeout_throw.js:* - undefined_reference_error_maker; - ^ -ReferenceError: undefined_reference_error_maker is not defined - at Timeout._onTimeout (*test*message*timeout_throw.js:*:*) - at listOnTimeout (node:internal/timers:*:*) - at process.processTimers (node:internal/timers:*:*) - -Node.js * diff --git a/test/message/undefined_reference_in_new_context.out b/test/message/undefined_reference_in_new_context.out deleted file mode 100644 index 8d8228bd902950..00000000000000 --- a/test/message/undefined_reference_in_new_context.out +++ /dev/null @@ -1,13 +0,0 @@ -before -evalmachine.:1 -Error.stackTraceLimit = 5; foo.bar = 5; - ^ - -ReferenceError: foo is not defined - at evalmachine.:*:* - at Script.runInContext (node:vm:*) - at Script.runInNewContext (node:vm:*) - at Object.runInNewContext (node:vm:*) - at Object. (*test*message*undefined_reference_in_new_context.js:*) - -Node.js * diff --git a/test/message/unhandled_promise_trace_warnings.out b/test/message/unhandled_promise_trace_warnings.out deleted file mode 100644 index a8717d0e13d1e4..00000000000000 --- a/test/message/unhandled_promise_trace_warnings.out +++ /dev/null @@ -1,26 +0,0 @@ -(node:*) UnhandledPromiseRejectionWarning: Error: This was rejected - at * (*test*message*unhandled_promise_trace_warnings.js:*) - at * - at * - at * - at * - at * - at * - at * - at * - at * -(node:*) Error: This was rejected - at * (*test*message*unhandled_promise_trace_warnings.js:*) - at * - at * - at * - at * - at * - at * -(node:*) PromiseRejectionHandledWarning: Promise rejection was handled asynchronously (rejection id: 1) - at handledRejection (node:internal/process/promises:*) - at promiseRejectHandler (node:internal/process/promises:*) - at Promise.then * - at Promise.catch * - at Immediate. (*test*message*unhandled_promise_trace_warnings.js:*) - at * diff --git a/test/parallel/test-node-output-errors.mjs b/test/parallel/test-node-output-errors.mjs index 5be920627ad70e..c0acee2bfc8c12 100644 --- a/test/parallel/test-node-output-errors.mjs +++ b/test/parallel/test-node-output-errors.mjs @@ -49,7 +49,9 @@ describe('errors output', { concurrency: true }, () => { { name: 'errors/async_error_microtask_main.js' }, { name: 'errors/async_error_nexttick_main.js' }, { name: 'errors/async_error_sync_main.js' }, + { name: 'errors/core_line_numbers.js' }, { name: 'errors/async_error_sync_esm.mjs' }, + { name: 'errors/test-no-extra-info-on-fatal-exception.js' }, { name: 'errors/error_aggregateTwoErrors.js', transform: errTransform }, { name: 'errors/error_exit.js', transform: errTransform }, { name: 'errors/error_with_nul.js', transform: errTransform }, @@ -57,10 +59,18 @@ describe('errors output', { concurrency: true }, () => { { 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/if-error-has-good-stack.js', transform: errTransform }, { name: 'errors/throw_custom_error.js', transform: errTransform }, + { name: 'errors/throw_error_with_getter_throw.js', transform: errTransform }, { name: 'errors/throw_in_line_with_tabs.js', transform: errTransform }, { name: 'errors/throw_non_error.js', transform: errTransform }, + { name: 'errors/throw_null.js', transform: errTransform }, + { name: 'errors/throw_undefined.js', transform: errTransform }, + { name: 'errors/timeout_throw.js', transform: errTransform }, + { name: 'errors/undefined_reference_in_new_context.js', transform: errTransform }, { name: 'errors/promise_always_throw_unhandled.js', transform: promiseTransform }, + { name: 'errors/promise_unhandled_warn_with_error.js', transform: promiseTransform }, + { name: 'errors/unhandled_promise_trace_warnings.js', transform: promiseTransform }, { skip: skipForceColors, name: 'errors/force_colors.js', transform: forceColorsTransform, env: { FORCE_COLOR: 1 } }, ];