From e4f61de14f8cfb83f1ce0ad1597b86278cd5f5f1 Mon Sep 17 00:00:00 2001 From: Shelley Vohr Date: Fri, 16 Aug 2024 16:29:22 +0200 Subject: [PATCH] test: make snapshot comparison more flexible PR-URL: https://github.com/nodejs/node/pull/54375 Reviewed-By: Antoine du Hamel Reviewed-By: Luigi Pinca --- .../errors/promise_unhandled_warn_with_error.snapshot | 2 +- test/fixtures/errors/throw_error_with_getter_throw.snapshot | 2 +- test/fixtures/errors/throw_null.snapshot | 2 +- test/fixtures/errors/throw_undefined.snapshot | 2 +- test/parallel/test-node-output-errors.mjs | 5 ++++- 5 files changed, 8 insertions(+), 5 deletions(-) diff --git a/test/fixtures/errors/promise_unhandled_warn_with_error.snapshot b/test/fixtures/errors/promise_unhandled_warn_with_error.snapshot index 6acc3fd2b8093a..4b3ed8640dc221 100644 --- a/test/fixtures/errors/promise_unhandled_warn_with_error.snapshot +++ b/test/fixtures/errors/promise_unhandled_warn_with_error.snapshot @@ -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) diff --git a/test/fixtures/errors/throw_error_with_getter_throw.snapshot b/test/fixtures/errors/throw_error_with_getter_throw.snapshot index 30bbb336a22aaf..1786f96f19856c 100644 --- a/test/fixtures/errors/throw_error_with_getter_throw.snapshot +++ b/test/fixtures/errors/throw_error_with_getter_throw.snapshot @@ -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 * diff --git a/test/fixtures/errors/throw_null.snapshot b/test/fixtures/errors/throw_null.snapshot index 88494ec6832205..1a1191ca9ced90 100644 --- a/test/fixtures/errors/throw_null.snapshot +++ b/test/fixtures/errors/throw_null.snapshot @@ -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 * diff --git a/test/fixtures/errors/throw_undefined.snapshot b/test/fixtures/errors/throw_undefined.snapshot index baae7384453373..b6b6060b17839f 100644 --- a/test/fixtures/errors/throw_undefined.snapshot +++ b/test/fixtures/errors/throw_undefined.snapshot @@ -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 * diff --git a/test/parallel/test-node-output-errors.mjs b/test/parallel/test-node-output-errors.mjs index 8b321ed158b66c..1f93330834ea64 100644 --- a/test/parallel/test-node-output-errors.mjs +++ b/test/parallel/test-node-output-errors.mjs @@ -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) {