UNPKG

tia

Version:

Time is All (logs driven test engine with ExtJs support)

196 lines 5.63 kB
"use strict"; 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 mPath = __importStar(require("path")); const fileUtils = __importStar(require("../utils/file-utils")); let isPassCountingEnabled = true; let isPassPrintingEnabled = true; function getPassCountingEnabled() { return isPassCountingEnabled; } exports.getPassCountingEnabled = getPassCountingEnabled; function setPassCountingEnabled(enable) { isPassCountingEnabled = enable; } exports.setPassCountingEnabled = setPassCountingEnabled; function getPassPrintingEnabled() { return isPassPrintingEnabled; } exports.getPassPrintingEnabled = getPassPrintingEnabled; function setPassPrintingEnabled(enable) { isPassPrintingEnabled = enable; } exports.setPassPrintingEnabled = setPassPrintingEnabled; class TestInfo { // TODO: To investigate the need for throws count. constructor(isDir, title, path) { this.run = 0; this.passed = 0; this.failed = 0; this.diffed = 0; // For dir this can be > 1, for file it can be 0 or 1. this.expDiffed = 0; // expectedly diffed (e.g. for purpose of testing). this.skipped = 0; this.screenShotCounter = 0; this.children = null; this.time = 0; // Execution time in milliseconds. this.isSuiteRoot = false; this.title = title; this.path = path; if (isDir) { this.children = []; } } } exports.TestInfo = TestInfo; // Singleton. let data = null; function getData() { return data; } exports.getData = getData; function setData(newData) { data = newData; } exports.setData = setData; function setPassed(newCount) { data.passed = newCount; } exports.setPassed = setPassed; function setFailed(newCount) { data.failed = newCount; } exports.setFailed = setFailed; function getPassed() { return data.passed; } exports.getPassed = getPassed; function getFailed() { return data.failed; } exports.getFailed = getFailed; function setSkipped(newCount) { data.skipped = newCount; } exports.setSkipped = setSkipped; function setRun(newCount) { data.run = newCount; } exports.setRun = setRun; function setDiffed(newCount) { data.diffed = newCount; } exports.setDiffed = setDiffed; function setExpDiffed(newCount) { data.expDiffed = newCount; } exports.setExpDiffed = setExpDiffed; function setTime(newTime) { data.time = newTime; } exports.setTime = setTime; function setTitle(title) { data.title = title; } exports.setTitle = setTitle; // TODO: Unclear logic. function formLogPart(str, count) { let strNew = str; if (!count) { strNew = strNew.toLowerCase(); } strNew += `: ${count}`; return strNew; } /** * Forms the string for test statistics for tests and for directories. * @param parameters * @param parameters.curInfo - Directory info or Test info structure. * @param parameters.isDir * @param parameters.verbose * @param parameters.noTime * @param parameters.noTitle * @returns {String} */ function testInfoToString(parameters) { const { curInfo, isDir, verbose, noTime, noTitle, noEol } = parameters; let diffed; let ediffed; let skipped; let run; if (isDir) { diffed = formLogPart('Dif', curInfo.diffed); ediffed = formLogPart('EDif', curInfo.expDiffed); skipped = formLogPart('Skip', curInfo.skipped); if (curInfo.isSuiteRoot && gT.cLParams.slogSubj.includes('run')) { run = formLogPart('Run', curInfo.run); } } else { if (curInfo.diffed) { diffed = 'DIF'; } else if (curInfo.expDiffed) { diffed = 'EDIF'; } else { diffed = 'OK'; } ediffed = ''; skipped = curInfo.skipped ? 'SKIP' : ''; } let filePath; if (isDir && curInfo.isSuiteRoot) { filePath = ` "${fileUtils.getDirectoryAlias(curInfo.path)}"`; } else { filePath = `"${mPath.basename(curInfo.path)}"`; } const title = noTitle ? '' : `"${curInfo.title}"`; const passed = (curInfo.isSuiteRoot && gT.cLParams.slogSubj.includes('pass')) || !isDir ? formLogPart('Pass', curInfo.passed) : null; const failed = formLogPart('Fail', curInfo.failed); const time = noTime ? '' : `${curInfo.time.toFixed(2)} ms`; const arr = verbose ? [filePath, diffed, failed, ediffed, skipped, passed, run, time, title] : [filePath, diffed, failed]; let res = `${arr.filter(Boolean).join(', ')}`; // join only non-empty strings. if (!noEol) { res += '\n'; } return res; } exports.testInfoToString = testInfoToString; /** * * @param isDir - true - directory, false - file. */ function createTestInfo(isDir, title, path) { return new TestInfo(isDir, title, path); } exports.createTestInfo = createTestInfo; function addFail() { if (gT.config.ignorePassAndFailCounters) { return; } data.failed++; // From global sandbox. } exports.addFail = addFail; function addPassForce() { data.passed++; } exports.addPassForce = addPassForce; function addPass() { if (!isPassCountingEnabled || gT.config.ignorePassAndFailCounters) { return; } data.passed++; // From global sandbox. } exports.addPass = addPass; //# sourceMappingURL=test-info.js.map