Run before,afterAlls as 'eachs' when specifying runnablesToRun
- Fix bug where beforeAlls were being mutated in Suite#execute - When Env.execute() receives a list of runnables, beforeAlls and afterAlls are collected as beforeEachs and afterEachs. This allows runnables to be specified in any order, regardless of if any of them have before/afterAlls. - Spec constructor takes a single function that returns both before and afters, instead of two functions. This breaks the current interface for constructing a Spec. [#73742528]
This commit is contained in:
committed by
Greg Cobb and Tim Jarratt
parent
61bf9ac7d7
commit
b984ff2fa6
@@ -91,11 +91,8 @@ describe("Spec", function() {
|
||||
}) },
|
||||
spec = new j$.Spec({
|
||||
queueableFn: queueableFn,
|
||||
beforeFns: function() {
|
||||
return [before]
|
||||
},
|
||||
afterFns: function() {
|
||||
return [after]
|
||||
beforeAndAfterFns: function() {
|
||||
return {befores: [before], afters: [after]}
|
||||
},
|
||||
queueRunnerFactory: fakeQueueRunner
|
||||
});
|
||||
|
||||
@@ -460,8 +460,6 @@ describe("Env integration", function() {
|
||||
env.execute();
|
||||
});
|
||||
|
||||
|
||||
|
||||
it("Allows specifying which specs and suites to run", function(done) {
|
||||
var env = new j$.Env(),
|
||||
calls = [],
|
||||
@@ -498,6 +496,44 @@ describe("Env integration", function() {
|
||||
env.execute([secondSuite.id, firstSpec.id]);
|
||||
});
|
||||
|
||||
it('runs before and after all functions for focused specs', function(done) {
|
||||
var env = new j$.Env(),
|
||||
calls = [],
|
||||
first_spec,
|
||||
second_spec;
|
||||
|
||||
var assertions = function() {
|
||||
expect(calls).toEqual([
|
||||
"before",
|
||||
"first spec",
|
||||
"after",
|
||||
"before",
|
||||
"second spec",
|
||||
"after"
|
||||
]);
|
||||
done();
|
||||
};
|
||||
|
||||
env.addReporter({jasmineDone: assertions});
|
||||
|
||||
env.describe("first suite", function() {
|
||||
env.beforeAll(function() {
|
||||
calls.push("before");
|
||||
});
|
||||
env.afterAll(function() {
|
||||
calls.push("after")
|
||||
});
|
||||
first_spec = env.it("spec", function() {
|
||||
calls.push('first spec');
|
||||
});
|
||||
second_spec = env.it("spec 2", function() {
|
||||
calls.push("second spec");
|
||||
});
|
||||
});
|
||||
|
||||
env.execute([first_spec.id, second_spec.id]);
|
||||
});
|
||||
|
||||
it("Functions can be spied on and have their calls tracked", function (done) {
|
||||
var env = new j$.Env();
|
||||
|
||||
|
||||
@@ -159,7 +159,7 @@ describe("jasmine spec running", function () {
|
||||
];
|
||||
expect(actions).toEqual(expected);
|
||||
done();
|
||||
}
|
||||
};
|
||||
|
||||
env.addReporter({jasmineDone: assertions});
|
||||
|
||||
|
||||
@@ -101,25 +101,23 @@ getJasmineRequireObj().Env = function(j$) {
|
||||
delete runnableResources[id];
|
||||
};
|
||||
|
||||
var beforeFns = function(suite) {
|
||||
var beforeAndAfterFns = function(suite, runnablesExplictlySet) {
|
||||
return function() {
|
||||
var befores = [];
|
||||
while(suite) {
|
||||
befores = befores.concat(suite.beforeFns);
|
||||
suite = suite.parentSuite;
|
||||
}
|
||||
return befores.reverse();
|
||||
};
|
||||
};
|
||||
|
||||
var afterFns = function(suite) {
|
||||
return function() {
|
||||
var afters = [];
|
||||
while(suite) {
|
||||
if (runnablesExplictlySet()) {
|
||||
befores = befores.concat(suite.beforeAllFns);
|
||||
afters = afters.concat(suite.afterAllFns);
|
||||
}
|
||||
befores = befores.concat(suite.beforeFns);
|
||||
afters = afters.concat(suite.afterFns);
|
||||
suite = suite.parentSuite;
|
||||
}
|
||||
return afters;
|
||||
return {
|
||||
befores: befores.reverse(),
|
||||
afters: afters
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
@@ -194,6 +192,9 @@ getJasmineRequireObj().Env = function(j$) {
|
||||
};
|
||||
|
||||
this.execute = function(runnablesToRun) {
|
||||
if(runnablesToRun) {
|
||||
runnablesExplictlySet = true;
|
||||
}
|
||||
runnablesToRun = runnablesToRun || [topSuite.id];
|
||||
|
||||
var allFns = [];
|
||||
@@ -284,13 +285,17 @@ getJasmineRequireObj().Env = function(j$) {
|
||||
return suite;
|
||||
};
|
||||
|
||||
var runnablesExplictlySet = false;
|
||||
|
||||
var runnablesExplictlySetGetter = function(){
|
||||
return runnablesExplictlySet;
|
||||
};
|
||||
|
||||
var specFactory = function(description, fn, suite) {
|
||||
totalSpecsDefined++;
|
||||
|
||||
var spec = new j$.Spec({
|
||||
id: getNextSpecId(),
|
||||
beforeFns: beforeFns(suite),
|
||||
afterFns: afterFns(suite),
|
||||
beforeAndAfterFns: beforeAndAfterFns(suite, runnablesExplictlySetGetter),
|
||||
expectationFactory: expectationFactory,
|
||||
exceptionFormatter: exceptionFormatter,
|
||||
resultCallback: specResultCallback,
|
||||
|
||||
@@ -5,8 +5,7 @@ getJasmineRequireObj().Spec = function(j$) {
|
||||
this.id = attrs.id;
|
||||
this.description = attrs.description || '';
|
||||
this.queueableFn = attrs.queueableFn;
|
||||
this.beforeFns = attrs.beforeFns || function() { return []; };
|
||||
this.afterFns = attrs.afterFns || function() { return []; };
|
||||
this.beforeAndAfterFns = attrs.beforeAndAfterFns || function() { return {befores: [], afters: []}; };
|
||||
this.userContext = attrs.userContext || function() { return {}; };
|
||||
this.onStart = attrs.onStart || function() {};
|
||||
this.exceptionFormatter = attrs.exceptionFormatter || function() {};
|
||||
@@ -48,7 +47,8 @@ getJasmineRequireObj().Spec = function(j$) {
|
||||
return;
|
||||
}
|
||||
|
||||
var allFns = this.beforeFns().concat(this.queueableFn).concat(this.afterFns());
|
||||
var fns = this.beforeAndAfterFns();
|
||||
var allFns = fns.befores.concat(this.queueableFn).concat(fns.afters);
|
||||
|
||||
this.queueRunnerFactory({
|
||||
queueableFns: allFns,
|
||||
|
||||
@@ -75,7 +75,7 @@ getJasmineRequireObj().Suite = function() {
|
||||
var allFns = [];
|
||||
|
||||
if (this.isExecutable()) {
|
||||
allFns = this.beforeAllFns;
|
||||
allFns = allFns.concat(this.beforeAllFns);
|
||||
|
||||
for (var i = 0; i < this.children.length; i++) {
|
||||
allFns.push(wrapChildAsAsync(this.children[i]));
|
||||
|
||||
Reference in New Issue
Block a user