"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());
    });
};
var __importStar = (this && this.__importStar) || function (mod) {
    if (mod && mod.__esModule) return mod;
    var result = {};
    if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
    result["default"] = mod;
    return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
const src_1 = require("../../util/src");
const build_1 = require("./build");
const Urlencode = __importStar(require("urlencode"));
var iOS;
(function (iOS) {
    function pick(device) {
        src_1.Console.info(`发送提取指令`);
        src_1.ACUtils.spawnSync('xcrun', ['simctl', 'openurl', device, `rubik:/test/pick`]);
        return Promise.resolve();
    }
    iOS.pick = pick;
    function run(casepath, device) {
        return __awaiter(this, void 0, void 0, function* () {
            const cost = new src_1.Cost();
            const cases = yield build_1.Build.allCases(casepath);
            src_1.Console.info(`提取用例信息(${cases.length})个`);
            let index = 1;
            for (const acase of cases) {
                try {
                    src_1.Console.info(`执行用例 ${acase.ID} [${index}/${cases.length}]`);
                    src_1.ACUtils.spawnSync('xcrun', ['simctl', 'terminate', device, 'com.cube.demo']);
                    src_1.ACUtils.spawnSync('xcrun', ['simctl', 'launch', device, 'com.cube.demo']);
                    src_1.ACUtils.spawnSync(`xcrun simctl openurl ${device} 'rubik:/test?caseId=${Urlencode.encode(acase.ID ? acase.ID : '')}&manifest=${Urlencode.encode(JSON.stringify(acase))}&source=rubik&portrait=true'`);
                    const duration = 5000;
                    src_1.Console.info(`等待用例执行(${duration / 1000}秒)...`);
                    yield sleep(duration);
                    src_1.ACUtils.spawnSync('xcrun', ['simctl', 'terminate', device, 'com.cube.demo']);
                }
                catch (error) {
                    src_1.Console.error(`执行异常 ${error}`);
                }
                index++;
            }
            cost.mark();
            return Promise.resolve();
        });
    }
    iOS.run = run;
})(iOS = exports.iOS || (exports.iOS = {}));
function sleep(ms) {
    return new Promise(resolve => setTimeout(resolve, ms));
}
//# sourceMappingURL=run.js.map