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({
|
spec = new j$.Spec({
|
||||||
queueableFn: queueableFn,
|
queueableFn: queueableFn,
|
||||||
beforeFns: function() {
|
beforeAndAfterFns: function() {
|
||||||
return [before]
|
return {befores: [before], afters: [after]}
|
||||||
},
|
|
||||||
afterFns: function() {
|
|
||||||
return [after]
|
|
||||||
},
|
},
|
||||||
queueRunnerFactory: fakeQueueRunner
|
queueRunnerFactory: fakeQueueRunner
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -460,8 +460,6 @@ describe("Env integration", function() {
|
|||||||
env.execute();
|
env.execute();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
it("Allows specifying which specs and suites to run", function(done) {
|
it("Allows specifying which specs and suites to run", function(done) {
|
||||||
var env = new j$.Env(),
|
var env = new j$.Env(),
|
||||||
calls = [],
|
calls = [],
|
||||||
@@ -498,6 +496,44 @@ describe("Env integration", function() {
|
|||||||
env.execute([secondSuite.id, firstSpec.id]);
|
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) {
|
it("Functions can be spied on and have their calls tracked", function (done) {
|
||||||
var env = new j$.Env();
|
var env = new j$.Env();
|
||||||
|
|
||||||
|
|||||||
@@ -159,7 +159,7 @@ describe("jasmine spec running", function () {
|
|||||||
];
|
];
|
||||||
expect(actions).toEqual(expected);
|
expect(actions).toEqual(expected);
|
||||||
done();
|
done();
|
||||||
}
|
};
|
||||||
|
|
||||||
env.addReporter({jasmineDone: assertions});
|
env.addReporter({jasmineDone: assertions});
|
||||||
|
|
||||||
|
|||||||
+20
-15
@@ -101,25 +101,23 @@ getJasmineRequireObj().Env = function(j$) {
|
|||||||
delete runnableResources[id];
|
delete runnableResources[id];
|
||||||
};
|
};
|
||||||
|
|
||||||
var beforeFns = function(suite) {
|
var beforeAndAfterFns = function(suite, runnablesExplictlySet) {
|
||||||
return function() {
|
return function() {
|
||||||
var befores = [];
|
var befores = [];
|
||||||
while(suite) {
|
|
||||||
befores = befores.concat(suite.beforeFns);
|
|
||||||
suite = suite.parentSuite;
|
|
||||||
}
|
|
||||||
return befores.reverse();
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
var afterFns = function(suite) {
|
|
||||||
return function() {
|
|
||||||
var afters = [];
|
var afters = [];
|
||||||
while(suite) {
|
while(suite) {
|
||||||
|
if (runnablesExplictlySet()) {
|
||||||
|
befores = befores.concat(suite.beforeAllFns);
|
||||||
|
afters = afters.concat(suite.afterAllFns);
|
||||||
|
}
|
||||||
|
befores = befores.concat(suite.beforeFns);
|
||||||
afters = afters.concat(suite.afterFns);
|
afters = afters.concat(suite.afterFns);
|
||||||
suite = suite.parentSuite;
|
suite = suite.parentSuite;
|
||||||
}
|
}
|
||||||
return afters;
|
return {
|
||||||
|
befores: befores.reverse(),
|
||||||
|
afters: afters
|
||||||
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -194,6 +192,9 @@ getJasmineRequireObj().Env = function(j$) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
this.execute = function(runnablesToRun) {
|
this.execute = function(runnablesToRun) {
|
||||||
|
if(runnablesToRun) {
|
||||||
|
runnablesExplictlySet = true;
|
||||||
|
}
|
||||||
runnablesToRun = runnablesToRun || [topSuite.id];
|
runnablesToRun = runnablesToRun || [topSuite.id];
|
||||||
|
|
||||||
var allFns = [];
|
var allFns = [];
|
||||||
@@ -284,13 +285,17 @@ getJasmineRequireObj().Env = function(j$) {
|
|||||||
return suite;
|
return suite;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
var runnablesExplictlySet = false;
|
||||||
|
|
||||||
|
var runnablesExplictlySetGetter = function(){
|
||||||
|
return runnablesExplictlySet;
|
||||||
|
};
|
||||||
|
|
||||||
var specFactory = function(description, fn, suite) {
|
var specFactory = function(description, fn, suite) {
|
||||||
totalSpecsDefined++;
|
totalSpecsDefined++;
|
||||||
|
|
||||||
var spec = new j$.Spec({
|
var spec = new j$.Spec({
|
||||||
id: getNextSpecId(),
|
id: getNextSpecId(),
|
||||||
beforeFns: beforeFns(suite),
|
beforeAndAfterFns: beforeAndAfterFns(suite, runnablesExplictlySetGetter),
|
||||||
afterFns: afterFns(suite),
|
|
||||||
expectationFactory: expectationFactory,
|
expectationFactory: expectationFactory,
|
||||||
exceptionFormatter: exceptionFormatter,
|
exceptionFormatter: exceptionFormatter,
|
||||||
resultCallback: specResultCallback,
|
resultCallback: specResultCallback,
|
||||||
|
|||||||
+3
-3
@@ -5,8 +5,7 @@ getJasmineRequireObj().Spec = function(j$) {
|
|||||||
this.id = attrs.id;
|
this.id = attrs.id;
|
||||||
this.description = attrs.description || '';
|
this.description = attrs.description || '';
|
||||||
this.queueableFn = attrs.queueableFn;
|
this.queueableFn = attrs.queueableFn;
|
||||||
this.beforeFns = attrs.beforeFns || function() { return []; };
|
this.beforeAndAfterFns = attrs.beforeAndAfterFns || function() { return {befores: [], afters: []}; };
|
||||||
this.afterFns = attrs.afterFns || function() { return []; };
|
|
||||||
this.userContext = attrs.userContext || function() { return {}; };
|
this.userContext = attrs.userContext || function() { return {}; };
|
||||||
this.onStart = attrs.onStart || function() {};
|
this.onStart = attrs.onStart || function() {};
|
||||||
this.exceptionFormatter = attrs.exceptionFormatter || function() {};
|
this.exceptionFormatter = attrs.exceptionFormatter || function() {};
|
||||||
@@ -48,7 +47,8 @@ getJasmineRequireObj().Spec = function(j$) {
|
|||||||
return;
|
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({
|
this.queueRunnerFactory({
|
||||||
queueableFns: allFns,
|
queueableFns: allFns,
|
||||||
|
|||||||
+1
-1
@@ -75,7 +75,7 @@ getJasmineRequireObj().Suite = function() {
|
|||||||
var allFns = [];
|
var allFns = [];
|
||||||
|
|
||||||
if (this.isExecutable()) {
|
if (this.isExecutable()) {
|
||||||
allFns = this.beforeAllFns;
|
allFns = allFns.concat(this.beforeAllFns);
|
||||||
|
|
||||||
for (var i = 0; i < this.children.length; i++) {
|
for (var i = 0; i < this.children.length; i++) {
|
||||||
allFns.push(wrapChildAsAsync(this.children[i]));
|
allFns.push(wrapChildAsAsync(this.children[i]));
|
||||||
|
|||||||
Reference in New Issue
Block a user