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:
@@ -646,11 +646,11 @@ getJasmineRequireObj().Env = function(j$) {
|
||||
this.fdescribe = function(description, specDefinitions) {
|
||||
var suite = suiteFactory(description);
|
||||
suite.isFocused = true;
|
||||
|
||||
focusedRunnables.push(suite.id);
|
||||
unfocusAncestors();
|
||||
addSpecsToSuite(suite, specDefinitions);
|
||||
|
||||
if (!hasFocusedAncestor(suite.parentSuite)) {
|
||||
focusedRunnables.push(suite.id);
|
||||
}
|
||||
return suite;
|
||||
};
|
||||
|
||||
@@ -675,15 +675,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 unfocusAncestors() {
|
||||
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;
|
||||
@@ -744,13 +756,12 @@ getJasmineRequireObj().Env = function(j$) {
|
||||
};
|
||||
|
||||
var focusedRunnables = [];
|
||||
|
||||
this.fit = function(description, fn ){
|
||||
var spec = this.it(description, fn);
|
||||
|
||||
if (!hasFocusedAncestor(currentDeclarationSuite)) {
|
||||
focusedRunnables.push(spec.id);
|
||||
}
|
||||
|
||||
focusedRunnables.push(spec.id);
|
||||
unfocusAncestors();
|
||||
return spec;
|
||||
};
|
||||
|
||||
|
||||
@@ -408,23 +408,68 @@ describe("jasmine spec running", function () {
|
||||
env.execute();
|
||||
});
|
||||
|
||||
it('runs fits and fdescribes in fdescribes only once', function(done){
|
||||
it('focused specs in focused suites cause non-focused siblings to not run', function(done){
|
||||
var actions = [];
|
||||
|
||||
env.fdescribe('focused suite', function() {
|
||||
env.it('unfocused spec', function() {
|
||||
actions.push('unfocused spec')
|
||||
});
|
||||
env.fit('focused spec', function() {
|
||||
actions.push('focused spec')
|
||||
});
|
||||
});
|
||||
|
||||
var assertions = function() {
|
||||
var expected = ['focused spec'];
|
||||
expect(actions).toEqual(expected);
|
||||
done();
|
||||
};
|
||||
|
||||
env.addReporter({jasmineDone: assertions});
|
||||
env.execute();
|
||||
});
|
||||
|
||||
it('focused suites in focused suites cause non-focused siblings to not run', function(done){
|
||||
var actions = [];
|
||||
|
||||
env.fdescribe('focused suite', function() {
|
||||
env.it('unfocused spec', function() {
|
||||
actions.push('unfocused spec')
|
||||
});
|
||||
env.fdescribe('inner focused suite', function() {
|
||||
env.it('inner spec', function() {
|
||||
actions.push('unfocused spec');
|
||||
actions.push('inner spec');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
var assertions = function() {
|
||||
var expected = ['focused spec', 'unfocused spec'];
|
||||
var expected = ['inner spec'];
|
||||
expect(actions).toEqual(expected);
|
||||
done();
|
||||
};
|
||||
|
||||
env.addReporter({jasmineDone: assertions});
|
||||
env.execute();
|
||||
});
|
||||
|
||||
it('focused runnables unfocus ancestor focused suites', function() {
|
||||
var actions = [];
|
||||
|
||||
env.fdescribe('focused suite', function() {
|
||||
env.it('unfocused spec', function() {
|
||||
actions.push('unfocused spec')
|
||||
});
|
||||
env.describe('inner focused suite', function() {
|
||||
env.fit('focused spec', function() {
|
||||
actions.push('focused spec');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
var assertions = function() {
|
||||
var expected = ['focused spec'];
|
||||
expect(actions).toEqual(expected);
|
||||
done();
|
||||
};
|
||||
|
||||
@@ -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;
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user