Clarify what's currently treated as private vs internal in Suite and Spec

This commit is contained in:
Steve Gravrock
2025-08-31 09:18:16 -07:00
parent e1532be726
commit ca4fbcbccb
6 changed files with 99 additions and 102 deletions

View File

@@ -1,5 +1,10 @@
getJasmineRequireObj().Spec = function(j$) {
class Spec {
#autoCleanClosures;
#throwOnExpectationFailure;
#timer;
#metadata;
constructor(attrs) {
this.expectationFactory = attrs.expectationFactory;
this.asyncExpectationFactory = attrs.asyncExpectationFactory;
@@ -18,23 +23,17 @@ getJasmineRequireObj().Spec = function(j$) {
function() {
return {};
};
this.autoCleanClosures =
attrs.autoCleanClosures === undefined
? true
: !!attrs.autoCleanClosures;
this.getPath = function() {
return attrs.getPath ? attrs.getPath(this) : [];
};
this.#autoCleanClosures =
attrs.autoCleanClosures === undefined
? true
: !!attrs.autoCleanClosures;
this.onLateError = attrs.onLateError || function() {};
this.catchingExceptions =
attrs.catchingExceptions ||
function() {
return true;
};
this.throwOnExpectationFailure = !!attrs.throwOnExpectationFailure;
this.timer = attrs.timer || new j$.Timer();
this.#throwOnExpectationFailure = !!attrs.throwOnExpectationFailure;
this.#timer = attrs.timer || new j$.Timer();
if (!this.queueableFn.fn) {
this.exclude();
@@ -60,7 +59,7 @@ getJasmineRequireObj().Spec = function(j$) {
}
}
if (this.throwOnExpectationFailure && !isError) {
if (this.#throwOnExpectationFailure && !isError) {
throw new j$.errors.ExpectationFailed();
}
}
@@ -77,16 +76,16 @@ getJasmineRequireObj().Spec = function(j$) {
}
executionStarted() {
this.timer.start();
this.#timer.start();
}
executionFinished(excluded, failSpecWithNoExp) {
if (this.autoCleanClosures) {
if (this.#autoCleanClosures) {
this.queueableFn.fn = null;
}
this.result.status = this.status(excluded, failSpecWithNoExp);
this.result.duration = this.timer.elapsed();
this.result.status = this.#status(excluded, failSpecWithNoExp);
this.result.duration = this.#timer.elapsed();
if (this.result.status !== 'failed') {
this.result.debugLogs = null;
@@ -177,11 +176,11 @@ getJasmineRequireObj().Spec = function(j$) {
// TODO: ensure that all access to result goes through .getResult()
// so that the status is correct.
getResult() {
this.result.status = this.status();
this.result.status = this.#status();
return this.result;
}
status(excluded, failSpecWithNoExpectations) {
#status(excluded, failSpecWithNoExpectations) {
if (excluded === true) {
return 'excluded';
}
@@ -229,7 +228,7 @@ getJasmineRequireObj().Spec = function(j$) {
*/
this.result.debugLogs.push({
message: msg,
timestamp: this.timer.elapsed()
timestamp: this.#timer.elapsed()
});
}
@@ -243,8 +242,8 @@ getJasmineRequireObj().Spec = function(j$) {
// actual Spec instances are still passed to Configuration#specFilter. Until
// that is fixed, it's important to make sure that all metadata properties
// also exist in compatible form on the underlying Spec.
if (!this.metadata_) {
this.metadata_ = {
if (!this.#metadata) {
this.#metadata = {
/**
* The unique ID of this spec.
* @name Spec#id
@@ -283,7 +282,7 @@ getJasmineRequireObj().Spec = function(j$) {
};
}
return this.metadata_;
return this.#metadata;
}
}

View File

@@ -1,26 +1,30 @@
getJasmineRequireObj().Suite = function(j$) {
class Suite {
#reportedParentSuiteId;
#throwOnExpectationFailure;
#autoCleanClosures;
#timer;
constructor(attrs) {
this.env = attrs.env;
this.id = attrs.id;
this.parentSuite = attrs.parentSuite;
this.description = attrs.description;
this.reportedParentSuiteId = attrs.reportedParentSuiteId;
this.filename = attrs.filename;
this.expectationFactory = attrs.expectationFactory;
this.asyncExpectationFactory = attrs.asyncExpectationFactory;
this.throwOnExpectationFailure = !!attrs.throwOnExpectationFailure;
this.autoCleanClosures =
this.onLateError = attrs.onLateError || function() {};
this.#reportedParentSuiteId = attrs.reportedParentSuiteId;
this.#throwOnExpectationFailure = !!attrs.throwOnExpectationFailure;
this.#autoCleanClosures =
attrs.autoCleanClosures === undefined
? true
: !!attrs.autoCleanClosures;
this.onLateError = attrs.onLateError || function() {};
this.#timer = attrs.timer || new j$.Timer();
this.beforeFns = [];
this.afterFns = [];
this.beforeAllFns = [];
this.afterAllFns = [];
this.timer = attrs.timer || new j$.Timer();
this.children = [];
this.reset();
@@ -74,15 +78,15 @@ getJasmineRequireObj().Suite = function(j$) {
}
startTimer() {
this.timer.start();
this.#timer.start();
}
endTimer() {
this.result.duration = this.timer.elapsed();
this.result.duration = this.#timer.elapsed();
}
cleanupBeforeAfter() {
if (this.autoCleanClosures) {
if (this.#autoCleanClosures) {
removeFns(this.beforeAllFns);
removeFns(this.afterAllFns);
removeFns(this.beforeFns);
@@ -114,7 +118,7 @@ getJasmineRequireObj().Suite = function(j$) {
id: this.id,
description: this.description,
fullName: this.getFullName(),
parentSuiteId: this.reportedParentSuiteId,
parentSuiteId: this.#reportedParentSuiteId,
filename: this.filename,
failedExpectations: [],
deprecationWarnings: [],
@@ -136,7 +140,7 @@ getJasmineRequireObj().Suite = function(j$) {
this.children.push(child);
}
status() {
#status() {
if (this.markedPending) {
return 'pending';
}
@@ -149,7 +153,7 @@ getJasmineRequireObj().Suite = function(j$) {
}
getResult() {
this.result.status = this.status();
this.result.status = this.#status();
return this.result;
}
@@ -234,7 +238,7 @@ getJasmineRequireObj().Suite = function(j$) {
}
}
if (this.throwOnExpectationFailure) {
if (this.#throwOnExpectationFailure) {
throw new j$.errors.ExpectationFailed();
}
}