diff --git a/test/common/assertSnapshot.js b/test/common/assertSnapshot.js index d0fa3c0216f07b..10a5941b41ff37 100644 --- a/test/common/assertSnapshot.js +++ b/test/common/assertSnapshot.js @@ -5,7 +5,7 @@ const test = require('node:test'); const fs = require('node:fs/promises'); const assert = require('node:assert/strict'); -const stackFramesRegexp = /(\s+)((.+?)\s+\()?(?:\(?(.+?):(\d+)(?::(\d+))?)\)?(\s+\{)?(\[\d+m)?(\n|$)/g; +const stackFramesRegexp = /(?<=\n)(\s+)((.+?)\s+\()?(?:\(?(.+?):(\d+)(?::(\d+))?)\)?(\s+\{)?(\[\d+m)?(\n|$)/g; const windowNewlineRegexp = /\r/g; function replaceStackTrace(str, replacement = '$1*$7$8\n') { diff --git a/test/parallel/test-node-output-errors.mjs b/test/parallel/test-node-output-errors.mjs index fe9e3c0f37dd57..4c4fc08c0cf382 100644 --- a/test/parallel/test-node-output-errors.mjs +++ b/test/parallel/test-node-output-errors.mjs @@ -21,7 +21,13 @@ function replaceStackTrace(str) { describe('errors output', { concurrency: true }, () => { function normalize(str) { - 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:*/'); + 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) { @@ -51,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 }); }); } });