UNPKG

lite-unit-test

Version:

Its a wrapper tool to build unit test in node with the native assert library

96 lines (95 loc) 3.43 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var node_process_1 = require("node:process"); var CliForTests = /** @class */ (function () { function CliForTests() { } CliForTests.prototype.produceTestReport = function (limit, successes, errors) { // datos para el titulo formateado en consola var testStatsObject = { "Total tests": limit.toString(), Pass: successes.toString(), Fail: errors.length.toString(), }; // if there are errors print them in red if (errors.length > 0) { var failedTestsObject_1 = {}; errors.forEach(function (e) { failedTestsObject_1[e.name] = e.error; }); this.renderErrorDetails("BEGIN ERROR DETAILS", failedTestsObject_1); } this.renderObjectStyle("BEGIN TEST REPORT", testStatsObject, 32); // end the test this.renderObjectStyle("END OF TESTS", {}); // for integration tests, exit the app process.exit(0); }; CliForTests.prototype.renderErrorDetails = function (title, errors) { var _this = this; // CLI FORMAT Helpers this.horizontalLine(); this.centered(title); this.horizontalLine(); // cli.verticalSpace() // Show each command, followed by its explination Object.keys(errors).forEach(function (e) { var line = "\x1b[31m" + e + "\x1b[0m: "; line += errors[e]; console.log(line); _this.verticalSpace(); }); }; CliForTests.prototype.renderObjectStyle = function (title, obj, color) { if (color === void 0) { color = 33; } // CLI FORMAT Helpers this.horizontalLine(); this.centered(title); this.horizontalLine(); // cli.verticalSpace() // Show each command, followed by its explination Object.keys(obj).forEach(function (e) { var line = e === "Fail" ? "\x1b[31m" + e + "\x1b[0m" : "\u001B[".concat(color, "m") + e + "\x1b[0m"; var value = obj[e]; var padding = 75 - line.length; for (var i = 0; i < padding; i++) { line += " "; } line += value; console.log(line); // cli.verticalSpace() }); }; CliForTests.prototype.horizontalLine = function () { var width = node_process_1.stdout.columns; var line = ""; for (var i = 0; i < width; i++) { line += "-"; } console.log(line); }; CliForTests.prototype.centered = function (title) { title = typeof title === "string" && title.length > 0 ? title.trim() : ""; // get the width var width = node_process_1.stdout.columns; // calculate de left padding var leftPadding = Math.floor((width - title.length) / 2); var line = ""; for (var i = 0; i < leftPadding; i++) { line += " "; } line += title; console.log(line); }; CliForTests.prototype.verticalSpace = function (lines) { if (lines === void 0) { lines = 1; } lines = lines > 0 ? lines : 1; for (var i = 0; i < lines; i++) { console.log(""); } }; return CliForTests; }()); exports.default = new CliForTests();