appium-xcuitest-driver
Version:
Appium driver for iOS using XCUITest for backend
62 lines • 2.06 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.makeContextUpdatedEvent = void 0;
exports.makeNetworkMonitorEvent = makeNetworkMonitorEvent;
exports.makeLogEntryAddedEvent = makeLogEntryAddedEvent;
const constants_1 = require("../constants");
const constants_2 = require("./constants");
function toContextUpdatedEvent(method, contextName) {
return {
method,
params: {
name: contextName,
type: contextName === constants_1.NATIVE_WIN ? 'NATIVE' : 'WEB',
},
};
}
const makeContextUpdatedEvent = (contextName) => toContextUpdatedEvent(constants_2.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: constants_1.NATIVE_WIN,
method: constants_2.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_2.LOG_ENTRY_ADDED_EVENT,
params: {
type,
level: adjustLogLevel(entry.level),
source: {
realm: '',
context,
},
text: entry.message,
timestamp: entry.timestamp,
},
};
}
function adjustLogLevel(originalLevel) {
const originalLevelLc = String(originalLevel).toLowerCase();
switch (originalLevelLc) {
case 'debug':
case 'info':
case 'warn':
case 'error':
return originalLevelLc;
default:
return 'info';
}
}
//# sourceMappingURL=models.js.map