Add jasmine.Reporter no-op base class for reporters.

This commit is contained in:
Christian Williams 2009-07-08 18:18:17 -07:00
parent 0c24c2df2e
commit e1408a9f58
8 changed files with 79 additions and 7 deletions

View File

@ -2,7 +2,7 @@ desc 'Builds lib/jasmine from source'
task :build do
# these files must be better
sources = ["src/base.js", "src/util.js", "src/Env.js"]
sources = ["src/base.js", "src/util.js", "src/Env.js", "src/ActionCollection.js", "src/Reporter.js"]
sources += Dir.glob('src/*.js').reject{|f| sources.include?(f)}

View File

@ -569,7 +569,8 @@ jasmine.util.argsToArray = function(args) {
/**
* Environment for Jasmine
* @
*
* @constructor
*/
jasmine.Env = function() {
this.currentSpec = null;
@ -597,7 +598,7 @@ 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.
* @param {jasmine.Reporter} reporter An object which will receive status updates.
*/
jasmine.Env.prototype.addReporter = function(reporter) {
this.reporter.addReporter(reporter);
@ -844,6 +845,29 @@ jasmine.ActionCollection.prototype.waitForDone = function(action) {
}
}, 150);
};
/** No-op base class for Jasmine reporters.
*
* @constructor
*/
jasmine.Reporter = function() {
};
//noinspection JSUnusedLocalSymbols
jasmine.Reporter.prototype.reportRunnerResults = function(runner) {
};
//noinspection JSUnusedLocalSymbols
jasmine.Reporter.prototype.reportSuiteResults = function(suite) {
};
//noinspection JSUnusedLocalSymbols
jasmine.Reporter.prototype.reportSpecResults = function(spec) {
};
//noinspection JSUnusedLocalSymbols
jasmine.Reporter.prototype.log = function (str) {
};
jasmine.Matchers = function(env, actual, results) {
this.env = env;
this.actual = actual;
@ -1280,6 +1304,7 @@ window.clearInterval = function(timeoutKey) {
jasmine.MultiReporter = function() {
this.subReporters_ = [];
};
jasmine.util.inherit(jasmine.MultiReporter, jasmine.Reporter);
jasmine.MultiReporter.prototype.addReporter = function(reporter) {
this.subReporters_.push(reporter);

View File

@ -10,6 +10,7 @@
<script type="text/javascript" src="../src/util.js"></script>
<script type="text/javascript" src="../src/Env.js"></script>
<script type="text/javascript" src="../src/ActionCollection.js"></script>
<script type="text/javascript" src="../src/Reporter.js"></script>
<script type="text/javascript" src="../src/Matchers.js"></script>
<script type="text/javascript" src="../src/MultiReporter.js"></script>
<script type="text/javascript" src="../src/NestedResults.js"></script>
@ -22,11 +23,11 @@
<script type="text/javascript" src="../src/mock-timeout.js"></script>
<script type="text/javascript" src="../lib/TrivialReporter.js"></script>
<script type="text/javascript" src="../lib/json_reporter.js"></script>
<script type="text/javascript">
jasmine.include('suites/ExceptionsTest.js', true);
jasmine.include('suites/EnvTest.js', true);
jasmine.include('suites/JsonReporterTest.js', true);
jasmine.include('suites/MatchersTest.js', true);
jasmine.include('suites/MultiReporterTest.js', true);

21
spec/suites/EnvTest.js Normal file
View File

@ -0,0 +1,21 @@
describe("jasmine.Env", function() {
describe("reporting", function() {
var env;
var fakeReporter;
beforeEach(function() {
env = new jasmine.Env();
fakeReporter = jasmine.createSpyObj("fakeReporter", ["log"]);
});
it("should allow reporters to be registered", function() {
env.addReporter(fakeReporter);
env.reporter.log("message");
expect(fakeReporter.log).wasCalledWith("message");
});
xit("should report when the tests start running", function() {
});
});
});

View File

@ -1,4 +1,4 @@
describe("MultiReporter", function() {
describe("jasmine.MultiReporter", function() {
it("should delegate to any and all subreporters", function() {
var multiReporter = new jasmine.MultiReporter();
var fakeReporter1 = jasmine.createSpyObj("fakeReporter1", ["reportSpecResults"]);

View File

@ -1,6 +1,7 @@
/**
* Environment for Jasmine
* @
*
* @constructor
*/
jasmine.Env = function() {
this.currentSpec = null;
@ -28,7 +29,7 @@ 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.
* @param {jasmine.Reporter} reporter An object which will receive status updates.
*/
jasmine.Env.prototype.addReporter = function(reporter) {
this.reporter.addReporter(reporter);

View File

@ -4,6 +4,7 @@
jasmine.MultiReporter = function() {
this.subReporters_ = [];
};
jasmine.util.inherit(jasmine.MultiReporter, jasmine.Reporter);
jasmine.MultiReporter.prototype.addReporter = function(reporter) {
this.subReporters_.push(reporter);

23
src/Reporter.js Normal file
View File

@ -0,0 +1,23 @@
/** No-op base class for Jasmine reporters.
*
* @constructor
*/
jasmine.Reporter = function() {
};
//noinspection JSUnusedLocalSymbols
jasmine.Reporter.prototype.reportRunnerResults = function(runner) {
};
//noinspection JSUnusedLocalSymbols
jasmine.Reporter.prototype.reportSuiteResults = function(suite) {
};
//noinspection JSUnusedLocalSymbols
jasmine.Reporter.prototype.reportSpecResults = function(spec) {
};
//noinspection JSUnusedLocalSymbols
jasmine.Reporter.prototype.log = function (str) {
};