@case-contract-testing/case
Version:
Next-generation contract testing suite
42 lines (41 loc) • 2.08 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.AndCombinationMatcher = void 0;
const entities_1 = require("../../entities");
const context_1 = require("../../entities/context");
const types_1 = require("../../entities/types");
const strip = (matcher, matchContext) => {
const firstStrippedResult = matcher['case:matcher:children']
.map((additionalMatcher, index) => {
try {
return matchContext.descendAndStrip(additionalMatcher, (0, context_1.addLocation)(`:and[${index}]`, matchContext));
}
catch (e) {
if (e instanceof entities_1.StripUnsupportedError) {
matchContext.logger.maintainerDebug(`AndCombinationMatcher is ignoring StripUnsupportedError from ${(0, types_1.isCaseNode)(additionalMatcher)
? additionalMatcher['case:matcher:type']
: additionalMatcher}`);
return e;
}
throw e;
}
})
.find((item) => !(item instanceof entities_1.StripUnsupportedError));
if (firstStrippedResult === undefined ||
firstStrippedResult instanceof entities_1.StripUnsupportedError // This check isn't necessary, but the compiler now knows that it's not returning an error
) {
matchContext.logger.maintainerDebug(`AndCombinationMatcher had no matchers that supported strip`);
throw new entities_1.StripUnsupportedError(matcher, matchContext);
}
return firstStrippedResult;
};
const check = async (matcher, matchContext, actual) => (await Promise.all(matcher['case:matcher:children']
.map((expectedChild, index) => matchContext.descendAndCheck(expectedChild, (0, context_1.addLocation)(`:and[${index}]`, matchContext), actual))
.flat())).flat();
exports.AndCombinationMatcher = {
describe: (matcher, matchContext) => matcher['case:matcher:children']
.map((child, index) => matchContext.descendAndDescribe(child, (0, context_1.addLocation)(`:and[${index}]`, matchContext)))
.join(' and '),
check,
strip,
};