From 48f6d9a975852818c0178ed598f3846ff582e184 Mon Sep 17 00:00:00 2001 From: Antoine du Hamel Date: Thu, 3 Aug 2023 23:52:30 +0200 Subject: [PATCH] test: refactor `test-node-output-errors` The main reason is to not have the test fail if the CWD contains some special URL chars. PR-URL: https://github.com/nodejs/node/pull/48992 Backport-PR-URL: https://github.com/nodejs/node/pull/50669 Reviewed-By: Moshe Atlow Reviewed-By: Chemi Atlow --- test/parallel/test-node-output-errors.mjs | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/test/parallel/test-node-output-errors.mjs b/test/parallel/test-node-output-errors.mjs index fca2149fea3212..4c4fc08c0cf382 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 { pathToFileURL } from 'node:url'; const skipForceColors = process.config.variables.icu_gyp_path !== 'tools/icu/icu-generic.gyp' || @@ -20,7 +21,13 @@ function replaceStackTrace(str) { describe('errors output', { concurrency: true }, () => { function normalize(str) { - return str.replaceAll(snapshot.replaceWindowsPaths(process.cwd()), '').replaceAll('//', '*').replaceAll(/\/(\w)/g, '*$1').replaceAll('*test*', '*').replaceAll('*fixtures*errors*', '*').replaceAll('file:**', 'file:*/'); + 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:*/'); } function normalizeNoNumbers(str) { @@ -50,11 +57,11 @@ describe('errors output', { concurrency: true }, () => { { name: 'errors/throw_in_line_with_tabs.js', transform: errTransform }, { name: 'errors/throw_non_error.js', transform: errTransform }, { name: 'errors/promise_always_throw_unhandled.js', transform: promiseTransform }, - !skipForceColors ? { name: 'errors/force_colors.js', env: { FORCE_COLOR: 1 } } : null, - ].filter(Boolean); - for (const { name, transform, env } of tests) { - it(name, async () => { - await snapshot.spawnAndAssert(fixtures.path(name), transform ?? defaultTransform, { env }); + { skip: skipForceColors, name: 'errors/force_colors.js', env: { FORCE_COLOR: 1 } }, + ]; + for (const { name, transform = defaultTransform, env, skip = false } of tests) { + it(name, { skip }, async () => { + await snapshot.spawnAndAssert(fixtures.path(name), transform, { env }); }); } });