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

@@ -772,6 +772,11 @@ getJasmineRequireObj().util = function(j$) {
getJasmineRequireObj().Spec = function(j$) {
class Spec {
#autoCleanClosures;
#throwOnExpectationFailure;
#timer;
#metadata;
constructor(attrs) {
this.expectationFactory = attrs.expectationFactory;
this.asyncExpectationFactory = attrs.asyncExpectationFactory;
@@ -790,23 +795,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();
@@ -832,7 +831,7 @@ getJasmineRequireObj().Spec = function(j$) {
}
}
if (this.throwOnExpectationFailure && !isError) {
if (this.#throwOnExpectationFailure && !isError) {
throw new j$.errors.ExpectationFailed();
}
}
@@ -849,16 +848,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;
@@ -949,11 +948,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';
}
@@ -1001,7 +1000,7 @@ getJasmineRequireObj().Spec = function(j$) {
*/
this.result.debugLogs.push({
message: msg,
timestamp: this.timer.elapsed()
timestamp: this.#timer.elapsed()
});
}
@@ -1015,8 +1014,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
@@ -1055,7 +1054,7 @@ getJasmineRequireObj().Spec = function(j$) {
};
}
return this.metadata_;
return this.#metadata;
}
}
@@ -10476,27 +10475,31 @@ getJasmineRequireObj().StackTrace = function(j$) {
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();
@@ -10550,15 +10553,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);
@@ -10590,7 +10593,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: [],
@@ -10612,7 +10615,7 @@ getJasmineRequireObj().Suite = function(j$) {
this.children.push(child);
}
status() {
#status() {
if (this.markedPending) {
return 'pending';
}
@@ -10625,7 +10628,7 @@ getJasmineRequireObj().Suite = function(j$) {
}
getResult() {
this.result.status = this.status();
this.result.status = this.#status();
return this.result;
}
@@ -10710,7 +10713,7 @@ getJasmineRequireObj().Suite = function(j$) {
}
}
if (this.throwOnExpectationFailure) {
if (this.#throwOnExpectationFailure) {
throw new j$.errors.ExpectationFailed();
}
}

View File

@@ -33,18 +33,6 @@ describe('Spec', function() {
expect(jasmineUnderTest.Spec.isPendingSpecException(void 0)).toBe(false);
});
it('is marked pending if created without a function body', function() {
const startCallback = jasmine.createSpy('startCallback'),
resultCallback = jasmine.createSpy('resultCallback'),
spec = new jasmineUnderTest.Spec({
onStart: startCallback,
queueableFn: { fn: null },
resultCallback: resultCallback
});
expect(spec.status()).toBe('pending');
});
describe('#executionFinished', function() {
it('removes the fn if autoCleanClosures is true', function() {
const spec = new jasmineUnderTest.Spec({
@@ -116,32 +104,25 @@ describe('Spec', function() {
});
});
it('#status returns passing by default', function() {
const spec = new jasmineUnderTest.Spec({
queueableFn: { fn: jasmine.createSpy('spec body') }
});
expect(spec.status()).toBe('passed');
});
describe('#status', function() {
it('returns "passed"" by default', function() {
describe('status', function() {
it('is "passed" by default', function() {
const spec = new jasmineUnderTest.Spec({
queueableFn: { fn: () => {} }
});
expect(spec.status()).toBe('passed');
expect(spec.getResult().status).toBe('passed');
});
it('returns "passed"" if all expectations passed', function() {
it('is "passed" if all expectations passed', function() {
const spec = new jasmineUnderTest.Spec({
queueableFn: { fn: () => {} }
});
spec.addExpectationResult(true, {});
expect(spec.status()).toBe('passed');
expect(spec.getResult().status).toBe('passed');
});
it('returns "failed" if any expectation failed', function() {
it('is "failed" if any expectation failed', function() {
const spec = new jasmineUnderTest.Spec({
queueableFn: { fn: () => {} }
});
@@ -149,7 +130,19 @@ describe('Spec', function() {
spec.addExpectationResult(true, {});
spec.addExpectationResult(false, {});
expect(spec.status()).toBe('failed');
expect(spec.getResult().status).toBe('failed');
});
it('is "pending" if created without a function body', function() {
const startCallback = jasmine.createSpy('startCallback'),
resultCallback = jasmine.createSpy('resultCallback'),
spec = new jasmineUnderTest.Spec({
onStart: startCallback,
queueableFn: { fn: null },
resultCallback: resultCallback
});
expect(spec.getResult().status).toBe('pending');
});
});

View File

@@ -115,7 +115,7 @@ describe('Suite', function() {
const suite = new jasmineUnderTest.Suite({});
suite.addExpectationResult(false, {});
expect(suite.status()).toBe('failed');
expect(suite.getResult().status).toBe('failed');
});
it('retrieves a result with updated status', function() {
@@ -140,7 +140,7 @@ describe('Suite', function() {
suite.addExpectationResult(false, { message: 'failed' });
}).toThrowError(jasmineUnderTest.errors.ExpectationFailed);
expect(suite.status()).toBe('failed');
expect(suite.getResult().status).toBe('failed');
expect(suite.result.failedExpectations).toEqual([
jasmine.objectContaining({ message: 'failed' })
]);

View File

@@ -114,7 +114,6 @@ describe('TreeRunner', function() {
expect(specRunQueueArgs.queueableFns[1]).toEqual(queueableFn);
queueableFn.fn();
expect(spec.status()).toEqual('pending');
expect(spec.getResult().status).toEqual('pending');
expect(spec.getResult().pendingReason).toEqual('');
});
@@ -136,7 +135,6 @@ describe('TreeRunner', function() {
expect(specRunQueueArgs.queueableFns[1]).toEqual(queueableFn);
queueableFn.fn();
expect(spec.status()).toEqual('pending');
expect(spec.getResult().status).toEqual('pending');
expect(spec.getResult().pendingReason).toEqual('some reason');
});

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();
}
}