UNPKG

detox-allure2-adapter

Version:
79 lines 2.64 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.AndroidDescriptionProcessor = void 0; const utils_1 = require("../../utils"); const classes_1 = require("../classes"); const type_guards_1 = require("./type-guards"); class AndroidDescriptionProcessor { process(payload) { if (!(0, type_guards_1.isDetoxMessage)(payload)) { return null; } if (payload.type === 'reactNativeReload') { return (0, utils_1.msg)('Reload React Native'); } if (payload.type === 'invoke') { const result = payload.params ? this.processInvocation(payload.params) : null; if ((0, type_guards_1.isStepDescription)(result)) { return result; } if ((0, type_guards_1.isStepDescriptionFriendly)(result)) { return result.toJSON(); } } return null; } processInvocation(invocation) { try { const targetClass = this.processNode(invocation.target); if (!targetClass) { return null; } const methodName = invocation.method; const processedArgs = this.processArguments(invocation.args); const targetClassObj = targetClass; if (typeof targetClassObj[methodName] !== 'function') { return null; } return targetClassObj[methodName](...processedArgs); } catch { return null; } } processArguments(args) { return args.map((arg) => this.processNode(arg)); } processNode(node) { if (node == null) { return null; } if (Array.isArray(node)) { return node.map((item) => this.processNode(item)); } if (typeof node !== 'object') { return node; } if ((0, type_guards_1.isClassObject)(node)) { return this.processClassNode(node); } if ((0, type_guards_1.isInvocationObject)(node)) { return this.processInvocation(node.value); } if ((0, type_guards_1.isPrimitiveTypeObject)(node)) { return node.value; } return '#ERROR!'; } processClassNode(node) { const className = node.value; if (!(className in classes_1.classRegistry)) { return null; } return classes_1.classRegistry[className]; } } exports.AndroidDescriptionProcessor = AndroidDescriptionProcessor; //# sourceMappingURL=AndroidDescriptionProcessor.js.map