Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[v20.x backport] snapshot test improvments #49942

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions test/common/assertSnapshot.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ const assert = require('node:assert/strict');
const stackFramesRegexp = /(?<=\n)(\s+)((.+?)\s+\()?(?:\(?(.+?):(\d+)(?::(\d+))?)\)?(\s+\{)?(\[\d+m)?(\n|$)/g;
const windowNewlineRegexp = /\r/g;

function replaceNodeVersion(str) {
return str.replaceAll(process.version, '*');
}

function replaceStackTrace(str, replacement = '$1*$7$8\n') {
return str.replace(stackFramesRegexp, replacement);
}
Expand Down Expand Up @@ -84,6 +88,7 @@ module.exports = {
assertSnapshot,
getSnapshotPath,
replaceFullPaths,
replaceNodeVersion,
replaceStackTrace,
replaceWindowsLineEndings,
replaceWindowsPaths,
Expand Down
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:52

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

Node.js *
12 changes: 6 additions & 6 deletions test/fixtures/errors/force_colors.snapshot
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ throw new Error('Should include grayed stack trace')

Error: Should include grayed stack trace
at Object.<anonymous> (/test*force_colors.js:1:7)
 at Module._compile (node:internal*modules*cjs*loader:1241:14)
 at Module._extensions..js (node:internal*modules*cjs*loader:1295:10)
 at Module.load (node:internal*modules*cjs*loader:1091:32)
 at Module._load (node:internal*modules*cjs*loader:938:12)
 at Function.executeUserEntryPoint [as runMain] (node:internal*modules*run_main:83:12)
 at node:internal*main*run_main_module:23:47
 at *
 at *
 at *
 at *
 at *
 at *

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 *
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
Error: an exception.
at Object.<anonymous> (*typescript-sourcemapping_url_string.ts:3:7)
at Module._compile (node:internal*modules*cjs*loader:1241:14)
*
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.

Loading
Loading