Preserve relative order of "alls" w.r.t. "eachs"

[Finishes #73742528]
This commit is contained in:
Greg Cobb and Tim Jarratt
2014-08-28 11:52:34 -07:00
committed by Greg Cobb and Tim Jarratt
parent b984ff2fa6
commit 980509cd7b
2 changed files with 151 additions and 8 deletions

View File

@@ -228,6 +228,144 @@ describe("jasmine spec running", function () {
env.execute();
});
it('should run beforeAlls before beforeEachs and afterAlls after afterEachs', function() {
var actions = [];
env.beforeAll(function() {
actions.push('runner beforeAll');
});
env.afterAll(function() {
actions.push('runner afterAll');
});
env.beforeEach(function () {
actions.push('runner beforeEach');
});
env.afterEach(function () {
actions.push('runner afterEach');
});
env.describe('Something', function() {
env.beforeEach(function() {
actions.push('inner beforeEach');
});
env.afterEach(function() {
actions.push('inner afterEach');
});
env.beforeAll(function() {
actions.push('inner beforeAll');
});
env.afterAll(function() {
actions.push('inner afterAll');
});
env.it('does something or other', function() {
actions.push('it');
});
});
var assertions = function() {
var expected = [
"runner beforeAll",
"inner beforeAll",
"runner beforeEach",
"inner beforeEach",
"it",
"inner afterEach",
"runner afterEach",
"inner afterAll",
"runner afterAll"
];
expect(actions).toEqual(expected);
done();
};
env.addReporter({jasmineDone: assertions});
env.execute();
});
it('should run beforeAlls and afterAlls as beforeEachs and afterEachs in the order declared when runnablesToRun is provided', function() {
var actions = [],
spec,
spec2;
env.beforeAll(function() {
actions.push('runner beforeAll');
});
env.afterAll(function() {
actions.push('runner afterAll');
});
env.beforeEach(function () {
actions.push('runner beforeEach');
});
env.afterEach(function () {
actions.push('runner afterEach');
});
env.describe('Something', function() {
env.beforeEach(function() {
actions.push('inner beforeEach');
});
env.afterEach(function() {
actions.push('inner afterEach');
});
env.beforeAll(function() {
actions.push('inner beforeAll');
});
env.afterAll(function() {
actions.push('inner afterAll');
});
spec = env.it('does something', function() {
actions.push('it');
});
spec2 = env.it('does something or other', function() {
actions.push('it2');
});
});
var assertions = function() {
var expected = [
"runner beforeAll",
"inner beforeAll",
"runner beforeEach",
"inner beforeEach",
"it",
"inner afterEach",
"runner afterEach",
"inner afterAll",
"runner afterAll",
"runner beforeAll",
"inner beforeAll",
"runner beforeEach",
"inner beforeEach",
"it2",
"inner afterEach",
"runner afterEach",
"inner afterAll",
"runner afterAll"
];
expect(actions).toEqual(expected);
done();
};
env.addReporter({jasmineDone: assertions});
env.execute([spec.id, spec2.id]);
});
it("shouldn't run disabled suites", function(done) {
var specInADisabledSuite = jasmine.createSpy("specInADisabledSuite"),
suite = env.describe('A Suite', function() {

View File

@@ -103,20 +103,25 @@ getJasmineRequireObj().Env = function(j$) {
var beforeAndAfterFns = function(suite, runnablesExplictlySet) {
return function() {
var befores = [];
var afters = [];
var befores = [],
afters = [],
beforeAlls = [],
afterAlls = [];
while(suite) {
if (runnablesExplictlySet()) {
befores = befores.concat(suite.beforeAllFns);
afters = afters.concat(suite.afterAllFns);
}
befores = befores.concat(suite.beforeFns);
afters = afters.concat(suite.afterFns);
if (runnablesExplictlySet()) {
beforeAlls = beforeAlls.concat(suite.beforeAllFns);
afterAlls = afterAlls.concat(suite.afterAllFns);
}
suite = suite.parentSuite;
}
return {
befores: befores.reverse(),
afters: afters
befores: beforeAlls.reverse().concat(befores.reverse()),
afters: afters.concat(afterAlls)
};
};
};