UNPKG

appcenter-cli

Version:

Command line tool for Visual Studio App Center

86 lines (85 loc) 3.99 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 }); exports.XCUITestPreparer = void 0; const iba = require("../../../util/misc/ios-bundle-archiver"); const path = require("path"); const pfs = require("../../../util/misc/promisfied-fs"); const pglob = require("../../../util/misc/promisfied-glob"); const test_cloud_error_1 = require("./test-cloud-error"); class XCUITestPreparer { constructor(artifactsDir, buildDir, testIpaPath, include) { if (!artifactsDir) { throw new Error("Argument --artifacts-dir is required"); } if (!(buildDir || testIpaPath)) { throw new Error("Either --build-dir or --test-ipa-path argument is required"); } if (buildDir && testIpaPath) { throw new Error("Arguments --build-dir and --test-ipa-path cannot be used together"); } if (include && include.length) { throw new Error("Argument --include cannot be used for XCUITest"); } this.artifactsDir = artifactsDir; this.buildDir = buildDir; this.testIpaPath = testIpaPath; } prepare() { return __awaiter(this, void 0, void 0, function* () { if (!(yield pfs.exists(this.artifactsDir))) { yield pfs.mkdir(this.artifactsDir); } if (this.buildDir) { yield this.generateTestIpa(); } else { if (!(yield pfs.fileExists(this.testIpaPath))) { throw new Error(`File not found for test ipa path: "${this.testIpaPath}"`); } yield pfs.cpFile(this.testIpaPath, path.join(this.artifactsDir, path.basename(this.testIpaPath))); } const manifestPath = path.join(this.artifactsDir, "manifest.json"); const manifest = yield this.createXCUITestManifest(); const manifestJson = JSON.stringify(manifest, null, 1); yield pfs.writeFile(manifestPath, manifestJson); return manifestPath; }); } createXCUITestManifest() { return __awaiter(this, void 0, void 0, function* () { const ipaArtifactsPath = path.basename(this.testIpaPath); const result = { schemaVersion: "1.0.0", files: [ipaArtifactsPath], testFramework: { name: "xcuitest", data: {}, }, }; return result; }); } generateTestIpa() { return __awaiter(this, void 0, void 0, function* () { const runnerAppPaths = yield pglob.glob(path.join(this.buildDir, "*-Runner.app")); if (runnerAppPaths.length === 0) { throw new test_cloud_error_1.TestCloudError(`Unable to find test runner app within ${this.buildDir}`); } if (runnerAppPaths.length > 1) { throw new test_cloud_error_1.TestCloudError(`Multiple test runner apps found within ${this.buildDir}`); } this.testIpaPath = path.join(this.artifactsDir, `${path.parse(runnerAppPaths[0]).name}.ipa`); yield iba.archiveAppBundle(runnerAppPaths[0], this.testIpaPath); }); } } exports.XCUITestPreparer = XCUITestPreparer;