Allow for registration of multiple Reporter with Jasmine.

This commit is contained in:
Christian Williams
2009-07-08 17:55:25 -07:00
parent 521f839753
commit a6aa9c652b
7 changed files with 98 additions and 8 deletions

View File

@@ -567,12 +567,18 @@ jasmine.util.argsToArray = function(args) {
return arrayOfArgs;
};
/**
* Environment for Jasmine
* @
*/
jasmine.Env = function() {
this.currentSpec = null;
this.currentSuite = null;
this.currentRunner = new jasmine.Runner(this);
this.currentlyRunningTests = false;
this.reporter = new jasmine.MultiReporter();
this.updateInterval = 0;
this.lastUpdate = 0;
this.specFilter = function() {
@@ -589,6 +595,14 @@ jasmine.Env.prototype.clearTimeout = jasmine.clearTimeout;
jasmine.Env.prototype.setInterval = jasmine.setInterval;
jasmine.Env.prototype.clearInterval = jasmine.clearInterval;
/**
* Register a reporter to receive status updates from Jasmine.
* @param {Object} reporter An object which will receive status updates.
*/
jasmine.Env.prototype.addReporter = function(reporter) {
this.reporter.addReporter(reporter);
};
jasmine.Env.prototype.execute = function() {
this.currentRunner.execute();
};
@@ -1260,6 +1274,30 @@ window.clearInterval = function(timeoutKey) {
return jasmine.Clock.installed.clearInterval.apply(this, arguments);
};
/**
* @constructor
*/
jasmine.MultiReporter = function() {
this.subReporters_ = [];
};
jasmine.MultiReporter.prototype.addReporter = function(reporter) {
this.subReporters_.push(reporter);
};
(function() {
var functionNames = ["reportRunnerResults", "reportSuiteResults", "reportSpecResults", "log"];
for (var i = 0; i < functionNames.length; i++) {
var functionName = functionNames[i];
jasmine.MultiReporter.prototype[functionName] = (function(functionName) {
return function() {
for (var j = 0; j < this.subReporters_.length; j++) {
this.subReporters_[j][functionName].apply(this.subReporters_[j], arguments);
}
};
})(functionName);
}
})();
/**
* Holds results for a set of Jasmine spec. Allows for the results array to hold another jasmine.NestedResults
*
@@ -1602,8 +1640,8 @@ jasmine.Runner.prototype.getResults = function() {
};
/**
* Internal representation of a Jasmine specification, or test.
* @private
* @constructs
*
* @constructor
* @param {jasmine.Env} env
* @param {jasmine.Suite} suite
* @param {String} description
@@ -1806,7 +1844,7 @@ jasmine.Spec.prototype.removeAllSpies = function() {
};
/**
* For storing & executing a Jasmine suite.
* Internal representation of a Jasmine suite.
*
* @constructor
* @param {jasmine.Env} env