Ensure focused tests are only run once

Required duplicating some of the logic for constructing a suite from
describe so that we could mark a suite as focused in fdescribe, but
otherwise this prevents focused tests from being run more than once.

[#73742944]
This commit is contained in:
Greg Cobb and Tim Jarratt
2014-08-28 17:54:42 -07:00
parent 14824b5f9e
commit 08a35d134d
2 changed files with 48 additions and 5 deletions

View File

@@ -408,17 +408,23 @@ describe("jasmine spec running", function () {
env.execute(); env.execute();
}); });
it('runs fits in fdescribes twice', function(done){ it('runs fits and fdescribes in fdescribes only once', function(done){
var actions = []; var actions = [];
env.fdescribe('focused suite', function() { env.fdescribe('focused suite', function() {
env.fit('focused spec', function() { env.fit('focused spec', function() {
actions.push('focused spec') actions.push('focused spec')
}); });
env.fdescribe('inner focused suite', function() {
env.it('inner spec', function() {
actions.push('unfocused spec');
});
});
}); });
var assertions = function() { var assertions = function() {
var expected = ['focused spec', 'focused spec']; var expected = ['focused spec', 'unfocused spec'];
expect(actions).toEqual(expected); expect(actions).toEqual(expected);
done(); done();
}; };

View File

@@ -295,11 +295,44 @@ getJasmineRequireObj().Env = function(j$) {
}; };
this.fdescribe = function(description, specDefinitions) { this.fdescribe = function(description, specDefinitions) {
var suite = this.describe(description, specDefinitions); var suite = suiteFactory(description);
focusedRunnables.push(suite.id); suite.isFocused = true;
var parentSuite = currentDeclarationSuite;
parentSuite.addChild(suite);
currentDeclarationSuite = suite;
var declarationError = null;
try {
specDefinitions.call(suite);
} catch (e) {
declarationError = e;
}
if (declarationError) {
this.it('encountered a declaration exception', function() {
throw declarationError;
});
}
currentDeclarationSuite = parentSuite;
if (!hasFocusedAncestor(parentSuite)) {
focusedRunnables.push(suite.id);
}
return suite; return suite;
}; };
function hasFocusedAncestor(suite) {
while (suite) {
if (suite.isFocused) {
return true;
}
suite = suite.parentSuite;
}
return false;
}
var runnablesExplictlySet = false; var runnablesExplictlySet = false;
var runnablesExplictlySetGetter = function(){ var runnablesExplictlySetGetter = function(){
@@ -361,7 +394,11 @@ getJasmineRequireObj().Env = function(j$) {
var focusedRunnables = []; var focusedRunnables = [];
this.fit = function(description, fn ){ this.fit = function(description, fn ){
var spec = this.it(description, fn); var spec = this.it(description, fn);
focusedRunnables.push(spec.id);
if (!hasFocusedAncestor(currentDeclarationSuite)) {
focusedRunnables.push(spec.id);
}
return spec; return spec;
}; };