Call buildExpectationResult directly from Suite and Spec
This removes quite a bit of indirection from result processing, at the cost of making a few of the tests more awkward.
This commit is contained in:
@@ -1501,7 +1501,7 @@ getJasmineRequireObj().Env = function(j$) {
|
||||
error.matcherName !== undefined && error.passed !== undefined;
|
||||
const result = isExpectationResult
|
||||
? error
|
||||
: expectationResultFactory({
|
||||
: j$.buildExpectationResult({
|
||||
error,
|
||||
passed: false,
|
||||
matcherName: '',
|
||||
@@ -1651,16 +1651,6 @@ getJasmineRequireObj().Env = function(j$) {
|
||||
return fullName.join(' ');
|
||||
};
|
||||
|
||||
// TODO: we may just be able to pass in the fn instead of wrapping here
|
||||
var buildExpectationResult = j$.buildExpectationResult,
|
||||
exceptionFormatter = new j$.ExceptionFormatter(),
|
||||
expectationResultFactory = function(attrs) {
|
||||
attrs.messageFormatter = exceptionFormatter.message;
|
||||
attrs.stackFormatter = exceptionFormatter.stack;
|
||||
|
||||
return buildExpectationResult(attrs);
|
||||
};
|
||||
|
||||
/**
|
||||
* Causes a deprecation warning to be logged to the console and reported to
|
||||
* reporters.
|
||||
@@ -1726,7 +1716,7 @@ getJasmineRequireObj().Env = function(j$) {
|
||||
description: 'Jasmine__TopLevel__Suite',
|
||||
expectationFactory: expectationFactory,
|
||||
asyncExpectationFactory: suiteAsyncExpectationFactory,
|
||||
expectationResultFactory: expectationResultFactory,
|
||||
expectationResultFactory: j$.buildExpectationResult,
|
||||
autoCleanClosures: config.autoCleanClosures,
|
||||
onLateError: recordLateError
|
||||
});
|
||||
@@ -2185,7 +2175,7 @@ getJasmineRequireObj().Env = function(j$) {
|
||||
timer: new j$.Timer(),
|
||||
expectationFactory: expectationFactory,
|
||||
asyncExpectationFactory: suiteAsyncExpectationFactory,
|
||||
expectationResultFactory: expectationResultFactory,
|
||||
expectationResultFactory: j$.buildExpectationResult,
|
||||
throwOnExpectationFailure: config.stopSpecOnExpectationFailure,
|
||||
autoCleanClosures: config.autoCleanClosures,
|
||||
onLateError: recordLateError
|
||||
@@ -2294,7 +2284,7 @@ getJasmineRequireObj().Env = function(j$) {
|
||||
},
|
||||
onStart: specStarted,
|
||||
description: description,
|
||||
expectationResultFactory: expectationResultFactory,
|
||||
expectationResultFactory: j$.buildExpectationResult,
|
||||
queueRunnerFactory: queueRunnerFactory,
|
||||
userContext: function() {
|
||||
return suite.clonedSharedUserContext();
|
||||
@@ -3131,8 +3121,7 @@ getJasmineRequireObj().Truthy = function(j$) {
|
||||
//TODO: expectation result may make more sense as a presentation of an expectation.
|
||||
getJasmineRequireObj().buildExpectationResult = function(j$) {
|
||||
function buildExpectationResult(options) {
|
||||
const messageFormatter = options.messageFormatter || function() {};
|
||||
const stackFormatter = options.stackFormatter || function() {};
|
||||
const exceptionFormatter = new j$.ExceptionFormatter();
|
||||
|
||||
/**
|
||||
* @typedef Expectation
|
||||
@@ -3182,7 +3171,7 @@ getJasmineRequireObj().buildExpectationResult = function(j$) {
|
||||
} else if (options.message) {
|
||||
return options.message;
|
||||
} else if (options.error) {
|
||||
return messageFormatter(options.error);
|
||||
return exceptionFormatter.message(options.error);
|
||||
}
|
||||
return '';
|
||||
}
|
||||
@@ -3209,7 +3198,7 @@ getJasmineRequireObj().buildExpectationResult = function(j$) {
|
||||
}
|
||||
// Omit the message from the stack trace because it will be
|
||||
// included elsewhere.
|
||||
return stackFormatter(error, { omitMessage: true });
|
||||
return exceptionFormatter.stack(error, { omitMessage: true });
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user