@contract-case/case-core
Version:
Core functionality for the ContractCase contract testing suite
45 lines • 2.5 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.handleResult = void 0;
const case_plugin_base_1 = require("@contract-case/case-plugin-base");
const handleResult = (example, exampleIndex, context) => {
context.logger.deepMaintainerDebug('Handling a result of', example);
if (example.result === 'FAILED') {
context.logger.deepMaintainerDebug(`Printing a failure title for`, example, exampleIndex, context);
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
// TODO: This should be refactored so that it's not possible to reach the end
// without checking all types
const triggerError = example.errors.find((i) => i.type === case_plugin_base_1.ERROR_TYPE_TRIGGER);
if (triggerError) {
throw new case_plugin_base_1.CaseTriggerError(`The provided trigger function failed during execution:\n\n ${triggerError.message}`, {
'_case:currentRun:context:location': triggerError.location,
});
}
if (example.errors.some((i) => i.type === case_plugin_base_1.ERROR_TYPE_MATCHING || i.type === case_plugin_base_1.ERROR_TYPE_RAW_MATCH)) {
context.logger.debug(`Matching errors present`);
if (context['_case:currentRun:context:throwOnFail']) {
context.logger.maintainerDebug(`Throwing a CaseFailedAssertionError with`, example.errors);
throw new case_plugin_base_1.CaseFailedAssertionError(example.errors);
}
else {
context.logger.maintainerDebug(`Not erroring because throwOnFail is false`);
}
}
const verificationError = example.errors.find((i) => i.type === case_plugin_base_1.ERROR_TYPE_TEST_RESPONSE);
if (verificationError && context['_case:currentRun:context:throwOnFail']) {
throw verificationError.error;
}
if (example.errors.some((i) => i.type === case_plugin_base_1.ERROR_TYPE_CONFIGURATION)) {
throw new case_plugin_base_1.CaseConfigurationError(example.errors.map((e) => e.message).join());
}
}
else {
context.resultPrinter.printSuccessTitle(example, exampleIndex, context);
}
};
exports.handleResult = handleResult;
//# sourceMappingURL=handlers.js.map