Only run focused runnables inside focused suites

- Focused runnables now walk up the tree to unfocus the first focused
  ancestor. Because of the way the tree is constructed, this makes sure
  that each focused runnable has no focused ancestors.

[#78289686]
This commit is contained in:
Greg Cobb
2014-09-05 12:25:28 -07:00
parent 3b19d66268
commit 3332f93a24
3 changed files with 91 additions and 24 deletions

View File

@@ -270,14 +270,16 @@ getJasmineRequireObj().Env = function(j$) {
return suite;
};
var focusedRunnables = [];
this.fdescribe = function(description, specDefinitions) {
var suite = suiteFactory(description);
suite.isFocused = true;
focusedRunnables.push(suite.id);
unfocusAncestor();
addSpecsToSuite(suite, specDefinitions);
if (!hasFocusedAncestor(suite.parentSuite)) {
focusedRunnables.push(suite.id);
}
return suite;
};
@@ -302,15 +304,27 @@ getJasmineRequireObj().Env = function(j$) {
currentDeclarationSuite = parentSuite;
}
function hasFocusedAncestor(suite) {
function findFocusedAncestor(suite) {
while (suite) {
if (suite.isFocused) {
return true;
return suite.id;
}
suite = suite.parentSuite;
}
return false;
return null;
}
function unfocusAncestor() {
var focusedAncestor = findFocusedAncestor(currentDeclarationSuite);
if (focusedAncestor) {
for (var i = 0; i < focusedRunnables.length; i++) {
if (focusedRunnables[i] === focusedAncestor) {
focusedRunnables.splice(i, 1);
break;
}
}
}
}
var runnablesExplictlySet = false;
@@ -370,14 +384,11 @@ getJasmineRequireObj().Env = function(j$) {
return spec;
};
var focusedRunnables = [];
this.fit = function(description, fn ){
var spec = this.it(description, fn);
if (!hasFocusedAncestor(currentDeclarationSuite)) {
focusedRunnables.push(spec.id);
}
focusedRunnables.push(spec.id);
unfocusAncestor();
return spec;
};