From 38579e7cfea6a8d618d004c8f294c38ccaab85b4 Mon Sep 17 00:00:00 2001 From: Antoine du Hamel Date: Tue, 1 Aug 2023 23:44:09 +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. --- 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 }); }); } });