UNPKG

appium-xcuitest-driver

Version:

Appium driver for iOS using XCUITest for backend

66 lines 2.25 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.makeContextUpdatedEvent = void 0; exports.makeNetworkMonitorEvent = makeNetworkMonitorEvent; exports.makeLogEntryAddedEvent = makeLogEntryAddedEvent; const utils_1 = require("../../utils"); const constants_1 = require("./constants"); const lodash_1 = __importDefault(require("lodash")); function toContextUpdatedEvent(method, contextName) { return { method, params: { name: contextName, type: contextName === utils_1.NATIVE_WIN ? 'NATIVE' : 'WEB', }, }; } const makeContextUpdatedEvent = (contextName) => toContextUpdatedEvent(constants_1.CONTEXT_UPDATED_EVENT, contextName); exports.makeContextUpdatedEvent = makeContextUpdatedEvent; /** * Builds a BiDi event for a single DVT NetworkMonitor instrument payload. * Clones the payload with `structuredClone` so subscribers get a plain snapshot (safe if anything * downstream mutates) without the lossiness of `JSON.stringify` (e.g. `NaN`, `undefined` handling). */ function makeNetworkMonitorEvent(event) { return { context: utils_1.NATIVE_WIN, method: constants_1.NETWORK_MONITOR_EVENT, params: { event: structuredClone(event), }, }; } /** Builds the BiDi log.entryAdded payload from an internal log entry. */ function makeLogEntryAddedEvent(entry, context, type) { return { context, method: constants_1.LOG_ENTRY_ADDED_EVENT, params: { type, level: adjustLogLevel(entry.level), source: { realm: '', context, }, text: entry.message, timestamp: entry.timestamp, }, }; } function adjustLogLevel(originalLevel) { const originalLevelLc = lodash_1.default.toLower(originalLevel); switch (originalLevelLc) { case 'debug': case 'info': case 'warn': case 'error': return originalLevelLc; default: return 'info'; } } //# sourceMappingURL=models.js.map