diff --git a/lib/jasmine-core/jasmine.js b/lib/jasmine-core/jasmine.js index 5a8e11b4..8b449d97 100644 --- a/lib/jasmine-core/jasmine.js +++ b/lib/jasmine-core/jasmine.js @@ -1661,7 +1661,8 @@ getJasmineRequireObj().Env = function(j$) { queueRunnerFactory ); - this.execute = function(runnablesToRun) { + // Both params are optional. + this.execute = function(runnablesToRun, onComplete) { installGlobalErrors(); if (!runnablesToRun) { @@ -1769,7 +1770,11 @@ getJasmineRequireObj().Env = function(j$) { failedExpectations: topSuite.result.failedExpectations, deprecationWarnings: topSuite.result.deprecationWarnings }, - function() {} + function() { + if (onComplete) { + onComplete(); + } + } ); }); } @@ -6917,6 +6922,8 @@ getJasmineRequireObj().makePrettyPrinter = function(j$) { }; getJasmineRequireObj().QueueRunner = function(j$) { + var nextid = 1; + function StopExecutionError() {} StopExecutionError.prototype = new Error(); j$.StopExecutionError = StopExecutionError; @@ -6936,6 +6943,7 @@ getJasmineRequireObj().QueueRunner = function(j$) { function emptyFn() {} function QueueRunner(attrs) { + this.id_ = nextid++; var queueableFns = attrs.queueableFns || []; this.queueableFns = queueableFns.concat(attrs.cleanupFns || []); this.firstCleanupIx = queueableFns.length; diff --git a/spec/core/EnvSpec.js b/spec/core/EnvSpec.js index e32d8eda..77ae38a2 100644 --- a/spec/core/EnvSpec.js +++ b/spec/core/EnvSpec.js @@ -334,20 +334,16 @@ describe('Env', function() { expectationFactory('actual', specInstance); }); - env.addReporter({ - jasmineDone: function() { - expect(jasmineUnderTest.makePrettyPrinter).toHaveBeenCalledWith([ - customObjectFormatter - ]); - expect(jasmineUnderTest.MatchersUtil).toHaveBeenCalledWith({ - customTesters: [customEqualityTester], - pp: prettyPrinter - }); - done(); - } + env.execute(null, function() { + expect(jasmineUnderTest.makePrettyPrinter).toHaveBeenCalledWith([ + customObjectFormatter + ]); + expect(jasmineUnderTest.MatchersUtil).toHaveBeenCalledWith({ + customTesters: [customEqualityTester], + pp: prettyPrinter + }); + done(); }); - - env.execute(); }); it('creates an asyncExpectationFactory that uses the current custom equality testers and object formatters', function(done) { @@ -371,19 +367,15 @@ describe('Env', function() { asyncExpectationFactory('actual', specInstance); }); - env.addReporter({ - jasmineDone: function() { - expect(jasmineUnderTest.makePrettyPrinter).toHaveBeenCalledWith([ - customObjectFormatter - ]); - expect(jasmineUnderTest.MatchersUtil).toHaveBeenCalledWith({ - customTesters: [customEqualityTester], - pp: prettyPrinter - }); - done(); - } + env.execute(null, function() { + expect(jasmineUnderTest.makePrettyPrinter).toHaveBeenCalledWith([ + customObjectFormatter + ]); + expect(jasmineUnderTest.MatchersUtil).toHaveBeenCalledWith({ + customTesters: [customEqualityTester], + pp: prettyPrinter + }); + done(); }); - - env.execute(); }); }); diff --git a/spec/core/ExceptionsSpec.js b/spec/core/ExceptionsSpec.js index c5e65754..d950d2e2 100644 --- a/spec/core/ExceptionsSpec.js +++ b/spec/core/ExceptionsSpec.js @@ -29,8 +29,7 @@ describe('Exceptions:', function() { done(); }; - env.addReporter({ jasmineDone: expectations }); - env.execute(); + env.execute(null, expectations); }); it('should handle exceptions thrown directly in top-level describe blocks and continue', function(done) { @@ -49,7 +48,6 @@ describe('Exceptions:', function() { done(); }; - env.addReporter({ jasmineDone: expectations }); - env.execute(); + env.execute(null, expectations); }); }); diff --git a/spec/core/integration/AsymmetricEqualityTestersSpec.js b/spec/core/integration/AsymmetricEqualityTestersSpec.js index 1ccf2801..518c5bde 100644 --- a/spec/core/integration/AsymmetricEqualityTestersSpec.js +++ b/spec/core/integration/AsymmetricEqualityTestersSpec.js @@ -19,8 +19,8 @@ describe('Asymmetric equality testers (Integration)', function () { .toBeUndefined(); }; - env.addReporter({specDone: specExpectations, jasmineDone: done}); - env.execute(); + env.addReporter({specDone: specExpectations}); + env.execute(null, done); }); } @@ -43,8 +43,8 @@ describe('Asymmetric equality testers (Integration)', function () { .not.toEqual(''); }; - env.addReporter({specDone: specExpectations, jasmineDone: done}); - env.execute(); + env.addReporter({specDone: specExpectations}); + env.execute(null, done); }); } diff --git a/spec/core/integration/CustomAsyncMatchersSpec.js b/spec/core/integration/CustomAsyncMatchersSpec.js index 1b60bb45..4e97185f 100644 --- a/spec/core/integration/CustomAsyncMatchersSpec.js +++ b/spec/core/integration/CustomAsyncMatchersSpec.js @@ -28,8 +28,8 @@ describe('Custom Async Matchers (Integration)', function() { expect(result.status).toEqual('passed'); }; - env.addReporter({ specDone: specExpectations, jasmineDone: done }); - env.execute(); + env.addReporter({ specDone: specExpectations }); + env.execute(null, done); }); it('uses the negative compare function for a negative comparison, if provided', function(done) { @@ -52,8 +52,8 @@ describe('Custom Async Matchers (Integration)', function() { expect(result.status).toEqual('passed'); }; - env.addReporter({ specDone: specExpectations, jasmineDone: done }); - env.execute(); + env.addReporter({ specDone: specExpectations }); + env.execute(null, done); }); it('generates messages with the same rules as built in matchers absent a custom message', function(done) { @@ -77,8 +77,8 @@ describe('Custom Async Matchers (Integration)', function() { expect(result.failedExpectations[0].message).toEqual("Expected 'a' to be real."); }; - env.addReporter({ specDone: specExpectations, jasmineDone: done }); - env.execute(); + env.addReporter({ specDone: specExpectations }); + env.execute(null, done); }); // TODO: remove this in the next major release. @@ -113,8 +113,8 @@ describe('Custom Async Matchers (Integration)', function() { ); }; - env.addReporter({ specDone: specExpectations, jasmineDone: done }); - env.execute(); + env.addReporter({ specDone: specExpectations }); + env.execute(null, done); }); it("provides custom equality testers to the matcher factory via matchersUtil", function(done) { @@ -145,7 +145,7 @@ describe('Custom Async Matchers (Integration)', function() { expect(result.failedExpectations).toEqual([]); }; - env.addReporter({ specDone: specExpectations, jasmineDone: done }); - env.execute(); + env.addReporter({ specDone: specExpectations }); + env.execute(null, done); }); }); diff --git a/spec/core/integration/CustomMatchersSpec.js b/spec/core/integration/CustomMatchersSpec.js index c9812949..c299c6ac 100644 --- a/spec/core/integration/CustomMatchersSpec.js +++ b/spec/core/integration/CustomMatchersSpec.js @@ -37,9 +37,9 @@ describe("Custom Matchers (Integration)", function () { expect(firstSpecResult.failedExpectations[0].message).toEqual("matcherForSpec: actual: zzz; expected: yyy"); done(); }; - env.addReporter({ specDone:specDoneSpy, jasmineDone: expectations}); + env.addReporter({ specDone:specDoneSpy }); - env.execute(); + env.execute(null, expectations); }); it("passes the spec if the custom matcher passes", function(done) { @@ -57,8 +57,8 @@ describe("Custom Matchers (Integration)", function () { expect(result.status).toEqual('passed'); }; - env.addReporter({ specDone: specExpectations, jasmineDone: done }); - env.execute(); + env.addReporter({ specDone: specExpectations }); + env.execute(null, done); }); it("passes the spec if the custom equality matcher passes for types nested inside asymmetric equality testers", function(done) { @@ -81,8 +81,8 @@ describe("Custom Matchers (Integration)", function () { expect(result.status).toEqual('passed'); }; - env.addReporter({ specDone: specExpectations, jasmineDone: done }); - env.execute(); + env.addReporter({ specDone: specExpectations }); + env.execute(null, done); }); it("supports asymmetric equality testers that take a list of custom equality testers", function(done) { @@ -111,8 +111,8 @@ describe("Custom Matchers (Integration)", function () { expect(result.status).toEqual('passed'); }; - env.addReporter({ specDone: specExpectations, jasmineDone: done }); - env.execute(); + env.addReporter({ specDone: specExpectations }); + env.execute(null, done); }); it("displays an appropriate failure message if a custom equality matcher fails", function(done) { @@ -135,8 +135,8 @@ describe("Custom Matchers (Integration)", function () { ); }; - env.addReporter({ specDone: specExpectations, jasmineDone: done }); - env.execute(); + env.addReporter({ specDone: specExpectations }); + env.execute(null, done); }); it("uses the negative compare function for a negative comparison, if provided", function(done) { @@ -157,8 +157,8 @@ describe("Custom Matchers (Integration)", function () { expect(result.status).toEqual('passed'); }; - env.addReporter({ specDone: specExpectations, jasmineDone: done }); - env.execute(); + env.addReporter({ specDone: specExpectations }); + env.execute(null, done); }); it("generates messages with the same rules as built in matchers absent a custom message", function(done) { @@ -180,8 +180,8 @@ describe("Custom Matchers (Integration)", function () { expect(result.failedExpectations[0].message).toEqual("Expected 'a' to be real."); }; - env.addReporter({ specDone: specExpectations, jasmineDone: done }); - env.execute(); + env.addReporter({ specDone: specExpectations }); + env.execute(null, done); }); it("passes the expected and actual arguments to the comparison function", function(done) { @@ -205,8 +205,8 @@ describe("Custom Matchers (Integration)", function () { expect(argumentSpy).toHaveBeenCalledWith(true, "arg1", "arg2"); }; - env.addReporter({ specDone: specExpectations, jasmineDone: done }); - env.execute(); + env.addReporter({ specDone: specExpectations }); + env.execute(null, done); }); // TODO: remove this in the next major release. @@ -232,8 +232,8 @@ describe("Custom Matchers (Integration)", function () { ); }; - env.addReporter({ specDone: specExpectations, jasmineDone: done }); - env.execute(); + env.addReporter({ specDone: specExpectations }); + env.execute(null, done); }); it("provides custom equality testers to the matcher factory via matchersUtil", function (done) { @@ -262,7 +262,7 @@ describe("Custom Matchers (Integration)", function () { expect(result.failedExpectations).toEqual([]); }; - env.addReporter({specDone: specExpectations, jasmineDone: done}); - env.execute(); + env.addReporter({specDone: specExpectations}); + env.execute(null, done); }); }); diff --git a/spec/core/integration/CustomObjectFormatterSpec.js b/spec/core/integration/CustomObjectFormatterSpec.js index 10ed4d71..3337f452 100644 --- a/spec/core/integration/CustomObjectFormatterSpec.js +++ b/spec/core/integration/CustomObjectFormatterSpec.js @@ -25,9 +25,9 @@ describe("Custom object formatters", function() { expect(specResults[1].failedExpectations[0].message).toEqual("Expected 42 to be undefined."); done(); }; - env.addReporter({ specDone:specDone, jasmineDone: expectations}); + env.addReporter({ specDone:specDone }); - env.execute(); + env.execute(null, expectations); }); it("scopes custom object formatters to a suite", function(done) { @@ -54,9 +54,9 @@ describe("Custom object formatters", function() { expect(specResults[1].failedExpectations[0].message).toEqual("Expected custom(42) to be undefined."); done(); }; - env.addReporter({ specDone:specDone, jasmineDone: expectations}); + env.addReporter({ specDone:specDone }); - env.execute(); + env.execute(null, expectations); }); it("throws an exception if you try to add a custom object formatter outside a runable", function() { diff --git a/spec/core/integration/CustomSpyStrategiesSpec.js b/spec/core/integration/CustomSpyStrategiesSpec.js index 7ab4d28d..e05b0773 100644 --- a/spec/core/integration/CustomSpyStrategiesSpec.js +++ b/spec/core/integration/CustomSpyStrategiesSpec.js @@ -15,6 +15,7 @@ describe('Custom Spy Strategies (Integration)', function() { .and.returnValue(42); var strategy = jasmine.createSpy('custom strategy') .and.returnValue(plan); + var jasmineDone = jasmine.createSpy('jasmineDone'); env.describe('suite defining a custom spy strategy', function() { env.beforeEach(function() { @@ -33,13 +34,14 @@ describe('Custom Spy Strategies (Integration)', function() { expect(env.createSpy('something').and.frobnicate).toBeUndefined(); }); - function jasmineDone(result) { + function expectations() { + var result = jasmineDone.calls.argsFor(0)[0]; expect(result.overallStatus).toEqual('passed'); done(); } env.addReporter({ jasmineDone: jasmineDone }); - env.execute(); + env.execute(null, expectations); }); it('allows adding more strategies local to a spec', function(done) { @@ -47,6 +49,7 @@ describe('Custom Spy Strategies (Integration)', function() { .and.returnValue(42); var strategy = jasmine.createSpy('custom strategy') .and.returnValue(plan); + var jasmineDone = jasmine.createSpy('jasmineDone'); env.it('spec defining a custom spy strategy', function() { env.addSpyStrategy('frobnicate', strategy); @@ -60,13 +63,14 @@ describe('Custom Spy Strategies (Integration)', function() { expect(env.createSpy('something').and.frobnicate).toBeUndefined(); }); - function jasmineDone(result) { + function expectations() { + var result = jasmineDone.calls.argsFor(0)[0]; expect(result.overallStatus).toEqual('passed'); done(); } env.addReporter({ jasmineDone: jasmineDone }); - env.execute(); + env.execute(null, expectations); }); it('allows using custom strategies on a per-argument basis', function(done) { @@ -74,6 +78,7 @@ describe('Custom Spy Strategies (Integration)', function() { .and.returnValue(42); var strategy = jasmine.createSpy('custom strategy') .and.returnValue(plan); + var jasmineDone = jasmine.createSpy('jasmineDone'); env.it('spec defining a custom spy strategy', function() { env.addSpyStrategy('frobnicate', strategy); @@ -91,13 +96,14 @@ describe('Custom Spy Strategies (Integration)', function() { expect(env.createSpy('something').and.frobnicate).toBeUndefined(); }); - function jasmineDone(result) { + function expectations() { + var result = jasmineDone.calls.argsFor(0)[0]; expect(result.overallStatus).toEqual('passed'); done(); } env.addReporter({ jasmineDone: jasmineDone }); - env.execute(); + env.execute(null, expectations); }); it('allows multiple custom strategies to be used', function(done) { @@ -105,7 +111,9 @@ describe('Custom Spy Strategies (Integration)', function() { strategy1 = jasmine.createSpy('strat 1').and.returnValue(plan1), plan2 = jasmine.createSpy('plan 2').and.returnValue(24), strategy2 = jasmine.createSpy('strat 2').and.returnValue(plan2), - specDone = jasmine.createSpy('specDone'); + specDone = jasmine.createSpy('specDone'), + jasmineDone = jasmine.createSpy('jasmineDone'); + env.beforeEach(function() { env.addSpyStrategy('frobnicate', strategy1); @@ -130,13 +138,14 @@ describe('Custom Spy Strategies (Integration)', function() { expect(plan2).toHaveBeenCalled(); }); - function jasmineDone(result) { + function expectations() { + var result = jasmineDone.calls.argsFor(0)[0]; expect(result.overallStatus).toEqual('passed'); expect(specDone.calls.count()).toBe(2); done(); } env.addReporter({ jasmineDone: jasmineDone, specDone: specDone }); - env.execute(); + env.execute(null, expectations); }); }); diff --git a/spec/core/integration/DefaultSpyStrategySpec.js b/spec/core/integration/DefaultSpyStrategySpec.js index 584b25b2..50a11544 100644 --- a/spec/core/integration/DefaultSpyStrategySpec.js +++ b/spec/core/integration/DefaultSpyStrategySpec.js @@ -29,13 +29,15 @@ describe('Default Spy Strategy (Integration)', function() { expect(spy()).toBeUndefined(); }); - function jasmineDone(result) { + function expectations() { + var result = jasmineDone.calls.argsFor(0)[0]; expect(result.overallStatus).toEqual('passed'); done(); } + var jasmineDone = jasmine.createSpy('jasmineDone'); env.addReporter({ jasmineDone: jasmineDone }); - env.execute(); + env.execute(null, expectations); }); it('uses the default spy strategy defined when the spy is created', function (done) { @@ -61,12 +63,14 @@ describe('Default Spy Strategy (Integration)', function() { expect(d.and.isConfigured()).toBe(false); }); - function jasmineDone(result) { + function expectations() { + var result = jasmineDone.calls.argsFor(0)[0]; expect(result.overallStatus).toEqual('passed'); done(); } + var jasmineDone = jasmine.createSpy('jasmineDone'); env.addReporter({ jasmineDone: jasmineDone }); - env.execute(); + env.execute(null, expectations); }); }); diff --git a/spec/core/integration/EnvSpec.js b/spec/core/integration/EnvSpec.js index ae7cd0d6..cf1e997d 100644 --- a/spec/core/integration/EnvSpec.js +++ b/spec/core/integration/EnvSpec.js @@ -22,7 +22,6 @@ describe("Env integration", function() { done(); }; - env.addReporter({ jasmineDone: assertions}); env.configure({random: false}); env.describe("A Suite", function() { @@ -34,7 +33,7 @@ describe("Env integration", function() { }); }); - env.execute(); + env.execute(null, assertions); }); it("Nested Suites execute as expected", function(done) { @@ -50,7 +49,6 @@ describe("Env integration", function() { done(); }; - env.addReporter({ jasmineDone: assertions }); env.configure({random: false}); env.describe("Outer suite", function() { @@ -67,7 +65,7 @@ describe("Env integration", function() { }); }); - env.execute(); + env.execute(null, assertions); }); it("Multiple top-level Suites execute as expected", function(done) { @@ -84,7 +82,6 @@ describe("Env integration", function() { done(); }; - env.addReporter({ jasmineDone: assertions }); env.configure({random: false}); @@ -108,57 +105,13 @@ describe("Env integration", function() { }); }); - env.execute(); + env.execute(null, assertions); }); it('explicitly fails a spec', function(done) { var specDone = jasmine.createSpy('specDone'); - env.addReporter({ - specDone: specDone, - jasmineDone: function() { - expect(specDone).toHaveBeenCalledWith(jasmine.objectContaining({ - description: 'has a default message', - failedExpectations: [jasmine.objectContaining({ - message: 'Failed' - })] - })); - expect(specDone).toHaveBeenCalledWith(jasmine.objectContaining({ - description: 'specifies a message', - failedExpectations: [jasmine.objectContaining({ - message: 'Failed: messy message' - })] - })); - expect(specDone).toHaveBeenCalledWith(jasmine.objectContaining({ - description: 'has a message and stack trace from an Error', - failedExpectations: [jasmine.objectContaining({ - message: 'Failed: error message', - stack: { - asymmetricMatch: function(other) { - if (!other) { - // IE doesn't give us a stacktrace so just ignore it. - return true; - } - var split = other.split('\n'), - firstLine = split[0]; - if (firstLine.indexOf('error message') >= 0) { - // Chrome inserts the message and a newline before the first stacktrace line. - firstLine = split[1]; - } - return firstLine.indexOf('EnvSpec') >= 0; - } - } - })] - })); - expect(specDone).toHaveBeenCalledWith(jasmine.objectContaining({ - description: 'pretty prints objects', - failedExpectations: [jasmine.objectContaining({ - message: 'Failed: Object({ prop: \'value\', arr: [ \'works\', true ] })' - })] - })); - done(); - } - }); + env.addReporter({specDone: specDone}); env.describe('failing', function() { env.it('has a default message', function() { @@ -178,15 +131,51 @@ describe("Env integration", function() { }) }); - env.execute(); + env.execute(null, function() { + expect(specDone).toHaveBeenCalledWith(jasmine.objectContaining({ + description: 'has a default message', + failedExpectations: [jasmine.objectContaining({ + message: 'Failed' + })] + })); + expect(specDone).toHaveBeenCalledWith(jasmine.objectContaining({ + description: 'specifies a message', + failedExpectations: [jasmine.objectContaining({ + message: 'Failed: messy message' + })] + })); + expect(specDone).toHaveBeenCalledWith(jasmine.objectContaining({ + description: 'has a message and stack trace from an Error', + failedExpectations: [jasmine.objectContaining({ + message: 'Failed: error message', + stack: { + asymmetricMatch: function(other) { + if (!other) { + // IE doesn't give us a stacktrace so just ignore it. + return true; + } + var split = other.split('\n'), + firstLine = split[0]; + if (firstLine.indexOf('error message') >= 0) { + // Chrome inserts the message and a newline before the first stacktrace line. + firstLine = split[1]; + } + return firstLine.indexOf('EnvSpec') >= 0; + } + } + })] + })); + expect(specDone).toHaveBeenCalledWith(jasmine.objectContaining({ + description: 'pretty prints objects', + failedExpectations: [jasmine.objectContaining({ + message: 'Failed: Object({ prop: \'value\', arr: [ \'works\', true ] })' + })] + })); + done(); + }); }); it("produces an understandable error message when 'fail' is used outside of a current spec", function(done) { - var reporter = jasmine.createSpyObj('fakeReporter', ['jasmineDone']); - - reporter.jasmineDone.and.callFake(done); - env.addReporter(reporter); - env.describe("A Suite", function() { env.it("an async spec that is actually synchronous", function(underTestCallback) { underTestCallback(); @@ -194,12 +183,11 @@ describe("Env integration", function() { expect(function() { env.fail(); }).toThrowError(/'fail' was used when there was no current spec/); }); - env.execute(); + env.execute(null, done); }); it("calls associated befores/specs/afters with the same 'this'", function(done) { - env.addReporter({jasmineDone: done}); env.configure({random: false}); env.describe("tests", function() { var firstTimeThrough = true, firstSpecContext, secondSpecContext; @@ -231,12 +219,10 @@ describe("Env integration", function() { }); }); - env.execute(); + env.execute(null, done); }); it("calls associated befores/its/afters with the same 'this' for an async spec", function(done) { - env.addReporter({jasmineDone: done}); - env.describe("with an async spec", function() { var specContext; @@ -255,22 +241,13 @@ describe("Env integration", function() { }); }); - env.execute(); + env.execute(null, done); }); it("calls associated beforeAlls/afterAlls only once per suite", function(done) { var before = jasmine.createSpy('beforeAll'), after = jasmine.createSpy('afterAll'); - env.addReporter({ - jasmineDone: function() { - expect(after).toHaveBeenCalled(); - expect(after.calls.count()).toBe(1); - expect(before.calls.count()).toBe(1); - done(); - } - }); - env.describe("with beforeAll and afterAll", function() { env.it("spec", function() { expect(before).toHaveBeenCalled(); @@ -286,22 +263,18 @@ describe("Env integration", function() { env.afterAll(after); }); - env.execute(); + env.execute(null, function() { + expect(after).toHaveBeenCalled(); + expect(after.calls.count()).toBe(1); + expect(before.calls.count()).toBe(1); + done(); + }); }); it("calls associated beforeAlls/afterAlls only once per suite for async", function(done) { var before = jasmine.createSpy('beforeAll'), after = jasmine.createSpy('afterAll'); - env.addReporter({ - jasmineDone: function() { - expect(after).toHaveBeenCalled(); - expect(after.calls.count()).toBe(1); - expect(before.calls.count()).toBe(1); - done(); - } - }); - env.describe("with beforeAll and afterAll", function() { env.it("spec", function() { expect(before).toHaveBeenCalled(); @@ -324,12 +297,15 @@ describe("Env integration", function() { }); }); - env.execute(); + env.execute(null, function() { + expect(after).toHaveBeenCalled(); + expect(after.calls.count()).toBe(1); + expect(before.calls.count()).toBe(1); + done(); + }); }); it("calls associated beforeAlls/afterAlls with the cascaded 'this'", function(done) { - env.addReporter({jasmineDone: done}); - env.describe("with beforeAll and afterAll", function() { env.beforeAll(function() { this.x = 1; @@ -376,14 +352,11 @@ describe("Env integration", function() { }); }); - env.execute(); + env.execute(null, done); }); it("tags top-level afterAll failures with a type", function(done) { - env.addReporter({jasmineDone: function(result) { - expect(result.failedExpectations[0].globalErrorType).toEqual('afterAll'); - done(); - }}); + var jasmineDone = jasmine.createSpy('jasmineDone'); env.it('has a spec', function() {}); @@ -391,20 +364,22 @@ describe("Env integration", function() { throw 'nope'; }); - env.execute(); + env.addReporter({ jasmineDone: jasmineDone }); + env.execute(null, function() {{ + var result = jasmineDone.calls.argsFor(0)[0]; + expect(result.failedExpectations[0].globalErrorType).toEqual('afterAll'); + done(); + }}); }); it("does not tag suite afterAll failures with a type", function(done) { var reporter = { - jasmineDone: function() { - expect(reporter.suiteDone).toHaveBeenCalled(); - done(); - }, suiteDone: jasmine.createSpy('suiteDone').and.callFake(function(result) { expect(result.failedExpectations[0].globalErrorType).toBeFalsy(); }) }; + env.addReporter(reporter); env.describe('a suite', function() { @@ -415,20 +390,23 @@ describe("Env integration", function() { }); }); - env.execute(); + env.execute(null, function() { + expect(reporter.suiteDone).toHaveBeenCalled(); + done(); + }); }); it("when the beforeAll fails, error at suite level", function (done) { - var reporter = jasmine.createSpyObj('fakeReporter', [ "specDone", "suiteDone", "jasmineDone" ]); + var reporter = jasmine.createSpyObj('fakeReporter', [ "specDone", "suiteDone" ]); - reporter.jasmineDone.and.callFake(function() { + var assertions = function() { expect(reporter.specDone.calls.count()).toEqual(2); expect(reporter.specDone).toHaveFailedExpectationsForRunnable('A suite spec that will pass', []); expect(reporter.specDone).toHaveFailedExpectationsForRunnable('A suite nesting another spec to pass', []); expect(reporter.suiteDone).toHaveFailedExpectationsForRunnable('A suite', ['Expected 1 to be 2.']); done(); - }); + }; env.addReporter(reporter); @@ -446,7 +424,7 @@ describe("Env integration", function() { }); }); - env.execute(); + env.execute(null, assertions); }); it("copes with async failures after done has been called", function(done) { @@ -457,13 +435,13 @@ describe("Env integration", function() { spyOn(jasmineUnderTest, 'getGlobal').and.returnValue(global); env.cleanup_(); env = new jasmineUnderTest.Env(); - var reporter = jasmine.createSpyObj('fakeReporter', [ "specDone", "jasmineDone", "suiteDone" ]); + var reporter = jasmine.createSpyObj('fakeReporter', [ "specDone", "suiteDone" ]); - reporter.jasmineDone.and.callFake(function() { + var assertions = function() { expect(reporter.specDone).not.toHaveFailedExpectationsForRunnable('A suite fails', ['fail thrown']); expect(reporter.suiteDone).toHaveFailedExpectationsForRunnable('A suite', ['fail thrown']); done(); - }); + }; env.addReporter(reporter); @@ -484,20 +462,20 @@ describe("Env integration", function() { env.it('is not run', function() {}); }); - env.execute(); + env.execute(null, assertions); }); describe('suiteDone reporting', function(){ it("reports when an afterAll fails an expectation", function(done) { - var reporter = jasmine.createSpyObj('fakeReport', ['jasmineDone','suiteDone']); + var reporter = jasmine.createSpyObj('fakeReport', ['suiteDone']); - reporter.jasmineDone.and.callFake(function() { + var assertions = function() { expect(reporter.suiteDone).toHaveFailedExpectationsForRunnable('my suite', [ 'Expected 1 to equal 2.', 'Expected 2 to equal 3.' ]); done(); - }); + }; env.addReporter(reporter); @@ -511,19 +489,19 @@ describe("Env integration", function() { }); }); - env.execute(); + env.execute(null, assertions); }); it("if there are no specs, it still reports correctly", function(done) { - var reporter = jasmine.createSpyObj('fakeReport', ['jasmineDone','suiteDone']); + var reporter = jasmine.createSpyObj('fakeReport', ['suiteDone']); - reporter.jasmineDone.and.callFake(function() { + var assertions = function() { expect(reporter.suiteDone).toHaveFailedExpectationsForRunnable('outer suite', [ 'Expected 1 to equal 2.', 'Expected 2 to equal 3.' ]); done(); - }); + }; env.addReporter(reporter); @@ -538,19 +516,19 @@ describe("Env integration", function() { }); }); - env.execute(); + env.execute(null, assertions); }); it("reports when afterAll throws an exception", function(done) { var error = new Error('After All Exception'), - reporter = jasmine.createSpyObj('fakeReport', ['jasmineDone','suiteDone']); + reporter = jasmine.createSpyObj('fakeReport', ['suiteDone']); - reporter.jasmineDone.and.callFake(function() { + var assertions = function() { expect(reporter.suiteDone).toHaveFailedExpectationsForRunnable('my suite', [ (/^Error: After All Exception/) ]); done(); - }); + }; env.addReporter(reporter); @@ -563,18 +541,18 @@ describe("Env integration", function() { }); }); - env.execute(); + env.execute(null, assertions); }); it("reports when an async afterAll fails an expectation", function(done) { - var reporter = jasmine.createSpyObj('fakeReport', ['jasmineDone','suiteDone']); + var reporter = jasmine.createSpyObj('fakeReport', ['suiteDone']); - reporter.jasmineDone.and.callFake(function() { + var assertions = function() { expect(reporter.suiteDone).toHaveFailedExpectationsForRunnable('my suite', [ 'Expected 1 to equal 2.' ]); done(); - }); + }; env.addReporter(reporter); @@ -588,20 +566,20 @@ describe("Env integration", function() { }); }); - env.execute(); + env.execute(null, assertions); }); it("reports when an async afterAll throws an exception", function(done) { var error = new Error('After All Exception'), - reporter = jasmine.createSpyObj('fakeReport', ['jasmineDone','suiteDone']); + reporter = jasmine.createSpyObj('fakeReport', ['suiteDone']); - reporter.jasmineDone.and.callFake(function() { + var assertions = function() { expect(reporter.suiteDone).toHaveFailedExpectationsForRunnable('my suite', [ (/^Error: After All Exception/) ]); done(); - }); + }; env.addReporter(reporter); @@ -614,7 +592,7 @@ describe("Env integration", function() { }); }); - env.execute(); + env.execute(null, assertions); }); it('reports the duration of the suite', function(done) { @@ -624,10 +602,6 @@ describe("Env integration", function() { suiteDone: function(result) { expect(duration).toBeUndefined(); duration = result.duration; - }, - jasmineDone: function() { - expect(duration).toBeGreaterThanOrEqual(10); - done(); } }); @@ -639,7 +613,10 @@ describe("Env integration", function() { }) }); - env.execute(); + env.execute(null, function() { + expect(duration).toBeGreaterThanOrEqual(10); + done(); + }); }); }); @@ -651,10 +628,6 @@ describe("Env integration", function() { specDone: function(result) { expect(duration).toBeUndefined(); duration = result.duration; - }, - jasmineDone: function() { - expect(duration).toBeGreaterThanOrEqual(10); - done(); } }); @@ -666,19 +639,16 @@ describe("Env integration", function() { }) }); - env.execute(); + env.execute(null, function() { + expect(duration).toBeGreaterThanOrEqual(10); + done(); + }); }); }); it('reports expectation failures in global beforeAll', function(done) { var reporter = jasmine.createSpyObj(['specDone', 'jasmineDone']); - reporter.jasmineDone.and.callFake(function(results) { - expect(results.failedExpectations).toEqual([jasmine.objectContaining({ message: 'Expected 1 to be 0.' })]); - expect(reporter.specDone).toHaveFailedExpectationsForRunnable('is a spec', []); - done(); - }); - env.beforeAll(function() { env.expect(1).toBe(0); }); @@ -689,17 +659,17 @@ describe("Env integration", function() { env.addReporter(reporter); - env.execute(); + env.execute(null, function() { + var results = reporter.jasmineDone.calls.argsFor(0)[0]; + expect(results.failedExpectations).toEqual([jasmine.objectContaining({ message: 'Expected 1 to be 0.' })]); + expect(reporter.specDone).toHaveFailedExpectationsForRunnable('is a spec', []); + done(); + }); }); it('reports expectation failures in global afterAll', function(done) { var reporter = jasmine.createSpyObj(['jasmineDone']); - reporter.jasmineDone.and.callFake(function(results) { - expect(results.failedExpectations).toEqual([jasmine.objectContaining({ message: 'Expected 1 to be 0.' })]); - done(); - }); - env.afterAll(function() { env.expect(1).toBe(0); }); @@ -710,7 +680,11 @@ describe("Env integration", function() { env.addReporter(reporter); - env.execute(); + env.execute(null, function() { + var results = reporter.jasmineDone.calls.argsFor(0)[0]; + expect(results.failedExpectations).toEqual([jasmine.objectContaining({ message: 'Expected 1 to be 0.' })]); + done(); + }); }); it("Allows specifying which specs and suites to run", function(done) { @@ -719,16 +693,7 @@ describe("Env integration", function() { firstSpec, secondSuite; - var assertions = function() { - expect(calls).toEqual([ - 'third spec', - 'first spec' - ]); - expect(suiteCallback).toHaveBeenCalled(); - done(); - }; - - env.addReporter({jasmineDone: assertions, suiteDone: suiteCallback}); + env.addReporter({ suiteDone: suiteCallback}); env.describe("first suite", function() { firstSpec = env.it("first spec", function() { @@ -745,7 +710,14 @@ describe("Env integration", function() { }); }); - env.execute([secondSuite.id, firstSpec.id]); + env.execute([secondSuite.id, firstSpec.id], function() { + expect(calls).toEqual([ + 'third spec', + 'first spec' + ]); + expect(suiteCallback).toHaveBeenCalled(); + done(); + }); }); it('runs before and after all functions for runnables provided to .execute()', function(done) { @@ -753,18 +725,6 @@ describe("Env integration", function() { first_spec, second_spec; - var assertions = function() { - expect(calls).toEqual([ - "before", - "first spec", - "second spec", - "after" - ]); - done(); - }; - - env.addReporter({jasmineDone: assertions}); - env.describe("first suite", function() { env.beforeAll(function() { calls.push("before"); @@ -780,7 +740,15 @@ describe("Env integration", function() { }); }); - env.execute([first_spec.id, second_spec.id]); + env.execute([first_spec.id, second_spec.id], function() { + expect(calls).toEqual([ + "before", + "first spec", + "second spec", + "after" + ]); + done(); + }); }); it("Allows filtering out specs and suites to run programmatically", function(done) { @@ -789,17 +757,7 @@ describe("Env integration", function() { firstSpec, secondSuite; - var assertions = function() { - expect(calls.length).toEqual(2); - expect(calls).toEqual(jasmine.arrayContaining([ - 'first spec', - 'second spec' - ])); - expect(suiteCallback).toHaveBeenCalled(); - done(); - }; - - env.addReporter({jasmineDone: assertions, suiteDone: suiteCallback}); + env.addReporter({suiteDone: suiteCallback}); env.describe("first suite", function() { env.it("first spec", function() { @@ -822,7 +780,15 @@ describe("Env integration", function() { } }); - env.execute(); + env.execute(null, function() { + expect(calls.length).toEqual(2); + expect(calls).toEqual(jasmine.arrayContaining([ + 'first spec', + 'second spec' + ])); + expect(suiteCallback).toHaveBeenCalled(); + done(); + }); }); it("Functions can be spied on and have their calls tracked", function (done) { @@ -834,8 +800,6 @@ describe("Env integration", function() { } }; - env.addReporter({jasmineDone: done}); - env.it("works with spies", function() { var spy = env.spyOn(subject, 'spiedFunc').and.returnValue("stubbed result"); @@ -885,7 +849,7 @@ describe("Env integration", function() { }).toThrowError('You must use the new keyword.'); }); - env.execute(); + env.execute(null, done); }); it('can be configured to allow respying on functions', function (done) { @@ -896,7 +860,6 @@ describe("Env integration", function() { }; env.allowRespy(true); - env.addReporter({ jasmineDone: done }); env.describe('test suite', function() { env.it('spec 0', function() { @@ -910,7 +873,7 @@ describe("Env integration", function() { }); }); - env.execute(); + env.execute(null, done); }); it('removes all spies added in a spec after the spec is complete', function(done) { @@ -929,15 +892,11 @@ describe("Env integration", function() { env.it('spec 1', secondSpec); }); - var assertions = function() { + env.execute(null, function() { expect(firstSpec).toHaveBeenCalled(); expect(secondSpec).toHaveBeenCalled(); done(); - }; - - env.addReporter({ jasmineDone: assertions }); - - env.execute(); + }); }); it('removes all spies added in a suite after the suite is complete', function(done) { @@ -964,9 +923,7 @@ describe("Env integration", function() { }); }); - env.addReporter({ jasmineDone: done }); - - env.execute(); + env.execute(null, done); }); it('removes a spy from the top suite after the run is complete', function(done) { @@ -983,14 +940,10 @@ describe("Env integration", function() { expect(jasmineUnderTest.isSpy(testObj.foo)).toBe(true); }); - env.addReporter({ - jasmineDone: function() { - expect(jasmineUnderTest.isSpy(testObj.foo)).toBe(false); - done(); - } + env.execute(null, function() { + expect(jasmineUnderTest.isSpy(testObj.foo)).toBe(false); + done(); }); - - env.execute(); }); it("Mock clock can be installed and used in tests", function(done) { @@ -1001,14 +954,6 @@ describe("Env integration", function() { env.cleanup_(); env = new jasmineUnderTest.Env({global: { setTimeout: globalSetTimeout, clearTimeout: clearTimeout, setImmediate: function(cb) { setTimeout(cb, 0); } }}); - var assertions = function() { - expect(delayedFunctionForMockClock).toHaveBeenCalled(); - expect(globalSetTimeout).toHaveBeenCalledWith(delayedFunctionForGlobalClock, 100); - - done(); - }; - - env.addReporter({ jasmineDone: assertions }); env.configure({random: false}); env.describe("tests", function() { @@ -1026,17 +971,16 @@ describe("Env integration", function() { expect(globalSetTimeout).not.toHaveBeenCalled(); expect(delayedFunctionForMockClock).not.toHaveBeenCalled(); - env.execute(); + env.execute(null, function() { + expect(delayedFunctionForMockClock).toHaveBeenCalled(); + expect(globalSetTimeout).toHaveBeenCalledWith(delayedFunctionForGlobalClock, 100); + + done(); + }); }); it("should run async specs in order, waiting for them to complete", function(done) { - var reporter = jasmine.createSpyObj('reporter', ['jasmineDone']), - mutatedVar; - - reporter.jasmineDone.and.callFake(function() { - done(); - }); - env.addReporter(reporter); + var mutatedVar; env.describe("tests", function() { env.beforeEach(function() { @@ -1055,7 +999,7 @@ describe("Env integration", function() { }); }); - env.execute(); + env.execute(null, done); }); describe("with a mock clock", function() { @@ -1068,9 +1012,9 @@ describe("Env integration", function() { setTimeout: function(cb, t) { var stack = jasmine.util.errorWithStack().stack; if (stack.indexOf('ClearStack') >= 0) { - realSetTimeout(cb, t); + return realSetTimeout(cb, t); } else { - setTimeout(cb, t); + return setTimeout(cb, t); } }, clearTimeout: clearTimeout, @@ -1095,7 +1039,7 @@ describe("Env integration", function() { it("should wait a default interval before failing specs that haven't called done yet", function(done) { createMockedEnv(); - var reporter = jasmine.createSpyObj('fakeReporter', [ "specDone", "jasmineDone" ]); + var reporter = jasmine.createSpyObj('fakeReporter', [ "specDone" ]); reporter.specDone.and.callFake(function(result) { expect(result).toEqual(jasmine.objectContaining({status: 'failed'})); @@ -1104,12 +1048,6 @@ describe("Env integration", function() { }, 0); }); - reporter.jasmineDone.and.callFake(function() { - expect(reporter.specDone.calls.count()).toEqual(1); - jasmine.clock().tick(1); - realSetTimeout(done); - }); - env.addReporter(reporter); jasmineUnderTest.DEFAULT_TIMEOUT_INTERVAL = 8414; @@ -1119,12 +1057,16 @@ describe("Env integration", function() { jasmine.clock().tick(1); }); - env.execute(); + env.execute(null, function() { + expect(reporter.specDone.calls.count()).toEqual(1); + jasmine.clock().tick(1); + realSetTimeout(done); + }); }); it("should not use the mock clock for asynchronous timeouts", function(done){ createMockedEnv(); - var reporter = jasmine.createSpyObj('fakeReporter', [ "specDone", "jasmineDone" ]), + var reporter = jasmine.createSpyObj('fakeReporter', [ "specDone" ]), clock = env.clock; reporter.specDone.and.callFake(function() { @@ -1133,13 +1075,6 @@ describe("Env integration", function() { }, 0); }); - reporter.jasmineDone.and.callFake(function() { - expect(reporter.specDone).toHaveBeenCalledTimes(1); - expect(reporter.specDone.calls.argsFor(0)[0]).toEqual(jasmine.objectContaining({status: 'passed'})); - jasmine.clock().tick(1); - realSetTimeout(done); - }); - env.addReporter(reporter); jasmineUnderTest.DEFAULT_TIMEOUT_INTERVAL = 5; @@ -1157,25 +1092,18 @@ describe("Env integration", function() { realSetTimeout(innerDone); }); - env.execute(); + env.execute(null, function() { + expect(reporter.specDone).toHaveBeenCalledTimes(1); + expect(reporter.specDone.calls.argsFor(0)[0]).toEqual(jasmine.objectContaining({status: 'passed'})); + jasmine.clock().tick(1); + realSetTimeout(done); + }); }); it('should wait a custom interval before reporting async functions that fail to complete', function(done) { createMockedEnv(); var reporter = jasmine.createSpyObj('fakeReport', ['jasmineDone', 'suiteDone', 'specDone']); - reporter.jasmineDone.and.callFake(function(r) { - expect(r.failedExpectations).toEqual([]); - expect(reporter.suiteDone).toHaveFailedExpectationsForRunnable('suite beforeAll', [ /^Error: Timeout - Async function did not complete within 5000ms \(custom timeout\)/ ]); - expect(reporter.suiteDone).toHaveFailedExpectationsForRunnable('suite afterAll', [ /^Error: Timeout - Async function did not complete within 2000ms \(custom timeout\)/ ]); - expect(reporter.specDone).toHaveFailedExpectationsForRunnable('suite beforeEach times out', [/^Error: Timeout - Async function did not complete within 1000ms \(custom timeout\)/]); - expect(reporter.specDone).toHaveFailedExpectationsForRunnable('suite afterEach times out', [ /^Error: Timeout - Async function did not complete within 4000ms \(custom timeout\)/ ]); - expect(reporter.specDone).toHaveFailedExpectationsForRunnable('suite it times out', [ /^Error: Timeout - Async function did not complete within 6000ms \(custom timeout\)/ ]); - - jasmine.clock().tick(1); - realSetTimeout(done); - }); - env.addReporter(reporter); jasmineUnderTest.DEFAULT_TIMEOUT_INTERVAL = 10000; @@ -1256,35 +1184,25 @@ describe("Env integration", function() { }, 6000); }); - env.execute(); + env.execute(null, function() { + var r = reporter.jasmineDone.calls.argsFor(0)[0]; + expect(r.failedExpectations).toEqual([]); + expect(reporter.suiteDone).toHaveFailedExpectationsForRunnable('suite beforeAll', [ /^Error: Timeout - Async function did not complete within 5000ms \(custom timeout\)/ ]); + expect(reporter.suiteDone).toHaveFailedExpectationsForRunnable('suite afterAll', [ /^Error: Timeout - Async function did not complete within 2000ms \(custom timeout\)/ ]); + expect(reporter.specDone).toHaveFailedExpectationsForRunnable('suite beforeEach times out', [/^Error: Timeout - Async function did not complete within 1000ms \(custom timeout\)/]); + expect(reporter.specDone).toHaveFailedExpectationsForRunnable('suite afterEach times out', [ /^Error: Timeout - Async function did not complete within 4000ms \(custom timeout\)/ ]); + expect(reporter.specDone).toHaveFailedExpectationsForRunnable('suite it times out', [ /^Error: Timeout - Async function did not complete within 6000ms \(custom timeout\)/ ]); + + jasmine.clock().tick(1); + realSetTimeout(done); + }); }); }); it('explicitly fails an async spec', function(done) { var specDone = jasmine.createSpy('specDone'); - env.addReporter({ - specDone: specDone, - jasmineDone: function() { - expect(specDone).toHaveFailedExpectationsForRunnable('failing has a default message', - ['Failed'] - ); - expect(specDone).toHaveFailedExpectationsForRunnable('failing specifies a message', - ['Failed: messy message'] - ); - expect(specDone).toHaveFailedExpectationsForRunnable('failing fails via the done callback', - ['Failed: done failed'] - ); - expect(specDone).toHaveFailedExpectationsForRunnable('failing has a message from an Error', - ['Failed: error message'] - ); - expect(specDone).toHaveFailedExpectationsForRunnable('failing has a message from an Error to done', - ['Failed: done error'] - ); - - setTimeout(done); - } - }); + env.addReporter({specDone: specDone}); env.describe('failing', function() { env.it('has a default message', function(innerDone) { @@ -1321,20 +1239,31 @@ describe("Env integration", function() { }); }); - env.execute(); + env.execute(null, function() { + expect(specDone).toHaveFailedExpectationsForRunnable('failing has a default message', + ['Failed'] + ); + expect(specDone).toHaveFailedExpectationsForRunnable('failing specifies a message', + ['Failed: messy message'] + ); + expect(specDone).toHaveFailedExpectationsForRunnable('failing fails via the done callback', + ['Failed: done failed'] + ); + expect(specDone).toHaveFailedExpectationsForRunnable('failing has a message from an Error', + ['Failed: error message'] + ); + expect(specDone).toHaveFailedExpectationsForRunnable('failing has a message from an Error to done', + ['Failed: done error'] + ); + + setTimeout(done); + }); }); describe('focused tests', function() { it('should only run the focused tests', function(done) { var calls = []; - var assertions = function() { - expect(calls).toEqual(['focused']); - done(); - }; - - env.addReporter({jasmineDone: assertions}); - env.describe('a suite', function() { env.fit('is focused', function() { calls.push('focused'); @@ -1345,19 +1274,15 @@ describe("Env integration", function() { }) }); - env.execute(); + env.execute(null, function() { + expect(calls).toEqual(['focused']); + done(); + }); }); it('should only run focused suites', function(done){ var calls = []; - var assertions = function() { - expect(calls).toEqual(['focused']); - done(); - }; - - env.addReporter({jasmineDone: assertions}); - env.fdescribe('a focused suite', function() { env.it('is focused', function() { calls.push('focused'); @@ -1370,20 +1295,30 @@ describe("Env integration", function() { }) }); - env.execute(); + env.execute(null, function() { + expect(calls).toEqual(['focused']); + done(); + }); }); it('should run focused tests inside an xdescribe', function(done) { var reporter = jasmine.createSpyObj('fakeReporter', [ "jasmineStarted", - "jasmineDone", "suiteStarted", "suiteDone", "specStarted", "specDone" ]); - reporter.jasmineDone.and.callFake(function() { + env.addReporter(reporter); + + env.xdescribe("xd suite", function() { + env.fit("with a fit spec", function() { + env.expect(true).toBe(false); + }); + }); + + env.execute(null, function() { expect(reporter.jasmineStarted).toHaveBeenCalledWith({ totalSpecsDefined: 1, order: jasmine.any(jasmineUnderTest.Order) @@ -1396,29 +1331,28 @@ describe("Env integration", function() { done(); }); - - env.addReporter(reporter); - - env.xdescribe("xd suite", function() { - env.fit("with a fit spec", function() { - env.expect(true).toBe(false); - }); - }); - - env.execute(); }); it('should run focused suites inside an xdescribe', function(done) { var reporter = jasmine.createSpyObj('fakeReporter', [ "jasmineStarted", - "jasmineDone", "suiteStarted", "suiteDone", "specStarted", "specDone" ]); - reporter.jasmineDone.and.callFake(function() { + env.addReporter(reporter); + + env.xdescribe("xd suite", function() { + env.fdescribe("fd suite", function() { + env.it("with a spec", function() { + env.expect(true).toBe(false); + }); + }); + }); + + env.execute(null, function() { expect(reporter.jasmineStarted).toHaveBeenCalledWith({ totalSpecsDefined: 1, order: jasmine.any(jasmineUnderTest.Order) @@ -1431,32 +1365,42 @@ describe("Env integration", function() { done(); }); - - env.addReporter(reporter); - - env.xdescribe("xd suite", function() { - env.fdescribe("fd suite", function() { - env.it("with a spec", function() { - env.expect(true).toBe(false); - }); - }); - }); - - env.execute(); }); }); it("should report as expected", function(done) { var reporter = jasmine.createSpyObj('fakeReporter', [ "jasmineStarted", - "jasmineDone", "suiteStarted", "suiteDone", "specStarted", "specDone" ]); - reporter.jasmineDone.and.callFake(function() { + env.addReporter(reporter); + + env.describe("A Suite", function() { + env.it("with a top level spec", function() { + env.expect(true).toBe(true); + }); + env.describe("with a nested suite", function() { + env.xit("with an x'ed spec", function() { + env.expect(true).toBe(true); + }); + env.it("with a spec", function() { + env.expect(true).toBe(false); + }); + }); + + env.describe('with only non-executable specs', function() { + env.it('is pending'); + env.xit('is xed', function() { + env.expect(true).toBe(true); + }); + }); + }); + + env.execute(null, function() { expect(reporter.jasmineStarted).toHaveBeenCalledWith({ totalSpecsDefined: 5, order: jasmine.any(jasmineUnderTest.Order) @@ -1492,31 +1436,6 @@ describe("Env integration", function() { done(); }); - - env.addReporter(reporter); - - env.describe("A Suite", function() { - env.it("with a top level spec", function() { - env.expect(true).toBe(true); - }); - env.describe("with a nested suite", function() { - env.xit("with an x'ed spec", function() { - env.expect(true).toBe(true); - }); - env.it("with a spec", function() { - env.expect(true).toBe(false); - }); - }); - - env.describe('with only non-executable specs', function() { - env.it('is pending'); - env.xit('is xed', function() { - env.expect(true).toBe(true); - }); - }); - }); - - env.execute(); }); it("should report the random seed at the beginning and end of execution", function(done) { @@ -1530,36 +1449,23 @@ describe("Env integration", function() { ]); env.configure({random: true, seed: '123456'}); - reporter.jasmineDone.and.callFake(function(doneArg) { + env.addReporter(reporter); + env.configure({random: true}); + env.execute(null, function() { expect(reporter.jasmineStarted).toHaveBeenCalled(); var startedArg = reporter.jasmineStarted.calls.argsFor(0)[0]; expect(startedArg.order.random).toEqual(true); expect(startedArg.order.seed).toEqual('123456'); + var doneArg = reporter.jasmineDone.calls.argsFor(0)[0]; expect(doneArg.order.random).toEqual(true); expect(doneArg.order.seed).toEqual('123456'); done(); }); - - env.addReporter(reporter); - env.configure({random: true}); - env.execute(); }); it('should report pending spec messages', function(done) { - var reporter = jasmine.createSpyObj('fakeReporter', [ - 'specDone', - 'jasmineDone' - ]); - - reporter.jasmineDone.and.callFake(function() { - var specStatus = reporter.specDone.calls.argsFor(0)[0]; - - expect(specStatus.status).toBe('pending'); - expect(specStatus.pendingReason).toBe('with a message'); - - done(); - }); + var reporter = jasmine.createSpyObj('fakeReporter', ['specDone']); env.addReporter(reporter); @@ -1567,7 +1473,14 @@ describe("Env integration", function() { env.pending('with a message'); }); - env.execute(); + env.execute(null, function() { + var specStatus = reporter.specDone.calls.argsFor(0)[0]; + + expect(specStatus.status).toBe('pending'); + expect(specStatus.pendingReason).toBe('with a message'); + + done(); + }); }); it('should report pending spec messages from promise-returning functions', function(done) { @@ -1583,19 +1496,7 @@ describe("Env integration", function() { reject(this.exception); }; - var reporter = jasmine.createSpyObj('fakeReporter', [ - 'specDone', - 'jasmineDone' - ]); - - reporter.jasmineDone.and.callFake(function() { - var specStatus = reporter.specDone.calls.argsFor(0)[0]; - - expect(specStatus.status).toBe('pending'); - expect(specStatus.pendingReason).toBe('with a message'); - - done(); - }); + var reporter = jasmine.createSpyObj('fakeReporter', ['specDone']); env.addReporter(reporter); @@ -1605,7 +1506,14 @@ describe("Env integration", function() { }); }); - env.execute(); + env.execute(null, function() { + var specStatus = reporter.specDone.calls.argsFor(0)[0]; + + expect(specStatus.status).toBe('pending'); + expect(specStatus.pendingReason).toBe('with a message'); + + done(); + }); }); it('should report using fallback reporter', function(done) { @@ -1632,26 +1540,12 @@ describe("Env integration", function() { it('should report xdescribes as expected', function(done) { var reporter = jasmine.createSpyObj('fakeReporter', [ "jasmineStarted", - "jasmineDone", "suiteStarted", "suiteDone", "specStarted", "specDone" ]); - reporter.jasmineDone.and.callFake(function() { - expect(reporter.jasmineStarted).toHaveBeenCalledWith({ - totalSpecsDefined: 1, - order: jasmine.any(jasmineUnderTest.Order) - }); - - expect(reporter.specDone).toHaveBeenCalledWith(jasmine.objectContaining({ status: 'pending' })); - expect(reporter.suiteDone).toHaveBeenCalledWith(jasmine.objectContaining({ description: 'xd out', status: 'pending' })); - expect(reporter.suiteDone.calls.count()).toBe(4); - - done(); - }); - env.addReporter(reporter); env.describe("A Suite", function() { @@ -1666,7 +1560,18 @@ describe("Env integration", function() { }); }); - env.execute(); + env.execute(null, function() { + expect(reporter.jasmineStarted).toHaveBeenCalledWith({ + totalSpecsDefined: 1, + order: jasmine.any(jasmineUnderTest.Order) + }); + + expect(reporter.specDone).toHaveBeenCalledWith(jasmine.objectContaining({ status: 'pending' })); + expect(reporter.suiteDone).toHaveBeenCalledWith(jasmine.objectContaining({ description: 'xd out', status: 'pending' })); + expect(reporter.suiteDone.calls.count()).toBe(4); + + done(); + }); }); it("should be possible to get full name from a spec", function() { @@ -1691,20 +1596,7 @@ describe("Env integration", function() { }); it("Custom equality testers should be per spec", function(done) { - var reporter = jasmine.createSpyObj('fakeReporter', [ - "jasmineDone", - "specDone" - ]); - - reporter.jasmineDone.and.callFake(function() { - var firstSpecResult = reporter.specDone.calls.first().args[0], - secondSpecResult = reporter.specDone.calls.mostRecent().args[0]; - - expect(firstSpecResult.status).toEqual("passed"); - expect(secondSpecResult.status).toEqual("failed"); - - done(); - }); + var reporter = jasmine.createSpyObj('fakeReporter', ["specDone"]); env.addReporter(reporter); env.configure({random: false}); @@ -1720,26 +1612,20 @@ describe("Env integration", function() { }); }); - env.execute(); - }); - - it("Custom equality testers should be per suite", function(done) { - var reporter = jasmine.createSpyObj('fakeReporter', [ - "jasmineDone", - "specDone" - ]); - - reporter.jasmineDone.and.callFake(function() { + env.execute(null, function() { var firstSpecResult = reporter.specDone.calls.first().args[0], - secondSpecResult = reporter.specDone.calls.argsFor(0)[0], - thirdSpecResult = reporter.specDone.calls.mostRecent().args[0]; + secondSpecResult = reporter.specDone.calls.mostRecent().args[0]; expect(firstSpecResult.status).toEqual("passed"); - expect(secondSpecResult.status).toEqual("passed"); - expect(thirdSpecResult.status).toEqual("failed"); + expect(secondSpecResult.status).toEqual("failed"); done(); }); + }); + + it("Custom equality testers should be per suite", function(done) { + var reporter = jasmine.createSpyObj('fakeReporter', ["specDone"]); + env.addReporter(reporter); env.configure({random: false}); @@ -1762,24 +1648,21 @@ describe("Env integration", function() { }); }); - env.execute(); - }); - - it("Custom equality testers for toContain should be per spec", function(done) { - var reporter = jasmine.createSpyObj('fakeReporter', [ - "jasmineDone", - "specDone" - ]); - - reporter.jasmineDone.and.callFake(function() { + env.execute(null, function() { var firstSpecResult = reporter.specDone.calls.first().args[0], - secondSpecResult = reporter.specDone.calls.mostRecent().args[0]; + secondSpecResult = reporter.specDone.calls.argsFor(0)[0], + thirdSpecResult = reporter.specDone.calls.mostRecent().args[0]; expect(firstSpecResult.status).toEqual("passed"); - expect(secondSpecResult.status).toEqual("failed"); + expect(secondSpecResult.status).toEqual("passed"); + expect(thirdSpecResult.status).toEqual("failed"); done(); }); + }); + + it("Custom equality testers for toContain should be per spec", function(done) { + var reporter = jasmine.createSpyObj('fakeReporter', ["specDone"]); env.addReporter(reporter); env.configure({random: false}); @@ -1795,15 +1678,18 @@ describe("Env integration", function() { }); }); - env.execute(); + env.execute(null, function() { + var firstSpecResult = reporter.specDone.calls.first().args[0], + secondSpecResult = reporter.specDone.calls.mostRecent().args[0]; + + expect(firstSpecResult.status).toEqual("passed"); + expect(secondSpecResult.status).toEqual("failed"); + + done(); + }); }); it("produces an understandable error message when an 'expect' is used outside of a current spec", function(done) { - var reporter = jasmine.createSpyObj('fakeReporter', ['jasmineDone']); - - reporter.jasmineDone.and.callFake(done); - env.addReporter(reporter); - env.describe("A Suite", function() { env.it("an async spec that is actually synchronous", function(underTestCallback) { underTestCallback(); @@ -1811,26 +1697,11 @@ describe("Env integration", function() { expect(function() { env.expect('a').toEqual('a'); }).toThrowError(/'expect' was used when there was no current spec/); }); - env.execute(); + env.execute(null, done); }); it("Custom equality testers for toContain should be per suite", function(done) { - var reporter = jasmine.createSpyObj('fakeReporter', [ - "jasmineDone", - "specDone" - ]); - - reporter.jasmineDone.and.callFake(function() { - var firstSpecResult = reporter.specDone.calls.first().args[0], - secondSpecResult = reporter.specDone.calls.argsFor(1)[0], - thirdSpecResult = reporter.specDone.calls.mostRecent().args[0]; - - expect(firstSpecResult.status).toEqual("passed"); - expect(secondSpecResult.status).toEqual("passed"); - expect(thirdSpecResult.status).toEqual("failed"); - - done(); - }); + var reporter = jasmine.createSpyObj('fakeReporter', ["specDone"]); env.addReporter(reporter); env.configure({random: false}); @@ -1853,7 +1724,17 @@ describe("Env integration", function() { }); }); - env.execute(); + env.execute(null, function() { + var firstSpecResult = reporter.specDone.calls.first().args[0], + secondSpecResult = reporter.specDone.calls.argsFor(1)[0], + thirdSpecResult = reporter.specDone.calls.mostRecent().args[0]; + + expect(firstSpecResult.status).toEqual("passed"); + expect(secondSpecResult.status).toEqual("passed"); + expect(thirdSpecResult.status).toEqual("failed"); + + done(); + }); }); it("Custom matchers should be per spec", function(done) { @@ -1872,9 +1753,7 @@ describe("Env integration", function() { }); }); - env.addReporter({jasmineDone: done}); - - env.execute(); + env.execute(null, done); }); it("Custom matchers should be per suite", function(done) { @@ -1900,9 +1779,7 @@ describe("Env integration", function() { }); }); - env.addReporter({jasmineDone: done}); - - env.execute(); + env.execute(null, done); }); it('throws an exception if you try to create a spy outside of a runnable', function (done) { @@ -1917,14 +1794,10 @@ describe("Env integration", function() { } }); - var assertions = function() { + env.execute(null, function() { expect(exception.message).toBe('Spies must be created in a before function or a spec'); done(); - }; - - env.addReporter({jasmineDone: assertions}); - - env.execute(); + }); }); it('throws an exception if you try to add a matcher outside of a runnable', function (done) { @@ -1939,14 +1812,10 @@ describe("Env integration", function() { } }); - var assertions = function() { + env.execute(null, function() { expect(exception.message).toBe('Matchers must be added in a before function or a spec'); done(); - }; - - env.addReporter({jasmineDone: assertions}); - - env.execute(); + }); }); it('throws an exception if you try to add a custom equality outside of a runnable', function (done) { @@ -1961,30 +1830,28 @@ describe("Env integration", function() { } }); - var assertions = function() { + env.execute(null, function() { expect(exception.message).toBe('Custom Equalities must be added in a before function or a spec'); done(); - }; - - env.addReporter({jasmineDone: assertions}); - - env.execute(); + }); }); it('reports test properties on specs', function(done) { var env = new jasmineUnderTest.Env(), - reporter = jasmine.createSpyObj('reporter', ['jasmineDone', 'suiteDone', 'specDone']); + reporter = jasmine.createSpyObj('reporter', ['suiteDone', 'specDone']); reporter.specDone.and.callFake(function(e) { expect(e.properties).toEqual({a: 'Bee'}); - done(); }); env.addReporter(reporter); env.it('calls setSpecProperty', function() { env.setSpecProperty('a', 'Bee') }); - env.execute(); + env.execute(null, function() { + expect(reporter.specDone).toHaveBeenCalled(); + done(); + }); }); it('throws an exception if you try to setSpecProperty outside of a spec', function (done) { @@ -2000,14 +1867,10 @@ describe("Env integration", function() { } }); - var assertions = function() { + env.execute(null, function() { expect(exception.message).toBe("'setSpecProperty' was used when there was no current spec"); done(); - }; - - env.addReporter({jasmineDone: assertions}); - - env.execute(); + }); }); it('reports test properties on suites', function(done) { @@ -2016,7 +1879,6 @@ describe("Env integration", function() { reporter.suiteDone.and.callFake(function(e) { expect(e.properties).toEqual({b: 'Sweet'}); - done(); }); env.addReporter(reporter); @@ -2029,7 +1891,10 @@ describe("Env integration", function() { }); }); - env.execute(); + env.execute(null, function() { + expect(reporter.suiteDone).toHaveBeenCalled(); + done(); + }); }); it('throws an exception if you try to setSuiteProperty outside of a suite', function (done) { @@ -2044,17 +1909,7 @@ describe("Env integration", function() { }); it("should associate errors thrown from async code with the correct runnable", function(done) { - var reporter = jasmine.createSpyObj('fakeReport', ['jasmineDone','suiteDone','specDone']); - - reporter.jasmineDone.and.callFake(function() { - expect(reporter.suiteDone).toHaveFailedExpectationsForRunnable('async suite', [ - /^(((Uncaught )?(exception: )?Error: suite( thrown)?)|(suite thrown))$/ - ]); - expect(reporter.specDone).toHaveFailedExpectationsForRunnable('suite async spec', [ - /^(((Uncaught )?(exception: )?Error: spec( thrown)?)|(spec thrown))$/ - ]); - done(); - }); + var reporter = jasmine.createSpyObj('fakeReport', ['suiteDone','specDone']); env.addReporter(reporter); @@ -2072,31 +1927,19 @@ describe("Env integration", function() { }, 10); }); - env.execute(); + env.execute(null, function() { + expect(reporter.suiteDone).toHaveFailedExpectationsForRunnable('async suite', [ + /^(((Uncaught )?(exception: )?Error: suite( thrown)?)|(suite thrown))$/ + ]); + expect(reporter.specDone).toHaveFailedExpectationsForRunnable('suite async spec', [ + /^(((Uncaught )?(exception: )?Error: spec( thrown)?)|(spec thrown))$/ + ]); + done(); + }); }); it('should throw on suites/specs/befores/afters nested in methods other than \'describe\'', function(done) { - var reporter = jasmine.createSpyObj('reporter', ['jasmineDone', 'suiteDone', 'specDone']); - - reporter.jasmineDone.and.callFake(function() { - var msg = /\'.*\' should only be used in \'describe\' function/; - - expect(reporter.specDone).toHaveFailedExpectationsForRunnable('suite describe', [msg]); - expect(reporter.specDone).toHaveFailedExpectationsForRunnable('suite xdescribe', [msg]); - expect(reporter.specDone).toHaveFailedExpectationsForRunnable('suite fdescribe', [msg]); - - expect(reporter.specDone).toHaveFailedExpectationsForRunnable('spec it', [msg]); - expect(reporter.specDone).toHaveFailedExpectationsForRunnable('spec xit', [msg]); - expect(reporter.specDone).toHaveFailedExpectationsForRunnable('spec fit', [msg]); - - expect(reporter.suiteDone).toHaveFailedExpectationsForRunnable('beforeAll', [msg]); - expect(reporter.specDone).toHaveFailedExpectationsForRunnable('beforeEach spec', [msg]); - - expect(reporter.suiteDone).toHaveFailedExpectationsForRunnable('afterAll', [msg]); - expect(reporter.specDone).toHaveFailedExpectationsForRunnable('afterEach spec', [msg]); - - done(); - }); + var reporter = jasmine.createSpyObj('reporter', ['suiteDone', 'specDone']); env.addReporter(reporter); @@ -2132,7 +1975,25 @@ describe("Env integration", function() { env.it('spec', function() {}); }); - env.execute(); + env.execute(null, function() { + var msg = /\'.*\' should only be used in \'describe\' function/; + + expect(reporter.specDone).toHaveFailedExpectationsForRunnable('suite describe', [msg]); + expect(reporter.specDone).toHaveFailedExpectationsForRunnable('suite xdescribe', [msg]); + expect(reporter.specDone).toHaveFailedExpectationsForRunnable('suite fdescribe', [msg]); + + expect(reporter.specDone).toHaveFailedExpectationsForRunnable('spec it', [msg]); + expect(reporter.specDone).toHaveFailedExpectationsForRunnable('spec xit', [msg]); + expect(reporter.specDone).toHaveFailedExpectationsForRunnable('spec fit', [msg]); + + expect(reporter.suiteDone).toHaveFailedExpectationsForRunnable('beforeAll', [msg]); + expect(reporter.specDone).toHaveFailedExpectationsForRunnable('beforeEach spec', [msg]); + + expect(reporter.suiteDone).toHaveFailedExpectationsForRunnable('afterAll', [msg]); + expect(reporter.specDone).toHaveFailedExpectationsForRunnable('afterEach spec', [msg]); + + done(); + }); }); it('reports errors that occur during loading', function(done) { @@ -2147,7 +2008,12 @@ describe("Env integration", function() { env = new jasmineUnderTest.Env(); var reporter = jasmine.createSpyObj('reporter', ['jasmineDone', 'suiteDone', 'specDone']); - reporter.jasmineDone.and.callFake(function(e) { + env.addReporter(reporter); + global.onerror('Uncaught SyntaxError: Unexpected end of input', 'borkenSpec.js', 42, undefined, {stack: 'a stack'}); + global.onerror('Uncaught Error: ENOCHEESE'); + + env.execute(null, function() { + var e = reporter.jasmineDone.calls.argsFor(0)[0]; expect(e.failedExpectations).toEqual([ { passed: false, @@ -2169,12 +2035,6 @@ describe("Env integration", function() { done(); }); - - env.addReporter(reporter); - global.onerror('Uncaught SyntaxError: Unexpected end of input', 'borkenSpec.js', 42, undefined, {stack: 'a stack'}); - global.onerror('Uncaught Error: ENOCHEESE'); - - env.execute(); }); describe('If suppressLoadErrors: true was passed', function() { @@ -2195,16 +2055,15 @@ describe("Env integration", function() { env = new jasmineUnderTest.Env({suppressLoadErrors: true}); var reporter = jasmine.createSpyObj('reporter', ['jasmineDone', 'suiteDone', 'specDone']); - reporter.jasmineDone.and.callFake(function(e) { + env.addReporter(reporter); + global.onerror('Uncaught Error: ENOCHEESE'); + + env.execute(null, function() { + var e = reporter.jasmineDone.calls.argsFor(0)[0]; expect(e.failedExpectations).toEqual([]); expect(originalOnerror).toHaveBeenCalledWith('Uncaught Error: ENOCHEESE'); done(); }); - - env.addReporter(reporter); - global.onerror('Uncaught Error: ENOCHEESE'); - - env.execute(); }); }); @@ -2213,14 +2072,13 @@ describe("Env integration", function() { it('is "passed"', function(done) { var reporter = jasmine.createSpyObj('reporter', ['jasmineDone', 'suiteDone', 'specDone']); - reporter.jasmineDone.and.callFake(function(e) { + env.addReporter(reporter); + env.it('passes', function() {}); + env.execute(null, function() { + var e = reporter.jasmineDone.calls.argsFor(0)[0]; expect(e.overallStatus).toEqual('passed'); done(); }); - - env.addReporter(reporter); - env.it('passes', function() {}); - env.execute(); }); }); @@ -2228,16 +2086,15 @@ describe("Env integration", function() { it('is "failed"', function(done) { var reporter = jasmine.createSpyObj('reporter', ['jasmineDone', 'suiteDone', 'specDone']); - reporter.jasmineDone.and.callFake(function(e) { - expect(e.overallStatus).toEqual('failed'); - done(); - }); - env.addReporter(reporter); env.it('fails', function() { env.expect(true).toBe(false); }); - env.execute(); + env.execute(null, function() { + var e = reporter.jasmineDone.calls.argsFor(0)[0]; + expect(e.overallStatus).toEqual('failed'); + done(); + }) }); }); @@ -2255,23 +2112,21 @@ describe("Env integration", function() { }); it('should report "failed" status if "failSpecWithNoExpectations" is enabled', function(done) { - reporter.jasmineDone.and.callFake(function(e) { + env.configure({ failSpecWithNoExpectations: true }); + env.execute(null, function() { + var e = reporter.jasmineDone.calls.argsFor(0)[0]; expect(e.overallStatus).toEqual('failed'); done(); }); - - env.configure({ failSpecWithNoExpectations: true }); - env.execute(); }); it('should report "passed" status if "failSpecWithNoExpectations" is disabled', function(done) { - reporter.jasmineDone.and.callFake(function(e) { + env.configure({ failSpecWithNoExpectations: false }); + env.execute(null, function() { + var e = reporter.jasmineDone.calls.argsFor(0)[0]; expect(e.overallStatus).toEqual('passed'); done(); }); - - env.configure({ failSpecWithNoExpectations: false }); - env.execute(); }); }); @@ -2279,17 +2134,16 @@ describe("Env integration", function() { it('is "failed"', function(done) { var reporter = jasmine.createSpyObj('reporter', ['jasmineDone', 'suiteDone', 'specDone']); - reporter.jasmineDone.and.callFake(function(e) { - expect(e.overallStatus).toEqual('failed'); - done(); - }); - env.addReporter(reporter); env.beforeAll(function() { throw new Error('nope'); }); env.it('does not run', function() {}); - env.execute(); + env.execute(null, function() { + var e = reporter.jasmineDone.calls.argsFor(0)[0]; + expect(e.overallStatus).toEqual('failed'); + done(); + }); }); }); @@ -2297,11 +2151,6 @@ describe("Env integration", function() { it('is "failed"', function(done) { var reporter = jasmine.createSpyObj('reporter', ['jasmineDone', 'suiteDone', 'specDone']); - reporter.jasmineDone.and.callFake(function(e) { - expect(e.overallStatus).toEqual('failed'); - done(); - }); - env.addReporter(reporter); env.describe('something', function() { env.beforeAll(function() { @@ -2309,7 +2158,11 @@ describe("Env integration", function() { }); env.it('does not run', function() {}); }); - env.execute(); + env.execute(null, function() { + var e = reporter.jasmineDone.calls.argsFor(0)[0]; + expect(e.overallStatus).toEqual('failed'); + done(); + }); }); }); @@ -2317,17 +2170,16 @@ describe("Env integration", function() { it('is "failed"', function(done) { var reporter = jasmine.createSpyObj('reporter', ['jasmineDone', 'suiteDone', 'specDone']); - reporter.jasmineDone.and.callFake(function(e) { - expect(e.overallStatus).toEqual('failed'); - done(); - }); - env.addReporter(reporter); env.afterAll(function() { throw new Error('nope'); }); env.it('does not run', function() {}); - env.execute(); + env.execute(null, function() { + var e = reporter.jasmineDone.calls.argsFor(0)[0]; + expect(e.overallStatus).toEqual('failed'); + done(); + }); }); }); @@ -2335,11 +2187,6 @@ describe("Env integration", function() { it('is "failed"', function(done) { var reporter = jasmine.createSpyObj('reporter', ['jasmineDone', 'suiteDone', 'specDone']); - reporter.jasmineDone.and.callFake(function(e) { - expect(e.overallStatus).toEqual('failed'); - done(); - }); - env.addReporter(reporter); env.describe('something', function() { env.afterAll(function() { @@ -2347,7 +2194,11 @@ describe("Env integration", function() { }); env.it('does not run', function() {}); }); - env.execute(); + env.execute(null, function() { + var e = reporter.jasmineDone.calls.argsFor(0)[0]; + expect(e.overallStatus).toEqual('failed'); + done(); + }); }); }); @@ -2365,13 +2216,15 @@ describe("Env integration", function() { reporter.jasmineDone.and.callFake(function(e) { expect(e.overallStatus).toEqual('failed'); - done(); }); env.addReporter(reporter); env.it('passes', function() {}); global.onerror('Uncaught Error: ENOCHEESE'); - env.execute(); + env.execute(null, function() { + expect(reporter.jasmineDone).toHaveBeenCalled(); + done(); + }); }); }); @@ -2379,14 +2232,13 @@ describe("Env integration", function() { it('is "incomplete"', function(done) { var reporter = jasmine.createSpyObj('reporter', ['jasmineDone', 'suiteDone', 'specDone']); - reporter.jasmineDone.and.callFake(function(e) { + env.addReporter(reporter); + env.execute(null, function() { + var e = reporter.jasmineDone.calls.argsFor(0)[0]; expect(e.overallStatus).toEqual('incomplete'); expect(e.incompleteReason).toEqual('No specs found'); done(); }); - - env.addReporter(reporter); - env.execute(); }); }); @@ -2394,15 +2246,14 @@ describe("Env integration", function() { it('is "incomplete"', function(done) { var reporter = jasmine.createSpyObj('reporter', ['jasmineDone', 'suiteDone', 'specDone']); - reporter.jasmineDone.and.callFake(function(e) { + env.addReporter(reporter); + env.fit('is focused', function() {}); + env.execute(null, function(e) { + var e = reporter.jasmineDone.calls.argsFor(0)[0]; expect(e.overallStatus).toEqual('incomplete'); expect(e.incompleteReason).toEqual('fit() or fdescribe() was found'); done(); }); - - env.addReporter(reporter); - env.fit('is focused', function() {}); - env.execute(); }); }); @@ -2410,17 +2261,16 @@ describe("Env integration", function() { it('is "incomplete"', function(done) { var reporter = jasmine.createSpyObj('reporter', ['jasmineDone', 'suiteDone', 'specDone']); - reporter.jasmineDone.and.callFake(function(e) { - expect(e.overallStatus).toEqual('incomplete'); - expect(e.incompleteReason).toEqual('fit() or fdescribe() was found'); - done(); - }); - env.addReporter(reporter); env.fdescribe('something focused', function() { env.it('does a thing', function() {}); }); - env.execute(); + env.execute(null, function() { + var e = reporter.jasmineDone.calls.argsFor(0)[0]; + expect(e.overallStatus).toEqual('incomplete'); + expect(e.incompleteReason).toEqual('fit() or fdescribe() was found'); + done(); + }); }); }); @@ -2428,17 +2278,16 @@ describe("Env integration", function() { it('is "failed"', function(done) { var reporter = jasmine.createSpyObj('reporter', ['jasmineDone', 'suiteDone', 'specDone']); - reporter.jasmineDone.and.callFake(function(e) { - expect(e.overallStatus).toEqual('failed'); - expect(e.incompleteReason).toBeUndefined(); - done(); - }); - env.addReporter(reporter); env.fit('is focused', function() { env.expect(true).toBe(false); }); - env.execute(); + env.execute(null, function() { + var e = reporter.jasmineDone.calls.argsFor(0)[0]; + expect(e.overallStatus).toEqual('failed'); + expect(e.incompleteReason).toBeUndefined(); + done(); + }); }); }); }); @@ -2449,7 +2298,22 @@ describe("Env integration", function() { // prevent deprecation from being displayed spyOn(console, "error"); - reporter.jasmineDone.and.callFake(function(result) { + env.addReporter(reporter); + + env.deprecated('top level deprecation'); + + env.describe('suite', function() { + env.beforeAll(function() { + env.deprecated('suite level deprecation'); + }); + + env.it('spec', function() { + env.deprecated('spec level deprecation'); + }); + }); + + env.execute(null, function() { + var result = reporter.jasmineDone.calls.argsFor(0)[0]; expect(result.deprecationWarnings).toEqual([ jasmine.objectContaining({ message: 'top level deprecation' }) ]); @@ -2470,22 +2334,6 @@ describe("Env integration", function() { done(); }); - - env.addReporter(reporter); - - env.deprecated('top level deprecation'); - - env.describe('suite', function() { - env.beforeAll(function() { - env.deprecated('suite level deprecation'); - }); - - env.it('spec', function() { - env.deprecated('spec level deprecation'); - }); - }); - - env.execute(); }); it('should report deprecation stack with an error object', function(done) { @@ -2500,7 +2348,22 @@ describe("Env integration", function() { // prevent deprecation from being displayed spyOn(console, "error"); - reporter.jasmineDone.and.callFake(function(result) { + env.addReporter(reporter); + + env.deprecated(topLevelError); + + env.describe('suite', function() { + env.beforeAll(function() { + env.deprecated(suiteLevelError); + }); + + env.it('spec', function() { + env.deprecated(specLevelError); + }); + }); + + env.execute(null, function() { + var result = reporter.jasmineDone.calls.argsFor(0)[0]; expect(result.deprecationWarnings).toEqual([ jasmine.objectContaining({ message: topLevelError.message, @@ -2530,54 +2393,19 @@ describe("Env integration", function() { done(); }); - - env.addReporter(reporter); - - env.deprecated(topLevelError); - - env.describe('suite', function() { - env.beforeAll(function() { - env.deprecated(suiteLevelError); - }); - - env.it('spec', function() { - env.deprecated(specLevelError); - }); - }); - - env.execute(); }); it('supports async matchers', function(done) { jasmine.getEnv().requirePromises(); var specDone = jasmine.createSpy('specDone'), - suiteDone = jasmine.createSpy('suiteDone'); + suiteDone = jasmine.createSpy('suiteDone'), + jasmineDone = jasmine.createSpy('jasmineDone'); env.addReporter({ specDone: specDone, suiteDone: suiteDone, - jasmineDone: function(result) { - expect(result.failedExpectations).toEqual([jasmine.objectContaining({ - message: 'Expected [object Promise] to be rejected.' - })]); - - expect(specDone).toHaveBeenCalledWith(jasmine.objectContaining({ - description: 'has an async failure', - failedExpectations: [jasmine.objectContaining({ - message: 'Expected [object Promise] to be rejected.' - })] - })); - - expect(suiteDone).toHaveBeenCalledWith(jasmine.objectContaining({ - description: 'a suite', - failedExpectations: [jasmine.objectContaining({ - message: 'Expected [object Promise] to be rejected.' - })] - })); - - done(); - } + jasmineDone: jasmineDone }); function fail(innerDone) { @@ -2593,7 +2421,28 @@ describe("Env integration", function() { env.it('has an async failure', fail); }); - env.execute(); + env.execute(null, function() { + var result = jasmineDone.calls.argsFor(0)[0]; + expect(result.failedExpectations).toEqual([jasmine.objectContaining({ + message: 'Expected [object Promise] to be rejected.' + })]); + + expect(specDone).toHaveBeenCalledWith(jasmine.objectContaining({ + description: 'has an async failure', + failedExpectations: [jasmine.objectContaining({ + message: 'Expected [object Promise] to be rejected.' + })] + })); + + expect(suiteDone).toHaveBeenCalledWith(jasmine.objectContaining({ + description: 'a suite', + failedExpectations: [jasmine.objectContaining({ + message: 'Expected [object Promise] to be rejected.' + })] + })); + + done(); + }); }); it('provides custom equality testers to async matchers', function(done) { @@ -2601,16 +2450,7 @@ describe("Env integration", function() { var specDone = jasmine.createSpy('specDone'); - env.addReporter({ - specDone: specDone, - jasmineDone: function() { - expect(specDone).toHaveBeenCalledWith(jasmine.objectContaining({ - description: 'has an async failure', - failedExpectations: [] - })); - done(); - } - }); + env.addReporter({specDone: specDone}); env.it('has an async failure', function() { env.addCustomEqualityTester(function() { return true; }); @@ -2618,7 +2458,13 @@ describe("Env integration", function() { return env.expectAsync(p).toBeResolvedTo('something else'); }); - env.execute(); + env.execute(null, function() { + expect(specDone).toHaveBeenCalledWith(jasmine.objectContaining({ + description: 'has an async failure', + failedExpectations: [] + })); + done(); + }); }); it('includes useful stack frames in async matcher failures', function(done) { @@ -2626,17 +2472,7 @@ describe("Env integration", function() { var specDone = jasmine.createSpy('specDone'); - env.addReporter({ - specDone: specDone, - jasmineDone: function() { - expect(specDone).toHaveBeenCalledWith(jasmine.objectContaining({ - failedExpectations: [jasmine.objectContaining({ - stack: jasmine.stringMatching('EnvSpec.js') - })] - })); - done(); - } - }); + env.addReporter({specDone: specDone}); env.it('has an async failure', function() { env.addCustomEqualityTester(function() { return true; }); @@ -2644,13 +2480,21 @@ describe("Env integration", function() { return env.expectAsync(p).toBeRejected(); }); - env.execute(); + env.execute(null, function() { + expect(specDone).toHaveBeenCalledWith(jasmine.objectContaining({ + failedExpectations: [jasmine.objectContaining({ + stack: jasmine.stringMatching('EnvSpec.js') + })] + })); + done(); + }); }); it('reports an error when an async expectation occurs after the spec finishes', function(done) { jasmine.getEnv().requirePromises(); var resolve, + jasmineDone = jasmine.createSpy('jasmineDone'), promise = new Promise(function(res) { resolve = res; }); // eslint-disable-line compat/compat env.describe('a suite', function() { @@ -2666,39 +2510,41 @@ describe("Env integration", function() { specDone: function() { resolve(); }, - jasmineDone: function (result) { - expect(result.failedExpectations).toEqual([ - jasmine.objectContaining({ - passed: false, - globalErrorType: 'lateExpectation', - message: 'Spec "a suite does not wait" ran a "toBeResolved" expectation ' + - 'after it finished.\n' + - 'Did you forget to return or await the result of expectAsync?', - matcherName: 'toBeResolved' - }), - jasmine.objectContaining({ - passed: false, - globalErrorType: 'lateExpectation', - message: 'Spec "a suite does not wait" ran a "toBeResolvedTo" expectation ' + - 'after it finished.\n' + - 'Message: "Expected a promise to be resolved to \'something else\' ' + - 'but it was resolved to undefined."\n' + - 'Did you forget to return or await the result of expectAsync?', - matcherName: 'toBeResolvedTo' - }) - ]); - - done(); - } + jasmineDone: jasmineDone }); - env.execute(); + env.execute(null, function () { + var result = jasmineDone.calls.argsFor(0)[0]; + expect(result.failedExpectations).toEqual([ + jasmine.objectContaining({ + passed: false, + globalErrorType: 'lateExpectation', + message: 'Spec "a suite does not wait" ran a "toBeResolved" expectation ' + + 'after it finished.\n' + + 'Did you forget to return or await the result of expectAsync?', + matcherName: 'toBeResolved' + }), + jasmine.objectContaining({ + passed: false, + globalErrorType: 'lateExpectation', + message: 'Spec "a suite does not wait" ran a "toBeResolvedTo" expectation ' + + 'after it finished.\n' + + 'Message: "Expected a promise to be resolved to \'something else\' ' + + 'but it was resolved to undefined."\n' + + 'Did you forget to return or await the result of expectAsync?', + matcherName: 'toBeResolvedTo' + }) + ]); + + done(); + }); }); it('reports an error when an async expectation occurs after the suite finishes', function(done) { jasmine.getEnv().requirePromises(); var resolve, + jasmineDone = jasmine.createSpy('jasmineDone'), promise = new Promise(function(res) { resolve = res; }); // eslint-disable-line compat/compat env.describe('a suite', function() { @@ -2715,23 +2561,24 @@ describe("Env integration", function() { suiteDone: function() { resolve(); }, - jasmineDone: function (result) { - expect(result.failedExpectations).toEqual([ - jasmine.objectContaining({ - passed: false, - globalErrorType: 'lateExpectation', - message: 'Suite "a suite" ran a "toBeResolved" expectation ' + - 'after it finished.\n' + - 'Did you forget to return or await the result of expectAsync?', - matcherName: 'toBeResolved' - }) - ]); - - done(); - } + jasmineDone: jasmineDone }); - env.execute(); + env.execute(null, function () { + var result = jasmineDone.calls.argsFor(0)[0]; + expect(result.failedExpectations).toEqual([ + jasmine.objectContaining({ + passed: false, + globalErrorType: 'lateExpectation', + message: 'Suite "a suite" ran a "toBeResolved" expectation ' + + 'after it finished.\n' + + 'Did you forget to return or await the result of expectAsync?', + matcherName: 'toBeResolved' + }) + ]); + + done(); + }); }); it("supports asymmetric equality testers that take a matchersUtil", function(done) { @@ -2759,7 +2606,89 @@ describe("Env integration", function() { expect(result.status).toEqual('passed'); }; - env.addReporter({ specDone: specExpectations, jasmineDone: done }); - env.execute(); + env.addReporter({ specDone: specExpectations }); + env.execute(null, done); + }); + + describe('The optional callback argument to #execute', function() { + beforeEach(function() { + this.savedInterval = jasmineUnderTest.DEFAULT_TIMEOUT_INTERVAL; + }); + + afterEach(function() { + jasmineUnderTest.DEFAULT_TIMEOUT_INTERVAL = this.savedInterval; + }); + + it('is called after reporter events are dispatched', function(done) { + var reporter = jasmine.createSpyObj( + 'reporter', + ['specDone', 'suiteDone', 'jasmineDone'] + ); + + env.addReporter(reporter); + env.describe('suite', function () { + env.it('spec', function() {}); + }); + + env.execute(null, function() { + expect(reporter.specDone).toHaveBeenCalled(); + expect(reporter.suiteDone).toHaveBeenCalled(); + expect(reporter.jasmineDone).toHaveBeenCalled(); + done(); + }); + }); + + it('is called after the stack is cleared', function(done) { + var realClearStack = jasmineUnderTest.getClearStack(jasmineUnderTest.getGlobal()), + clearStackSpy = jasmine.createSpy('clearStack').and.callFake(realClearStack); + spyOn(jasmineUnderTest, 'getClearStack').and.returnValue(clearStackSpy); + + // Create a new env that has the clearStack defined above + env.cleanup_(); + env = new jasmineUnderTest.Env(); + + env.describe('suite', function () { + env.it('spec', function() {}); + }); + + env.execute(null, function() { + expect(clearStackSpy).toHaveBeenCalled(); // (many times) + clearStackSpy.calls.reset(); + setTimeout(function() { + expect(clearStackSpy).not.toHaveBeenCalled(); + done(); + }); + }); + }); + + it('is called after QueueRunner timeouts are cleared', function(done) { + var setTimeoutSpy = spyOn(jasmineUnderTest.getGlobal(), 'setTimeout') + .and.callThrough(); + var clearTimeoutSpy = spyOn(jasmineUnderTest.getGlobal(), 'clearTimeout') + .and.callThrough(); + + jasmineUnderTest.DEFAULT_TIMEOUT_INTERVAL = 123456; // a distinctive value + + env = new jasmineUnderTest.Env(); + + env.describe('suite', function () { + env.it('spec', function () { + }); + }); + + env.execute(null, function () { + var timeoutIds = setTimeoutSpy.calls.all() + .filter(function(call) { return call.args[1] === 123456; }) + .map(function(call) { return call.returnValue; }); + + expect(timeoutIds.length).toBeGreaterThan(0); + + timeoutIds.forEach(function(timeoutId) { + expect(clearTimeoutSpy).toHaveBeenCalledWith(timeoutId); + }); + + done(); + }); + }); }); }); diff --git a/spec/core/integration/MatchersSpec.js b/spec/core/integration/MatchersSpec.js index 92b7307f..8174faf8 100644 --- a/spec/core/integration/MatchersSpec.js +++ b/spec/core/integration/MatchersSpec.js @@ -28,8 +28,8 @@ describe('Matchers (Integration)', function() { .toBeUndefined(); }; - env.addReporter({ specDone: specExpectations, jasmineDone: done }); - env.execute(); + env.addReporter({ specDone: specExpectations }); + env.execute(null, done); }); } @@ -54,8 +54,8 @@ describe('Matchers (Integration)', function() { .not.toEqual(''); }; - env.addReporter({ specDone: specExpectations, jasmineDone: done }); - env.execute(); + env.addReporter({ specDone: specExpectations }); + env.execute(null, done); }); } @@ -75,8 +75,8 @@ describe('Matchers (Integration)', function() { .toEqual(config.expectedMessage); }; - env.addReporter({specDone: specExpectations, jasmineDone: done}); - env.execute(); + env.addReporter({ specDone: specExpectations }); + env.execute(null, done); }); } @@ -101,8 +101,8 @@ describe('Matchers (Integration)', function() { .toBeUndefined(); }; - env.addReporter({ specDone: specExpectations, jasmineDone: done }); - env.execute(); + env.addReporter({ specDone: specExpectations }); + env.execute(null, done); }); } @@ -126,8 +126,8 @@ describe('Matchers (Integration)', function() { .not.toEqual(''); }; - env.addReporter({ specDone: specExpectations, jasmineDone: done }); - env.execute(); + env.addReporter({ specDone: specExpectations }); + env.execute(null, done); }); } @@ -149,8 +149,8 @@ describe('Matchers (Integration)', function() { .toEqual(config.expectedMessage); }; - env.addReporter({specDone: specExpectations, jasmineDone: done}); - env.execute(); + env.addReporter({ specDone: specExpectations }); + env.execute(null, done); }); } diff --git a/spec/core/integration/SpecRunningSpec.js b/spec/core/integration/SpecRunningSpec.js index d522cf86..33459d02 100644 --- a/spec/core/integration/SpecRunningSpec.js +++ b/spec/core/integration/SpecRunningSpec.js @@ -66,17 +66,14 @@ describe("spec running", function () { expect(bar).toEqual(0); expect(baz).toEqual(0); expect(quux).toEqual(0); - var assertions = function() { + + env.execute(null, function() { expect(foo).toEqual(1); expect(bar).toEqual(1); expect(baz).toEqual(1); expect(quux).toEqual(1); done(); - }; - - env.addReporter({ jasmineDone: assertions }); - - env.execute(); + }); }); it("should permit nested describes", function(done) { @@ -136,7 +133,7 @@ describe("spec running", function () { }); }); - var assertions = function() { + env.execute(null, function() { var expected = [ "topSuite beforeEach", "outer beforeEach", @@ -168,11 +165,7 @@ describe("spec running", function () { ]; expect(actions).toEqual(expected); done(); - }; - - env.addReporter({jasmineDone: assertions}); - - env.execute(); + }); }); it("should run multiple befores and afters ordered so functions declared later are treated as more specific", function(done) { @@ -232,7 +225,7 @@ describe("spec running", function () { }); }); - var assertions = function() { + env.execute(null, function() { var expected = [ "runner beforeAll1", "runner beforeAll2", @@ -250,11 +243,7 @@ describe("spec running", function () { ]; expect(actions).toEqual(expected); done(); - }; - - env.addReporter({jasmineDone: assertions}); - - env.execute(); + }); }); it('should run beforeAlls before beforeEachs and afterAlls after afterEachs', function(done) { @@ -298,7 +287,7 @@ describe("spec running", function () { }); }); - var assertions = function() { + env.execute(null, function() { var expected = [ "runner beforeAll", "inner beforeAll", @@ -312,10 +301,7 @@ describe("spec running", function () { ]; expect(actions).toEqual(expected); done(); - }; - - env.addReporter({jasmineDone: assertions}); - env.execute(); + }); }); it('should run beforeAlls and afterAlls in the order declared when runnablesToRun is provided', function(done) { @@ -365,7 +351,7 @@ describe("spec running", function () { }); }); - var assertions = function() { + env.execute([spec2.id, spec.id], function() { var expected = [ "runner beforeAll", "inner beforeAll", @@ -385,10 +371,7 @@ describe("spec running", function () { ]; expect(actions).toEqual(expected); done(); - }; - - env.addReporter({jasmineDone: assertions}); - env.execute([spec2.id, spec.id]); + }); }); it('only runs *Alls once in a focused suite', function(done){ @@ -406,13 +389,10 @@ describe("spec running", function () { }); }); - var assertions = function() { + env.execute(null, function() { expect(actions).toEqual(['beforeAll', 'spec', 'afterAll']); done(); - }; - - env.addReporter({jasmineDone: assertions}); - env.execute(); + }); }); describe('focused runnables', function() { @@ -435,7 +415,7 @@ describe("spec running", function () { }); }); - var assertions = function() { + env.execute(null, function() { var expected = [ 'beforeAll', 'beforeEach', @@ -449,10 +429,7 @@ describe("spec running", function () { ]; expect(actions).toEqual(expected); done(); - }; - - env.addReporter({jasmineDone: assertions}); - env.execute(); + }); }); it('focused specs in focused suites cause non-focused siblings to not run', function(done){ @@ -467,14 +444,11 @@ describe("spec running", function () { }); }); - var assertions = function() { + env.execute(null, function() { var expected = ['focused spec']; expect(actions).toEqual(expected); done(); - }; - - env.addReporter({jasmineDone: assertions}); - env.execute(); + }); }); it('focused suites in focused suites cause non-focused siblings to not run', function(done){ @@ -491,14 +465,11 @@ describe("spec running", function () { }); }); - var assertions = function() { + env.execute(null, function() { var expected = ['inner spec']; expect(actions).toEqual(expected); done(); - }; - - env.addReporter({jasmineDone: assertions}); - env.execute(); + }); }); it('focused runnables unfocus ancestor focused suites', function(done) { @@ -515,14 +486,11 @@ describe("spec running", function () { }); }); - var assertions = function() { + env.execute(null, function() { var expected = ['focused spec']; expect(actions).toEqual(expected); done(); - }; - - env.addReporter({jasmineDone: assertions}); - env.execute(); + }); }); }); @@ -534,14 +502,10 @@ describe("spec running", function () { }); }); - var assertions = function() { + env.execute(null, function() { expect(specInADisabledSuite).not.toHaveBeenCalled(); done(); - }; - - env.addReporter({jasmineDone: assertions}); - - env.execute(); + }); }); it("shouldn't run before/after functions in disabled suites", function(done) { @@ -556,14 +520,10 @@ describe("spec running", function () { env.it('spec inside a disabled suite', shouldNotRun); }); - var assertions = function() { + env.execute(null, function() { expect(shouldNotRun).not.toHaveBeenCalled(); done(); - }; - - env.addReporter({jasmineDone: assertions}); - - env.execute(); + }); }); it("should allow top level suites to be disabled", function(done) { @@ -577,15 +537,11 @@ describe("spec running", function () { env.it('another spec', otherSpec); }); - var assertions = function() { + env.execute(null, function() { expect(specInADisabledSuite).not.toHaveBeenCalled(); expect(otherSpec).toHaveBeenCalled(); done(); - }; - - env.addReporter({jasmineDone: assertions}); - - env.execute(); + }); }); it("should set all pending specs to pending when a suite is run", function(done) { @@ -594,31 +550,20 @@ describe("spec running", function () { pendingSpec = env.it("I am a pending spec"); }); - var assertions = function() { + env.execute(null, function() { expect(pendingSpec.status()).toBe("pending"); done(); - }; - - env.addReporter({jasmineDone: assertions}); - - env.execute(); + }); }); it("should recover gracefully when there are errors in describe functions", function(done) { var specs = [], - reporter = jasmine.createSpyObj(['specDone', 'suiteDone', 'jasmineDone']); + reporter = jasmine.createSpyObj(['specDone', 'suiteDone']); reporter.specDone.and.callFake(function(result) { specs.push(result.fullName); }); - reporter.jasmineDone.and.callFake(function() { - expect(specs).toEqual(['outer1 inner1 should thingy', 'outer1 inner2 should other thingy', 'outer2 should xxx']); - expect(reporter.suiteDone).toHaveFailedExpectationsForRunnable('outer1 inner1', [/inner error/]); - expect(reporter.suiteDone).toHaveFailedExpectationsForRunnable('outer1', [/outer error/]); - done(); - }); - expect(function() { env.describe("outer1", function() { env.describe("inner1", function() { @@ -647,7 +592,12 @@ describe("spec running", function () { }); env.addReporter(reporter); - env.execute(); + env.execute(null, function() { + expect(specs).toEqual(['outer1 inner1 should thingy', 'outer1 inner2 should other thingy', 'outer2 should xxx']); + expect(reporter.suiteDone).toHaveFailedExpectationsForRunnable('outer1 inner1', [/inner error/]); + expect(reporter.suiteDone).toHaveFailedExpectationsForRunnable('outer1', [/outer error/]); + done(); + }); }); it("re-enters suites that have no *Alls", function(done) { @@ -668,14 +618,10 @@ describe("spec running", function () { actions.push("spec3"); }); - env.addReporter({ - jasmineDone: function() { - expect(actions).toEqual(["spec2", "spec3", "spec1"]); - done(); - } + env.execute([spec2.id, spec3.id, spec1.id], function() { + expect(actions).toEqual(["spec2", "spec3", "spec1"]); + done(); }); - - env.execute([spec2.id, spec3.id, spec1.id]); }); it("refuses to re-enter suites with a beforeAll", function() { @@ -698,16 +644,10 @@ describe("spec running", function () { actions.push("spec3"); }); - env.addReporter({ - jasmineDone: function() { - expect(actions).toEqual([]); - done(); - } - }); - expect(function() { env.execute([spec2.id, spec3.id, spec1.id]); }).toThrowError(/beforeAll/); + expect(actions).toEqual([]); }); it("refuses to re-enter suites with a afterAll", function() { @@ -730,16 +670,10 @@ describe("spec running", function () { actions.push("spec3"); }); - env.addReporter({ - jasmineDone: function() { - expect(actions).toEqual([]); - done(); - } - }); - expect(function() { env.execute([spec2.id, spec3.id, spec1.id]); }).toThrowError(/afterAll/); + expect(actions).toEqual([]); }); it("should run the tests in a consistent order when a seed is supplied", function(done) { @@ -800,7 +734,7 @@ describe("spec running", function () { }); }); - var assertions = function() { + env.execute(null, function() { var expected = [ 'topSuite beforeEach', 'outer beforeEach', @@ -832,11 +766,7 @@ describe("spec running", function () { ]; expect(actions).toEqual(expected); done(); - }; - - env.addReporter({jasmineDone: assertions}); - - env.execute(); + }); }); describe("When throwOnExpectationFailure is set", function() { @@ -870,18 +800,14 @@ describe("spec running", function () { env.configure({oneFailurePerSpec: true}); - var assertions = function() { + env.execute(null, function() { expect(actions).toEqual([ 'outer beforeEach', 'inner afterEach', 'outer afterEach' ]); done(); - }; - - env.addReporter({jasmineDone: assertions}); - - env.execute(); + }); }); it("skips to cleanup functions after done.fail is called", function(done) { @@ -905,17 +831,13 @@ describe("spec running", function () { env.configure({oneFailurePerSpec: true}); - var assertions = function() { + env.execute(null, function() { expect(actions).toEqual([ 'beforeEach', 'afterEach' ]); done(); - }; - - env.addReporter({jasmineDone: assertions}); - - env.execute(); + }); }); it("skips to cleanup functions when an async function times out", function(done) { @@ -937,17 +859,13 @@ describe("spec running", function () { env.configure({oneFailurePerSpec: true}); - var assertions = function() { + env.execute(null, function() { expect(actions).toEqual([ 'beforeEach', 'afterEach' ]); done(); - }; - - env.addReporter({jasmineDone: assertions}); - - env.execute(); + }); }); it("skips to cleanup functions after an error with deprecations", function(done) { @@ -982,7 +900,7 @@ describe("spec running", function () { env.throwOnExpectationFailure(true); - var assertions = function() { + env.execute(null, function() { expect(actions).toEqual([ 'outer beforeEach', 'inner afterEach', @@ -990,11 +908,7 @@ describe("spec running", function () { ]); expect(env.deprecated).toHaveBeenCalled(); done(); - }; - - env.addReporter({jasmineDone: assertions}); - - env.execute(); + }); }); it("skips to cleanup functions after done.fail is called with deprecations", function(done) { @@ -1020,18 +934,14 @@ describe("spec running", function () { env.throwOnExpectationFailure(true); - var assertions = function() { + env.execute(null, function() { expect(actions).toEqual([ 'beforeEach', 'afterEach' ]); expect(env.deprecated).toHaveBeenCalled(); done(); - }; - - env.addReporter({jasmineDone: assertions}); - - env.execute(); + }); }); it("skips to cleanup functions when an async function times out with deprecations", function(done) { @@ -1055,18 +965,14 @@ describe("spec running", function () { env.throwOnExpectationFailure(true); - var assertions = function() { + env.execute(null, function() { expect(actions).toEqual([ 'beforeEach', 'afterEach' ]); expect(env.deprecated).toHaveBeenCalled(); done(); - }; - - env.addReporter({jasmineDone: assertions}); - - env.execute(); + }); }); }); @@ -1089,13 +995,10 @@ describe("spec running", function () { env.configure({random: false, failFast: true}); - var assertions = function() { + env.execute(null, function() { expect(actions).toEqual(['fails']); done(); - }; - - env.addReporter({ jasmineDone: assertions }); - env.execute(); + }); }); it("does not run further specs when one fails when configured with deprecated option", function(done) { @@ -1119,14 +1022,11 @@ describe("spec running", function () { env.configure({random: false}); env.stopOnSpecFailure(true); - var assertions = function() { + env.execute(null, function() { expect(actions).toEqual(['fails']); expect(env.deprecated).toHaveBeenCalled(); done(); - }; - - env.addReporter({ jasmineDone: assertions }); - env.execute(); + }); }); }); }); diff --git a/src/core/Env.js b/src/core/Env.js index d7fdd4c0..7e299717 100644 --- a/src/core/Env.js +++ b/src/core/Env.js @@ -705,7 +705,8 @@ getJasmineRequireObj().Env = function(j$) { queueRunnerFactory ); - this.execute = function(runnablesToRun) { + // Both params are optional. + this.execute = function(runnablesToRun, onComplete) { installGlobalErrors(); if (!runnablesToRun) { @@ -813,7 +814,11 @@ getJasmineRequireObj().Env = function(j$) { failedExpectations: topSuite.result.failedExpectations, deprecationWarnings: topSuite.result.deprecationWarnings }, - function() {} + function() { + if (onComplete) { + onComplete(); + } + } ); }); } diff --git a/src/core/QueueRunner.js b/src/core/QueueRunner.js index 28c1153f..df383632 100644 --- a/src/core/QueueRunner.js +++ b/src/core/QueueRunner.js @@ -1,4 +1,6 @@ getJasmineRequireObj().QueueRunner = function(j$) { + var nextid = 1; + function StopExecutionError() {} StopExecutionError.prototype = new Error(); j$.StopExecutionError = StopExecutionError; @@ -18,6 +20,7 @@ getJasmineRequireObj().QueueRunner = function(j$) { function emptyFn() {} function QueueRunner(attrs) { + this.id_ = nextid++; var queueableFns = attrs.queueableFns || []; this.queueableFns = queueableFns.concat(attrs.cleanupFns || []); this.firstCleanupIx = queueableFns.length;