diff --git a/test/common/assertSnapshot.js b/test/common/assertSnapshot.js index 0bd0fc18534f8b..88f40281e069b7 100644 --- a/test/common/assertSnapshot.js +++ b/test/common/assertSnapshot.js @@ -8,6 +8,10 @@ const assert = require('node:assert/strict'); const stackFramesRegexp = /(?<=\n)(\s+)((.+?)\s+\()?(?:\(?(.+?):(\d+)(?::(\d+))?)\)?(\s+\{)?(\[\d+m)?(\n|$)/g; const windowNewlineRegexp = /\r/g; +function replaceNodeVersion(str) { + return str.replaceAll(process.version, '*'); +} + function replaceStackTrace(str, replacement = '$1*$7$8\n') { return str.replace(stackFramesRegexp, replacement); } @@ -84,6 +88,7 @@ module.exports = { assertSnapshot, getSnapshotPath, replaceFullPaths, + replaceNodeVersion, replaceStackTrace, replaceWindowsLineEndings, replaceWindowsPaths, diff --git a/test/fixtures/errors/force_colors.snapshot b/test/fixtures/errors/force_colors.snapshot index f843a3586ee800..3624d9f0804545 100644 --- a/test/fixtures/errors/force_colors.snapshot +++ b/test/fixtures/errors/force_colors.snapshot @@ -4,11 +4,11 @@ throw new Error('Should include grayed stack trace') Error: Should include grayed stack trace at Object. (/test*force_colors.js:1:7) - at Module._compile (node:internal*modules*cjs*loader:1264:14) - at Module._extensions..js (node:internal*modules*cjs*loader:1318:10) - at Module.load (node:internal*modules*cjs*loader:1113:32) - at Module._load (node:internal*modules*cjs*loader:954:12) - at Function.executeUserEntryPoint [as runMain] (node:internal*modules*run_main:80:12) - at node:internal*main*run_main_module:23:47 + at * + at * + at * + at * + at * + at * Node.js * diff --git a/test/fixtures/source-map/output/source_map_sourcemapping_url_string.snapshot b/test/fixtures/source-map/output/source_map_sourcemapping_url_string.snapshot index a2a988e82eda2c..6a109c904e1155 100644 --- a/test/fixtures/source-map/output/source_map_sourcemapping_url_string.snapshot +++ b/test/fixtures/source-map/output/source_map_sourcemapping_url_string.snapshot @@ -1,3 +1,3 @@ Error: an exception. at Object. (*typescript-sourcemapping_url_string.ts:3:7) - at Module._compile (node:internal*modules*cjs*loader:1264:14) + * diff --git a/test/parallel/test-node-output-errors.mjs b/test/parallel/test-node-output-errors.mjs index 4c4fc08c0cf382..5be920627ad70e 100644 --- a/test/parallel/test-node-output-errors.mjs +++ b/test/parallel/test-node-output-errors.mjs @@ -11,14 +11,15 @@ const skipForceColors = (common.isWindows && (Number(os.release().split('.')[0]) !== 10 || Number(os.release().split('.')[2]) < 14393)); // See https://github.com/nodejs/node/pull/33132 -function replaceNodeVersion(str) { - return str.replaceAll(process.version, '*'); -} - function replaceStackTrace(str) { return snapshot.replaceStackTrace(str, '$1at *$7\n'); } +function replaceForceColorsStackTrace(str) { + // eslint-disable-next-line no-control-regex + return str.replaceAll(/(\[90m\W+)at .*node:.*/g, '$1at *'); +} + describe('errors output', { concurrency: true }, () => { function normalize(str) { return str.replaceAll(snapshot.replaceWindowsPaths(process.cwd()), '') @@ -35,9 +36,12 @@ describe('errors output', { concurrency: true }, () => { } const common = snapshot .transform(snapshot.replaceWindowsLineEndings, snapshot.replaceWindowsPaths); - const defaultTransform = snapshot.transform(common, normalize, replaceNodeVersion); - const errTransform = snapshot.transform(common, normalizeNoNumbers, replaceNodeVersion); - const promiseTransform = snapshot.transform(common, replaceStackTrace, normalizeNoNumbers, replaceNodeVersion); + const defaultTransform = snapshot.transform(common, normalize, snapshot.replaceNodeVersion); + const errTransform = snapshot.transform(common, normalizeNoNumbers, snapshot.replaceNodeVersion); + const promiseTransform = snapshot.transform(common, replaceStackTrace, + normalizeNoNumbers, snapshot.replaceNodeVersion); + const forceColorsTransform = snapshot.transform(common, normalize, + replaceForceColorsStackTrace, snapshot.replaceNodeVersion); const tests = [ { name: 'errors/async_error_eval_cjs.js' }, @@ -57,7 +61,8 @@ 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 }, - { skip: skipForceColors, name: 'errors/force_colors.js', env: { FORCE_COLOR: 1 } }, + { skip: skipForceColors, name: 'errors/force_colors.js', + transform: forceColorsTransform, env: { FORCE_COLOR: 1 } }, ]; for (const { name, transform = defaultTransform, env, skip = false } of tests) { it(name, { skip }, async () => { diff --git a/test/parallel/test-node-output-sourcemaps.mjs b/test/parallel/test-node-output-sourcemaps.mjs index 2043fa57f06a8d..b01f30765c7de8 100644 --- a/test/parallel/test-node-output-sourcemaps.mjs +++ b/test/parallel/test-node-output-sourcemaps.mjs @@ -4,10 +4,6 @@ import * as snapshot from '../common/assertSnapshot.js'; import * as path from 'node:path'; import { describe, it } from 'node:test'; -function replaceNodeVersion(str) { - return str.replaceAll(process.version, '*'); -} - describe('sourcemaps output', { concurrency: true }, () => { function normalize(str) { const result = str @@ -16,7 +12,8 @@ describe('sourcemaps output', { concurrency: true }, () => { .replaceAll('/Users/bencoe/oss/coffee-script-test', '') .replaceAll(/\/(\w)/g, '*$1') .replaceAll('*test*', '*') - .replaceAll('*fixtures*source-map*', '*'); + .replaceAll('*fixtures*source-map*', '*') + .replaceAll(/(\W+).*node:internal\*modules.*/g, '$1*'); if (common.isWindows) { const currentDeviceLetter = path.parse(process.cwd()).root.substring(0, 1).toLowerCase(); const regex = new RegExp(`${currentDeviceLetter}:/?`, 'gi'); @@ -25,7 +22,8 @@ describe('sourcemaps output', { concurrency: true }, () => { return result; } const defaultTransform = snapshot - .transform(snapshot.replaceWindowsLineEndings, snapshot.replaceWindowsPaths, normalize, replaceNodeVersion); + .transform(snapshot.replaceWindowsLineEndings, snapshot.replaceWindowsPaths, + normalize, snapshot.replaceNodeVersion); const tests = [ { name: 'source-map/output/source_map_disabled_by_api.js' },