UNPKG

appcenter-cli

Version:

Command line tool for Visual Studio App Center

150 lines (149 loc) 6.23 kB
"use strict"; 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 }); const fs = require("fs"); const path = require("path"); const commandline_1 = require("../../../../util/commandline"); const interaction_1 = require("../../../../util/interaction"); const uitest_1 = require("../../run/uitest"); const fs_helper_1 = require("../../../../util/misc/fs-helper"); class RunUitestWizardTestCommand extends commandline_1.AppCommand { constructor(args, interactiveArgs) { super(args); this._args = args; this._args.args.push(...interactiveArgs); } run(client, portalBaseUrl) { return __awaiter(this, void 0, void 0, function* () { const searchFolder = this.scanFolder(); if (this._args.args.indexOf("--async") < 0) { const mergeXml = yield this.promptMergeXml(); if (mergeXml) { this._args.args.push("--merge-nunit-xml"); } } const foundFolders = yield searchFolder; const folder = yield this.promptFolder(foundFolders); this._args.args.push("--build-dir", folder); interaction_1.out.text("\nRunning command: appcenter test run uitest " + this._args.args.join(" ") + "\n"); return new uitest_1.default(this._args).run(client, portalBaseUrl); }); } promptMergeXml() { return __awaiter(this, void 0, void 0, function* () { const questions = [ { type: "list", name: "merge", message: "Should the xml files be merged in to the <output.xml> file?", choices: [ { name: "Yes", value: "true", }, { name: "No", value: "false", }, ], }, ]; const answers = yield interaction_1.prompt.question(questions); return answers.merge === "true" ? true : false; }); } scanFolder() { return __awaiter(this, void 0, void 0, function* () { const foundFolders = []; yield this.scanRecurse(process.cwd(), foundFolders); return foundFolders; }); } scanRecurse(dirname, folders) { return __awaiter(this, void 0, void 0, function* () { const dirContent = fs.readdirSync(dirname); for (const dir of dirContent) { const fullDir = path.join(dirname, dir); if (!fs.lstatSync(fullDir).isDirectory()) { continue; } if (dir === "node_modules") { continue; } const subDirContent = fs.readdirSync(fullDir); if (subDirContent.length === 0) { continue; } const xamarinNunitDll = this.findXamarinNunitDll(subDirContent); if (!xamarinNunitDll) { yield this.scanRecurse(fullDir, folders); } else { const foundFolder = { name: path.relative(process.cwd(), fullDir), path: fullDir, }; if (!folders) { folders = [foundFolder]; } else { folders.push(foundFolder); } } } }); } findXamarinNunitDll(dirContent) { return dirContent.indexOf("Xamarin.UITest.dll") > -1 && dirContent.indexOf("nunit.framework.dll") > -1; } promptFolder(listOfFolders) { return __awaiter(this, void 0, void 0, function* () { if (listOfFolders.length === 0) { return yield interaction_1.prompt("We could not find any folders with Xamarin tests. Please provide the path to them."); } const choices = listOfFolders.map((folder) => { return { name: folder.name, value: folder.path, }; }); choices.push({ name: "Enter path manually", value: "manual", }); const questions = [ { type: "list", name: "folderPath", message: "Pick the folder containing your compiled Xamarin.UITest tests", choices: choices, }, ]; const answers = yield interaction_1.prompt.question(questions); if (answers.folderPath === "manual") { let pathIsValid; let dirPath; while (!pathIsValid) { dirPath = yield interaction_1.prompt(`Please provide the path to the folder containing your compiled Xamarin.UITest tests.`); if (dirPath.length === 0) { pathIsValid = false; } else { pathIsValid = fs_helper_1.directoryExistsSync(path.resolve(dirPath)); } } return dirPath; } return answers.folderPath; }); } } exports.default = RunUitestWizardTestCommand;