tia
Version:
Time is All (logs driven test engine with ExtJs support)
119 lines • 3.54 kB
JavaScript
;
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
result["default"] = mod;
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
const util = __importStar(require("util"));
const path_1 = require("path");
function removeSelSid(str) {
const re = /\?_dc=\d+/g;
return str.replace(re, '');
}
exports.removeSelSid = removeSelSid;
function filterStack(strStack) {
const stArr = strStack.split('\n');
const newArr = stArr.filter(el => {
const startingFrom = el.indexOf('/tia/');
return !el.includes(`${path_1.sep}node_modules${path_1.sep}`, startingFrom);
});
return newArr.join('\n');
}
exports.filterStack = filterStack;
function excToStr(err, noStack) {
if (typeof err === 'undefined') {
return '\nNo Exception info\n';
}
let errStr = err.toString(); // (typeof err.message === 'undefined') ? err : err.message;
if ( /* gT.cLParams.stackToLog || */!noStack) {
if (typeof err.stack !== 'undefined') {
errStr += `\n${filterStack(err.stack)}`;
}
else {
errStr += '\n No stack trace\n';
}
}
return errStr;
}
exports.excToStr = excToStr;
function winToUnixSep(path) {
return path.replace(/\\\\/g, '/');
}
exports.winToUnixSep = winToUnixSep;
function changeExt(jsPath, newExt) {
return jsPath.substr(0, jsPath.length - 3) + newExt;
}
exports.changeExt = changeExt;
function jsToEt(jsPath) {
return changeExt(jsPath, '.et');
}
exports.jsToEt = jsToEt;
function jsToTs(jsPath) {
return changeExt(jsPath, '.ts');
}
exports.jsToTs = jsToTs;
/**
* Creates log path knowing js file path.
* Just replaces two last symbols by 'log' at the end of string.
* @param jsPath - path to js file.
*/
function jsToLog(jsPath) {
return changeExt(jsPath, '.log');
}
exports.jsToLog = jsToLog;
function jsToDif(jsPath) {
return changeExt(jsPath, '.dif');
}
exports.jsToDif = jsToDif;
function expandHost(str) {
return str.replace('$(host)', gT.config.selHost);
}
exports.expandHost = expandHost;
function collapseHost(str) {
return str.replace(gT.config.selHost, '$(host)');
}
exports.collapseHost = collapseHost;
function valToStr(value) {
if (Buffer.isBuffer(value)) {
return value.toString('utf8');
}
if (typeof value === 'string') {
return value;
}
return util.inspect(value, { compact: false, sorted: true, depth: Infinity });
}
exports.valToStr = valToStr;
function v2s(value) {
if (Buffer.isBuffer(value)) {
return value.toString('utf8');
}
if (typeof value === 'string') {
return value;
}
return util.inspect(value, {
compact: true,
sorted: true,
depth: Infinity,
breakLength: 200,
});
}
exports.v2s = v2s;
// function escapeRegExp(string) {
// return string.replace(/([.*+?^=!:${}()|\[\]\/\\])/g, "\\$1");
// }
//
// export function prepareHostRE(){
// let str = escapeRegExp(gT.config.selHost);
// hostRe = new RegExp(str, g);
// };
// // Multi-line version.
// export function collapseHostML(str){
// // TODO: optimize, this function should be called only if gT.config.selHost is changed.
// // For now there are not even such use cases.
// prepareHostRE();
// return str.replace(hostRe, '$(host)');
// };
//# sourceMappingURL=text-utils.js.map