146 lines
3.3 KiB
JavaScript
146 lines
3.3 KiB
JavaScript
getJasmineRequireObj().Suite = function() {
|
|
function Suite(attrs) {
|
|
this.env = attrs.env;
|
|
this.id = attrs.id;
|
|
this.parentSuite = attrs.parentSuite;
|
|
this.description = attrs.description;
|
|
this.onStart = attrs.onStart || function() {};
|
|
this.resultCallback = attrs.resultCallback || function() {};
|
|
this.clearStack = attrs.clearStack || function(fn) {fn();};
|
|
|
|
this.beforeFns = [];
|
|
this.afterFns = [];
|
|
this.beforeAllFns = [];
|
|
this.afterAllFns = [];
|
|
this.queueRunner = attrs.queueRunner || function() {};
|
|
this.disabled = false;
|
|
|
|
this.children = [];
|
|
|
|
this.result = {
|
|
id: this.id,
|
|
status: this.disabled ? 'disabled' : '',
|
|
description: this.description,
|
|
fullName: this.getFullName()
|
|
};
|
|
}
|
|
|
|
Suite.prototype.getFullName = function() {
|
|
var fullName = this.description;
|
|
for (var parentSuite = this.parentSuite; parentSuite; parentSuite = parentSuite.parentSuite) {
|
|
if (parentSuite.parentSuite) {
|
|
fullName = parentSuite.description + ' ' + fullName;
|
|
}
|
|
}
|
|
return fullName;
|
|
};
|
|
|
|
Suite.prototype.disable = function() {
|
|
this.disabled = true;
|
|
};
|
|
|
|
Suite.prototype.beforeEach = function(fn) {
|
|
this.beforeFns.unshift(fn);
|
|
};
|
|
|
|
Suite.prototype.beforeAll = function(fn) {
|
|
this.beforeAllFns.push(fn);
|
|
};
|
|
|
|
Suite.prototype.afterEach = function(fn) {
|
|
this.afterFns.unshift(fn);
|
|
};
|
|
|
|
Suite.prototype.afterAll = function(fn) {
|
|
this.afterAllFns.push(fn);
|
|
};
|
|
|
|
Suite.prototype.addChild = function(child) {
|
|
this.children.push(child);
|
|
};
|
|
|
|
Suite.prototype.execute = function(onComplete) {
|
|
var self = this;
|
|
if (this.disabled) {
|
|
complete();
|
|
return;
|
|
}
|
|
|
|
var allFns = [];
|
|
|
|
if (this.isExecutable()) {
|
|
for (var b = 0; b < this.beforeAllFns.length; b++) {
|
|
allFns.push(this.beforeAllFns[b]);
|
|
}
|
|
|
|
for (var i = 0; i < this.children.length; i++) {
|
|
allFns.push(wrapChildAsAsync(this.children[i]));
|
|
}
|
|
|
|
for (var a = 0; a < this.afterAllFns.length; a++) {
|
|
allFns.push(this.afterAllFns[a]);
|
|
}
|
|
}
|
|
|
|
this.onStart(this);
|
|
|
|
this.queueRunner({
|
|
fns: allFns,
|
|
onComplete: complete,
|
|
userContext: this.sharedUserContext()
|
|
});
|
|
|
|
function complete() {
|
|
self.resultCallback(self.result);
|
|
|
|
if (onComplete) {
|
|
onComplete();
|
|
}
|
|
}
|
|
|
|
function wrapChildAsAsync(child) {
|
|
return function(done) { child.execute(done); };
|
|
}
|
|
};
|
|
|
|
Suite.prototype.isExecutable = function() {
|
|
var foundActive = false;
|
|
for(var i = 0; i < this.children.length; i++) {
|
|
if(this.children[i].isExecutable()) {
|
|
foundActive = true;
|
|
break;
|
|
}
|
|
}
|
|
return foundActive;
|
|
};
|
|
|
|
Suite.prototype.sharedUserContext = function() {
|
|
if (!this.sharedContext) {
|
|
this.sharedContext = this.parentSuite ? clone(this.parentSuite.sharedUserContext()) : {};
|
|
}
|
|
|
|
return this.sharedContext;
|
|
};
|
|
|
|
Suite.prototype.clonedSharedUserContext = function() {
|
|
return clone(this.sharedUserContext());
|
|
};
|
|
|
|
function clone(obj) {
|
|
var clonedObj = {};
|
|
for (var prop in obj) {
|
|
if (obj.hasOwnProperty(prop)) {
|
|
clonedObj[prop] = obj[prop];
|
|
}
|
|
}
|
|
|
|
return clonedObj;
|
|
}
|
|
|
|
return Suite;
|
|
};
|
|
|
|
if (typeof window == void 0 && typeof exports == 'object') {
|
|
exports.Suite = jasmineRequire.Suite;
|
|
}
|