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:
@@ -349,7 +349,7 @@ getJasmineRequireObj().Env = function(j$) {
|
||||
error.matcherName !== undefined && error.passed !== undefined;
|
||||
const result = isExpectationResult
|
||||
? error
|
||||
: expectationResultFactory({
|
||||
: j$.buildExpectationResult({
|
||||
error,
|
||||
passed: false,
|
||||
matcherName: '',
|
||||
@@ -499,16 +499,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.
|
||||
@@ -574,7 +564,6 @@ getJasmineRequireObj().Env = function(j$) {
|
||||
description: 'Jasmine__TopLevel__Suite',
|
||||
expectationFactory: expectationFactory,
|
||||
asyncExpectationFactory: suiteAsyncExpectationFactory,
|
||||
expectationResultFactory: expectationResultFactory,
|
||||
autoCleanClosures: config.autoCleanClosures,
|
||||
onLateError: recordLateError
|
||||
});
|
||||
@@ -1033,7 +1022,6 @@ getJasmineRequireObj().Env = function(j$) {
|
||||
timer: new j$.Timer(),
|
||||
expectationFactory: expectationFactory,
|
||||
asyncExpectationFactory: suiteAsyncExpectationFactory,
|
||||
expectationResultFactory: expectationResultFactory,
|
||||
throwOnExpectationFailure: config.stopSpecOnExpectationFailure,
|
||||
autoCleanClosures: config.autoCleanClosures,
|
||||
onLateError: recordLateError
|
||||
@@ -1142,7 +1130,6 @@ getJasmineRequireObj().Env = function(j$) {
|
||||
},
|
||||
onStart: specStarted,
|
||||
description: description,
|
||||
expectationResultFactory: expectationResultFactory,
|
||||
queueRunnerFactory: queueRunnerFactory,
|
||||
userContext: function() {
|
||||
return suite.clonedSharedUserContext();
|
||||
|
||||
@@ -43,8 +43,6 @@ getJasmineRequireObj().Spec = function(j$) {
|
||||
function() {
|
||||
return '';
|
||||
};
|
||||
this.expectationResultFactory =
|
||||
attrs.expectationResultFactory || function() {};
|
||||
this.onLateError = attrs.onLateError || function() {};
|
||||
this.queueRunnerFactory = attrs.queueRunnerFactory || function() {};
|
||||
this.catchingExceptions =
|
||||
@@ -91,7 +89,7 @@ getJasmineRequireObj().Spec = function(j$) {
|
||||
}
|
||||
|
||||
Spec.prototype.addExpectationResult = function(passed, data, isError) {
|
||||
const expectationResult = this.expectationResultFactory(data);
|
||||
const expectationResult = j$.buildExpectationResult(data);
|
||||
if (passed) {
|
||||
this.result.passedExpectations.push(expectationResult);
|
||||
} else {
|
||||
@@ -296,7 +294,7 @@ getJasmineRequireObj().Spec = function(j$) {
|
||||
deprecation = { message: deprecation };
|
||||
}
|
||||
this.result.deprecationWarnings.push(
|
||||
this.expectationResultFactory(deprecation)
|
||||
j$.buildExpectationResult(deprecation)
|
||||
);
|
||||
};
|
||||
|
||||
|
||||
@@ -25,7 +25,6 @@ getJasmineRequireObj().Suite = function(j$) {
|
||||
this.description = attrs.description;
|
||||
this.expectationFactory = attrs.expectationFactory;
|
||||
this.asyncExpectationFactory = attrs.asyncExpectationFactory;
|
||||
this.expectationResultFactory = attrs.expectationResultFactory;
|
||||
this.throwOnExpectationFailure = !!attrs.throwOnExpectationFailure;
|
||||
this.autoCleanClosures =
|
||||
attrs.autoCleanClosures === undefined ? true : !!attrs.autoCleanClosures;
|
||||
@@ -210,14 +209,14 @@ getJasmineRequireObj().Suite = function(j$) {
|
||||
return;
|
||||
}
|
||||
|
||||
var data = {
|
||||
const data = {
|
||||
matcherName: '',
|
||||
passed: false,
|
||||
expected: '',
|
||||
actual: '',
|
||||
error: arguments[0]
|
||||
};
|
||||
var failedExpectation = this.expectationResultFactory(data);
|
||||
const failedExpectation = j$.buildExpectationResult(data);
|
||||
|
||||
if (!this.parentSuite) {
|
||||
failedExpectation.globalErrorType = 'afterAll';
|
||||
@@ -255,7 +254,7 @@ getJasmineRequireObj().Suite = function(j$) {
|
||||
Suite.prototype.addExpectationResult = function() {
|
||||
if (isFailure(arguments)) {
|
||||
const data = arguments[1];
|
||||
const expectationResult = this.expectationResultFactory(data);
|
||||
const expectationResult = j$.buildExpectationResult(data);
|
||||
|
||||
if (this.reportedDone) {
|
||||
this.onLateError(expectationResult);
|
||||
@@ -274,7 +273,7 @@ getJasmineRequireObj().Suite = function(j$) {
|
||||
deprecation = { message: deprecation };
|
||||
}
|
||||
this.result.deprecationWarnings.push(
|
||||
this.expectationResultFactory(deprecation)
|
||||
j$.buildExpectationResult(deprecation)
|
||||
);
|
||||
};
|
||||
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
//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
|
||||
@@ -52,7 +51,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 '';
|
||||
}
|
||||
@@ -79,7 +78,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