UNPKG

@contract-case/case-core

Version:

Core functionality for the ContractCase contract testing suite

73 lines 3 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.verificationError = exports.triggerError = exports.configurationError = exports.failedExpectationError = void 0; const case_plugin_base_1 = require("@contract-case/case-plugin-base"); /** * This represents a mismatch during a case execution that isn't covered by a * matcher (usually this is a misconfiguration that is not well described by a * {@link ../../entities/errors#CaseConfigurationError | CaseConfigurationError}) * * @param message - The message that describes this error * @param actual - The actual value that was recieved * @param code - A code that can be looked up in the documentation. This should * be a unique code specific to this kind of error that users * could look up in the documentation for more information. * @param context - The match context this occurred in * @param expected - An optional expected value (might be a description of what was expected) * @returns CaseError */ const failedExpectationError = (message, actual, code, context, expected) => ({ type: case_plugin_base_1.ERROR_TYPE_RAW_MATCH, message, expected, actual, code, location: context['_case:currentRun:context:location'], toString: () => `${(0, case_plugin_base_1.locationString)(context)}: ${message}`, }); exports.failedExpectationError = failedExpectationError; /** * This represents an error during execution of an example due to user configuration. * * @param error - The error thrown * @param context - the context that the error was in * @returns ExecutionError */ const configurationError = (error, context) => ({ type: case_plugin_base_1.ERROR_TYPE_CONFIGURATION, message: error.message, code: 'ConfigurationError', location: context['_case:currentRun:context:location'], }); exports.configurationError = configurationError; /** * This represents an error thrown by user code during execution of an example * (eg, when a user's trigger is called) * @param error - The error thrown * @param context - the context that the error was in * @returns ExecutionError */ const triggerError = (error, context) => ({ type: case_plugin_base_1.ERROR_TYPE_TRIGGER, message: error.message, code: 'TriggerFunctionError', location: context['_case:currentRun:context:location'], }); exports.triggerError = triggerError; /** * This represents an error thrown during verification using the provided * verification function * * @param error - The VerifyTriggerReturnObjectError from the verification * @param context - the context that the error was in * @returns VerificationError */ const verificationError = (error, context) => ({ type: case_plugin_base_1.ERROR_TYPE_TEST_RESPONSE, message: error.message, code: error.name, error, location: context['_case:currentRun:context:location'], }); exports.verificationError = verificationError; //# sourceMappingURL=MatchingError.js.map