Convert Suite and SuiteMetadata to ES6 classes
This commit is contained in:
@@ -10475,7 +10475,8 @@ getJasmineRequireObj().StackTrace = function(j$) {
|
||||
};
|
||||
|
||||
getJasmineRequireObj().Suite = function(j$) {
|
||||
function Suite(attrs) {
|
||||
class Suite {
|
||||
constructor(attrs) {
|
||||
this.env = attrs.env;
|
||||
this.id = attrs.id;
|
||||
this.parentSuite = attrs.parentSuite;
|
||||
@@ -10486,7 +10487,9 @@ getJasmineRequireObj().Suite = function(j$) {
|
||||
this.asyncExpectationFactory = attrs.asyncExpectationFactory;
|
||||
this.throwOnExpectationFailure = !!attrs.throwOnExpectationFailure;
|
||||
this.autoCleanClosures =
|
||||
attrs.autoCleanClosures === undefined ? true : !!attrs.autoCleanClosures;
|
||||
attrs.autoCleanClosures === undefined
|
||||
? true
|
||||
: !!attrs.autoCleanClosures;
|
||||
this.onLateError = attrs.onLateError || function() {};
|
||||
|
||||
this.beforeFns = [];
|
||||
@@ -10499,12 +10502,12 @@ getJasmineRequireObj().Suite = function(j$) {
|
||||
this.reset();
|
||||
}
|
||||
|
||||
Suite.prototype.setSuiteProperty = function(key, value) {
|
||||
setSuiteProperty(key, value) {
|
||||
this.result.properties = this.result.properties || {};
|
||||
this.result.properties[key] = value;
|
||||
};
|
||||
}
|
||||
|
||||
Suite.prototype.getFullName = function() {
|
||||
getFullName() {
|
||||
const fullName = [];
|
||||
for (
|
||||
let parentSuite = this;
|
||||
@@ -10516,64 +10519,54 @@ getJasmineRequireObj().Suite = function(j$) {
|
||||
}
|
||||
}
|
||||
return fullName.join(' ');
|
||||
};
|
||||
}
|
||||
|
||||
/*
|
||||
* Mark the suite with "pending" status
|
||||
*/
|
||||
Suite.prototype.pend = function() {
|
||||
// Mark the suite with "pending" status
|
||||
pend() {
|
||||
this.markedPending = true;
|
||||
};
|
||||
}
|
||||
|
||||
/*
|
||||
* Like {@link Suite#pend}, but pending state will survive {@link Spec#reset}
|
||||
* Useful for fdescribe, xdescribe, where pending state should remain.
|
||||
*/
|
||||
Suite.prototype.exclude = function() {
|
||||
// Like pend(), but pending state will survive reset().
|
||||
// Useful for fdescribe, xdescribe, where pending state should remain.
|
||||
exclude() {
|
||||
this.pend();
|
||||
this.markedExcluding = true;
|
||||
};
|
||||
}
|
||||
|
||||
Suite.prototype.beforeEach = function(fn) {
|
||||
beforeEach(fn) {
|
||||
this.beforeFns.unshift({ ...fn, suite: this });
|
||||
};
|
||||
}
|
||||
|
||||
Suite.prototype.beforeAll = function(fn) {
|
||||
beforeAll(fn) {
|
||||
this.beforeAllFns.push({ ...fn, type: 'beforeAll', suite: this });
|
||||
};
|
||||
}
|
||||
|
||||
Suite.prototype.afterEach = function(fn) {
|
||||
afterEach(fn) {
|
||||
this.afterFns.unshift({ ...fn, suite: this, type: 'afterEach' });
|
||||
};
|
||||
}
|
||||
|
||||
Suite.prototype.afterAll = function(fn) {
|
||||
afterAll(fn) {
|
||||
this.afterAllFns.unshift({ ...fn, type: 'afterAll' });
|
||||
};
|
||||
}
|
||||
|
||||
Suite.prototype.startTimer = function() {
|
||||
startTimer() {
|
||||
this.timer.start();
|
||||
};
|
||||
}
|
||||
|
||||
Suite.prototype.endTimer = function() {
|
||||
endTimer() {
|
||||
this.result.duration = this.timer.elapsed();
|
||||
};
|
||||
|
||||
function removeFns(queueableFns) {
|
||||
for (const qf of queueableFns) {
|
||||
qf.fn = null;
|
||||
}
|
||||
}
|
||||
|
||||
Suite.prototype.cleanupBeforeAfter = function() {
|
||||
cleanupBeforeAfter() {
|
||||
if (this.autoCleanClosures) {
|
||||
removeFns(this.beforeAllFns);
|
||||
removeFns(this.afterAllFns);
|
||||
removeFns(this.beforeFns);
|
||||
removeFns(this.afterFns);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
Suite.prototype.reset = function() {
|
||||
reset() {
|
||||
/**
|
||||
* @typedef SuiteResult
|
||||
* @property {String} id - The unique id of this suite.
|
||||
@@ -10609,17 +10602,17 @@ getJasmineRequireObj().Suite = function(j$) {
|
||||
child.reset();
|
||||
});
|
||||
this.reportedDone = false;
|
||||
};
|
||||
}
|
||||
|
||||
Suite.prototype.removeChildren = function() {
|
||||
removeChildren() {
|
||||
this.children = [];
|
||||
};
|
||||
}
|
||||
|
||||
Suite.prototype.addChild = function(child) {
|
||||
addChild(child) {
|
||||
this.children.push(child);
|
||||
};
|
||||
}
|
||||
|
||||
Suite.prototype.status = function() {
|
||||
status() {
|
||||
if (this.markedPending) {
|
||||
return 'pending';
|
||||
}
|
||||
@@ -10629,18 +10622,18 @@ getJasmineRequireObj().Suite = function(j$) {
|
||||
} else {
|
||||
return 'passed';
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
Suite.prototype.canBeReentered = function() {
|
||||
return this.beforeAllFns.length === 0 && this.afterAllFns.length === 0;
|
||||
};
|
||||
|
||||
Suite.prototype.getResult = function() {
|
||||
getResult() {
|
||||
this.result.status = this.status();
|
||||
return this.result;
|
||||
};
|
||||
}
|
||||
|
||||
Suite.prototype.sharedUserContext = function() {
|
||||
canBeReentered() {
|
||||
return this.beforeAllFns.length === 0 && this.afterAllFns.length === 0;
|
||||
}
|
||||
|
||||
sharedUserContext() {
|
||||
if (!this.sharedContext) {
|
||||
this.sharedContext = this.parentSuite
|
||||
? this.parentSuite.clonedSharedUserContext()
|
||||
@@ -10648,13 +10641,13 @@ getJasmineRequireObj().Suite = function(j$) {
|
||||
}
|
||||
|
||||
return this.sharedContext;
|
||||
};
|
||||
}
|
||||
|
||||
Suite.prototype.clonedSharedUserContext = function() {
|
||||
clonedSharedUserContext() {
|
||||
return j$.UserContext.fromExisting(this.sharedUserContext());
|
||||
};
|
||||
}
|
||||
|
||||
Suite.prototype.handleException = function() {
|
||||
handleException() {
|
||||
if (arguments[0] instanceof j$.errors.ExpectationFailed) {
|
||||
return;
|
||||
}
|
||||
@@ -10677,12 +10670,12 @@ getJasmineRequireObj().Suite = function(j$) {
|
||||
} else {
|
||||
this.result.failedExpectations.push(failedExpectation);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
Suite.prototype.onMultipleDone = function() {
|
||||
onMultipleDone() {
|
||||
let msg;
|
||||
|
||||
// Issue a deprecation. Include the context ourselves and pass
|
||||
// Issue an error. Include the context ourselves and pass
|
||||
// ignoreRunnable: true, since getting here always means that we've already
|
||||
// moved on and the current runnable isn't the one that caused the problem.
|
||||
if (this.parentSuite) {
|
||||
@@ -10699,9 +10692,9 @@ getJasmineRequireObj().Suite = function(j$) {
|
||||
}
|
||||
|
||||
this.onLateError(new Error(msg));
|
||||
};
|
||||
}
|
||||
|
||||
Suite.prototype.addExpectationResult = function() {
|
||||
addExpectationResult() {
|
||||
if (isFailure(arguments)) {
|
||||
const data = arguments[1];
|
||||
const expectationResult = j$.buildExpectationResult(data);
|
||||
@@ -10721,18 +10714,18 @@ getJasmineRequireObj().Suite = function(j$) {
|
||||
throw new j$.errors.ExpectationFailed();
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
Suite.prototype.addDeprecationWarning = function(deprecation) {
|
||||
addDeprecationWarning(deprecation) {
|
||||
if (typeof deprecation === 'string') {
|
||||
deprecation = { message: deprecation };
|
||||
}
|
||||
this.result.deprecationWarnings.push(
|
||||
j$.buildExpectationResult(deprecation)
|
||||
);
|
||||
};
|
||||
}
|
||||
|
||||
Suite.prototype.hasChildWithDescription = function(description) {
|
||||
hasChildWithDescription(description) {
|
||||
for (const child of this.children) {
|
||||
if (child.description === description) {
|
||||
return true;
|
||||
@@ -10740,25 +10733,33 @@ getJasmineRequireObj().Suite = function(j$) {
|
||||
}
|
||||
|
||||
return false;
|
||||
};
|
||||
}
|
||||
|
||||
Object.defineProperty(Suite.prototype, 'metadata', {
|
||||
get: function() {
|
||||
get metadata() {
|
||||
if (!this.metadata_) {
|
||||
this.metadata_ = new SuiteMetadata(this);
|
||||
}
|
||||
|
||||
return this.metadata_;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function removeFns(queueableFns) {
|
||||
for (const qf of queueableFns) {
|
||||
qf.fn = null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @interface Suite
|
||||
* @see Env#topSuite
|
||||
* @since 2.0.0
|
||||
*/
|
||||
function SuiteMetadata(suite) {
|
||||
this.suite_ = suite;
|
||||
class SuiteMetadata {
|
||||
#suite;
|
||||
|
||||
constructor(suite) {
|
||||
this.#suite = suite;
|
||||
/**
|
||||
* The unique ID of this suite.
|
||||
* @name Suite#id
|
||||
@@ -10793,9 +10794,9 @@ getJasmineRequireObj().Suite = function(j$) {
|
||||
* @returns {string}
|
||||
* @since 2.0.0
|
||||
*/
|
||||
SuiteMetadata.prototype.getFullName = function() {
|
||||
return this.suite_.getFullName();
|
||||
};
|
||||
getFullName() {
|
||||
return this.#suite.getFullName();
|
||||
}
|
||||
|
||||
/**
|
||||
* The suite's children.
|
||||
@@ -10803,11 +10804,10 @@ getJasmineRequireObj().Suite = function(j$) {
|
||||
* @type {Array.<(Spec|Suite)>}
|
||||
* @since 2.0.0
|
||||
*/
|
||||
Object.defineProperty(SuiteMetadata.prototype, 'children', {
|
||||
get: function() {
|
||||
return this.suite_.children.map(child => child.metadata);
|
||||
get children() {
|
||||
return this.#suite.children.map(child => child.metadata);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
function isFailure(args) {
|
||||
return !args[0];
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
getJasmineRequireObj().Suite = function(j$) {
|
||||
function Suite(attrs) {
|
||||
class Suite {
|
||||
constructor(attrs) {
|
||||
this.env = attrs.env;
|
||||
this.id = attrs.id;
|
||||
this.parentSuite = attrs.parentSuite;
|
||||
@@ -10,7 +11,9 @@ getJasmineRequireObj().Suite = function(j$) {
|
||||
this.asyncExpectationFactory = attrs.asyncExpectationFactory;
|
||||
this.throwOnExpectationFailure = !!attrs.throwOnExpectationFailure;
|
||||
this.autoCleanClosures =
|
||||
attrs.autoCleanClosures === undefined ? true : !!attrs.autoCleanClosures;
|
||||
attrs.autoCleanClosures === undefined
|
||||
? true
|
||||
: !!attrs.autoCleanClosures;
|
||||
this.onLateError = attrs.onLateError || function() {};
|
||||
|
||||
this.beforeFns = [];
|
||||
@@ -23,12 +26,12 @@ getJasmineRequireObj().Suite = function(j$) {
|
||||
this.reset();
|
||||
}
|
||||
|
||||
Suite.prototype.setSuiteProperty = function(key, value) {
|
||||
setSuiteProperty(key, value) {
|
||||
this.result.properties = this.result.properties || {};
|
||||
this.result.properties[key] = value;
|
||||
};
|
||||
}
|
||||
|
||||
Suite.prototype.getFullName = function() {
|
||||
getFullName() {
|
||||
const fullName = [];
|
||||
for (
|
||||
let parentSuite = this;
|
||||
@@ -40,64 +43,54 @@ getJasmineRequireObj().Suite = function(j$) {
|
||||
}
|
||||
}
|
||||
return fullName.join(' ');
|
||||
};
|
||||
}
|
||||
|
||||
/*
|
||||
* Mark the suite with "pending" status
|
||||
*/
|
||||
Suite.prototype.pend = function() {
|
||||
// Mark the suite with "pending" status
|
||||
pend() {
|
||||
this.markedPending = true;
|
||||
};
|
||||
}
|
||||
|
||||
/*
|
||||
* Like {@link Suite#pend}, but pending state will survive {@link Spec#reset}
|
||||
* Useful for fdescribe, xdescribe, where pending state should remain.
|
||||
*/
|
||||
Suite.prototype.exclude = function() {
|
||||
// Like pend(), but pending state will survive reset().
|
||||
// Useful for fdescribe, xdescribe, where pending state should remain.
|
||||
exclude() {
|
||||
this.pend();
|
||||
this.markedExcluding = true;
|
||||
};
|
||||
}
|
||||
|
||||
Suite.prototype.beforeEach = function(fn) {
|
||||
beforeEach(fn) {
|
||||
this.beforeFns.unshift({ ...fn, suite: this });
|
||||
};
|
||||
}
|
||||
|
||||
Suite.prototype.beforeAll = function(fn) {
|
||||
beforeAll(fn) {
|
||||
this.beforeAllFns.push({ ...fn, type: 'beforeAll', suite: this });
|
||||
};
|
||||
}
|
||||
|
||||
Suite.prototype.afterEach = function(fn) {
|
||||
afterEach(fn) {
|
||||
this.afterFns.unshift({ ...fn, suite: this, type: 'afterEach' });
|
||||
};
|
||||
}
|
||||
|
||||
Suite.prototype.afterAll = function(fn) {
|
||||
afterAll(fn) {
|
||||
this.afterAllFns.unshift({ ...fn, type: 'afterAll' });
|
||||
};
|
||||
}
|
||||
|
||||
Suite.prototype.startTimer = function() {
|
||||
startTimer() {
|
||||
this.timer.start();
|
||||
};
|
||||
}
|
||||
|
||||
Suite.prototype.endTimer = function() {
|
||||
endTimer() {
|
||||
this.result.duration = this.timer.elapsed();
|
||||
};
|
||||
|
||||
function removeFns(queueableFns) {
|
||||
for (const qf of queueableFns) {
|
||||
qf.fn = null;
|
||||
}
|
||||
}
|
||||
|
||||
Suite.prototype.cleanupBeforeAfter = function() {
|
||||
cleanupBeforeAfter() {
|
||||
if (this.autoCleanClosures) {
|
||||
removeFns(this.beforeAllFns);
|
||||
removeFns(this.afterAllFns);
|
||||
removeFns(this.beforeFns);
|
||||
removeFns(this.afterFns);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
Suite.prototype.reset = function() {
|
||||
reset() {
|
||||
/**
|
||||
* @typedef SuiteResult
|
||||
* @property {String} id - The unique id of this suite.
|
||||
@@ -133,17 +126,17 @@ getJasmineRequireObj().Suite = function(j$) {
|
||||
child.reset();
|
||||
});
|
||||
this.reportedDone = false;
|
||||
};
|
||||
}
|
||||
|
||||
Suite.prototype.removeChildren = function() {
|
||||
removeChildren() {
|
||||
this.children = [];
|
||||
};
|
||||
}
|
||||
|
||||
Suite.prototype.addChild = function(child) {
|
||||
addChild(child) {
|
||||
this.children.push(child);
|
||||
};
|
||||
}
|
||||
|
||||
Suite.prototype.status = function() {
|
||||
status() {
|
||||
if (this.markedPending) {
|
||||
return 'pending';
|
||||
}
|
||||
@@ -153,18 +146,18 @@ getJasmineRequireObj().Suite = function(j$) {
|
||||
} else {
|
||||
return 'passed';
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
Suite.prototype.canBeReentered = function() {
|
||||
return this.beforeAllFns.length === 0 && this.afterAllFns.length === 0;
|
||||
};
|
||||
|
||||
Suite.prototype.getResult = function() {
|
||||
getResult() {
|
||||
this.result.status = this.status();
|
||||
return this.result;
|
||||
};
|
||||
}
|
||||
|
||||
Suite.prototype.sharedUserContext = function() {
|
||||
canBeReentered() {
|
||||
return this.beforeAllFns.length === 0 && this.afterAllFns.length === 0;
|
||||
}
|
||||
|
||||
sharedUserContext() {
|
||||
if (!this.sharedContext) {
|
||||
this.sharedContext = this.parentSuite
|
||||
? this.parentSuite.clonedSharedUserContext()
|
||||
@@ -172,13 +165,13 @@ getJasmineRequireObj().Suite = function(j$) {
|
||||
}
|
||||
|
||||
return this.sharedContext;
|
||||
};
|
||||
}
|
||||
|
||||
Suite.prototype.clonedSharedUserContext = function() {
|
||||
clonedSharedUserContext() {
|
||||
return j$.UserContext.fromExisting(this.sharedUserContext());
|
||||
};
|
||||
}
|
||||
|
||||
Suite.prototype.handleException = function() {
|
||||
handleException() {
|
||||
if (arguments[0] instanceof j$.errors.ExpectationFailed) {
|
||||
return;
|
||||
}
|
||||
@@ -201,12 +194,12 @@ getJasmineRequireObj().Suite = function(j$) {
|
||||
} else {
|
||||
this.result.failedExpectations.push(failedExpectation);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
Suite.prototype.onMultipleDone = function() {
|
||||
onMultipleDone() {
|
||||
let msg;
|
||||
|
||||
// Issue a deprecation. Include the context ourselves and pass
|
||||
// Issue an error. Include the context ourselves and pass
|
||||
// ignoreRunnable: true, since getting here always means that we've already
|
||||
// moved on and the current runnable isn't the one that caused the problem.
|
||||
if (this.parentSuite) {
|
||||
@@ -223,9 +216,9 @@ getJasmineRequireObj().Suite = function(j$) {
|
||||
}
|
||||
|
||||
this.onLateError(new Error(msg));
|
||||
};
|
||||
}
|
||||
|
||||
Suite.prototype.addExpectationResult = function() {
|
||||
addExpectationResult() {
|
||||
if (isFailure(arguments)) {
|
||||
const data = arguments[1];
|
||||
const expectationResult = j$.buildExpectationResult(data);
|
||||
@@ -245,18 +238,18 @@ getJasmineRequireObj().Suite = function(j$) {
|
||||
throw new j$.errors.ExpectationFailed();
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
Suite.prototype.addDeprecationWarning = function(deprecation) {
|
||||
addDeprecationWarning(deprecation) {
|
||||
if (typeof deprecation === 'string') {
|
||||
deprecation = { message: deprecation };
|
||||
}
|
||||
this.result.deprecationWarnings.push(
|
||||
j$.buildExpectationResult(deprecation)
|
||||
);
|
||||
};
|
||||
}
|
||||
|
||||
Suite.prototype.hasChildWithDescription = function(description) {
|
||||
hasChildWithDescription(description) {
|
||||
for (const child of this.children) {
|
||||
if (child.description === description) {
|
||||
return true;
|
||||
@@ -264,25 +257,33 @@ getJasmineRequireObj().Suite = function(j$) {
|
||||
}
|
||||
|
||||
return false;
|
||||
};
|
||||
}
|
||||
|
||||
Object.defineProperty(Suite.prototype, 'metadata', {
|
||||
get: function() {
|
||||
get metadata() {
|
||||
if (!this.metadata_) {
|
||||
this.metadata_ = new SuiteMetadata(this);
|
||||
}
|
||||
|
||||
return this.metadata_;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function removeFns(queueableFns) {
|
||||
for (const qf of queueableFns) {
|
||||
qf.fn = null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @interface Suite
|
||||
* @see Env#topSuite
|
||||
* @since 2.0.0
|
||||
*/
|
||||
function SuiteMetadata(suite) {
|
||||
this.suite_ = suite;
|
||||
class SuiteMetadata {
|
||||
#suite;
|
||||
|
||||
constructor(suite) {
|
||||
this.#suite = suite;
|
||||
/**
|
||||
* The unique ID of this suite.
|
||||
* @name Suite#id
|
||||
@@ -317,9 +318,9 @@ getJasmineRequireObj().Suite = function(j$) {
|
||||
* @returns {string}
|
||||
* @since 2.0.0
|
||||
*/
|
||||
SuiteMetadata.prototype.getFullName = function() {
|
||||
return this.suite_.getFullName();
|
||||
};
|
||||
getFullName() {
|
||||
return this.#suite.getFullName();
|
||||
}
|
||||
|
||||
/**
|
||||
* The suite's children.
|
||||
@@ -327,11 +328,10 @@ getJasmineRequireObj().Suite = function(j$) {
|
||||
* @type {Array.<(Spec|Suite)>}
|
||||
* @since 2.0.0
|
||||
*/
|
||||
Object.defineProperty(SuiteMetadata.prototype, 'children', {
|
||||
get: function() {
|
||||
return this.suite_.children.map(child => child.metadata);
|
||||
get children() {
|
||||
return this.#suite.children.map(child => child.metadata);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
function isFailure(args) {
|
||||
return !args[0];
|
||||
|
||||
Reference in New Issue
Block a user