Prevents *Alls from running when runnables are explicitly set
- This requires passing if runnables are set to the Suite. Hopefully in the future we will change how focused runnables and *Alls interact so this is no longer necessary. [#732]
This commit is contained in:
@@ -655,6 +655,7 @@ getJasmineRequireObj().Env = function(j$) {
|
|||||||
onStart: suiteStarted,
|
onStart: suiteStarted,
|
||||||
expectationFactory: expectationFactory,
|
expectationFactory: expectationFactory,
|
||||||
expectationResultFactory: expectationResultFactory,
|
expectationResultFactory: expectationResultFactory,
|
||||||
|
runnablesExplictlySetGetter: runnablesExplictlySetGetter,
|
||||||
resultCallback: function(attrs) {
|
resultCallback: function(attrs) {
|
||||||
if (!suite.disabled) {
|
if (!suite.disabled) {
|
||||||
clearResourcesForRunnable(suite.id);
|
clearResourcesForRunnable(suite.id);
|
||||||
@@ -1928,6 +1929,7 @@ getJasmineRequireObj().Suite = function() {
|
|||||||
this.clearStack = attrs.clearStack || function(fn) {fn();};
|
this.clearStack = attrs.clearStack || function(fn) {fn();};
|
||||||
this.expectationFactory = attrs.expectationFactory;
|
this.expectationFactory = attrs.expectationFactory;
|
||||||
this.expectationResultFactory = attrs.expectationResultFactory;
|
this.expectationResultFactory = attrs.expectationResultFactory;
|
||||||
|
this.runnablesExplictlySetGetter = attrs.runnablesExplictlySetGetter || function() {};
|
||||||
|
|
||||||
this.beforeFns = [];
|
this.beforeFns = [];
|
||||||
this.afterFns = [];
|
this.afterFns = [];
|
||||||
@@ -2039,14 +2041,8 @@ getJasmineRequireObj().Suite = function() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
Suite.prototype.isExecutable = function() {
|
Suite.prototype.isExecutable = function() {
|
||||||
var foundActive = false;
|
var runnablesExplicitlySet = this.runnablesExplictlySetGetter();
|
||||||
for(var i = 0; i < this.children.length; i++) {
|
return !runnablesExplicitlySet && hasExecutableChild(this.children);
|
||||||
if(this.children[i].isExecutable()) {
|
|
||||||
foundActive = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return foundActive;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
Suite.prototype.sharedUserContext = function() {
|
Suite.prototype.sharedUserContext = function() {
|
||||||
@@ -2099,6 +2095,17 @@ getJasmineRequireObj().Suite = function() {
|
|||||||
return !args[0];
|
return !args[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function hasExecutableChild(children) {
|
||||||
|
var foundActive = false;
|
||||||
|
for (var i = 0; i < children.length; i++) {
|
||||||
|
if (children[i].isExecutable()) {
|
||||||
|
foundActive = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return foundActive;
|
||||||
|
}
|
||||||
|
|
||||||
function clone(obj) {
|
function clone(obj) {
|
||||||
var clonedObj = {};
|
var clonedObj = {};
|
||||||
for (var prop in obj) {
|
for (var prop in obj) {
|
||||||
|
|||||||
@@ -117,6 +117,32 @@ describe("Suite", function() {
|
|||||||
expect(lastAfter).toHaveBeenCalled();
|
expect(lastAfter).toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("does not run *All functions if runnables are explicitly set", function(){
|
||||||
|
var env = new j$.Env(),
|
||||||
|
fakeQueueRunner = jasmine.createSpy('fake queue runner'),
|
||||||
|
suite = new j$.Suite({
|
||||||
|
env: env,
|
||||||
|
description: "I am a suite",
|
||||||
|
queueRunner: fakeQueueRunner,
|
||||||
|
runnablesExplictlySetGetter: function(){return true;}
|
||||||
|
}),
|
||||||
|
beforeAll = jasmine.createSpy('beforeAll'),
|
||||||
|
afterAll = jasmine.createSpy('afterAll'),
|
||||||
|
fakeIt = {execute: jasmine.createSpy('it'), isExecutable: function() { return true; } };
|
||||||
|
|
||||||
|
suite.beforeAll(beforeAll);
|
||||||
|
suite.afterAll(afterAll);
|
||||||
|
suite.addChild(fakeIt);
|
||||||
|
|
||||||
|
suite.execute();
|
||||||
|
var suiteFns = fakeQueueRunner.calls.mostRecent().args[0].queueableFns;
|
||||||
|
|
||||||
|
expect(suite.isExecutable()).toBeFalsy();
|
||||||
|
expect(suiteFns.length).toEqual(1);
|
||||||
|
expect(beforeAll).not.toHaveBeenCalled();
|
||||||
|
expect(afterAll).not.toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
|
||||||
it("can be disabled, but still calls callbacks", function() {
|
it("can be disabled, but still calls callbacks", function() {
|
||||||
var env = new j$.Env(),
|
var env = new j$.Env(),
|
||||||
fakeQueueRunner = jasmine.createSpy('fake queue runner'),
|
fakeQueueRunner = jasmine.createSpy('fake queue runner'),
|
||||||
|
|||||||
@@ -228,7 +228,7 @@ describe("jasmine spec running", function () {
|
|||||||
env.execute();
|
env.execute();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should run beforeAlls before beforeEachs and afterAlls after afterEachs', function() {
|
it('should run beforeAlls before beforeEachs and afterAlls after afterEachs', function(done) {
|
||||||
var actions = [];
|
var actions = [];
|
||||||
|
|
||||||
env.beforeAll(function() {
|
env.beforeAll(function() {
|
||||||
@@ -289,7 +289,7 @@ describe("jasmine spec running", function () {
|
|||||||
env.execute();
|
env.execute();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should run beforeAlls and afterAlls as beforeEachs and afterEachs in the order declared when runnablesToRun is provided', function() {
|
it('should run beforeAlls and afterAlls as beforeEachs and afterEachs in the order declared when runnablesToRun is provided', function(done) {
|
||||||
var actions = [],
|
var actions = [],
|
||||||
spec,
|
spec,
|
||||||
spec2;
|
spec2;
|
||||||
@@ -366,6 +366,30 @@ describe("jasmine spec running", function () {
|
|||||||
env.execute([spec.id, spec2.id]);
|
env.execute([spec.id, spec2.id]);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('only runs *Alls once in a focused suite', function(done){
|
||||||
|
var actions = [];
|
||||||
|
|
||||||
|
env.fdescribe('Suite', function() {
|
||||||
|
env.beforeAll(function(){
|
||||||
|
actions.push('beforeAll');
|
||||||
|
});
|
||||||
|
env.it('should run beforeAll once', function() {
|
||||||
|
actions.push('spec');
|
||||||
|
});
|
||||||
|
env.afterAll(function(){
|
||||||
|
actions.push('afterAll');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
var assertions = function() {
|
||||||
|
expect(actions).toEqual(['beforeAll', 'spec', 'afterAll']);
|
||||||
|
done();
|
||||||
|
};
|
||||||
|
|
||||||
|
env.addReporter({jasmineDone: assertions});
|
||||||
|
env.execute();
|
||||||
|
});
|
||||||
|
|
||||||
describe('focused runnables', function() {
|
describe('focused runnables', function() {
|
||||||
it('runs the relevant alls and eachs for each runnable', function(done) {
|
it('runs the relevant alls and eachs for each runnable', function(done) {
|
||||||
var actions = [];
|
var actions = [];
|
||||||
|
|||||||
@@ -237,6 +237,7 @@ getJasmineRequireObj().Env = function(j$) {
|
|||||||
onStart: suiteStarted,
|
onStart: suiteStarted,
|
||||||
expectationFactory: expectationFactory,
|
expectationFactory: expectationFactory,
|
||||||
expectationResultFactory: expectationResultFactory,
|
expectationResultFactory: expectationResultFactory,
|
||||||
|
runnablesExplictlySetGetter: runnablesExplictlySetGetter,
|
||||||
resultCallback: function(attrs) {
|
resultCallback: function(attrs) {
|
||||||
if (!suite.disabled) {
|
if (!suite.disabled) {
|
||||||
clearResourcesForRunnable(suite.id);
|
clearResourcesForRunnable(suite.id);
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ getJasmineRequireObj().Suite = function() {
|
|||||||
this.clearStack = attrs.clearStack || function(fn) {fn();};
|
this.clearStack = attrs.clearStack || function(fn) {fn();};
|
||||||
this.expectationFactory = attrs.expectationFactory;
|
this.expectationFactory = attrs.expectationFactory;
|
||||||
this.expectationResultFactory = attrs.expectationResultFactory;
|
this.expectationResultFactory = attrs.expectationResultFactory;
|
||||||
|
this.runnablesExplictlySetGetter = attrs.runnablesExplictlySetGetter || function() {};
|
||||||
|
|
||||||
this.beforeFns = [];
|
this.beforeFns = [];
|
||||||
this.afterFns = [];
|
this.afterFns = [];
|
||||||
@@ -120,14 +121,8 @@ getJasmineRequireObj().Suite = function() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
Suite.prototype.isExecutable = function() {
|
Suite.prototype.isExecutable = function() {
|
||||||
var foundActive = false;
|
var runnablesExplicitlySet = this.runnablesExplictlySetGetter();
|
||||||
for(var i = 0; i < this.children.length; i++) {
|
return !runnablesExplicitlySet && hasExecutableChild(this.children);
|
||||||
if(this.children[i].isExecutable()) {
|
|
||||||
foundActive = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return foundActive;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
Suite.prototype.sharedUserContext = function() {
|
Suite.prototype.sharedUserContext = function() {
|
||||||
@@ -180,6 +175,17 @@ getJasmineRequireObj().Suite = function() {
|
|||||||
return !args[0];
|
return !args[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function hasExecutableChild(children) {
|
||||||
|
var foundActive = false;
|
||||||
|
for (var i = 0; i < children.length; i++) {
|
||||||
|
if (children[i].isExecutable()) {
|
||||||
|
foundActive = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return foundActive;
|
||||||
|
}
|
||||||
|
|
||||||
function clone(obj) {
|
function clone(obj) {
|
||||||
var clonedObj = {};
|
var clonedObj = {};
|
||||||
for (var prop in obj) {
|
for (var prop in obj) {
|
||||||
|
|||||||
Reference in New Issue
Block a user