definition-tester
Version:
DefinitelyTyped repository testing infrastructure
280 lines • 11.5 kB
JavaScript
'use strict';
var os = require('os');
var Print = (function () {
function Print(version) {
this.version = version;
this.WIDTH = 77;
}
Print.prototype.init = function (tsFiles, typings) {
this.typings = typings;
this.tsFiles = tsFiles;
};
Print.prototype.out = function (s) {
process.stdout.write(s);
return this;
};
Print.prototype.repeat = function (s, times) {
return new Array(times + 1).join(s);
};
Print.prototype.printHeader = function (options) {
var totalMem = Math.round(os.totalmem() / 1024 / 1024) + ' mb';
var freemem = Math.round(os.freemem() / 1024 / 1024) + ' mb';
this.out('=============================================================================\n');
this.out(' \x1B[36m\x1B[1mDefinitelyTyped Test Runner 2.0.0\x1B[0m\n');
this.out('=============================================================================\n');
this.out(" \u001B[36m\u001B[1mTypescript version:\u001B[0m " + this.version + "\n");
this.out(" \u001B[36m\u001B[1mTypings :\u001B[0m " + this.typings + "\n");
this.out(" \u001B[36m\u001B[1mTypeScript files :\u001B[0m " + this.tsFiles + "\n");
this.out(" \u001B[36m\u001B[1mTotal Memory :\u001B[0m " + totalMem + "\n");
this.out(" \u001B[36m\u001B[1mFree Memory :\u001B[0m " + freemem + "\n");
this.out(" \u001B[36m\u001B[1mCores :\u001B[0m " + os.cpus().length + "\n");
this.out(" \u001B[36m\u001B[1mConcurrent :\u001B[0m " + options.concurrent + "\n");
};
Print.prototype.printSuiteHeader = function (title) {
var left = Math.floor((this.WIDTH - title.length) / 2) - 1;
var right = Math.ceil((this.WIDTH - title.length) / 2) - 1;
this.out(this.repeat('=', left)).out(' \x1B[34m\x1B[1m');
this.out(title);
this.out('\x1B[0m ').out(this.repeat('=', right)).printBreak();
};
Print.prototype.printDiv = function () {
this.out('-----------------------------------------------------------------------------\n');
};
Print.prototype.printBoldDiv = function () {
this.out('=============================================================================\n');
};
Print.prototype.printErrorsHeader = function () {
this.out('=============================================================================\n');
this.out(' \x1B[34m\x1B[1mErrors in files\x1B[0m \n');
this.out('=============================================================================\n');
};
Print.prototype.trimTravis = function (str) {
return String(str).replace(/^\/home\/travis\/build\/[\w\-\.]+\/[\w\-\.]+\//gm, '');
};
Print.prototype.printErrorsForFile = function (testResult) {
this.out("----------------- For file:" + testResult.targetFile.fullPath);
if (testResult.diagnostics) {
this.printBreak().out(this.trimTravis(testResult.diagnostics.join('\r\n'))).printBreak();
}
else {
this.printBreak().out('no stderr content').printBreak();
}
};
Print.prototype.printBreak = function () {
this.out('\n');
return this;
};
Print.prototype.clearCurrentLine = function () {
this.out('\r\x1B[K');
return this;
};
Print.prototype.printSuccessCount = function (current, total) {
var arb = (total === 0) ? 0 : (current / total);
this.out(" \u001B[36m\u001B[1mSuccessful :\u001B[0m \u001B[32m\u001B[1m" + (arb * 100).toFixed(2) + "% (" + current + "/" + total + ")\u001B[0m\n");
};
Print.prototype.printFailedCount = function (current, total) {
var arb = (total === 0) ? 0 : (current / total);
this.out(" \u001B[36m\u001B[1mFailure :\u001B[0m \u001B[31m\u001B[1m" + (arb * 100).toFixed(2) + "% (" + current + "/" + total + ")\u001B[0m\n");
};
Print.prototype.printTypingsWithoutTestsMessage = function () {
this.out(' \x1B[36m\x1B[1mTyping without tests\x1B[0m\n');
};
Print.prototype.printTotalMessage = function () {
this.out(' \x1B[36m\x1B[1mTotal\x1B[0m\n');
};
Print.prototype.printElapsedTime = function (time, s) {
this.out(" \u001B[36m\u001B[1mElapsed time :\u001B[0m ~" + time + " (" + s + "s)\n");
};
Print.prototype.printSuiteErrorCount = function (errorHeadline, current, total, warn) {
if (warn === void 0) { warn = false; }
var arb = (total === 0) ? 0 : (current / total);
this.out(' \x1B[36m\x1B[1m').out(errorHeadline).out(this.repeat(' ', 16 - errorHeadline.length));
if (warn) {
this.out(": \u001B[31m\u001B[1m" + (arb * 100).toFixed(2) + "% (" + current + "/" + total + ")\u001B[0m\n");
}
else {
this.out(": \u001B[33m\u001B[1m" + (arb * 100).toFixed(2) + "% (" + current + "/" + total + ")\u001B[0m\n");
}
};
Print.prototype.printSubHeader = function (file) {
this.out(" \u001B[36m\u001B[1m" + file + "\u001B[0m\n");
};
Print.prototype.printWarnCode = function (str) {
this.out(" \u001B[31m\u001B[1m<" + str.toLowerCase().replace(/ +/g, '-') + ">\u001B[0m\n");
};
Print.prototype.printLine = function (file) {
this.out(file + "\n");
};
Print.prototype.printElement = function (file) {
this.out(" - " + file + "\n");
};
Print.prototype.printElement2 = function (file) {
this.out(" - " + file + "\n");
};
Print.prototype.printTypingsWithoutTestName = function (file) {
this.out(" - \u001B[33m\u001B[1m" + file + "\u001B[0m\n");
};
Print.prototype.printTypingsWithoutTest = function (withoutTestTypings) {
var _this = this;
if (withoutTestTypings.length > 0) {
this.printTypingsWithoutTestsMessage();
this.printDiv();
withoutTestTypings.forEach(function (t) {
_this.printTypingsWithoutTestName(t);
});
}
};
Print.prototype.printTestComplete = function (testResult) {
var reporter = testResult.hostedBy.testReporter;
if (testResult.success) {
reporter.printPositiveCharacter(testResult);
}
else {
reporter.printNegativeCharacter(testResult);
}
};
Print.prototype.printSuiteComplete = function (suite) {
this.printBreak();
this.printDiv();
this.printElapsedTime(suite.timer.asString, suite.timer.time);
this.printSuccessCount(suite.okTests.length, suite.testResults.length);
this.printFailedCount(suite.ngTests.length, suite.testResults.length);
};
Print.prototype.printTests = function (adding) {
var _this = this;
this.printDiv();
this.printSubHeader('Testing');
this.printDiv();
var keys = Object.keys(adding);
if (keys.length > 0) {
keys.sort().map(function (src) {
_this.printLine(adding[src].fullPath);
return adding[src];
});
}
else {
this.printLine(' no files listed here');
}
};
Print.prototype.printQueue = function (files) {
var _this = this;
this.printDiv();
this.printSubHeader('Queued for testing');
this.printDiv();
if (files.length > 0) {
files.forEach(function (file) {
_this.printLine(file.fullPath);
});
}
else {
this.printLine(' no files listed here');
}
};
Print.prototype.printTestAll = function () {
this.printDiv();
this.printSubHeader('Ignoring changes, testing all files');
};
Print.prototype.printTestInternal = function () {
this.printDiv();
this.printSubHeader('Infrastructure change detected, testing all files');
};
Print.prototype.printFiles = function (files) {
var _this = this;
this.printDiv();
this.printSubHeader('Files');
this.printDiv();
if (files.length > 0) {
files.forEach(function (file) {
_this.printLine(file.fullPath);
});
}
else {
this.printLine(' no files listed here');
}
};
Print.prototype.printMissing = function (index, refMap) {
var _this = this;
this.printDiv();
this.printSubHeader('Missing references');
this.printDiv();
var keys = Object.keys(refMap);
if (keys.length > 0) {
keys.sort().forEach(function (src) {
var ref = index.getFile(src);
_this.printLine("\u001B[31m\u001B[1m" + ref.fullPath + "\u001B[0m");
refMap[src].forEach(function (file) {
_this.printElement(file.fullPath);
});
});
}
else {
this.printLine(' no files listed here');
}
};
Print.prototype.printAllChanges = function (paths) {
var _this = this;
this.printSubHeader('All changes');
this.printDiv();
if (paths.length > 0) {
paths.sort().forEach(function (line) {
_this.printLine(line);
});
}
else {
this.printLine(' no files listed here');
}
};
Print.prototype.printRelChanges = function (changeMap) {
var _this = this;
this.printDiv();
this.printSubHeader('Interesting files');
this.printDiv();
var keys = Object.keys(changeMap);
if (keys.length > 0) {
keys.sort().forEach(function (src) {
_this.printLine(changeMap[src].fullPath);
});
}
else {
this.printLine(' no files listed here');
}
};
Print.prototype.printRemovals = function (changeMap) {
var _this = this;
this.printDiv();
this.printSubHeader('Removed files');
this.printDiv();
var keys = Object.keys(changeMap);
if (keys.length > 0) {
keys.sort().forEach(function (src) {
_this.printLine(changeMap[src].fullPath);
});
}
else {
this.printLine(' no files listed here');
}
};
Print.prototype.printRefMap = function (index, refMap) {
var _this = this;
this.printDiv();
this.printSubHeader('Referring');
this.printDiv();
var keys = Object.keys(refMap);
if (keys.length > 0) {
keys.sort().forEach(function (src) {
var ref = index.getFile(src);
_this.printLine(ref.fullPath);
refMap[src].forEach(function (file) {
_this.printLine(" - " + file.fullPath);
});
});
}
else {
this.printLine(' no files listed here');
}
};
return Print;
}());
Object.defineProperty(exports, "__esModule", { value: true });
exports.default = Print;
//# sourceMappingURL=Print.js.map