From cc164257a78c8b9910597f292088f5c60ef659aa Mon Sep 17 00:00:00 2001 From: pivotal Date: Thu, 4 Dec 2008 10:56:58 -0800 Subject: [PATCH] dwf/rva: added JSONReporter --- jasmine.iws | 128 ++++++++++++++++++++++++------------------- lib/jasmine.js | 10 ++++ lib/json_reporter.js | 17 ++++++ test/bootstrap.html | 1 + test/bootstrap.js | 37 ++++++++++--- 5 files changed, 130 insertions(+), 63 deletions(-) create mode 100644 lib/json_reporter.js diff --git a/jasmine.iws b/jasmine.iws index abf9ed5..1e3128d 100644 --- a/jasmine.iws +++ b/jasmine.iws @@ -79,29 +79,38 @@ + + + + + + + + + - + - + - + - + - + @@ -109,14 +118,14 @@ - - - + + + @@ -296,6 +305,39 @@ + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - localhost @@ -498,15 +507,15 @@ - - - - + - + + + + @@ -522,26 +531,33 @@ - + + + + + + + + - + + + + + + + + - - - - - - - - + diff --git a/lib/jasmine.js b/lib/jasmine.js index 74b0d3f..b9c84e3 100755 --- a/lib/jasmine.js +++ b/lib/jasmine.js @@ -279,14 +279,24 @@ var Runner = function () { that.suites = that.actions; that.results.description = 'All Jasmine Suites'; + that.finishCallback = function () { + if (that.reporter) { + that.reporter.addResults(that.results); + that.reporter.report(); + } + } + Jasmine = that; return that; } +var JasmineReporters = {}; + var Jasmine = Runner(); var currentSuite; var currentSpec; + /* * TODO: //* - add spec or description to results diff --git a/lib/json_reporter.js b/lib/json_reporter.js new file mode 100644 index 0000000..11e397c --- /dev/null +++ b/lib/json_reporter.js @@ -0,0 +1,17 @@ +JasmineReporters.JSON = function () { + var that = { + results: {}, + + addResults: function (results) { + that.results = results; + }, + + report: function () { + return Object.toJSON(that.results); + } + } + return that; +} + +Jasmine.reporter = JasmineReporters.JSON(); + \ No newline at end of file diff --git a/test/bootstrap.html b/test/bootstrap.html index d344948..4b20bfd 100755 --- a/test/bootstrap.html +++ b/test/bootstrap.html @@ -5,6 +5,7 @@ Jasmine Tests + diff --git a/test/bootstrap.js b/test/bootstrap.js index d2f8d13..636a6d8 100755 --- a/test/bootstrap.js +++ b/test/bootstrap.js @@ -544,15 +544,13 @@ var testRunner = function() { var testRunnerFinishCallback = function () { var runner = Runner(); var foo = 0; + var s runner.finish(); - reporter.test((runner.finishCallback === undefined), - "Runner finish callback was defined"); reporter.test((runner.finished === true), "Runner finished flag was not set."); - runner.finishCallback = function () { foo++; } @@ -561,8 +559,6 @@ var testRunnerFinishCallback = function () { reporter.test((runner.finished === true), "Runner finished flag was not set."); - reporter.test((runner.finishCallback !== undefined), - "Runner finish callback was not defined"); reporter.test((foo === 1), "Runner finish callback was not called"); } @@ -619,7 +615,7 @@ var testNestedResults = function () { "Branch Results should have 2 failed, has " + branchResults.failedCount); } -var testReporting = function () { +var testResults = function () { var runner = Runner(); describe('one suite description', function () { it('should be a test', function() { @@ -652,6 +648,32 @@ var testReporting = function () { } +var testJSONReporter = function () { + var runner = Runner(); + describe('one suite description', function () { + it('should be a test', function() { + runs(function () { + this.expects_that(true).should_equal(true); + }); + }); + }); + + runner.reporter = JasmineReporters.JSON(); + + reporter.test((runner.reporter !== undefined), + "Runner's reporter is undefined"); + reporter.test((runner.finishCallback !== undefined), + "Runner's finishCallback is undefined"); + + runner.execute(); + + expectedJSONString = '{"totalCount": 1, "passedCount": 1, "failedCount": 0, "results": [{"totalCount": 1, "passedCount": 1, "failedCount": 0, "results": [{"totalCount": 1, "passedCount": 1, "failedCount": 0, "results": [{"passed": true, "message": "Passed."}], "description": "should be a test"}], "description": "one suite description"}], "description": "All Jasmine Suites"}'; + setTimeout(function() { + reporter.test((runner.reporter.report() === expectedJSONString), + 'Jasmine Reporter does not have the expected report, has: ' + runner.reporter.report()); + }, 500); +} + var runTests = function () { $('spinner').show(); @@ -666,7 +688,8 @@ var runTests = function () { testRunner(); testRunnerFinishCallback(); testNestedResults(); - testReporting(); + testResults(); + testJSONReporter(); setTimeout(function() { $('spinner').hide();