Refactor Runner to use Queue; remove ActionCollection
This commit is contained in:
@@ -1,92 +0,0 @@
|
||||
/**
|
||||
* 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);
|
||||
};
|
||||
@@ -47,7 +47,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;
|
||||
|
||||
@@ -5,27 +5,35 @@
|
||||
* @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;
|
||||
};
|
||||
};
|
||||
@@ -11,7 +11,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 = [];
|
||||
|
||||
Reference in New Issue
Block a user