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 { describe, it } from 'node:test'; 51cb0ef41Sopenharmony_ciimport { hostname } from 'node:os'; 61cb0ef41Sopenharmony_ci 71cb0ef41Sopenharmony_ciconst skipForceColors = 81cb0ef41Sopenharmony_ci process.config.variables.icu_gyp_path !== 'tools/icu/icu-generic.gyp' || 91cb0ef41Sopenharmony_ci process.config.variables.node_shared_openssl; 101cb0ef41Sopenharmony_ci 111cb0ef41Sopenharmony_cifunction replaceTestDuration(str) { 121cb0ef41Sopenharmony_ci return str 131cb0ef41Sopenharmony_ci .replaceAll(/duration_ms: [0-9.]+/g, 'duration_ms: *') 141cb0ef41Sopenharmony_ci .replaceAll(/duration_ms [0-9.]+/g, 'duration_ms *'); 151cb0ef41Sopenharmony_ci} 161cb0ef41Sopenharmony_ci 171cb0ef41Sopenharmony_ciconst color = '(\\[\\d+m)'; 181cb0ef41Sopenharmony_ciconst stackTraceBasePath = new RegExp(`${color}\\(${process.cwd()}/?${color}(.*)${color}\\)`, 'g'); 191cb0ef41Sopenharmony_ci 201cb0ef41Sopenharmony_cifunction replaceSpecDuration(str) { 211cb0ef41Sopenharmony_ci return str 221cb0ef41Sopenharmony_ci .replaceAll(/[0-9.]+ms/g, '*ms') 231cb0ef41Sopenharmony_ci .replaceAll(/duration_ms [0-9.]+/g, 'duration_ms *') 241cb0ef41Sopenharmony_ci .replace(stackTraceBasePath, '$3'); 251cb0ef41Sopenharmony_ci} 261cb0ef41Sopenharmony_ci 271cb0ef41Sopenharmony_cifunction replaceJunitDuration(str) { 281cb0ef41Sopenharmony_ci return str 291cb0ef41Sopenharmony_ci .replaceAll(/time="[0-9.]+"/g, 'time="*"') 301cb0ef41Sopenharmony_ci .replaceAll(/duration_ms [0-9.]+/g, 'duration_ms *') 311cb0ef41Sopenharmony_ci .replaceAll(hostname(), 'HOSTNAME') 321cb0ef41Sopenharmony_ci .replace(stackTraceBasePath, '$3'); 331cb0ef41Sopenharmony_ci} 341cb0ef41Sopenharmony_ci 351cb0ef41Sopenharmony_cifunction removeWindowsPathEscaping(str) { 361cb0ef41Sopenharmony_ci return common.isWindows ? str.replaceAll(/\\\\/g, '\\') : str; 371cb0ef41Sopenharmony_ci} 381cb0ef41Sopenharmony_ci 391cb0ef41Sopenharmony_cifunction replaceTestLocationLine(str) { 401cb0ef41Sopenharmony_ci return str.replaceAll(/(js:)(\d+)(:\d+)/g, '$1(LINE)$3'); 411cb0ef41Sopenharmony_ci} 421cb0ef41Sopenharmony_ci 431cb0ef41Sopenharmony_ciconst defaultTransform = snapshot.transform( 441cb0ef41Sopenharmony_ci snapshot.replaceWindowsLineEndings, 451cb0ef41Sopenharmony_ci snapshot.replaceStackTrace, 461cb0ef41Sopenharmony_ci removeWindowsPathEscaping, 471cb0ef41Sopenharmony_ci snapshot.replaceFullPaths, 481cb0ef41Sopenharmony_ci snapshot.replaceWindowsPaths, 491cb0ef41Sopenharmony_ci replaceTestDuration, 501cb0ef41Sopenharmony_ci replaceTestLocationLine, 511cb0ef41Sopenharmony_ci); 521cb0ef41Sopenharmony_ciconst specTransform = snapshot.transform( 531cb0ef41Sopenharmony_ci replaceSpecDuration, 541cb0ef41Sopenharmony_ci snapshot.replaceWindowsLineEndings, 551cb0ef41Sopenharmony_ci snapshot.replaceStackTrace, 561cb0ef41Sopenharmony_ci); 571cb0ef41Sopenharmony_ciconst junitTransform = snapshot.transform( 581cb0ef41Sopenharmony_ci replaceJunitDuration, 591cb0ef41Sopenharmony_ci snapshot.replaceWindowsLineEndings, 601cb0ef41Sopenharmony_ci snapshot.replaceStackTrace, 611cb0ef41Sopenharmony_ci); 621cb0ef41Sopenharmony_ci 631cb0ef41Sopenharmony_ciconst tests = [ 641cb0ef41Sopenharmony_ci { name: 'test-runner/output/abort.js' }, 651cb0ef41Sopenharmony_ci { name: 'test-runner/output/abort_suite.js' }, 661cb0ef41Sopenharmony_ci { name: 'test-runner/output/abort_hooks.js' }, 671cb0ef41Sopenharmony_ci { name: 'test-runner/output/describe_it.js' }, 681cb0ef41Sopenharmony_ci { name: 'test-runner/output/describe_nested.js' }, 691cb0ef41Sopenharmony_ci { name: 'test-runner/output/hooks.js' }, 701cb0ef41Sopenharmony_ci { name: 'test-runner/output/timeout_in_before_each_should_not_affect_further_tests.js' }, 711cb0ef41Sopenharmony_ci { name: 'test-runner/output/hooks-with-no-global-test.js' }, 721cb0ef41Sopenharmony_ci { name: 'test-runner/output/before-and-after-each-too-many-listeners.js' }, 731cb0ef41Sopenharmony_ci { name: 'test-runner/output/before-and-after-each-with-timeout-too-many-listeners.js' }, 741cb0ef41Sopenharmony_ci { name: 'test-runner/output/global_after_should_fail_the_test.js' }, 751cb0ef41Sopenharmony_ci { name: 'test-runner/output/no_refs.js' }, 761cb0ef41Sopenharmony_ci { name: 'test-runner/output/no_tests.js' }, 771cb0ef41Sopenharmony_ci { name: 'test-runner/output/only_tests.js' }, 781cb0ef41Sopenharmony_ci { name: 'test-runner/output/dot_reporter.js' }, 791cb0ef41Sopenharmony_ci { name: 'test-runner/output/junit_reporter.js', transform: junitTransform }, 801cb0ef41Sopenharmony_ci { name: 'test-runner/output/spec_reporter_successful.js', transform: specTransform }, 811cb0ef41Sopenharmony_ci { name: 'test-runner/output/spec_reporter.js', transform: specTransform }, 821cb0ef41Sopenharmony_ci { name: 'test-runner/output/spec_reporter_cli.js', transform: specTransform }, 831cb0ef41Sopenharmony_ci { name: 'test-runner/output/output.js' }, 841cb0ef41Sopenharmony_ci { name: 'test-runner/output/output_cli.js' }, 851cb0ef41Sopenharmony_ci { name: 'test-runner/output/name_pattern.js' }, 861cb0ef41Sopenharmony_ci { name: 'test-runner/output/name_pattern_with_only.js' }, 871cb0ef41Sopenharmony_ci { name: 'test-runner/output/unresolved_promise.js' }, 881cb0ef41Sopenharmony_ci { name: 'test-runner/output/default_output.js', transform: specTransform, tty: true }, 891cb0ef41Sopenharmony_ci { name: 'test-runner/output/arbitrary-output.js' }, 901cb0ef41Sopenharmony_ci { name: 'test-runner/output/async-test-scheduling.mjs' }, 911cb0ef41Sopenharmony_ci !skipForceColors ? { 921cb0ef41Sopenharmony_ci name: 'test-runner/output/arbitrary-output-colored.js', 931cb0ef41Sopenharmony_ci transform: snapshot.transform(specTransform, replaceTestDuration), tty: true 941cb0ef41Sopenharmony_ci } : false, 951cb0ef41Sopenharmony_ci { name: 'test-runner/output/dot_output_custom_columns.js', transform: specTransform, tty: true }, 961cb0ef41Sopenharmony_ci { 971cb0ef41Sopenharmony_ci name: 'test-runner/output/tap_escape.js', 981cb0ef41Sopenharmony_ci transform: snapshot.transform( 991cb0ef41Sopenharmony_ci snapshot.replaceWindowsLineEndings, 1001cb0ef41Sopenharmony_ci replaceTestDuration, 1011cb0ef41Sopenharmony_ci ), 1021cb0ef41Sopenharmony_ci }, 1031cb0ef41Sopenharmony_ci process.features.inspector ? { name: 'test-runner/output/coverage_failure.js' } : false, 1041cb0ef41Sopenharmony_ci] 1051cb0ef41Sopenharmony_ci.filter(Boolean) 1061cb0ef41Sopenharmony_ci.map(({ name, tty, transform }) => ({ 1071cb0ef41Sopenharmony_ci name, 1081cb0ef41Sopenharmony_ci fn: common.mustCall(async () => { 1091cb0ef41Sopenharmony_ci await snapshot.spawnAndAssert(fixtures.path(name), transform ?? defaultTransform, { tty }); 1101cb0ef41Sopenharmony_ci }), 1111cb0ef41Sopenharmony_ci})); 1121cb0ef41Sopenharmony_ci 1131cb0ef41Sopenharmony_cidescribe('test runner output', { concurrency: true }, () => { 1141cb0ef41Sopenharmony_ci for (const { name, fn } of tests) { 1151cb0ef41Sopenharmony_ci it(name, fn); 1161cb0ef41Sopenharmony_ci } 1171cb0ef41Sopenharmony_ci}); 118