Encapsulate spec result
This commit is contained in:
@@ -4,9 +4,7 @@ getJasmineRequireObj().Spec = function(j$) {
|
||||
#throwOnExpectationFailure;
|
||||
#timer;
|
||||
#metadata;
|
||||
// TODO: better naming. Don't make 'excluded' mean two things.
|
||||
#dynamicallyExcluded;
|
||||
#requireExpectations;
|
||||
#executionState;
|
||||
|
||||
constructor(attrs) {
|
||||
this.expectationFactory = attrs.expectationFactory;
|
||||
@@ -38,23 +36,23 @@ getJasmineRequireObj().Spec = function(j$) {
|
||||
this.#throwOnExpectationFailure = !!attrs.throwOnExpectationFailure;
|
||||
this.#timer = attrs.timer || new j$.Timer();
|
||||
|
||||
this.reset();
|
||||
|
||||
if (!this.queueableFn.fn) {
|
||||
this.exclude();
|
||||
}
|
||||
|
||||
this.reset();
|
||||
}
|
||||
|
||||
addExpectationResult(passed, data, isError) {
|
||||
const expectationResult = j$.private.buildExpectationResult(data);
|
||||
|
||||
if (passed) {
|
||||
this.result.passedExpectations.push(expectationResult);
|
||||
this.#executionState.passedExpectations.push(expectationResult);
|
||||
} else {
|
||||
if (this.reportedDone) {
|
||||
this.onLateError(expectationResult);
|
||||
} else {
|
||||
this.result.failedExpectations.push(expectationResult);
|
||||
this.#executionState.failedExpectations.push(expectationResult);
|
||||
}
|
||||
|
||||
if (this.#throwOnExpectationFailure && !isError) {
|
||||
@@ -64,8 +62,8 @@ getJasmineRequireObj().Spec = function(j$) {
|
||||
}
|
||||
|
||||
getSpecProperty(key) {
|
||||
this.result.properties = this.result.properties || {};
|
||||
return this.result.properties[key];
|
||||
this.#executionState.properties = this.#executionState.properties || {};
|
||||
return this.#executionState.properties[key];
|
||||
}
|
||||
|
||||
setSpecProperty(key, value) {
|
||||
@@ -74,8 +72,8 @@ getJasmineRequireObj().Spec = function(j$) {
|
||||
// Throw a better one now.
|
||||
j$.private.util.assertReporterCloneable(key, 'Key');
|
||||
j$.private.util.assertReporterCloneable(value, 'Value');
|
||||
this.result.properties = this.result.properties || {};
|
||||
this.result.properties[key] = value;
|
||||
this.#executionState.properties = this.#executionState.properties || {};
|
||||
this.#executionState.properties[key] = value;
|
||||
}
|
||||
|
||||
executionStarted() {
|
||||
@@ -83,17 +81,17 @@ getJasmineRequireObj().Spec = function(j$) {
|
||||
}
|
||||
|
||||
executionFinished(excluded, failSpecWithNoExp) {
|
||||
this.#dynamicallyExcluded = excluded;
|
||||
this.#requireExpectations = failSpecWithNoExp;
|
||||
this.#executionState.dynamicallyExcluded = excluded;
|
||||
this.#executionState.requireExpectations = failSpecWithNoExp;
|
||||
|
||||
if (this.#autoCleanClosures) {
|
||||
this.queueableFn.fn = null;
|
||||
}
|
||||
|
||||
this.result.duration = this.#timer.elapsed();
|
||||
this.#executionState.duration = this.#timer.elapsed();
|
||||
|
||||
if (this.status() !== 'failed') {
|
||||
this.result.debugLogs = null;
|
||||
this.#executionState.debugLogs = null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -112,24 +110,20 @@ getJasmineRequireObj().Spec = function(j$) {
|
||||
}
|
||||
|
||||
reset() {
|
||||
this.result = {
|
||||
id: this.id,
|
||||
description: this.description,
|
||||
fullName: this.getFullName(),
|
||||
parentSuiteId: this.parentSuiteId,
|
||||
filename: this.filename,
|
||||
this.#executionState = {
|
||||
failedExpectations: [],
|
||||
passedExpectations: [],
|
||||
deprecationWarnings: [],
|
||||
pendingReason: this.excludeMessage || '',
|
||||
duration: null,
|
||||
properties: null,
|
||||
debugLogs: null
|
||||
debugLogs: null,
|
||||
// TODO: better naming. Don't make 'excluded' mean two things.
|
||||
dynamicallyExcluded: false,
|
||||
requireExpectations: false,
|
||||
markedPending: this.markedExcluding
|
||||
};
|
||||
this.markedPending = this.markedExcluding;
|
||||
this.reportedDone = false;
|
||||
this.#dynamicallyExcluded = false;
|
||||
this.#requireExpectations = false;
|
||||
}
|
||||
|
||||
startedEvent() {
|
||||
@@ -188,7 +182,7 @@ getJasmineRequireObj().Spec = function(j$) {
|
||||
];
|
||||
|
||||
for (const k of toCopy) {
|
||||
event[k] = this.result[k];
|
||||
event[k] = this.#executionState[k];
|
||||
}
|
||||
|
||||
return event;
|
||||
@@ -226,12 +220,16 @@ getJasmineRequireObj().Spec = function(j$) {
|
||||
}
|
||||
|
||||
pend(message) {
|
||||
this.markedPending = true;
|
||||
this.#executionState.markedPending = true;
|
||||
if (message) {
|
||||
this.result.pendingReason = message;
|
||||
this.#executionState.pendingReason = message;
|
||||
}
|
||||
}
|
||||
|
||||
get markedPending() {
|
||||
return this.#executionState.markedPending;
|
||||
}
|
||||
|
||||
// Like pend(), but pending state will survive reset().
|
||||
// Useful for fit, xit, where pending state remains.
|
||||
exclude(message) {
|
||||
@@ -242,15 +240,8 @@ getJasmineRequireObj().Spec = function(j$) {
|
||||
this.pend(message);
|
||||
}
|
||||
|
||||
// TODO: ensure that all access to result goes through .getResult()
|
||||
// so that the status is correct.
|
||||
// Step 1: fix things so getResult() always returns correct status
|
||||
getResult() {
|
||||
return this.result;
|
||||
}
|
||||
|
||||
status() {
|
||||
if (this.#dynamicallyExcluded) {
|
||||
if (this.#executionState.dynamicallyExcluded) {
|
||||
return 'excluded';
|
||||
}
|
||||
|
||||
@@ -259,10 +250,10 @@ getJasmineRequireObj().Spec = function(j$) {
|
||||
}
|
||||
|
||||
if (
|
||||
this.result.failedExpectations.length > 0 ||
|
||||
(this.#requireExpectations &&
|
||||
this.result.failedExpectations.length +
|
||||
this.result.passedExpectations.length ===
|
||||
this.#executionState.failedExpectations.length > 0 ||
|
||||
(this.#executionState.requireExpectations &&
|
||||
this.#executionState.failedExpectations.length +
|
||||
this.#executionState.passedExpectations.length ===
|
||||
0)
|
||||
) {
|
||||
return 'failed';
|
||||
@@ -279,14 +270,14 @@ getJasmineRequireObj().Spec = function(j$) {
|
||||
if (typeof deprecation === 'string') {
|
||||
deprecation = { message: deprecation };
|
||||
}
|
||||
this.result.deprecationWarnings.push(
|
||||
this.#executionState.deprecationWarnings.push(
|
||||
j$.private.buildExpectationResult(deprecation)
|
||||
);
|
||||
}
|
||||
|
||||
debugLog(msg) {
|
||||
if (!this.result.debugLogs) {
|
||||
this.result.debugLogs = [];
|
||||
if (!this.#executionState.debugLogs) {
|
||||
this.#executionState.debugLogs = [];
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -295,7 +286,7 @@ getJasmineRequireObj().Spec = function(j$) {
|
||||
* @property {number} timestamp - The time when the entry was added, in
|
||||
* milliseconds from the spec's start time
|
||||
*/
|
||||
this.result.debugLogs.push({
|
||||
this.#executionState.debugLogs.push({
|
||||
message: msg,
|
||||
timestamp: this.#timer.elapsed()
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user