@intuitionrobotics/testelot
Version:
Nu-Art Sir Testelot
119 lines • 4.25 kB
JavaScript
;
/*
* Testelot is a typescript scenario composing framework
*
* Copyright (C) 2020 Intuition Robotics
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.ActionReport = exports.Reporter = void 0;
const Action_1 = require("./Action");
const ts_common_1 = require("@intuitionrobotics/ts-common");
class ReportSummary {
constructor() {
this.Running = 0;
this.Skipped = 0;
this.Success = 0;
this.Error = 0;
}
}
class Reporter extends ts_common_1.Logger {
constructor() {
super("Testelot");
this.reports = {};
this.summary = new ReportSummary();
this.reporter = new ReporterLogClient(this);
ts_common_1.BeLogged.addClient(this.reporter);
}
init() {
}
logMessage(logMessage) {
if (this.report)
this.report.appendLog(logMessage);
}
onActionStarted(action) {
this.reports[action.uuid] = this.report = new ActionReport(action);
// if (action.isContainer())
this.reporter.onContainerStarted();
}
onActionEnded(action) {
switch (action.status) {
case Action_1.Status.Ready:
case Action_1.Status.Running:
this.logWarning(`action state: ${action.status} found in action ended event`);
break;
case Action_1.Status.Skipped:
case Action_1.Status.Success:
case Action_1.Status.Error:
this.reporter.onContainerEnded();
if (action.isContainer()) {
return;
}
this.summary[action.status]++;
break;
}
}
}
exports.Reporter = Reporter;
class ActionReport {
constructor(action) {
this.logs = "";
this.action = action;
}
getLog() {
return this.logs;
}
appendLog(logMessage) {
this.logs += `${logMessage}\n`;
}
}
exports.ActionReport = ActionReport;
function pad(value, length) {
let s = "" + value;
while (s.length < (length || 2)) {
s = "0" + s;
}
return s;
}
class ReporterLogClient extends ts_common_1.LogClient {
constructor(report) {
super();
this.indent = "";
this.composer = (tag, level) => {
const successPart = `\x1b[32m${pad(this.report.summary.Success, 3)}${ts_common_1.NoColor}`;
const skippedPart = `\x1b[90m\x1b[1m${pad(this.report.summary.Skipped, 3)}${ts_common_1.NoColor}`;
const errorPart = `\x1b[31m${pad(this.report.summary.Error, 3)}${ts_common_1.NoColor}`;
const status = `${errorPart}/${skippedPart}/${successPart}`;
const defaultPrefix = (0, ts_common_1.DefaultLogPrefixComposer)("Testelot", level);
const color = ts_common_1.LogClient_Terminal.getColor(level);
return ` ${defaultPrefix} ${ts_common_1.NoColor}[${status}]:${color} ${this.indent}`;
};
this.report = report;
this.setComposer(this.composer);
}
logMessage(level, bold, prefix, toLog) {
const color = ts_common_1.LogClient_Terminal.getColor(level, bold);
const paramsAsStrings = (0, ts_common_1._logger_convertLogParamsToStrings)(toLog);
paramsAsStrings.forEach(str => console.log((0, ts_common_1._logger_indentNewLineBy)(color + prefix, str), ts_common_1.NoColor));
}
onContainerStarted() {
this.indent += ReporterLogClient.indent;
}
onContainerEnded() {
this.indent = this.indent.substring(0, this.indent.length - ReporterLogClient.indent.length);
return;
}
}
ReporterLogClient.indent = " ";
//# sourceMappingURL=Reporter.js.map