@intuitionrobotics/testelot
Version:
Nu-Art Sir Testelot
81 lines • 2.98 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.
*/
import { execSync } from "child_process";
import { BeLogged, LogLevel } from "@intuitionrobotics/ts-common";
import { Action_Custom, Action_Http, Action_Log, Action_Sleep, Action_ThrowException, ContextKey, HttpMethod, Scenario, TestException, } from "../index.js";
import { Reporter } from "./Reporter.js";
import objectHash from "object-hash";
export function __log(logMessage, level = LogLevel.Verbose) {
// @ts-expect-error TS struggles with this dynamic typing
return new Action_Log(logMessage, level);
}
export function __sleep(sleepMs) {
// @ts-expect-error TS struggles with this dynamic typing
return new Action_Sleep(sleepMs);
}
export function __http(method) {
// @ts-expect-error protected constructor
return new Action_Http(method);
}
export function __custom(action) {
// @ts-expect-error TS struggles with this dynamic typing
return new Action_Custom(action);
}
export function __compareKeys(key1, key2) {
return __custom(async (action) => {
if (objectHash(action.get(key1)) !== objectHash(action.get(key2)))
throw new TestException(`NON matched values for keys '${key1.key}' !== '${key2.key}'`);
});
}
export function __scenario(label, reporter) {
// @ts-expect-error TS struggles with this dynamic typing
const scenario = new Scenario();
scenario.setLabel(label);
if (reporter) {
scenario.setReporter(reporter);
}
return scenario;
}
export function __throwException(message) {
// @ts-expect-error TS struggles with this dynamic typing
return new Action_ThrowException(message);
}
export function enableTerminalLogReWrite() {
BeLogged.rewriteConsole = (lineCount => {
let rewriteCommand = "";
for (let i = 0; i < lineCount; i++) {
rewriteCommand += "tput cuu1 tput el;";
}
try {
execSync(rewriteCommand, { stdio: 'inherit' });
}
catch (_e) {
}
});
}
export function _executeScenario(scenario) {
new Promise(scenario.run)
.then(() => {
scenario.logInfo("-------------- COMPLETED -----------------");
})
.catch(reason => {
scenario.logError("---------------- ERROR -----------------");
scenario.logError(reason);
});
}
//# sourceMappingURL=_base_apis.js.map