diff --git a/jasmine.iws b/jasmine.iws index d1ede82..ab28ee2 100644 --- a/jasmine.iws +++ b/jasmine.iws @@ -79,20 +79,20 @@ - - - - + + + + - + @@ -101,7 +101,7 @@ - + @@ -110,7 +110,7 @@ - + @@ -118,14 +118,14 @@ - - - + + + @@ -305,6 +305,40 @@ + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - localhost @@ -507,15 +507,25 @@ - + + + + + + + + + + + @@ -533,31 +543,21 @@ - - - - - - - - - - - + - + - + diff --git a/lib/jasmine.js b/lib/jasmine.js index b9c84e3..efc9f30 100755 --- a/lib/jasmine.js +++ b/lib/jasmine.js @@ -58,7 +58,7 @@ var nestedResults = function() { * **/ var actionCollection = function () { - var that = { + var that = { actions: [], index: 0, finished: false, @@ -202,7 +202,15 @@ var it = function (description, func) { that.currentTimeout = 0; }, + finishCallback: function () { + if (Jasmine.reporter) { + Jasmine.reporter.addSpecResults(that.results); + Jasmine.reporter.report(); + } + }, + finish: function() { + that.finishCallback(); that.finished = true; }, diff --git a/lib/json_reporter.js b/lib/json_reporter.js index a9c6f53..cdacc46 100644 --- a/lib/json_reporter.js +++ b/lib/json_reporter.js @@ -1,26 +1,44 @@ -JasmineReporters.JSON = function (elementId) { +JasmineReporters.reporter = function (elementId) { var that = { - elementId: elementId, - results: {}, + element: document.getElementById(elementId), + output: '', - addResults: function (results) { - that.results = results; - }, + addResults: function (results) { that.output = ''; }, + + addSpecResults: function (results) { that.output = ''; }, report: function () { - var output = Object.toJSON(that.results); - - if (that.elementId) { - var element = document.getElementById(that.elementId); - if (element) { - element.innerHTML = output; - } + if (that.element) { + that.element.innerHTML += that.output; } - return output; + return that.output; } } + + // TODO: throw if no element? + if (that.element) { + that.element.innerHTML = ''; + } + return that; } -Jasmine.reporter = JasmineReporters.JSON(); - \ No newline at end of file +JasmineReporters.JSON = function (elementId) { + var that = JasmineReporters.reporter(elementId); + + that.addResults = function (results) { + that.output = Object.toJSON(results); + } + + return that; +} + +JasmineReporters.IncrementalJSON = function (elementId) { + var that = JasmineReporters.reporter(elementId); + + that.addSpecResults = function (results) { + that.output = Object.toJSON(results); + } + + return that; +} \ No newline at end of file diff --git a/test/bootstrap.html b/test/bootstrap.html index b216b31..4c2ef58 100755 --- a/test/bootstrap.html +++ b/test/bootstrap.html @@ -27,6 +27,7 @@ + diff --git a/test/bootstrap.js b/test/bootstrap.js index 024c4f2..0e8dbbf 100755 --- a/test/bootstrap.js +++ b/test/bootstrap.js @@ -91,7 +91,8 @@ var testMatchersReporting = function () { } var testSpecs = function () { - var currentSuite = describe('default current suite', function() {}); + var currentSuite = describe('default current suite', function() { + }); var spec = it('new spec'); reporter.test((spec.description == 'new spec'), @@ -549,7 +550,7 @@ var testRunnerFinishCallback = function () { runner.finish(); reporter.test((runner.finished === true), - "Runner finished flag was not set."); + "Runner finished flag was not set."); runner.finishCallback = function () { foo++; @@ -558,13 +559,12 @@ var testRunnerFinishCallback = function () { runner.finish(); reporter.test((runner.finished === true), - "Runner finished flag was not set."); + "Runner finished flag was not set."); reporter.test((foo === 1), - "Runner finish callback was not called"); + "Runner finish callback was not called"); } - var testNestedResults = function () { // Leaf case @@ -650,7 +650,7 @@ var testResults = function () { var testJSONReporter = function () { var runner = Runner(); - describe('one suite description', function () { + describe('Suite for JSON Reporter, NO DOM', function () { it('should be a test', function() { runs(function () { this.expects_that(true).should_equal(true); @@ -661,22 +661,22 @@ var testJSONReporter = function () { runner.reporter = JasmineReporters.JSON(); reporter.test((runner.reporter !== undefined), - "Runner's reporter is undefined"); + "Runner's reporter is undefined"); reporter.test((runner.finishCallback !== undefined), - "Runner's finishCallback is 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"}'; + var 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": "Suite for JSON Reporter, NO DOM"}], "description": "All Jasmine Suites"}'; setTimeout(function() { - reporter.test((runner.reporter.report() === expectedJSONString), - 'Jasmine Reporter does not have the expected report, has: ' + runner.reporter.report()); + reporter.test((runner.reporter.output === expectedJSONString), + 'Jasmine Reporter with No DOM does not have the expected report.
Expected:
' + expectedJSONString + '
Got:
' + runner.reporter.output); }, 500); } var testJSONReporterWithDOM = function () { var runner = Runner(); - describe('one suite description', function () { + describe('Suite for JSON Reporter/DOM', function () { it('should be a test', function() { runs(function () { this.expects_that(true).should_equal(true); @@ -688,14 +688,43 @@ var testJSONReporterWithDOM = function () { 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"}'; + var 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": "Suite for JSON Reporter/DOM"}], "description": "All Jasmine Suites"}'; setTimeout(function() { reporter.test((document.getElementById('json_reporter_results').innerHTML === expectedJSONString), - 'Jasmine Reporter did not output the string to the DOM'); - + 'Jasmine Reporter did not output the string to the DOM, got:' + document.getElementById('json_reporter_results').innerHTML); }, 500); } +var testJSONReporterWithIncrementalSpecReports = function() { + setTimeout( function () { + var runner = Runner(); + describe('Suite for Incremental JSON Reporter/DOM', function () { + it('should be a test', function() { + runs(function () { + this.expects_that(true).should_equal(true); + }); + }); + it('should be a failing test', function() { + runs(function () { + this.expects_that(false).should_equal(true); + }); + }); + }); + + runner.reporter = JasmineReporters.IncrementalJSON('json_reporter_results_incremental'); + runner.execute(); + var expectedJSONString = '{"totalCount": 1, "passedCount": 1, "failedCount": 0, "results": [{"passed": true, "message": "Passed."}], "description": "should be a test"}{"totalCount": 1, "passedCount": 0, "failedCount": 1, "results": [{"passed": false, "message": "Expected true but got false."}], "description": "should be a failing test"}' + + setTimeout(function() { + reporter.test((document.getElementById('json_reporter_results_incremental').innerHTML === expectedJSONString), + 'Jasmine Incremental Reporter did not output the correct string to the DOM, got ' + document.getElementById('json_reporter_results_incremental').innerHTML); + + }, 500); + }, 2500); + +} + + var runTests = function () { $('spinner').show(); @@ -713,6 +742,7 @@ var runTests = function () { testResults(); testJSONReporter(); testJSONReporterWithDOM(); + testJSONReporterWithIncrementalSpecReports(); setTimeout(function() { $('spinner').hide();