Skip to content

Commit

Permalink
test: make snapshot comparison more flexible
Browse files Browse the repository at this point in the history
PR-URL: nodejs#54375
Reviewed-By: Antoine du Hamel <[email protected]>
Reviewed-By: Luigi Pinca <[email protected]>
  • Loading branch information
codebytere authored Aug 16, 2024
1 parent f0134fa commit e4f61de
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@
at *
at *
at *
(Use `node --trace-warnings ...` to show where the warning was created)
(Use `* --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
Expand Up @@ -3,6 +3,6 @@
throw { * eslint-disable-line no-throw-literal
^
[object Object]
(Use `node --trace-uncaught ...` to show where the exception was thrown)
(Use `* --trace-uncaught ...` to show where the exception was thrown)

Node.js *
2 changes: 1 addition & 1 deletion test/fixtures/errors/throw_null.snapshot
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
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 *
2 changes: 1 addition & 1 deletion test/fixtures/errors/throw_undefined.snapshot
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
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 *
5 changes: 4 additions & 1 deletion test/parallel/test-node-output-errors.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import * as fixtures from '../common/fixtures.mjs';
import * as snapshot from '../common/assertSnapshot.js';
import * as os from 'node:os';
import { describe, it } from 'node:test';
import { basename } from 'node:path';
import { pathToFileURL } from 'node:url';

const skipForceColors =
Expand All @@ -20,13 +21,15 @@ function replaceForceColorsStackTrace(str) {

describe('errors output', { concurrency: !process.env.TEST_PARALLEL }, () => {
function normalize(str) {
const baseName = basename(process.argv0 || 'node', '.exe');
return str.replaceAll(snapshot.replaceWindowsPaths(process.cwd()), '')
.replaceAll(pathToFileURL(process.cwd()).pathname, '')
.replaceAll('//', '*')
.replaceAll(/\/(\w)/g, '*$1')
.replaceAll('*test*', '*')
.replaceAll('*fixtures*errors*', '*')
.replaceAll('file:**', 'file:*/');
.replaceAll('file:**', 'file:*/')
.replaceAll(`${baseName} --`, '* --');
}

function normalizeNoNumbers(str) {
Expand Down

0 comments on commit e4f61de

Please sign in to comment.