From 5ca065728dea0d93d849f316c126340952ac6bf5 Mon Sep 17 00:00:00 2001 From: John Bintz Date: Sat, 5 Nov 2011 14:19:41 -0400 Subject: [PATCH] finalize the runner, time to merge? --- ext/jasmine-webkit-specrunner/Runner.cpp | 7 ++++++- ext/jasmine-webkit-specrunner/Runner.h | 2 ++ .../jasmine.HeadlessConsoleReporter.coffee | 8 ++++---- vendor/assets/coffeescripts/prolog.coffee | 10 ++++++++-- .../javascripts/jasmine.HeadlessConsoleReporter.js | 8 ++++---- vendor/assets/javascripts/prolog.js | 8 ++++++-- 6 files changed, 30 insertions(+), 13 deletions(-) diff --git a/ext/jasmine-webkit-specrunner/Runner.cpp b/ext/jasmine-webkit-specrunner/Runner.cpp index 82d225b..1179d0e 100644 --- a/ext/jasmine-webkit-specrunner/Runner.cpp +++ b/ext/jasmine-webkit-specrunner/Runner.cpp @@ -14,6 +14,7 @@ using namespace std; Runner::Runner() : QObject() , runs(0) , hasErrors(false) + , _hasSpecFailure(false) , usedConsole(false) , isFinished(false) , useColors(false) @@ -99,6 +100,10 @@ void Runner::hasError() { hasErrors = true; } +void Runner::hasSpecFailure() { + _hasSpecFailure = true; +} + void Runner::reportFile(const QString &file) { reportFileName = file; } @@ -144,7 +149,7 @@ void Runner::timerEvent() { } int exitCode = 0; - if (hasErrors) { + if (_hasSpecFailure || hasErrors) { exitCode = 1; } else { if (usedConsole) { diff --git a/ext/jasmine-webkit-specrunner/Runner.h b/ext/jasmine-webkit-specrunner/Runner.h index 25126c7..c0744a8 100644 --- a/ext/jasmine-webkit-specrunner/Runner.h +++ b/ext/jasmine-webkit-specrunner/Runner.h @@ -29,6 +29,7 @@ class Runner: public QObject { void timerDone(); void hasUsedConsole(); void hasError(); + void hasSpecFailure(); void print(const QString &fh, const QString &content); void finishSuite(); @@ -43,6 +44,7 @@ class Runner: public QObject { QTimer ticker; int runs; bool hasErrors; + bool _hasSpecFailure; bool usedConsole; bool isFinished; bool useColors; diff --git a/vendor/assets/coffeescripts/jasmine.HeadlessConsoleReporter.coffee b/vendor/assets/coffeescripts/jasmine.HeadlessConsoleReporter.coffee index c8448bb..58638c2 100644 --- a/vendor/assets/coffeescripts/jasmine.HeadlessConsoleReporter.coffee +++ b/vendor/assets/coffeescripts/jasmine.HeadlessConsoleReporter.coffee @@ -10,9 +10,6 @@ class jasmine.HeadlessConsoleReporter reportRunnerResults: (runner) -> return if this.hasError() - if window.JHW - window.onbeforeunload = null - runtime = (new Date() - @startTime) / 1000.0 JHW.stdout.print("\n") @@ -23,12 +20,16 @@ class jasmine.HeadlessConsoleReporter JHW.stdout.puts("PASS: #{resultLine}".foreground('green')) else JHW.stdout.puts("FAIL: #{resultLine}".foreground('red')) + JHW.hasSpecFailure() output = "TOTAL||#{@length}||#{@failedCount}||#{runtime}||#{if JHW._hasErrors then "T" else "F"}" JHW.report.puts(output) result.print() for result in @results + if window.JHW + window.onbeforeunload = null + JHW.finishSuite() reportRunnerStarting: (runner) -> @@ -47,7 +48,6 @@ class jasmine.HeadlessConsoleReporter else JHW.stdout.print('F'.foreground('red')) JHW.report.puts("FAIL||" + spec.getJHWSpecInformation()) - JHW.hasError() @failedCount++ failureResult = new HeadlessReporterResult(spec.getFullName(), spec.getSpecSplitName()) diff --git a/vendor/assets/coffeescripts/prolog.coffee b/vendor/assets/coffeescripts/prolog.coffee index 8e2c025..75479c9 100644 --- a/vendor/assets/coffeescripts/prolog.coffee +++ b/vendor/assets/coffeescripts/prolog.coffee @@ -27,9 +27,15 @@ if window.JHW data window.onbeforeunload = (e) -> - JHW.stderr.puts('The code tried to leave the test page. Check for unhandled form submits and link clicks.') + e = e || window.event + JHW.hasError() - return false + JHW.stdout.puts('The code tried to leave the test page. Check for unhandled form submits and link clicks.') + + if e + e.returnValue = 'string' + + return 'string' window.confirm = (message) -> JHW.stderr.puts("#{"[confirm]".foreground('red')} jasmine-headless-webkit can't handle confirm() yet! You should mock window.confirm. Returning true.") diff --git a/vendor/assets/javascripts/jasmine.HeadlessConsoleReporter.js b/vendor/assets/javascripts/jasmine.HeadlessConsoleReporter.js index 74b07c1..2a3e934 100644 --- a/vendor/assets/javascripts/jasmine.HeadlessConsoleReporter.js +++ b/vendor/assets/javascripts/jasmine.HeadlessConsoleReporter.js @@ -14,9 +14,6 @@ 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); @@ -24,6 +21,7 @@ JHW.stdout.puts(("PASS: " + resultLine).foreground('green')); } else { JHW.stdout.puts(("FAIL: " + resultLine).foreground('red')); + JHW.hasSpecFailure(); } output = "TOTAL||" + this.length + "||" + this.failedCount + "||" + runtime + "||" + (JHW._hasErrors ? "T" : "F"); JHW.report.puts(output); @@ -32,6 +30,9 @@ result = _ref[_i]; result.print(); } + if (window.JHW) { + window.onbeforeunload = null; + } return JHW.finishSuite(); }; HeadlessConsoleReporter.prototype.reportRunnerStarting = function(runner) { @@ -51,7 +52,6 @@ } 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; diff --git a/vendor/assets/javascripts/prolog.js b/vendor/assets/javascripts/prolog.js index 2e70ab2..2fd358b 100644 --- a/vendor/assets/javascripts/prolog.js +++ b/vendor/assets/javascripts/prolog.js @@ -37,9 +37,13 @@ } }; window.onbeforeunload = function(e) { - JHW.stderr.puts('The code tried to leave the test page. Check for unhandled form submits and link clicks.'); + e = e || window.event; JHW.hasError(); - return false; + JHW.stdout.puts('The code tried to leave the test page. Check for unhandled form submits and link clicks.'); + if (e) { + e.returnValue = 'string'; + } + return 'string'; }; window.confirm = function(message) { JHW.stderr.puts("" + ("[confirm]".foreground('red')) + " jasmine-headless-webkit can't handle confirm() yet! You should mock window.confirm. Returning true.");