11cb0ef41Sopenharmony_ciimport * as common from '../common/index.mjs'; 21cb0ef41Sopenharmony_ciimport * as fixtures from '../common/fixtures.mjs'; 31cb0ef41Sopenharmony_ciimport * as snapshot from '../common/assertSnapshot.js'; 41cb0ef41Sopenharmony_ciimport * as os from 'node:os'; 51cb0ef41Sopenharmony_ciimport { describe, it } from 'node:test'; 61cb0ef41Sopenharmony_ciimport { pathToFileURL } from 'node:url'; 71cb0ef41Sopenharmony_ci 81cb0ef41Sopenharmony_ciconst skipForceColors = 91cb0ef41Sopenharmony_ci process.config.variables.icu_gyp_path !== 'tools/icu/icu-generic.gyp' || 101cb0ef41Sopenharmony_ci process.config.variables.node_shared_openssl || 111cb0ef41Sopenharmony_ci (common.isWindows && (Number(os.release().split('.')[0]) !== 10 || Number(os.release().split('.')[2]) < 14393)); // See https://github.com/nodejs/node/pull/33132 121cb0ef41Sopenharmony_ci 131cb0ef41Sopenharmony_ci 141cb0ef41Sopenharmony_cifunction replaceStackTrace(str) { 151cb0ef41Sopenharmony_ci return snapshot.replaceStackTrace(str, '$1at *$7\n'); 161cb0ef41Sopenharmony_ci} 171cb0ef41Sopenharmony_ci 181cb0ef41Sopenharmony_cifunction replaceForceColorsStackTrace(str) { 191cb0ef41Sopenharmony_ci // eslint-disable-next-line no-control-regex 201cb0ef41Sopenharmony_ci return str.replaceAll(/(\[90m\W+)at .*node:.*/g, '$1at *[39m'); 211cb0ef41Sopenharmony_ci} 221cb0ef41Sopenharmony_ci 231cb0ef41Sopenharmony_cidescribe('errors output', { concurrency: true }, () => { 241cb0ef41Sopenharmony_ci function normalize(str) { 251cb0ef41Sopenharmony_ci return str.replaceAll(snapshot.replaceWindowsPaths(process.cwd()), '') 261cb0ef41Sopenharmony_ci .replaceAll(pathToFileURL(process.cwd()).pathname, '') 271cb0ef41Sopenharmony_ci .replaceAll('//', '*') 281cb0ef41Sopenharmony_ci .replaceAll(/\/(\w)/g, '*$1') 291cb0ef41Sopenharmony_ci .replaceAll('*test*', '*') 301cb0ef41Sopenharmony_ci .replaceAll('*fixtures*errors*', '*') 311cb0ef41Sopenharmony_ci .replaceAll('file:**', 'file:*/'); 321cb0ef41Sopenharmony_ci } 331cb0ef41Sopenharmony_ci 341cb0ef41Sopenharmony_ci function normalizeNoNumbers(str) { 351cb0ef41Sopenharmony_ci return normalize(str).replaceAll(/\d+:\d+/g, '*:*').replaceAll(/:\d+/g, ':*').replaceAll('*fixtures*message*', '*'); 361cb0ef41Sopenharmony_ci } 371cb0ef41Sopenharmony_ci const common = snapshot 381cb0ef41Sopenharmony_ci .transform(snapshot.replaceWindowsLineEndings, snapshot.replaceWindowsPaths); 391cb0ef41Sopenharmony_ci const defaultTransform = snapshot.transform(common, normalize, snapshot.replaceNodeVersion); 401cb0ef41Sopenharmony_ci const errTransform = snapshot.transform(common, normalizeNoNumbers, snapshot.replaceNodeVersion); 411cb0ef41Sopenharmony_ci const promiseTransform = snapshot.transform(common, replaceStackTrace, 421cb0ef41Sopenharmony_ci normalizeNoNumbers, snapshot.replaceNodeVersion); 431cb0ef41Sopenharmony_ci const forceColorsTransform = snapshot.transform(common, normalize, 441cb0ef41Sopenharmony_ci replaceForceColorsStackTrace, snapshot.replaceNodeVersion); 451cb0ef41Sopenharmony_ci 461cb0ef41Sopenharmony_ci const tests = [ 471cb0ef41Sopenharmony_ci { name: 'errors/async_error_eval_cjs.js' }, 481cb0ef41Sopenharmony_ci { name: 'errors/async_error_eval_esm.js' }, 491cb0ef41Sopenharmony_ci { name: 'errors/async_error_microtask_main.js' }, 501cb0ef41Sopenharmony_ci { name: 'errors/async_error_nexttick_main.js' }, 511cb0ef41Sopenharmony_ci { name: 'errors/async_error_sync_main.js' }, 521cb0ef41Sopenharmony_ci { name: 'errors/async_error_sync_esm.mjs' }, 531cb0ef41Sopenharmony_ci { name: 'errors/error_aggregateTwoErrors.js', transform: errTransform }, 541cb0ef41Sopenharmony_ci { name: 'errors/error_exit.js', transform: errTransform }, 551cb0ef41Sopenharmony_ci { name: 'errors/error_with_nul.js', transform: errTransform }, 561cb0ef41Sopenharmony_ci { name: 'errors/events_unhandled_error_common_trace.js', transform: errTransform }, 571cb0ef41Sopenharmony_ci { name: 'errors/events_unhandled_error_nexttick.js', transform: errTransform }, 581cb0ef41Sopenharmony_ci { name: 'errors/events_unhandled_error_sameline.js', transform: errTransform }, 591cb0ef41Sopenharmony_ci { name: 'errors/events_unhandled_error_subclass.js', transform: errTransform }, 601cb0ef41Sopenharmony_ci { name: 'errors/throw_custom_error.js', transform: errTransform }, 611cb0ef41Sopenharmony_ci { name: 'errors/throw_in_line_with_tabs.js', transform: errTransform }, 621cb0ef41Sopenharmony_ci { name: 'errors/throw_non_error.js', transform: errTransform }, 631cb0ef41Sopenharmony_ci { name: 'errors/promise_always_throw_unhandled.js', transform: promiseTransform }, 641cb0ef41Sopenharmony_ci { skip: skipForceColors, name: 'errors/force_colors.js', 651cb0ef41Sopenharmony_ci transform: forceColorsTransform, env: { FORCE_COLOR: 1 } }, 661cb0ef41Sopenharmony_ci ]; 671cb0ef41Sopenharmony_ci for (const { name, transform = defaultTransform, env, skip = false } of tests) { 681cb0ef41Sopenharmony_ci it(name, { skip }, async () => { 691cb0ef41Sopenharmony_ci await snapshot.spawnAndAssert(fixtures.path(name), transform, { env }); 701cb0ef41Sopenharmony_ci }); 711cb0ef41Sopenharmony_ci } 721cb0ef41Sopenharmony_ci}); 73