@intuitionrobotics/testelot
Version:
Nu-Art Sir Testelot
99 lines • 3.69 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.
*/
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.__log = __log;
exports.__sleep = __sleep;
exports.__http = __http;
exports.__custom = __custom;
exports.__compareKeys = __compareKeys;
exports.__scenario = __scenario;
exports.__throwException = __throwException;
exports.enableTerminalLogReWrite = enableTerminalLogReWrite;
exports._executeScenario = _executeScenario;
const ts_common_1 = require("@intuitionrobotics/ts-common");
const index_1 = require("../index");
const objectHash = require("object-hash");
function __log(logMessage, level = ts_common_1.LogLevel.Verbose) {
// @ts-ignore
return new index_1.Action_Log(logMessage, level);
}
function __sleep(sleepMs) {
// @ts-ignore
return new index_1.Action_Sleep(sleepMs);
}
function __http(method) {
// @ts-ignore
return new index_1.Action_Http(method);
}
function __custom(action) {
// @ts-ignore
return new index_1.Action_Custom(action);
}
function __compareKeys(key1, key2) {
return __custom((action) => __awaiter(this, void 0, void 0, function* () {
if (objectHash(action.get(key1)) !== objectHash(action.get(key2)))
throw new index_1.TestException(`NON matched values for keys '${key1.key}' !== '${key2.key}'`);
}));
}
function __scenario(label, reporter) {
// @ts-ignore
const scenario = new index_1.Scenario();
scenario.setLabel(label);
if (reporter) {
scenario.setReporter(reporter);
}
return scenario;
}
function __throwException(message) {
// @ts-ignore
return new index_1.Action_ThrowException(message);
}
function enableTerminalLogReWrite() {
ts_common_1.BeLogged.rewriteConsole = (lineCount => {
let rewriteCommand = "";
for (let i = 0; i < lineCount; i++) {
rewriteCommand += "tput cuu1 tput el;";
}
try {
require("child_process").execSync(rewriteCommand, { stdio: 'inherit' });
}
catch (e) {
}
});
}
function _executeScenario(scenario) {
new Promise(scenario.run)
.then(() => {
scenario.logInfo("-------------- COMPLETED -----------------");
})
.catch(reason => {
scenario.logError("---------------- ERROR -----------------");
scenario.logError(reason);
});
}
//# sourceMappingURL=_base_apis.js.map