diff --git a/example/example.html b/example/example.html index 1776bfb..000eb99 100644 --- a/example/example.html +++ b/example/example.html @@ -13,10 +13,10 @@
+ + + +diff --git a/example/example.js b/example/example.js index 1c72179..4c03804 100644 --- a/example/example.js +++ b/example/example.js @@ -1,7 +1,7 @@ describe('one suite description', function () { it('should be a test', function() { runs(function () { - this.expects_that(true).should_equal(true); + expect(true).toEqual(true); }); }); }); \ No newline at end of file diff --git a/lib/TrivialReporter.js b/lib/TrivialReporter.js new file mode 100644 index 0000000..14c35ea --- /dev/null +++ b/lib/TrivialReporter.js @@ -0,0 +1,61 @@ +jasmine.TrivialReporter = function() { +}; + +jasmine.TrivialReporter.prototype.createDom = function(type, attrs, childrenVarArgs) { + var el = document.createElement(type); + + for (var i = 2; i < arguments.length; i++) { + var child = arguments[i]; + + if (typeof child === 'string') { + el.appendChild(document.createTextNode(child)); + } else { + el.appendChild(child); + } + } + + for (var attr in attrs) { + if (attr == 'className') { + el.setAttribute('class', attrs[attr]); + } else { + if (attr.indexOf('x-') == 0) { + el.setAttribute(attr, attrs[attr]); + } else { + el[attr] = attrs[attr]; + } + } + } + + return el; +}; + +jasmine.TrivialReporter.prototype.reportRunnerResults = function(runner) { + console.log(runner); +}; + +jasmine.TrivialReporter.prototype.reportSuiteResults = function(suite) { + console.log(suite); +}; + +jasmine.TrivialReporter.prototype.reportSpecResults = function(spec) { + var specDiv = this.createDom('div', { + className: spec.getResults().passed() ? 'spec passed' : 'spec failed' + }, spec.getFullName()); + + var resultItems = spec.getResults().getItems(); + for (var i = 0; i < resultItems.length; i++) { + var result = resultItems[i]; + if (!result.passed) { + var resultMessageDiv = this.createDom('div', {className: 'resultMessage'}); + resultMessageDiv.innerHTML = result.message; // todo: lame; mend + specDiv.appendChild(resultMessageDiv); + specDiv.appendChild(this.createDom('div', {className: 'stackTrace'}, result.trace.stack)); + } + } + + document.body.appendChild(specDiv); +}; + +jasmine.TrivialReporter.prototype.log = function() { + console.log.apply(console, arguments); +}; diff --git a/lib/json_reporter.js b/lib/json_reporter.js index 07ab322..36fd4c3 100644 --- a/lib/json_reporter.js +++ b/lib/json_reporter.js @@ -1,62 +1,35 @@ /* - * JasmineReporters.JSON -- + * jasmine.Reporters.JSON -- * Basic reporter that keeps a JSON string of the most recent Spec, Suite or Runner * result. Calling application can then do whatever it wants/needs with the string; */ -Jasmine.Reporters.JSON = function () { +jasmine.Reporters.JSON = function () { var toJSON = function(object){ return JSON.stringify(object); }; - var that = Jasmine.Reporters.reporter(); + var that = jasmine.Reporters.reporter(); that.specJSON = ''; that.suiteJSON = ''; that.runnerJSON = ''; - var saveSpecResults = function (results) { - that.specJSON = toJSON(results); + var saveSpecResults = function (spec) { + that.specJSON = toJSON(spec.getResults()); }; that.reportSpecResults = saveSpecResults; - var saveSuiteResults = function (results) { - that.suiteJSON = toJSON(results); + var saveSuiteResults = function (suite) { + that.suiteJSON = toJSON(suite.getResults()); }; that.reportSuiteResults = saveSuiteResults; - var saveRunnerResults = function (results) { - that.runnerJSON = toJSON(results); + var saveRunnerResults = function (runner) { + that.runnerJSON = toJSON(runner.getResults()); }; that.reportRunnerResults = saveRunnerResults; + this.log = function (str) { + console.log(str); + }; that.toJSON = toJSON; return that; }; - -Jasmine.Reporters.domWriter = function (elementId) { - var that = { - element: document.getElementById(elementId), - - write: function (text) { - if (that.element) { - that.element.innerHTML += text; - } - } - }; - - that.element.innerHTML = ''; - - return that; -}; - -Jasmine.Reporters.JSONtoDOM = function (elementId) { - var that = Jasmine.Reporters.JSON(); - - that.domWriter = Jasmine.Reporters.domWriter(elementId); - - var writeRunnerResults = function (results) { - that.domWriter.write(that.toJSON(results)); - }; - - that.reportRunnerResults = writeRunnerResults; - - return that; -}; diff --git a/runner.html b/runner.html new file mode 100644 index 0000000..ba53236 --- /dev/null +++ b/runner.html @@ -0,0 +1,72 @@ + + +
+
+ + + + + + + + + + + + + + + + + + + + + + + +
+