@contract-case/case-core
Version:
Core functionality for the ContractCase contract testing suite
82 lines • 3.36 kB
JavaScript
;
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");
const renderUserFacingStacktrace = (error) => {
if (error != null &&
typeof error === 'object' &&
'userFacingStackTrace' in error) {
return `\n\n${error.userFacingStackTrace}`;
}
return '';
};
/**
* 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 received
* @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}${renderUserFacingStacktrace(error)}`,
code: 'TriggerFunctionError',
location: context['_case:currentRun:context:location'],
userFacingStackTrace: error.userFacingStackTrace,
});
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}${renderUserFacingStacktrace(error)}`,
code: error.name,
error,
location: context['_case:currentRun:context:location'],
});
exports.verificationError = verificationError;
//# sourceMappingURL=MatchingError.js.map