Skip to content

Commit

Permalink
test: migrate message error tests from Python to JS
Browse files Browse the repository at this point in the history
Migrate the remaining error tests in the `test/message` folder
from Python to JS.

Fixes: #47707
PR-URL: #49721
Reviewed-By: Moshe Atlow <[email protected]>
Reviewed-By: Chemi Atlow <[email protected]>
  • Loading branch information
Yiyun Lei authored Sep 21, 2023
1 parent 85172c3 commit 853f572
Show file tree
Hide file tree
Showing 29 changed files with 112 additions and 101 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
'use strict';
require('../common');
require('../../common');
Error.stackTraceLimit = 3;

const punycode = require('punycode');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ node:punycode:49

RangeError: Invalid input
at error (node:punycode:49:8)
at Object.decode (node:punycode:*:*)
at Object.<anonymous> (*test*message*core_line_numbers.js:*:*)
at Object.decode (node:punycode:242:5)
at Object.<anonymous> (*core_line_numbers.js:13:10)

Node.js *
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';

require('../common');
require('../../common');
Error.stackTraceLimit = 4;

const assert = require('assert');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.<anonymous> (*if-error-has-good-stack.js:*:*)
Expand Down
Original file line number Diff line number Diff line change
@@ -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'));
Expand Down
10 changes: 10 additions & 0 deletions test/fixtures/errors/promise_unhandled_warn_with_error.snapshot
Original file line number Diff line number Diff line change
@@ -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)
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Flags: --no-extra-info-on-fatal-exception

'use strict';
require('../common');
require('../../common');
Error.stackTraceLimit = 1;

throw new Error('foo');
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
*test-no-extra-info-on-fatal-exception.js:7
throw new Error('foo');
^

Error: foo
at Object.<anonymous> (*test-no-extra-info-on-fatal-exception.js:7:7)
Original file line number Diff line number Diff line change
@@ -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');
Expand Down
8 changes: 8 additions & 0 deletions test/fixtures/errors/throw_error_with_getter_throw.snapshot
Original file line number Diff line number Diff line change
@@ -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 *
Original file line number Diff line number Diff line change
Expand Up @@ -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;
8 changes: 8 additions & 0 deletions test/fixtures/errors/throw_null.snapshot
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@

*throw_null.js:*
throw null;
^
null
(Use `node --trace-uncaught ...` to show where the exception was thrown)

Node.js *
Original file line number Diff line number Diff line change
Expand Up @@ -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;
8 changes: 8 additions & 0 deletions test/fixtures/errors/throw_undefined.snapshot
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@

*throw_undefined.js:*
throw undefined;
^
undefined
(Use `node --trace-uncaught ...` to show where the exception was thrown)

Node.js *
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 10 additions & 0 deletions test/fixtures/errors/timeout_throw.snapshot
Original file line number Diff line number Diff line change
@@ -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 *
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
// USE OR OTHER DEALINGS IN THE SOFTWARE.

'use strict';
require('../common');
require('../../common');
const vm = require('vm');

console.error('before');
Expand Down
13 changes: 13 additions & 0 deletions test/fixtures/errors/undefined_reference_in_new_context.snapshot
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
before
evalmachine.<anonymous>:*
Error.stackTraceLimit = 5; foo.bar = 5;
^

ReferenceError: foo is not defined
at evalmachine.<anonymous>:*:*
at Script.runInContext (node:vm:*:*)
at Script.runInNewContext (node:vm:*:*)
at Object.runInNewContext (node:vm:*:*)
at Object.<anonymous> (*undefined_reference_in_new_context.js:*:*)

Node.js *
Original file line number Diff line number Diff line change
@@ -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(() => {}));
26 changes: 26 additions & 0 deletions test/fixtures/errors/unhandled_promise_trace_warnings.snapshot
Original file line number Diff line number Diff line change
@@ -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 (<anonymous>)
at Promise.catch (<anonymous>)
at *
at *
10 changes: 0 additions & 10 deletions test/message/promise_unhandled_warn_with_error.out

This file was deleted.

6 changes: 0 additions & 6 deletions test/message/test-no-extra-info-on-fatal-exception.out

This file was deleted.

8 changes: 0 additions & 8 deletions test/message/throw_error_with_getter_throw.out

This file was deleted.

8 changes: 0 additions & 8 deletions test/message/throw_null.out

This file was deleted.

8 changes: 0 additions & 8 deletions test/message/throw_undefined.out

This file was deleted.

9 changes: 0 additions & 9 deletions test/message/timeout_throw.out

This file was deleted.

13 changes: 0 additions & 13 deletions test/message/undefined_reference_in_new_context.out

This file was deleted.

26 changes: 0 additions & 26 deletions test/message/unhandled_promise_trace_warnings.out

This file was deleted.

10 changes: 10 additions & 0 deletions test/parallel/test-node-output-errors.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -49,18 +49,28 @@ 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 },
{ 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/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 } },
];
Expand Down

0 comments on commit 853f572

Please sign in to comment.