UNPKG

appium-mac2-driver

Version:

XCTest-based Appium driver for macOS apps automation

46 lines 1.87 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.getModuleRoot = void 0; exports.listChildrenProcessIds = listChildrenProcessIds; const lodash_1 = __importDefault(require("lodash")); const teen_process_1 = require("teen_process"); const support_1 = require("appium/support"); const MODULE_NAME = 'appium-mac2-driver'; /** * Calculates the path to the current module's root folder * * @returns {string} The full path to module root * @throws {Error} If the current module root folder cannot be determined */ const getModuleRoot = lodash_1.default.memoize(function getModuleRoot() { const root = support_1.node.getModuleRootSync(MODULE_NAME, __filename); if (!root) { throw new Error(`Cannot find the root folder of the ${MODULE_NAME} Node.js module`); } return root; }); exports.getModuleRoot = getModuleRoot; /** * Retrieves process ids of all the children processes created by the given * parent process identifier * * @param {number|string} parentPid parent process ID * @returns {Promise<string[]>} the list of matched children process ids * or an empty list if none matched */ async function listChildrenProcessIds(parentPid) { const { stdout } = await (0, teen_process_1.exec)('ps', ['axu', '-o', 'ppid']); // USER PID %CPU %MEM VSZ RSS TT STAT STARTED TIME COMMAND PPID return stdout.split('\n') .filter(lodash_1.default.trim) .map((line) => { const [, pid, ...rest] = line.split(/\s+/).filter(lodash_1.default.trim); return [pid, lodash_1.default.last(rest)]; }) .filter(([, ppid]) => ppid === `${parentPid}`) .map(([pid]) => (String)(pid)); } //# sourceMappingURL=utils.js.map