share usercontext for full suite

This commit is contained in:
Gregg Van Hove and Sheel Choksi
2014-03-03 11:57:32 -08:00
parent ec5695acc1
commit e17a2cb1e0
5 changed files with 84 additions and 3 deletions

View File

@@ -272,6 +272,7 @@ getJasmineRequireObj().Env = function(j$) {
description: description,
expectationResultFactory: expectationResultFactory,
queueRunnerFactory: queueRunnerFactory,
userContext: function() { return suite.clonedSharedUserContext(); },
fn: fn
});

View File

@@ -17,7 +17,7 @@ getJasmineRequireObj().QueueRunner = function(j$) {
this.onException = attrs.onException || function() {};
this.catchException = attrs.catchException || function() { return true; };
this.enforceTimeout = attrs.enforceTimeout || function() { return false; };
this.userContext = {};
this.userContext = attrs.userContext || {};
this.timer = attrs.timeout || {setTimeout: setTimeout, clearTimeout: clearTimeout};
}

View File

@@ -7,6 +7,7 @@ getJasmineRequireObj().Spec = function(j$) {
this.fn = attrs.fn;
this.beforeFns = attrs.beforeFns || function() { return []; };
this.afterFns = attrs.afterFns || function() { return []; };
this.userContext = attrs.userContext || function() { return {}; };
this.onStart = attrs.onStart || function() {};
this.exceptionFormatter = attrs.exceptionFormatter || function() {};
this.getSpecName = attrs.getSpecName || function() { return ''; };
@@ -53,7 +54,8 @@ getJasmineRequireObj().Spec = function(j$) {
fns: allFns,
onException: onException,
onComplete: complete,
enforceTimeout: function() { return true; }
enforceTimeout: function() { return true; },
userContext: this.userContext()
});
function onException(e) {

View File

@@ -86,7 +86,8 @@ getJasmineRequireObj().Suite = function() {
this.queueRunner({
fns: allFns,
onComplete: complete
onComplete: complete,
userContext: this.sharedUserContext()
});
function complete() {
@@ -113,6 +114,29 @@ getJasmineRequireObj().Suite = function() {
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;
};