@case-contract-testing/case
Version:
Next-generation contract testing suite
32 lines (31 loc) • 1.49 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.handleResult = void 0;
const entities_1 = require("../../entities");
const types_1 = require("./types");
const handleResult = (example, exampleIndex, context) => {
if (example.result === 'FAILED') {
context.resultPrinter.printFailureTitle(example, exampleIndex, context);
example.errors.forEach((e) => {
context.resultPrinter.printError(e, context);
});
// Warning: **ALL** error types must be checked in this function
if (example.errors.some((i) => i.type === types_1.ERROR_TYPE_MATCHING || i.type === types_1.ERROR_TYPE_RAW_MATCH)) {
context.logger.debug(`Matching errors present`);
if (context['case:currentRun:context:throwOnFail']) {
throw new entities_1.CaseFailedAssertionError(example.errors);
}
}
const verificationError = example.errors.find((i) => i.type === types_1.ERROR_TYPE_TEST_RESPONSE);
if (verificationError && context['case:currentRun:context:throwOnFail']) {
throw verificationError.error;
}
if (example.errors.some((i) => i.type === types_1.ERROR_TYPE_EXECUTION)) {
throw new entities_1.CaseConfigurationError(example.errors.map((e) => e.message).join());
}
}
else {
context.resultPrinter.printSuccessTitle(example, exampleIndex, context);
}
};
exports.handleResult = handleResult;