diff --git a/Rakefile b/Rakefile index 63cc5c8b..f3922e4d 100644 --- a/Rakefile +++ b/Rakefile @@ -2,7 +2,7 @@ desc 'Builds lib/jasmine from source' task :build do # these files must be loaded first - sources = ["src/base.js", "src/util.js", "src/Env.js", "src/ActionCollection.js", "src/Reporter.js", "src/Block.js"] + sources = ["src/base.js", "src/util.js", "src/Env.js", "src/Reporter.js", "src/Block.js"] sources += Dir.glob('src/*.js').reject{|f| sources.include?(f)}.sort diff --git a/lib/jasmine.js b/lib/jasmine.js index d26b253a..cf8862c8 100644 --- a/lib/jasmine.js +++ b/lib/jasmine.js @@ -616,7 +616,7 @@ jasmine.Env.prototype.describe = function(description, specDefinitions) { if (parentSuite) { parentSuite.add(suite); } else { - this.currentRunner.suites.push(suite); + this.currentRunner.add(suite); } this.currentSuite = suite; @@ -754,98 +754,6 @@ jasmine.Env.prototype.contains_ = function(haystack, needle) { jasmine.Env.prototype.addEqualityTester = function(equalityTester) { this.equalityTesters_.push(equalityTester); }; -/** - * base for Runner & Suite: allows for a queue of functions to get executed, allowing for - * any one action to complete, including asynchronous calls, before going to the next - * action. - * - * @constructor - * @param {jasmine.Env} env - */ -jasmine.ActionCollection = function(env) { - this.env = env; - this.actions = []; - this.index = 0; - this.finished = false; -}; - -/** - * Marks the collection as done & calls the finish callback, if there is one - */ -jasmine.ActionCollection.prototype.finish = function() { - if (this.finishCallback) { - this.finishCallback(); - } - this.finished = true; -}; - -/** - * Starts executing the queue of functions/actions. - */ -jasmine.ActionCollection.prototype.execute = function() { - if (this.actions.length > 0) { - this.next(); - } -}; - -/** - * Gets the current action. - */ -jasmine.ActionCollection.prototype.getCurrentAction = function() { - return this.actions[this.index]; -}; - -/** - * Executes the next queued function/action. If there are no more in the queue, calls #finish. - */ -jasmine.ActionCollection.prototype.next = function() { - if (this.index >= this.actions.length) { - this.finish(); - return; - } - - var currentAction = this.getCurrentAction(); - - currentAction.execute(this); - - if (currentAction.afterCallbacks) { - for (var i = 0; i < currentAction.afterCallbacks.length; i++) { - try { - currentAction.afterCallbacks[i](); - } catch (e) { - alert(e); - } - } - } - - this.waitForDone(currentAction); -}; - -jasmine.ActionCollection.prototype.waitForDone = function(action) { - var self = this; - var afterExecute = function afterExecute() { - self.index++; - self.next(); - }; - - if (action.finished) { - var now = new Date().getTime(); - if (this.env.updateInterval && now - this.env.lastUpdate > this.env.updateInterval) { - this.env.lastUpdate = now; - this.env.setTimeout(afterExecute, 0); - } else { - afterExecute(); - } - return; - } - - var id = this.env.setInterval(function() { - if (action.finished) { - self.env.clearInterval(id); - afterExecute(); - } - }, 150); -}; /** No-op base class for Jasmine reporters. * * @constructor @@ -1562,27 +1470,35 @@ jasmine.Reporters.reporter = function(callbacks) { * @param {jasmine.Env} env */ jasmine.Runner = function(env) { - jasmine.ActionCollection.call(this, env); - - this.suites = this.actions; + var self = this; + self.env = env; + self.queue = new jasmine.Queue(); }; -jasmine.util.inherit(jasmine.Runner, jasmine.ActionCollection); jasmine.Runner.prototype.execute = function() { - if (this.env.reporter.reportRunnerStarting) { - this.env.reporter.reportRunnerStarting(this); + var self = this; + if (self.env.reporter.reportRunnerStarting) { + self.env.reporter.reportRunnerStarting(this); } - jasmine.ActionCollection.prototype.execute.call(this); + self.queue.start(function () { self.finishCallback(); }); }; jasmine.Runner.prototype.finishCallback = function() { this.env.reporter.reportRunnerResults(this); }; +jasmine.Runner.prototype.add = function(block) { + this.queue.add(block); +}; + jasmine.Runner.prototype.getResults = function() { var results = new jasmine.NestedResults(); - for (var i = 0; i < this.suites.length; i++) { - results.rollupCounts(this.suites[i].getResults()[0]); + var runnerResults = this.queue.getResults(); + for (var i=0; i < runnerResults.length; i++) { + var suiteResults = runnerResults[i]; + for (var j=0; j < suiteResults.length; j++) { + results.rollupCounts(suiteResults[j]); + } } return results; }; @@ -1789,7 +1705,7 @@ jasmine.Suite = function(env, description, specDefinitions, parentSuite) { var self = this; self.id = env.nextSuiteId_++; self.description = description; - self.queue = new jasmine.Queue(function () { self.finish(); }); + self.queue = new jasmine.Queue(); self.parentSuite = parentSuite; self.env = env; self.beforeQueue = []; diff --git a/spec/runner.html b/spec/runner.html index 595daaea..99db2a19 100644 --- a/spec/runner.html +++ b/spec/runner.html @@ -3,26 +3,25 @@ Jasmine Test Runner - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + - +