From 7b91fc5a76ef61797491cd692cbe4131204a5f9d Mon Sep 17 00:00:00 2001 From: John Bintz Date: Wed, 26 Oct 2011 20:05:05 -0400 Subject: [PATCH] more furniture rearranging --- lib/jasmine/files_list.rb | 2 +- skel/template.html.erb | 13 ++- ...smine.HeadlessConsoleReporter_spec.coffee} | 4 +- spec/lib/jasmine/files_list_spec.rb | 2 +- .../jasmine.HeadlessConsoleReporter.coffee | 85 +++++++++++++++++ .../jasmine.headless-reporter.coffee | 80 ---------------- vendor/assets/coffeescripts/prolog.coffee | 3 +- .../jasmine.HeadlessConsoleReporter.js | 95 +++++++++++++++++++ .../javascripts/jasmine.headless-reporter.js | 88 +---------------- 9 files changed, 195 insertions(+), 177 deletions(-) rename spec/javascripts/{jasmine.headless-reporter_spec.coffee => jasmine.HeadlessConsoleReporter_spec.coffee} (97%) create mode 100644 vendor/assets/coffeescripts/jasmine.HeadlessConsoleReporter.coffee create mode 100644 vendor/assets/javascripts/jasmine.HeadlessConsoleReporter.js diff --git a/lib/jasmine/files_list.rb b/lib/jasmine/files_list.rb index 11b1504..828637d 100644 --- a/lib/jasmine/files_list.rb +++ b/lib/jasmine/files_list.rb @@ -27,7 +27,7 @@ module Jasmine File.join(Jasmine::Core.path, "jasmine.js"), File.join(Jasmine::Core.path, "jasmine-html.js"), File.join(Jasmine::Core.path, "jasmine.css") - ] + %w{jasmine-extensions intense headless_reporter_result jasmine.headless-reporter jsDump beautify-html}.collect { |name| + ] + %w{jasmine-extensions intense headless_reporter_result jasmine.HeadlessConsoleReporter jsDump beautify-html}.collect { |name| Jasmine::Headless.root.join("vendor/assets/javascripts/#{name}.js").to_s } diff --git a/skel/template.html.erb b/skel/template.html.erb index 7b7e363..05f7038 100644 --- a/skel/template.html.erb +++ b/skel/template.html.erb @@ -3,7 +3,7 @@ Jasmine Test Runner - Generated by jasmine-headless-webkit - <%= files.join("\n") %> diff --git a/spec/javascripts/jasmine.headless-reporter_spec.coffee b/spec/javascripts/jasmine.HeadlessConsoleReporter_spec.coffee similarity index 97% rename from spec/javascripts/jasmine.headless-reporter_spec.coffee rename to spec/javascripts/jasmine.HeadlessConsoleReporter_spec.coffee index f70203e..6696b95 100644 --- a/spec/javascripts/jasmine.headless-reporter_spec.coffee +++ b/spec/javascripts/jasmine.HeadlessConsoleReporter_spec.coffee @@ -12,11 +12,11 @@ describe 'HeadlessReporterResult', -> expect(HeadlessReporterResult.findSpecLine([ 'name', 'of', 'test' ]).lineNumber).toEqual(3) expect(HeadlessReporterResult.findSpecLine([ 'other', 'of', 'test' ]).lineNumber).toEqual(10) -describe 'jasmine.HeadlessReporter', -> +describe 'jasmine.HeadlessConsoleReporter', -> reporter = null beforeEach -> - reporter = new jasmine.HeadlessReporter() + reporter = new jasmine.HeadlessConsoleReporter() it 'should stop running specs if there are errors reported', -> # otherwise it gets really confusing! diff --git a/spec/lib/jasmine/files_list_spec.rb b/spec/lib/jasmine/files_list_spec.rb index 88775a5..bb39811 100644 --- a/spec/lib/jasmine/files_list_spec.rb +++ b/spec/lib/jasmine/files_list_spec.rb @@ -17,7 +17,7 @@ describe Jasmine::FilesList do File.expand_path('vendor/assets/javascripts/jasmine-extensions.js'), File.expand_path('vendor/assets/javascripts/intense.js'), File.expand_path('vendor/assets/javascripts/headless_reporter_result.js'), - File.expand_path('vendor/assets/javascripts/jasmine.headless-reporter.js'), + File.expand_path('vendor/assets/javascripts/jasmine.HeadlessConsoleReporter.js'), File.expand_path('vendor/assets/javascripts/jsDump.js'), File.expand_path('vendor/assets/javascripts/beautify-html.js'), ] diff --git a/vendor/assets/coffeescripts/jasmine.HeadlessConsoleReporter.coffee b/vendor/assets/coffeescripts/jasmine.HeadlessConsoleReporter.coffee new file mode 100644 index 0000000..c8448bb --- /dev/null +++ b/vendor/assets/coffeescripts/jasmine.HeadlessConsoleReporter.coffee @@ -0,0 +1,85 @@ +if !jasmine? + throw new Error("jasmine not loaded!") + +class jasmine.HeadlessConsoleReporter + constructor: (@callback = null) -> + @results = [] + @failedCount = 0 + @length = 0 + + reportRunnerResults: (runner) -> + return if this.hasError() + + if window.JHW + window.onbeforeunload = null + + runtime = (new Date() - @startTime) / 1000.0 + + JHW.stdout.print("\n") + + resultLine = this._formatResultLine(runtime) + + if @failedCount == 0 + JHW.stdout.puts("PASS: #{resultLine}".foreground('green')) + else + JHW.stdout.puts("FAIL: #{resultLine}".foreground('red')) + + output = "TOTAL||#{@length}||#{@failedCount}||#{runtime}||#{if JHW._hasErrors then "T" else "F"}" + + JHW.report.puts(output) + result.print() for result in @results + + JHW.finishSuite() + + reportRunnerStarting: (runner) -> + @startTime = new Date() + JHW.stdout.puts("\nRunning Jasmine specs...".bright()) + + reportSpecResults: (spec) -> + return if this.hasError() + + results = spec.results() + + @length++ + if results.passed() + JHW.stdout.print('.'.foreground('green')) + JHW.report.puts("PASS||" + spec.getJHWSpecInformation()) + else + JHW.stdout.print('F'.foreground('red')) + JHW.report.puts("FAIL||" + spec.getJHWSpecInformation()) + JHW.hasError() + + @failedCount++ + failureResult = new HeadlessReporterResult(spec.getFullName(), spec.getSpecSplitName()) + testCount = 1 + + for result in results.getItems() + if result.type == 'expect' and !result.passed_ + if foundLine = result.expectations[testCount - 1] + [ result.line, result.lineNumber ] = foundLine + failureResult.addResult(result) + testCount += 1 + @results.push(failureResult) + + reportSpecStarting: (spec) -> + if this.hasError() + spec.finish() + spec.suite.finish() + + reportSuiteResults: (suite) -> + hasError: -> + JHW._hasErrors + + _formatResultLine: (runtime) -> + line = [] + line.push(@length) + line.push((if @length == 1 then "test" else "tests") + ',') + + line.push(@failedCount) + line.push((if @failedCount == 1 then "failure" else "failures") + ',') + + line.push(runtime) + line.push((if runtime == 1.0 then "sec" else "secs") + '.') + + line.join(' ') + diff --git a/vendor/assets/coffeescripts/jasmine.headless-reporter.coffee b/vendor/assets/coffeescripts/jasmine.headless-reporter.coffee index 2a8dd2b..349ba69 100644 --- a/vendor/assets/coffeescripts/jasmine.headless-reporter.coffee +++ b/vendor/assets/coffeescripts/jasmine.headless-reporter.coffee @@ -3,83 +3,3 @@ if !jasmine? # The reporter itself. class jasmine.HeadlessReporter - constructor: (@callback = null) -> - @results = [] - @failedCount = 0 - @length = 0 - - reportRunnerResults: (runner) -> - return if this.hasError() - - this.callback() if @callback - - runtime = (new Date() - @startTime) / 1000.0 - - JHW.stdout.print("\n") - - resultLine = this._formatResultLine(runtime) - - if @failedCount == 0 - JHW.stdout.puts("PASS: #{resultLine}".foreground('green')) - else - JHW.stdout.puts("FAIL: #{resultLine}".foreground('red')) - - output = "TOTAL||#{@length}||#{@failedCount}||#{runtime}||#{if JHW._hasErrors then "T" else "F"}" - - JHW.report.puts(output) - result.print() for result in @results - - JHW.finishSuite() - - reportRunnerStarting: (runner) -> - @startTime = new Date() - JHW.stdout.puts("\nRunning Jasmine specs...".bright()) - - reportSpecResults: (spec) -> - return if this.hasError() - - results = spec.results() - - @length++ - if results.passed() - JHW.stdout.print('.'.foreground('green')) - JHW.report.puts("PASS||" + spec.getJHWSpecInformation()) - else - JHW.stdout.print('F'.foreground('red')) - JHW.report.puts("FAIL||" + spec.getJHWSpecInformation()) - JHW.hasError() - - @failedCount++ - failureResult = new HeadlessReporterResult(spec.getFullName(), spec.getSpecSplitName()) - testCount = 1 - - for result in results.getItems() - if result.type == 'expect' and !result.passed_ - if foundLine = result.expectations[testCount - 1] - [ result.line, result.lineNumber ] = foundLine - failureResult.addResult(result) - testCount += 1 - @results.push(failureResult) - - reportSpecStarting: (spec) -> - if this.hasError() - spec.finish() - spec.suite.finish() - - reportSuiteResults: (suite) -> - hasError: -> - JHW._hasErrors - - _formatResultLine: (runtime) -> - line = [] - line.push(@length) - line.push((if @length == 1 then "test" else "tests") + ',') - - line.push(@failedCount) - line.push((if @failedCount == 1 then "failure" else "failures") + ',') - - line.push(runtime) - line.push((if runtime == 1.0 then "sec" else "secs") + '.') - - line.join(' ') - diff --git a/vendor/assets/coffeescripts/prolog.coffee b/vendor/assets/coffeescripts/prolog.coffee index b22c572..8e2c025 100644 --- a/vendor/assets/coffeescripts/prolog.coffee +++ b/vendor/assets/coffeescripts/prolog.coffee @@ -18,8 +18,10 @@ if window.JHW JHW.log(dump) else JHW.log("jsDump: #{dump}") + pp: (data) -> JHW.log(if jasmine then jasmine.pp(data) else console.log(data)) + peek: (data) -> console.log(data) data @@ -37,7 +39,6 @@ if window.JHW JHW.stderr.puts("[alert] ".foreground('red') + message) JHW._hasErrors = false - JHW._handleError = (message, lineNumber, sourceURL) -> JHW.stderr.puts(message) JHW._hasErrors = true diff --git a/vendor/assets/javascripts/jasmine.HeadlessConsoleReporter.js b/vendor/assets/javascripts/jasmine.HeadlessConsoleReporter.js new file mode 100644 index 0000000..74b07c1 --- /dev/null +++ b/vendor/assets/javascripts/jasmine.HeadlessConsoleReporter.js @@ -0,0 +1,95 @@ +(function() { + if (!(typeof jasmine !== "undefined" && jasmine !== null)) { + throw new Error("jasmine not loaded!"); + } + jasmine.HeadlessConsoleReporter = (function() { + function HeadlessConsoleReporter(callback) { + this.callback = callback != null ? callback : null; + this.results = []; + this.failedCount = 0; + this.length = 0; + } + HeadlessConsoleReporter.prototype.reportRunnerResults = function(runner) { + var output, result, resultLine, runtime, _i, _len, _ref; + if (this.hasError()) { + return; + } + if (window.JHW) { + window.onbeforeunload = null; + } + runtime = (new Date() - this.startTime) / 1000.0; + JHW.stdout.print("\n"); + resultLine = this._formatResultLine(runtime); + if (this.failedCount === 0) { + JHW.stdout.puts(("PASS: " + resultLine).foreground('green')); + } else { + JHW.stdout.puts(("FAIL: " + resultLine).foreground('red')); + } + output = "TOTAL||" + this.length + "||" + this.failedCount + "||" + runtime + "||" + (JHW._hasErrors ? "T" : "F"); + JHW.report.puts(output); + _ref = this.results; + for (_i = 0, _len = _ref.length; _i < _len; _i++) { + result = _ref[_i]; + result.print(); + } + return JHW.finishSuite(); + }; + HeadlessConsoleReporter.prototype.reportRunnerStarting = function(runner) { + this.startTime = new Date(); + return JHW.stdout.puts("\nRunning Jasmine specs...".bright()); + }; + HeadlessConsoleReporter.prototype.reportSpecResults = function(spec) { + var failureResult, foundLine, result, results, testCount, _i, _len, _ref; + if (this.hasError()) { + return; + } + results = spec.results(); + this.length++; + if (results.passed()) { + JHW.stdout.print('.'.foreground('green')); + return JHW.report.puts("PASS||" + spec.getJHWSpecInformation()); + } else { + JHW.stdout.print('F'.foreground('red')); + JHW.report.puts("FAIL||" + spec.getJHWSpecInformation()); + JHW.hasError(); + this.failedCount++; + failureResult = new HeadlessReporterResult(spec.getFullName(), spec.getSpecSplitName()); + testCount = 1; + _ref = results.getItems(); + for (_i = 0, _len = _ref.length; _i < _len; _i++) { + result = _ref[_i]; + if (result.type === 'expect' && !result.passed_) { + if (foundLine = result.expectations[testCount - 1]) { + result.line = foundLine[0], result.lineNumber = foundLine[1]; + } + failureResult.addResult(result); + } + testCount += 1; + } + return this.results.push(failureResult); + } + }; + HeadlessConsoleReporter.prototype.reportSpecStarting = function(spec) { + if (this.hasError()) { + spec.finish(); + return spec.suite.finish(); + } + }; + HeadlessConsoleReporter.prototype.reportSuiteResults = function(suite) {}; + HeadlessConsoleReporter.prototype.hasError = function() { + return JHW._hasErrors; + }; + HeadlessConsoleReporter.prototype._formatResultLine = function(runtime) { + var line; + line = []; + line.push(this.length); + line.push((this.length === 1 ? "test" : "tests") + ','); + line.push(this.failedCount); + line.push((this.failedCount === 1 ? "failure" : "failures") + ','); + line.push(runtime); + line.push((runtime === 1.0 ? "sec" : "secs") + '.'); + return line.join(' '); + }; + return HeadlessConsoleReporter; + })(); +}).call(this); diff --git a/vendor/assets/javascripts/jasmine.headless-reporter.js b/vendor/assets/javascripts/jasmine.headless-reporter.js index c0a7272..871018c 100644 --- a/vendor/assets/javascripts/jasmine.headless-reporter.js +++ b/vendor/assets/javascripts/jasmine.headless-reporter.js @@ -3,93 +3,7 @@ throw new Error("jasmine not laoded!"); } jasmine.HeadlessReporter = (function() { - function HeadlessReporter(callback) { - this.callback = callback != null ? callback : null; - this.results = []; - this.failedCount = 0; - this.length = 0; - } - HeadlessReporter.prototype.reportRunnerResults = function(runner) { - var output, result, resultLine, runtime, _i, _len, _ref; - if (this.hasError()) { - return; - } - if (this.callback) { - this.callback(); - } - runtime = (new Date() - this.startTime) / 1000.0; - JHW.stdout.print("\n"); - resultLine = this._formatResultLine(runtime); - if (this.failedCount === 0) { - JHW.stdout.puts(("PASS: " + resultLine).foreground('green')); - } else { - JHW.stdout.puts(("FAIL: " + resultLine).foreground('red')); - } - output = "TOTAL||" + this.length + "||" + this.failedCount + "||" + runtime + "||" + (JHW._hasErrors ? "T" : "F"); - JHW.report.puts(output); - _ref = this.results; - for (_i = 0, _len = _ref.length; _i < _len; _i++) { - result = _ref[_i]; - result.print(); - } - return JHW.finishSuite(); - }; - HeadlessReporter.prototype.reportRunnerStarting = function(runner) { - this.startTime = new Date(); - return JHW.stdout.puts("\nRunning Jasmine specs...".bright()); - }; - HeadlessReporter.prototype.reportSpecResults = function(spec) { - var failureResult, foundLine, result, results, testCount, _i, _len, _ref; - if (this.hasError()) { - return; - } - results = spec.results(); - this.length++; - if (results.passed()) { - JHW.stdout.print('.'.foreground('green')); - return JHW.report.puts("PASS||" + spec.getJHWSpecInformation()); - } else { - JHW.stdout.print('F'.foreground('red')); - JHW.report.puts("FAIL||" + spec.getJHWSpecInformation()); - JHW.hasError(); - this.failedCount++; - failureResult = new HeadlessReporterResult(spec.getFullName(), spec.getSpecSplitName()); - testCount = 1; - _ref = results.getItems(); - for (_i = 0, _len = _ref.length; _i < _len; _i++) { - result = _ref[_i]; - if (result.type === 'expect' && !result.passed_) { - if (foundLine = result.expectations[testCount - 1]) { - result.line = foundLine[0], result.lineNumber = foundLine[1]; - } - failureResult.addResult(result); - } - testCount += 1; - } - return this.results.push(failureResult); - } - }; - HeadlessReporter.prototype.reportSpecStarting = function(spec) { - if (this.hasError()) { - spec.finish(); - return spec.suite.finish(); - } - }; - HeadlessReporter.prototype.reportSuiteResults = function(suite) {}; - HeadlessReporter.prototype.hasError = function() { - return JHW._hasErrors; - }; - HeadlessReporter.prototype._formatResultLine = function(runtime) { - var line; - line = []; - line.push(this.length); - line.push((this.length === 1 ? "test" : "tests") + ','); - line.push(this.failedCount); - line.push((this.failedCount === 1 ? "failure" : "failures") + ','); - line.push(runtime); - line.push((runtime === 1.0 ? "sec" : "secs") + '.'); - return line.join(' '); - }; + function HeadlessReporter() {} return HeadlessReporter; })(); }).call(this);