@uuv/runner-commons
Version:
A common lib for uuv
107 lines (106 loc) • 4.44 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.UUVCliHelper = void 0;
const chalk_1 = __importDefault(require("chalk"));
const figlet_1 = __importDefault(require("figlet"));
const minimist_1 = __importDefault(require("minimist"));
const path_1 = __importDefault(require("path"));
const options_1 = require("./options");
const lodash_1 = require("lodash");
const child_process_1 = __importDefault(require("child_process"));
class UUVCliHelper {
/**
* Print runner banner
*/
static printBanner(runnerName, currentVersion) {
console.log(chalk_1.default.blueBright(figlet_1.default.textSync(`UUV - ${runnerName}`, {
font: "Big",
horizontalLayout: "default",
verticalLayout: "default",
width: 80,
whitespaceBreak: true
})));
console.info(chalk_1.default.blueBright(`Version: ${currentVersion}\n\n`));
}
static checkTargetCommand() {
const argv = (0, minimist_1.default)(process.argv.slice(2));
if (argv._.length < 1) {
throw new Error("No command specified");
}
}
static checkTargetTestFiles() {
const argv = (0, minimist_1.default)(process.argv.slice(2));
const targetTestFile = argv.targetTestFile;
if (!(0, lodash_1.isEmpty)(targetTestFile)) {
try {
new RegExp(targetTestFile, "gi");
}
catch (e) {
throw new Error("Invalid targetTestFile argument, this args should respect Glob pattern");
}
}
}
static getTargetCommand(argv) {
return options_1.UUV_TARGET_COMMAND[(argv._[0]).toUpperCase()];
}
static extractArgs(projectDir, defaultBrowser) {
const argv = (0, minimist_1.default)(process.argv.slice(2));
const browser = argv.browser ? argv.browser : defaultBrowser;
const env = argv.env ? JSON.parse(argv.env.replace(/'/g, "\"")) : {};
const targetTestFile = argv.targetTestFile ? argv.targetTestFile : null;
const reportDir = path_1.default.join(projectDir, "reports");
// eslint-disable-next-line dot-notation
process.env["ENABLE_TEAMCITY_LOGGING"] = env.enableTeamcityLogging;
// eslint-disable-next-line dot-notation
process.env["ENABLE_VSCODE_LISTENER"] = env.enableVsCodeListener;
return {
// eslint-disable-next-line dot-notation
baseUrl: process.env["UUV_BASE_URL"],
projectDir: process.cwd(),
browser,
extraArgs: env,
targetTestFile,
command: this.getTargetCommand(argv),
report: {
outputDir: reportDir,
a11y: {
enabled: argv.generateA11yReport,
relativePath: path_1.default.join("reports", "a11y-report.json"),
outputFile: path_1.default.join(process.cwd(), reportDir, "a11y-report.json")
},
html: {
enabled: argv.generateHtmlReport,
outputDir: path_1.default.join(reportDir, "e2e/html")
},
junit: {
enabled: argv.generateJunitReport,
outputFile: path_1.default.join(reportDir, "e2e/junit-report.xml")
}
}
};
}
static printVariables(options) {
console.debug(chalk_1.default.yellowBright("Variables: "));
if (options.baseUrl) {
console.debug(` -> baseUrl: ${options.baseUrl}`);
}
console.debug(` -> projectDir: ${options.projectDir}`);
console.debug(` -> browser: ${options.browser}`);
console.debug(` -> report: ${JSON.stringify(options.report)}`);
console.debug(` -> env: ${JSON.stringify(options.extraArgs)}`);
if (options.targetTestFile) {
console.debug(` -> targetTestFile: ${options.targetTestFile}`);
}
console.debug("\n");
}
static startIpcServer() {
return child_process_1.default.fork(path_1.default.join(__dirname, "start-ipc-server"));
}
static stopIpcServer(ipcServerProcess) {
return ipcServerProcess.kill();
}
}
exports.UUVCliHelper = UUVCliHelper;