UNPKG

appium-xcuitest-driver

Version:

Appium driver for iOS using XCUITest for backend

84 lines 3.64 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.RemoteXPCUnavailableError = exports.TUNNEL_CREATION_COMMAND = exports.REMOTE_XPC_TUNNEL_SETUP_DOC_LINK = void 0; exports.isRemoteXPCUnavailableError = isRemoteXPCUnavailableError; exports.isTunnelAvailabilityError = isTunnelAvailabilityError; exports.formatTunnelAvailabilityMessage = formatTunnelAvailabilityMessage; exports.wrapRemoteXPCConnectionError = wrapRemoteXPCConnectionError; exports.formatRemoteXPCFallbackLog = formatRemoteXPCFallbackLog; /** Published driver guide for Remote XPC tunnel setup on real devices (iOS/tvOS 18+). */ exports.REMOTE_XPC_TUNNEL_SETUP_DOC_LINK = 'https://appium.github.io/appium-xcuitest-driver/latest/guides/remotexpc-tunnels-real-devices/'; /** Driver script that starts the tunnel registry (must run with sudo/root). */ exports.TUNNEL_CREATION_COMMAND = 'sudo appium driver run xcuitest tunnel-creation'; /** * RemoteXPC cannot satisfy the request in a way the caller may handle without treating it as * a hard tunnel/connectivity failure (for example module missing or session ineligible). */ class RemoteXPCUnavailableError extends Error { constructor(message = 'RemoteXPC is not available') { super(message); this.name = 'RemoteXPCUnavailableError'; } } exports.RemoteXPCUnavailableError = RemoteXPCUnavailableError; /** Whether `err` is a {@link RemoteXPCUnavailableError}. */ function isRemoteXPCUnavailableError(err) { return err instanceof RemoteXPCUnavailableError; } /** * Whether the given error means RemoteXPC tunnel infrastructure is unavailable. */ function isTunnelAvailabilityError(err) { if (!err) { return false; } const candidate = err; if (candidate.code === 'ERR_TUNNEL_AVAILABILITY') { return true; } const name = candidate.name ?? candidate.constructor?.name; return name === 'TunnelAvailabilityError'; } /** * User-facing message for tunnel registry / tunnel-entry failures from appium-ios-remotexpc. */ function formatTunnelAvailabilityMessage(err) { let detail; if (err instanceof Error) { detail = err.message; } else if (typeof err === 'string') { detail = err; } else { detail = String(err); } const normalizedDetail = detail.toLowerCase(); const alreadySuggestsTunnelScript = normalizedDetail.includes('tunnel creation script'); const setupHint = alreadySuggestsTunnelScript ? '' : ` Start tunnels with \`${exports.TUNNEL_CREATION_COMMAND}\` (requires root).`; return `${detail}${setupHint} See ${exports.REMOTE_XPC_TUNNEL_SETUP_DOC_LINK}`; } /** * Wraps a RemoteXPC connection error with tunnel setup guidance when the cause is tunnel-related. */ function wrapRemoteXPCConnectionError(err, context) { if (isTunnelAvailabilityError(err)) { return new Error(`${context} (${formatTunnelAvailabilityMessage(err)})`, { cause: err }); } const detail = err instanceof Error ? err.message : String(err); return new Error(`${context} (${detail})`, { cause: err }); } /** * Log line when an optional RemoteXPC feature falls back after a connection failure. */ function formatRemoteXPCFallbackLog(feature, err) { const legacyNote = 'Falling back to appium-ios-device.'; if (isTunnelAvailabilityError(err)) { return `RemoteXPC ${feature} unavailable: ${formatTunnelAvailabilityMessage(err)} ${legacyNote}`; } const detail = err instanceof Error ? err.message : String(err); return `Failed ${feature} via RemoteXPC: ${detail}. ${legacyNote}`; } //# sourceMappingURL=utils.js.map