detox-allure2-adapter
Version:
Detox adapter for jest-allure2-reporter
57 lines • 2.37 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.formatSystemExpectation = exports.formatSystemAction = void 0;
const utils_1 = require("../../utils");
const predicate_formatters_1 = require("./predicate-formatters");
function formatSystemContext() {
return (0, utils_1.msg)('System:');
}
function formatSystemPredicate(predicate, atIndex) {
if (!predicate) {
return null;
}
const predicateWithIndex = { ...predicate, atIndex };
return (0, predicate_formatters_1.formatPredicate)(predicateWithIndex);
}
const formatSystemExpectationVerb = (invocation) => {
const hasNot = invocation.systemModifiers?.includes('not');
const expectation = invocation.systemExpectation || '';
const verb = expectation
.replace(/([A-Z])/g, ' $1')
.toLowerCase()
.trim();
const toOrNotTo = (0, utils_1.msg)(hasNot ? 'not to' : 'to');
const formatExpectationClause = () => {
const [expected] = invocation.params || [];
switch (expectation) {
case 'toHaveText': {
return (0, utils_1.msg)(`have text "${(0, utils_1.truncate)(expected)}"`, { expected_text: expected });
}
default: {
return (0, utils_1.msg)(verb.replace(/^to /, ''));
}
}
};
return (0, utils_1.concat)(toOrNotTo, formatExpectationClause());
};
const formatSystemAction = (invocation) => {
const { systemAction, systemPredicate, systemAtIndex } = invocation;
if (!systemAction) {
return null;
}
const context = formatSystemContext();
const target = formatSystemPredicate(systemPredicate, systemAtIndex);
const action = (0, utils_1.msg)(systemAction.charAt(0).toUpperCase() + systemAction.slice(1));
return (0, utils_1.concat)(context, action, 'on', target);
};
exports.formatSystemAction = formatSystemAction;
const formatSystemExpectation = (invocation) => {
if (!invocation.systemExpectation) {
return null;
}
const context = formatSystemContext();
const target = formatSystemPredicate(invocation.systemPredicate, invocation.systemAtIndex);
return (0, utils_1.concat)(context, 'Expect', target, formatSystemExpectationVerb(invocation));
};
exports.formatSystemExpectation = formatSystemExpectation;
//# sourceMappingURL=system-formatters.js.map