test: make snapshot comparison more flexible

PR-URL: https://github.com/nodejs/node/pull/54375
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
This commit is contained in:
Shelley Vohr
2024-08-16 16:29:22 +02:00
committed by GitHub
parent f0134fa6c3
commit e4f61de14f
5 changed files with 8 additions and 5 deletions

View File

@@ -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)

View File

@@ -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 *

View File

@@ -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 *

View File

@@ -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 *

View File

@@ -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 =
@@ -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) {