Remove access to non-public properties of suites and specs returned by describe, it, etc.
[#179064612]
This commit is contained in:
@@ -663,12 +663,6 @@ getJasmineRequireObj().Spec = function(j$) {
|
||||
this.expectationFactory = attrs.expectationFactory;
|
||||
this.asyncExpectationFactory = attrs.asyncExpectationFactory;
|
||||
this.resultCallback = attrs.resultCallback || function() {};
|
||||
/**
|
||||
* The unique ID of this spec.
|
||||
* @name Spec#id
|
||||
* @readonly
|
||||
* @type {string}
|
||||
*/
|
||||
this.id = attrs.id;
|
||||
this.description = attrs.description || '';
|
||||
this.queueableFn = attrs.queueableFn;
|
||||
@@ -898,34 +892,43 @@ getJasmineRequireObj().Spec = function(j$) {
|
||||
* @interface Spec
|
||||
* @see Configuration#specFilter
|
||||
*/
|
||||
Spec.prototype.buildMetadata = function() {
|
||||
return {
|
||||
/**
|
||||
* The description passed to the {@link it} that created this spec.
|
||||
* @name Spec#description
|
||||
* @readonly
|
||||
* @type {string}
|
||||
*/
|
||||
description: this.description,
|
||||
Object.defineProperty(Spec.prototype, 'metadata', {
|
||||
get: function() {
|
||||
if (!this.metadata_) {
|
||||
this.metadata_ = {
|
||||
/**
|
||||
* The unique ID of this spec.
|
||||
* @name Spec#id
|
||||
* @readonly
|
||||
* @type {string}
|
||||
*/
|
||||
id: this.id,
|
||||
|
||||
/**
|
||||
* The full description including all ancestors of this spec.
|
||||
* @name Spec#getFullName
|
||||
* @function
|
||||
* @returns {string}
|
||||
*/
|
||||
getFullName: this.getFullName.bind(this)
|
||||
};
|
||||
};
|
||||
/**
|
||||
* The description passed to the {@link it} that created this spec.
|
||||
* @name Spec#description
|
||||
* @readonly
|
||||
* @type {string}
|
||||
*/
|
||||
description: this.description,
|
||||
|
||||
/**
|
||||
* The full description including all ancestors of this spec.
|
||||
* @name Spec#getFullName
|
||||
* @function
|
||||
* @returns {string}
|
||||
*/
|
||||
getFullName: this.getFullName.bind(this)
|
||||
};
|
||||
}
|
||||
|
||||
return this.metadata_;
|
||||
}
|
||||
});
|
||||
|
||||
return Spec;
|
||||
};
|
||||
|
||||
if (typeof window == void 0 && typeof exports == 'object') {
|
||||
/* globals exports */
|
||||
exports.Spec = jasmineRequire.Spec;
|
||||
}
|
||||
|
||||
/*jshint bitwise: false*/
|
||||
|
||||
getJasmineRequireObj().Order = function() {
|
||||
@@ -1523,7 +1526,7 @@ getJasmineRequireObj().Env = function(j$) {
|
||||
* @return {Suite} the root suite
|
||||
*/
|
||||
this.topSuite = function() {
|
||||
return topSuite.buildMetadata(null);
|
||||
return topSuite.metadata;
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -1906,7 +1909,7 @@ getJasmineRequireObj().Env = function(j$) {
|
||||
if (suite.parentSuite && !suite.children.length) {
|
||||
throw new Error('describe with no children (describe() or it())');
|
||||
}
|
||||
return suite;
|
||||
return suite.metadata;
|
||||
};
|
||||
|
||||
this.xdescribe = function(description, specDefinitions) {
|
||||
@@ -1915,7 +1918,7 @@ getJasmineRequireObj().Env = function(j$) {
|
||||
var suite = suiteFactory(description);
|
||||
suite.pend();
|
||||
addSpecsToSuite(suite, specDefinitions);
|
||||
return suite;
|
||||
return suite.metadata;
|
||||
};
|
||||
|
||||
var focusedRunnables = [];
|
||||
@@ -1930,7 +1933,7 @@ getJasmineRequireObj().Env = function(j$) {
|
||||
unfocusAncestor();
|
||||
addSpecsToSuite(suite, specDefinitions);
|
||||
|
||||
return suite;
|
||||
return suite.metadata;
|
||||
};
|
||||
|
||||
function addSpecsToSuite(suite, specDefinitions) {
|
||||
@@ -2020,7 +2023,7 @@ getJasmineRequireObj().Env = function(j$) {
|
||||
}
|
||||
};
|
||||
|
||||
this.it = function(description, fn, timeout) {
|
||||
this.it_ = function(description, fn, timeout) {
|
||||
ensureIsNotNested('it');
|
||||
// it() sometimes doesn't have a fn argument, so only check the type if
|
||||
// it's given.
|
||||
@@ -2036,6 +2039,11 @@ getJasmineRequireObj().Env = function(j$) {
|
||||
return spec;
|
||||
};
|
||||
|
||||
this.it = function(description, fn, timeout) {
|
||||
const spec = this.it_(description, fn, timeout);
|
||||
return spec.metadata;
|
||||
};
|
||||
|
||||
this.xit = function(description, fn, timeout) {
|
||||
ensureIsNotNested('xit');
|
||||
// xit(), like it(), doesn't always have a fn argument, so only check the
|
||||
@@ -2043,9 +2051,9 @@ getJasmineRequireObj().Env = function(j$) {
|
||||
if (arguments.length > 1 && typeof fn !== 'undefined') {
|
||||
ensureIsFunctionOrAsync(fn, 'xit');
|
||||
}
|
||||
var spec = this.it.apply(this, arguments);
|
||||
var spec = this.it_.apply(this, arguments);
|
||||
spec.pend('Temporarily disabled with xit');
|
||||
return spec;
|
||||
return spec.metadata;
|
||||
};
|
||||
|
||||
this.fit = function(description, fn, timeout) {
|
||||
@@ -2055,7 +2063,7 @@ getJasmineRequireObj().Env = function(j$) {
|
||||
currentDeclarationSuite.addChild(spec);
|
||||
focusedRunnables.push(spec.id);
|
||||
unfocusAncestor();
|
||||
return spec;
|
||||
return spec.metadata;
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -9045,12 +9053,6 @@ getJasmineRequireObj().StackTrace = function(j$) {
|
||||
getJasmineRequireObj().Suite = function(j$) {
|
||||
function Suite(attrs) {
|
||||
this.env = attrs.env;
|
||||
/**
|
||||
* The unique ID of this suite.
|
||||
* @name Suite#id
|
||||
* @readonly
|
||||
* @type {string}
|
||||
*/
|
||||
this.id = attrs.id;
|
||||
this.parentSuite = attrs.parentSuite;
|
||||
this.description = attrs.description;
|
||||
@@ -9235,49 +9237,68 @@ getJasmineRequireObj().Suite = function(j$) {
|
||||
);
|
||||
};
|
||||
|
||||
Suite.prototype.buildMetadata = function(parentMetadata) {
|
||||
Object.defineProperty(Suite.prototype, 'metadata', {
|
||||
get: function() {
|
||||
if (!this.metadata_) {
|
||||
this.metadata_ = new SuiteMetadata(this);
|
||||
}
|
||||
|
||||
return this.metadata_;
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* @interface Suite
|
||||
* @see Env#topSuite
|
||||
*/
|
||||
function SuiteMetadata(suite) {
|
||||
this.suite_ = suite;
|
||||
/**
|
||||
* @interface Suite
|
||||
* @see Env#topSuite
|
||||
* The unique ID of this suite.
|
||||
* @name Suite#id
|
||||
* @readonly
|
||||
* @type {string}
|
||||
*/
|
||||
var result = {
|
||||
/**
|
||||
* The parent of this suite, or null if this is the top suite.
|
||||
* @name Suite#parentSuite
|
||||
* @readonly
|
||||
* @type {Suite}
|
||||
*/
|
||||
parentSuite: parentMetadata,
|
||||
|
||||
/**
|
||||
* The description passed to the {@link describe} that created this suite.
|
||||
* @name Suite#description
|
||||
* @readonly
|
||||
* @type {string}
|
||||
*/
|
||||
description: this.description,
|
||||
|
||||
/**
|
||||
* The full description including all ancestors of this suite.
|
||||
* @name Suite#getFullName
|
||||
* @function
|
||||
* @returns {string}
|
||||
*/
|
||||
getFullName: this.getFullName.bind(this)
|
||||
};
|
||||
this.id = suite.id;
|
||||
|
||||
/**
|
||||
* The suite's children.
|
||||
* @name Suite#children
|
||||
* @type {Array.<(Spec|Suite)>}
|
||||
* The parent of this suite, or null if this is the top suite.
|
||||
* @name Suite#parentSuite
|
||||
* @readonly
|
||||
* @type {Suite}
|
||||
*/
|
||||
result.children = this.children.map(function(child) {
|
||||
return child.buildMetadata(result);
|
||||
});
|
||||
this.parentSuite = suite.parentSuite ? suite.parentSuite.metadata : null;
|
||||
|
||||
return result;
|
||||
/**
|
||||
* The description passed to the {@link describe} that created this suite.
|
||||
* @name Suite#description
|
||||
* @readonly
|
||||
* @type {string}
|
||||
*/
|
||||
this.description = suite.description;
|
||||
}
|
||||
|
||||
/**
|
||||
* The full description including all ancestors of this suite.
|
||||
* @name Suite#getFullName
|
||||
* @function
|
||||
* @returns {string}
|
||||
*/
|
||||
SuiteMetadata.prototype.getFullName = function() {
|
||||
return this.suite_.getFullName();
|
||||
};
|
||||
|
||||
/**
|
||||
* The suite's children.
|
||||
* @name Suite#children
|
||||
* @type {Array.<(Spec|Suite)>}
|
||||
*/
|
||||
Object.defineProperty(SuiteMetadata.prototype, 'children', {
|
||||
get: function() {
|
||||
return this.suite_.children.map(child => child.metadata);
|
||||
}
|
||||
});
|
||||
|
||||
function isFailure(args) {
|
||||
return !args[0];
|
||||
}
|
||||
@@ -9285,11 +9306,6 @@ getJasmineRequireObj().Suite = function(j$) {
|
||||
return Suite;
|
||||
};
|
||||
|
||||
if (typeof window == void 0 && typeof exports == 'object') {
|
||||
/* globals exports */
|
||||
exports.Suite = jasmineRequire.Suite;
|
||||
}
|
||||
|
||||
getJasmineRequireObj().Timer = function() {
|
||||
var defaultNow = (function(Date) {
|
||||
return function() {
|
||||
|
||||
Reference in New Issue
Block a user