11cb0ef41Sopenharmony_ciconst { relative, dirname } = require('path') 21cb0ef41Sopenharmony_ci 31cb0ef41Sopenharmony_ci// normalize line endings (for ini) 41cb0ef41Sopenharmony_ciconst cleanNewlines = (s) => s.replace(/\r\n/g, '\n') 51cb0ef41Sopenharmony_ci 61cb0ef41Sopenharmony_ci// XXX: this also cleans quoted " in json snapshots 71cb0ef41Sopenharmony_ci// ideally this could be avoided but its easier to just 81cb0ef41Sopenharmony_ci// run this command inside cleanSnapshot 91cb0ef41Sopenharmony_ciconst normalizePath = (str) => cleanNewlines(str) 101cb0ef41Sopenharmony_ci .replace(/[A-z]:\\/g, '\\') // turn windows roots to posix ones 111cb0ef41Sopenharmony_ci .replace(/\\+/g, '/') // replace \ with / 121cb0ef41Sopenharmony_ci 131cb0ef41Sopenharmony_ciconst pathRegex = (p) => new RegExp(normalizePath(p), 'gi') 141cb0ef41Sopenharmony_ci 151cb0ef41Sopenharmony_ci// create a cwd replacer in the module scope, since some tests 161cb0ef41Sopenharmony_ci// overwrite process.cwd() 171cb0ef41Sopenharmony_ciconst CWD = pathRegex(process.cwd()) 181cb0ef41Sopenharmony_ciconst TESTDIR = pathRegex(relative(process.cwd(), dirname(require.main.filename))) 191cb0ef41Sopenharmony_ci 201cb0ef41Sopenharmony_ciconst cleanCwd = (path) => normalizePath(path) 211cb0ef41Sopenharmony_ci // repalce CWD, TESTDIR, and TAPDIR separately 221cb0ef41Sopenharmony_ci .replace(CWD, '{CWD}') 231cb0ef41Sopenharmony_ci .replace(TESTDIR, '{TESTDIR}') 241cb0ef41Sopenharmony_ci .replace(/tap-testdir-[\w-.]+/gi, '{TAPDIR}') 251cb0ef41Sopenharmony_ci // if everything ended up in line, reduce it all to CWD 261cb0ef41Sopenharmony_ci .replace(/\{CWD\}\/\{TESTDIR\}\/\{TAPDIR\}/g, '{CWD}') 271cb0ef41Sopenharmony_ci // replace for platform differences in global nodemodules 281cb0ef41Sopenharmony_ci .replace(/lib\/node_modules/g, 'node_modules') 291cb0ef41Sopenharmony_ci .replace(/global\/lib/g, 'global') 301cb0ef41Sopenharmony_ci 311cb0ef41Sopenharmony_ciconst cleanDate = (str) => 321cb0ef41Sopenharmony_ci str.replace(/\d{4}-\d{2}-\d{2}T\d{2}[_:]\d{2}[_:]\d{2}[_:.]\d{3}Z/g, '{DATE}') 331cb0ef41Sopenharmony_ci 341cb0ef41Sopenharmony_ciconst cleanTime = str => str.replace(/in [0-9]+m?s\s*$/gm, 'in {TIME}') 351cb0ef41Sopenharmony_ci 361cb0ef41Sopenharmony_ciconst cleanZlib = str => str 371cb0ef41Sopenharmony_ci .replace(/shasum:( *)[0-9a-f]{40}/g, 'shasum:$1{sha}') 381cb0ef41Sopenharmony_ci .replace(/integrity:( *).*/g, 'integrity:$1{integrity}') 391cb0ef41Sopenharmony_ci .replace(/package size:( *)[0-9 A-Z]*/g, 'package size:$1{size}') 401cb0ef41Sopenharmony_ci 411cb0ef41Sopenharmony_ci .replace(/"shasum": "[0-9a-f]{40}",/g, '"shasum": "{sha}",') 421cb0ef41Sopenharmony_ci .replace(/"integrity": ".*",/g, '"integrity": "{integrity}",') 431cb0ef41Sopenharmony_ci .replace(/"size": [0-9]*,/g, '"size": "{size}",') 441cb0ef41Sopenharmony_ci 451cb0ef41Sopenharmony_cimodule.exports = { 461cb0ef41Sopenharmony_ci cleanCwd, 471cb0ef41Sopenharmony_ci cleanDate, 481cb0ef41Sopenharmony_ci cleanNewlines, 491cb0ef41Sopenharmony_ci cleanTime, 501cb0ef41Sopenharmony_ci cleanZlib, 511cb0ef41Sopenharmony_ci normalizePath, 521cb0ef41Sopenharmony_ci pathRegex, 531cb0ef41Sopenharmony_ci} 54