Encapsulate spec status

This commit is contained in:
Steve Gravrock
2025-09-21 16:22:54 -07:00
parent 418393c496
commit d99bc3ab58
6 changed files with 150 additions and 69 deletions

View File

@@ -240,7 +240,7 @@ getJasmineRequireObj().Env = function(j$) {
expectationResult.globalErrorType = 'lateError';
}
r.result.failedExpectations.push(expectationResult);
r.addExpectationResult(false, expectationResult);
return;
}
}

View File

@@ -4,6 +4,9 @@ getJasmineRequireObj().Spec = function(j$) {
#throwOnExpectationFailure;
#timer;
#metadata;
// TODO: better naming. Don't make 'excluded' mean two things.
#dynamicallyExcluded;
#requireExpectations;
constructor(attrs) {
this.expectationFactory = attrs.expectationFactory;
@@ -52,11 +55,6 @@ getJasmineRequireObj().Spec = function(j$) {
this.onLateError(expectationResult);
} else {
this.result.failedExpectations.push(expectationResult);
// TODO: refactor so that we don't need to override cached status
if (this.result.status) {
this.result.status = 'failed';
}
}
if (this.#throwOnExpectationFailure && !isError) {
@@ -85,18 +83,34 @@ getJasmineRequireObj().Spec = function(j$) {
}
executionFinished(excluded, failSpecWithNoExp) {
this.#dynamicallyExcluded = excluded;
this.#requireExpectations = failSpecWithNoExp;
if (this.#autoCleanClosures) {
this.queueableFn.fn = null;
}
this.result.status = this.#status(excluded, failSpecWithNoExp);
this.result.duration = this.#timer.elapsed();
if (this.result.status !== 'failed') {
if (this.status() !== 'failed') {
this.result.debugLogs = null;
}
}
hadBeforeAllFailure() {
this.addExpectationResult(
false,
{
passed: false,
message:
'Not run because a beforeAll function failed. The ' +
'beforeAll failure will be reported on the suite that ' +
'caused it.'
},
true
);
}
reset() {
this.result = {
id: this.id,
@@ -114,6 +128,8 @@ getJasmineRequireObj().Spec = function(j$) {
};
this.markedPending = this.markedExcluding;
this.reportedDone = false;
this.#dynamicallyExcluded = false;
this.#requireExpectations = false;
}
startedEvent() {
@@ -158,14 +174,14 @@ getJasmineRequireObj().Spec = function(j$) {
* @since 6.0.0
*/
const event = {
...this.#commonEventFields()
...this.#commonEventFields(),
status: this.status()
};
const toCopy = [
'failedExpectations',
'passedExpectations',
'deprecationWarnings',
'pendingReason',
'status',
'duration',
'properties',
'debugLogs'
@@ -228,13 +244,13 @@ getJasmineRequireObj().Spec = function(j$) {
// 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() {
this.result.status = this.#status();
return this.result;
}
#status(excluded, failSpecWithNoExpectations) {
if (excluded === true) {
status() {
if (this.#dynamicallyExcluded) {
return 'excluded';
}
@@ -244,7 +260,7 @@ getJasmineRequireObj().Spec = function(j$) {
if (
this.result.failedExpectations.length > 0 ||
(failSpecWithNoExpectations &&
(this.#requireExpectations &&
this.result.failedExpectations.length +
this.result.passedExpectations.length ===
0)

View File

@@ -77,7 +77,7 @@ getJasmineRequireObj().TreeRunner = function(j$) {
);
},
onComplete: () => {
if (spec.result.status === 'failed') {
if (spec.status() === 'failed') {
specOverallDone(new j$.private.StopExecutionError('spec failed'));
} else {
specOverallDone();
@@ -109,7 +109,7 @@ getJasmineRequireObj().TreeRunner = function(j$) {
const complete = {
fn(done) {
spec.executionFinished(excluded, config.failSpecWithNoExpectations);
resultCallback(spec.result, done);
resultCallback(spec.doneEvent(), done);
},
type: 'specCleanup'
};
@@ -246,7 +246,7 @@ getJasmineRequireObj().TreeRunner = function(j$) {
this.#runableResources.clearForRunable(spec.id);
this.#currentRunableTracker.setCurrentSpec(null);
if (spec.result.status === 'failed') {
if (spec.status() === 'failed') {
this.#hasFailures = true;
}
@@ -272,19 +272,7 @@ getJasmineRequireObj().TreeRunner = function(j$) {
} else {
/* a spec */
await this.#reportDispatcher.specStarted(child.startedEvent());
child.addExpectationResult(
false,
{
passed: false,
message:
'Not run because a beforeAll function failed. The ' +
'beforeAll failure will be reported on the suite that ' +
'caused it.'
},
true
);
child.result.status = 'failed';
child.hadBeforeAllFailure();
await this.#reportSpecDone(child);
}
}