From bec51153e1722c81282b420b34902beabde8f5d6 Mon Sep 17 00:00:00 2001 From: Ognjen Jevremovic Date: Sat, 20 Jan 2024 12:49:04 +0100 Subject: [PATCH] test: migrate messages v8 tests from Python to JS Migrated messages v8 tests from Python to JavaScript. This change is part of an effort to enhance maintainability and consistency in the test suite. All relevant test files and dependencies have been updated accordingly. Refs: https://github.com/nodejs/node/issues/47707 --- test/fixtures/errors/assert_throws_stack.js | 11 +++ .../errors/assert_throws_stack.snapshot | 36 +++++++++ .../errors}/console_assert.js | 2 +- test/fixtures/errors/console_assert.snapshot | 1 + .../errors}/eval_messages.js | 17 ++-- test/fixtures/errors/eval_messages.snapshot | 76 ++++++++++++++++++ .../errors}/internal_assert.js | 2 +- test/fixtures/errors/internal_assert.snapshot | 19 +++++ .../errors}/internal_assert_fail.js | 2 +- .../errors/internal_assert_fail.snapshot | 20 +++++ test/message/assert_throws_stack.js | 6 -- test/message/assert_throws_stack.out | 36 --------- test/message/console_assert.out | 1 - test/message/eval_messages.out | 77 ------------------- test/message/internal_assert.out | 19 ----- test/message/internal_assert_fail.out | 20 ----- test/parallel/test-node-output-errors.mjs | 7 +- 17 files changed, 181 insertions(+), 171 deletions(-) create mode 100644 test/fixtures/errors/assert_throws_stack.js create mode 100644 test/fixtures/errors/assert_throws_stack.snapshot rename test/{message => fixtures/errors}/console_assert.js (69%) create mode 100644 test/fixtures/errors/console_assert.snapshot rename test/{message => fixtures/errors}/eval_messages.js (87%) create mode 100644 test/fixtures/errors/eval_messages.snapshot rename test/{message => fixtures/errors}/internal_assert.js (80%) create mode 100644 test/fixtures/errors/internal_assert.snapshot rename test/{message => fixtures/errors}/internal_assert_fail.js (82%) create mode 100644 test/fixtures/errors/internal_assert_fail.snapshot delete mode 100644 test/message/assert_throws_stack.js delete mode 100644 test/message/assert_throws_stack.out delete mode 100644 test/message/console_assert.out delete mode 100644 test/message/eval_messages.out delete mode 100644 test/message/internal_assert.out delete mode 100644 test/message/internal_assert_fail.out diff --git a/test/fixtures/errors/assert_throws_stack.js b/test/fixtures/errors/assert_throws_stack.js new file mode 100644 index 00000000000000..e5bea1b7ba0cba --- /dev/null +++ b/test/fixtures/errors/assert_throws_stack.js @@ -0,0 +1,11 @@ +'use strict'; + +require('../../common'); +const assert = require('assert').strict; + +assert.throws( + () => { + throw new Error('foo'); + }, + { bar: true } +); diff --git a/test/fixtures/errors/assert_throws_stack.snapshot b/test/fixtures/errors/assert_throws_stack.snapshot new file mode 100644 index 00000000000000..a6d6a6cb674dd5 --- /dev/null +++ b/test/fixtures/errors/assert_throws_stack.snapshot @@ -0,0 +1,36 @@ +node:assert:* + throw err; + ^ + +AssertionError [ERR_ASSERTION]: Expected values to be strictly deep-equal: ++ actual - expected + ++ Comparison {} +- Comparison { +- bar: true +- } + at Object. (*assert_throws_stack.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:*:* { + 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 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:*:*, + expected: { bar: true }, + operator: 'throws' +} + +Node.js * diff --git a/test/message/console_assert.js b/test/fixtures/errors/console_assert.js similarity index 69% rename from test/message/console_assert.js rename to test/fixtures/errors/console_assert.js index 14976312820d40..1b2d4697e4cbae 100644 --- a/test/message/console_assert.js +++ b/test/fixtures/errors/console_assert.js @@ -1,5 +1,5 @@ 'use strict'; -require('../common'); +require('../../common'); console.assert(false, Symbol('hello')); diff --git a/test/fixtures/errors/console_assert.snapshot b/test/fixtures/errors/console_assert.snapshot new file mode 100644 index 00000000000000..733ef609b71a80 --- /dev/null +++ b/test/fixtures/errors/console_assert.snapshot @@ -0,0 +1 @@ +Assertion failed Symbol(hello) diff --git a/test/message/eval_messages.js b/test/fixtures/errors/eval_messages.js similarity index 87% rename from test/message/eval_messages.js rename to test/fixtures/errors/eval_messages.js index 69dcbd6efa23a7..5fb9b17a0ed7bf 100644 --- a/test/message/eval_messages.js +++ b/test/fixtures/errors/eval_messages.js @@ -21,7 +21,7 @@ 'use strict'; -require('../common'); +require('../../common'); const spawn = require('child_process').spawn; @@ -35,17 +35,18 @@ function run(cmd, strict, cb) { child.on('close', cb); } -const queue = - [ 'with(this){__filename}', - '42', - 'throw new Error("hello")', - 'var x = 100; y = x;', - 'var ______________________________________________; throw 10' ]; +const queue = [ + 'with(this){__filename}', + '42', + 'throw new Error("hello")', + 'var x = 100; y = x;', + 'var ______________________________________________; throw 10', +]; function go() { const c = queue.shift(); if (!c) return console.log('done'); - run(c, false, function() { + run(c, false, function () { run(c, true, go); }); } diff --git a/test/fixtures/errors/eval_messages.snapshot b/test/fixtures/errors/eval_messages.snapshot new file mode 100644 index 00000000000000..69675699354764 --- /dev/null +++ b/test/fixtures/errors/eval_messages.snapshot @@ -0,0 +1,76 @@ +[eval] +[eval]:* +with(this){__filename} +^^^^ + +SyntaxError: Strict mode code may not include a with statement + at makeContextifyScript (node:internal*vm:*:*) + at node:internal*process*execution:*:* + at [eval]-wrapper:*:* + at runScript (node:internal*process*execution:*:*) + at evalScript (node:internal*process*execution:*:*) + at node:internal*main*eval_string:*:* + +Node.js * +42 +42 +[eval]:* +throw new Error("hello") +^ + +Error: hello + at [eval]:*:* + at runScriptInThisContext (node:internal*vm:*:*) + at node:internal*process*execution:*:* + at [eval]-wrapper:*:* + at runScript (node:internal*process*execution:*:*) + at evalScript (node:internal*process*execution:*:*) + at node:internal*main*eval_string:*:* + +Node.js * +[eval]:* +throw new Error("hello") +^ + +Error: hello + at [eval]:*:* + at runScriptInThisContext (node:internal*vm:*:*) + at node:internal*process*execution:*:* + at [eval]-wrapper:*:* + at runScript (node:internal*process*execution:*:*) + at evalScript (node:internal*process*execution:*:*) + at node:internal*main*eval_string:*:* + +Node.js * +100 +[eval]:* +var x = 100; y = x; + ^ + +ReferenceError: y is not defined + at [eval]:*:* + at runScriptInThisContext (node:internal*vm:*:*) + at node:internal*process*execution:*:* + at [eval]-wrapper:*:* + at runScript (node:internal*process*execution:*:*) + at evalScript (node:internal*process*execution:*:*) + at node:internal*main*eval_string:*:* + +Node.js * + +[eval]:* +var ______________________________________________; throw 10 + ^ +10 +(Use `node --trace-uncaught ...` to show where the exception was thrown) + +Node.js * + +[eval]:* +var ______________________________________________; throw 10 + ^ +10 +(Use `node --trace-uncaught ...` to show where the exception was thrown) + +Node.js * +done diff --git a/test/message/internal_assert.js b/test/fixtures/errors/internal_assert.js similarity index 80% rename from test/message/internal_assert.js rename to test/fixtures/errors/internal_assert.js index fdb459b67ca0fa..871504f0925a6f 100644 --- a/test/message/internal_assert.js +++ b/test/fixtures/errors/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/fixtures/errors/internal_assert.snapshot b/test/fixtures/errors/internal_assert.snapshot new file mode 100644 index 00000000000000..8c8f954b6b358d --- /dev/null +++ b/test/fixtures/errors/internal_assert.snapshot @@ -0,0 +1,19 @@ +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 + + at assert (node:internal*assert:*:*) + at Object. (*internal_assert.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:*:* { + code: 'ERR_INTERNAL_ASSERTION' +} + +Node.js * diff --git a/test/message/internal_assert_fail.js b/test/fixtures/errors/internal_assert_fail.js similarity index 82% rename from test/message/internal_assert_fail.js rename to test/fixtures/errors/internal_assert_fail.js index 1b2cf13552869b..503a1dcbc7264a 100644 --- a/test/message/internal_assert_fail.js +++ b/test/fixtures/errors/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/fixtures/errors/internal_assert_fail.snapshot b/test/fixtures/errors/internal_assert_fail.snapshot new file mode 100644 index 00000000000000..999d474e4605cc --- /dev/null +++ b/test/fixtures/errors/internal_assert_fail.snapshot @@ -0,0 +1,20 @@ +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 + + at Function.fail (node:internal*assert:*:*) + at Object. (*internal_assert_fail.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:*:* { + code: 'ERR_INTERNAL_ASSERTION' +} + +Node.js * diff --git a/test/message/assert_throws_stack.js b/test/message/assert_throws_stack.js deleted file mode 100644 index 36bc5734cae37f..00000000000000 --- a/test/message/assert_throws_stack.js +++ /dev/null @@ -1,6 +0,0 @@ -'use strict'; - -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/message/assert_throws_stack.out deleted file mode 100644 index 06eaa906442440..00000000000000 --- a/test/message/assert_throws_stack.out +++ /dev/null @@ -1,36 +0,0 @@ -node:assert:* - throw err; - ^ - -AssertionError [ERR_ASSERTION]: Expected values to be strictly deep-equal: -+ actual - expected - -+ Comparison {} -- Comparison { -- bar: true -- } - at Object. (*assert_throws_stack.js:*:*) - at * - at * - at * - at * - at * - at * { - 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 *, - expected: { bar: true }, - operator: 'throws' -} - -Node.js * diff --git a/test/message/console_assert.out b/test/message/console_assert.out deleted file mode 100644 index 259d18fa5cfc2f..00000000000000 --- a/test/message/console_assert.out +++ /dev/null @@ -1 +0,0 @@ -Assertion failed* Symbol(hello) diff --git a/test/message/eval_messages.out b/test/message/eval_messages.out deleted file mode 100644 index e07bbe4d6acd3c..00000000000000 --- a/test/message/eval_messages.out +++ /dev/null @@ -1,77 +0,0 @@ -[eval] -[eval]:1 -with(this){__filename} -^^^^ - -SyntaxError: Strict mode code may not include a with statement - at makeContextifyScript (node:internal/vm:*:*) - at node:internal/process/execution:*:* - at [eval]-wrapper:*:* - at runScript (node:internal/process/execution:*:*) - at evalScript (node:internal/process/execution:*:*) - at node:internal/main/eval_string:*:* - -Node.js * -42 -42 -[eval]:1 -throw new Error("hello") -^ - -Error: hello - at [eval]:1:7 - at runScriptInThisContext (node:internal/vm:*:*) - at node:internal/process/execution:*:* - at [eval]-wrapper:*:* - at runScript (node:internal/process/execution:*:*) - at evalScript (node:internal/process/execution:*:*) - at node:internal/main/eval_string:*:* - -Node.js * - -[eval]:1 -throw new Error("hello") -^ - -Error: hello - at [eval]:1:7 - at runScriptInThisContext (node:internal/vm:*:*) - at node:internal/process/execution:*:* - at [eval]-wrapper:*:* - at runScript (node:internal/process/execution:*:*) - at evalScript (node:internal/process/execution:*:*) - at node:internal/main/eval_string:*:* - -Node.js * -100 -[eval]:1 -var x = 100; y = x; - ^ - -ReferenceError: y is not defined - at [eval]:1:16 - at runScriptInThisContext (node:internal/vm:*:*) - at node:internal/process/execution:*:* - at [eval]-wrapper:*:* - at runScript (node:internal/process/execution:*:*) - at evalScript (node:internal/process/execution:*:*) - at node:internal/main/eval_string:*:* - -Node.js * - -[eval]:1 -var ______________________________________________; throw 10 - ^ -10 -(Use `* --trace-uncaught ...` to show where the exception was thrown) - -Node.js * - -[eval]:1 -var ______________________________________________; throw 10 - ^ -10 -(Use `* --trace-uncaught ...` to show where the exception was thrown) - -Node.js * -done diff --git a/test/message/internal_assert.out b/test/message/internal_assert.out deleted file mode 100644 index 197b863bf6ae69..00000000000000 --- a/test/message/internal_assert.out +++ /dev/null @@ -1,19 +0,0 @@ -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 - - at assert (node:internal/assert:*:*) - at * (*test*message*internal_assert.js:7:1) - at * - at * - at * - at * - at * - at * { - code: 'ERR_INTERNAL_ASSERTION' -} - -Node.js * diff --git a/test/message/internal_assert_fail.out b/test/message/internal_assert_fail.out deleted file mode 100644 index e6895691cda9c1..00000000000000 --- a/test/message/internal_assert_fail.out +++ /dev/null @@ -1,20 +0,0 @@ -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 - - at Function.fail (node:internal/assert:*:*) - at * (*test*message*internal_assert_fail.js:7:8) - at * - at * - at * - at * - at * - at * { - code: 'ERR_INTERNAL_ASSERTION' -} - -Node.js * diff --git a/test/parallel/test-node-output-errors.mjs b/test/parallel/test-node-output-errors.mjs index c0acee2bfc8c12..559405c289e815 100644 --- a/test/parallel/test-node-output-errors.mjs +++ b/test/parallel/test-node-output-errors.mjs @@ -48,18 +48,23 @@ describe('errors output', { concurrency: true }, () => { { name: 'errors/async_error_eval_esm.js' }, { name: 'errors/async_error_microtask_main.js' }, { name: 'errors/async_error_nexttick_main.js' }, + { name: 'errors/async_error_sync_esm.mjs' }, { 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/assert_throws_stack.js', transform: errTransform }, + { name: 'errors/console_assert.js', transform: errTransform }, { name: 'errors/error_aggregateTwoErrors.js', transform: errTransform }, { name: 'errors/error_exit.js', transform: errTransform }, { name: 'errors/error_with_nul.js', transform: errTransform }, + { name: 'errors/eval_messages.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/if-error-has-good-stack.js', transform: errTransform }, + { name: 'errors/internal_assert_fail.js', transform: errTransform }, + { name: 'errors/internal_assert.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 },