From dda84fdcb986cc6bd3dbaa4bdd49ae0c4d2632c8 Mon Sep 17 00:00:00 2001 From: John Bintz Date: Mon, 24 Oct 2011 16:40:08 -0400 Subject: [PATCH 01/12] first big switch to javascript doing all the work --- bin/jasmine-headless-webkit | 1 - ext/jasmine-webkit-specrunner/Runner.cpp | 84 ++--- ext/jasmine-webkit-specrunner/Runner.h | 13 +- jasmine/headless_reporter_result.coffee | 41 +++ jasmine/headless_reporter_result.js | 72 +++++ jasmine/intense.coffee | 20 ++ jasmine/intense.js | 28 ++ jasmine/jasmine-extensions.coffee | 86 +++++ jasmine/jasmine-extensions.js | 97 ++++++ jasmine/jasmine.headless-reporter.coffee | 229 ++++---------- jasmine/jasmine.headless-reporter.js | 298 +++++------------- lib/jasmine/files_list.rb | 3 + skel/template.html.erb | 17 +- .../jasmine.headless-reporter_spec.coffee | 2 +- 14 files changed, 544 insertions(+), 447 deletions(-) create mode 100644 jasmine/headless_reporter_result.coffee create mode 100644 jasmine/headless_reporter_result.js create mode 100644 jasmine/intense.coffee create mode 100644 jasmine/intense.js create mode 100644 jasmine/jasmine-extensions.coffee create mode 100644 jasmine/jasmine-extensions.js diff --git a/bin/jasmine-headless-webkit b/bin/jasmine-headless-webkit index 711de51..5495d33 100755 --- a/bin/jasmine-headless-webkit +++ b/bin/jasmine-headless-webkit @@ -18,7 +18,6 @@ begin files_list = Jasmine::FilesList.new(:config => runner.jasmine_config) files_list.files.each { |file| puts file } else - puts "Running Jasmine specs...".color(:white) exit runner.run end rescue CoffeeScript::CompilationError diff --git a/ext/jasmine-webkit-specrunner/Runner.cpp b/ext/jasmine-webkit-specrunner/Runner.cpp index 6c64ad3..19a8a74 100644 --- a/ext/jasmine-webkit-specrunner/Runner.cpp +++ b/ext/jasmine-webkit-specrunner/Runner.cpp @@ -35,6 +35,7 @@ void Runner::go() m_ticker.stop(); m_page.setPreferredContentsSize(QSize(1024, 600)); addJHW(); + loadSpec(); m_ticker.start(); @@ -46,6 +47,13 @@ void Runner::addJHW() void Runner::loadSpec() { + if (!reportFileName.isEmpty()) { + outputFile = new QFile(reportFileName); + outputFile->open(QIODevice::WriteOnly); + + ts = new QTextStream(outputFile); + } + m_page.mainFrame()->load(runnerFiles.dequeue()); m_ticker.start(); } @@ -59,11 +67,9 @@ void Runner::watch(bool ok) QApplication::instance()->exit(1); return; } - } -bool Runner::hasElement(const char *select) -{ +bool Runner::hasElement(const char *select) { return !m_page.mainFrame()->findFirstElement(select).isNull(); } @@ -75,10 +81,6 @@ void Runner::reportFile(const QString &file) { reportFileName = file; } -bool Runner::hasError() { - return hasErrors; -} - void Runner::timerPause() { m_ticker.stop(); } @@ -87,17 +89,21 @@ void Runner::timerDone() { m_ticker.start(); } -void Runner::specPassed(const QString &specDetail) { - consoleOutput.passed(specDetail); - reportFileOutput.passed(specDetail); -} +void Runner::print(const QString &fh, const QString &content) { + if (fh == "stdout") { + std::cout << qPrintable(content); + std::cout.flush(); + } -void Runner::specFailed(const QString &specDetail) { - consoleOutput.failed(specDetail); - reportFileOutput.failed(specDetail); + if (fh == "stderr") { + std::cerr << qPrintable(content); + std::cerr.flush(); + } - didFail = true; - failedSpecs.push(specDetail); + if (fh == "report") { + *ts << qPrintable(content); + ts->flush(); + } } void Runner::errorLog(const QString &msg, int lineNumber, const QString &sourceID) @@ -115,11 +121,9 @@ void Runner::internalLog(const QString ¬e, const QString &msg) { reportFileOutput.internalLog(note, msg); } -void Runner::log(const QString &msg) +void Runner::usedConsole() { usedConsole = true; - consoleOutput.consoleLog(msg); - reportFileOutput.consoleLog(msg); } void Runner::leavePageAttempt(const QString &msg) @@ -129,53 +133,19 @@ void Runner::leavePageAttempt(const QString &msg) hasErrors = true; } -void Runner::printName(const QString &name) -{ - consoleOutput.logSpecFilename(name); -} - -void Runner::printResult(const QString &result) -{ - consoleOutput.logSpecResult(result); -} - -void Runner::finishSuite(const QString &duration, const QString &total, const QString& failed) -{ - if (didFail) { - consoleOutput.reportFailure(total, failed, duration); - reportFileOutput.reportFailure(total, failed, duration); - } else { - if (hasErrors) { - consoleOutput.reportSuccessWithJSErrors(total, failed, duration); - reportFileOutput.reportSuccessWithJSErrors(total, failed, duration); - } else { - consoleOutput.reportSuccess(total, failed, duration); - reportFileOutput.reportSuccess(total, failed, duration); - } - } - - if (!reportFileName.isEmpty()) { - QFile outputFile(reportFileName); - outputFile.open(QIODevice::WriteOnly); - - QTextStream ts(&outputFile); - - ts << reportFileOutput.outputIO->str().c_str(); - - outputFile.close(); - } - +void Runner::finishSuite() { isFinished = true; } -void Runner::timerEvent() -{ +void Runner::timerEvent() { ++m_runs; if (hasErrors && m_runs > 2) QApplication::instance()->exit(1); if (isFinished) { + outputFile->close(); + int exitCode = 0; if (didFail || hasErrors) { exitCode = 1; diff --git a/ext/jasmine-webkit-specrunner/Runner.h b/ext/jasmine-webkit-specrunner/Runner.h index 96170b9..fdc9cc2 100644 --- a/ext/jasmine-webkit-specrunner/Runner.h +++ b/ext/jasmine-webkit-specrunner/Runner.h @@ -31,11 +31,10 @@ class Runner: public QObject { void leavePageAttempt(const QString &msg); void timerPause(); void timerDone(); - void specPassed(const QString &specDetail); - void specFailed(const QString &specDetail); - void printName(const QString &name); - void printResult(const QString &result); - void finishSuite(const QString &duration, const QString &total, const QString& failed); + + void print(const QString &fh, const QString &content); + + void finishSuite(); private slots: void watch(bool ok); void errorLog(const QString &msg, int lineNumber, const QString &sourceID); @@ -55,12 +54,14 @@ class Runner: public QObject { QQueue runnerFiles; QStack failedSpecs; - ConsoleOutput consoleOutput; ReportFileOutput reportFileOutput; QString reportFileName; void loadSpec(); + + QFile *outputFile; + QTextStream *ts; }; #endif diff --git a/jasmine/headless_reporter_result.coffee b/jasmine/headless_reporter_result.coffee new file mode 100644 index 0000000..fbf296f --- /dev/null +++ b/jasmine/headless_reporter_result.coffee @@ -0,0 +1,41 @@ +# Try to get the line number of a failed spec +class window.HeadlessReporterResult + constructor: (@name, @splitName) -> + @results = [] + addResult: (message) -> + @results.push(message) + print: -> + output = @name.foreground('red') + bestChoice = HeadlessReporterResult.findSpecLine(@splitName) + output += " (#{bestChoice.file}:#{bestChoice.lineNumber})".foreground('blue') if bestChoice.file + + JHW.stdout.puts "\n\n#{output}" + for result in @results + output = result.message.foreground('red') + if result.lineNumber + output += " (line ~#{bestChoice.lineNumber + result.lineNumber})".foreground('red').bright() + JHW.stdout.puts(" " + output) + JHW.stdout.puts(" #{result.line}".foreground('yellow')) + @findSpecLine: (splitName) -> + bestChoice = { accuracy: 0, file: null, lineNumber: null } + + for file, lines of HeadlessReporterResult.specLineNumbers + index = 0 + lineNumber = 0 + while newLineNumberInfo = lines[splitName[index]] + if newLineNumberInfo.length == 0 + lineNumber = newLineNumberInfo[0] + else + lastLine = null + for line in newLineNumberInfo + lastLine = line + break if line > lineNumber + + lineNumber = lastLine + + index++ + + if index > bestChoice.accuracy + bestChoice = { accuracy: index, file: file, lineNumber: lineNumber } + + bestChoice diff --git a/jasmine/headless_reporter_result.js b/jasmine/headless_reporter_result.js new file mode 100644 index 0000000..9848308 --- /dev/null +++ b/jasmine/headless_reporter_result.js @@ -0,0 +1,72 @@ +(function() { + window.HeadlessReporterResult = (function() { + function HeadlessReporterResult(name, splitName) { + this.name = name; + this.splitName = splitName; + this.results = []; + } + HeadlessReporterResult.prototype.addResult = function(message) { + return this.results.push(message); + }; + HeadlessReporterResult.prototype.print = function() { + var bestChoice, output, result, _i, _len, _ref, _results; + output = this.name.foreground('red'); + bestChoice = HeadlessReporterResult.findSpecLine(this.splitName); + if (bestChoice.file) { + output += (" (" + bestChoice.file + ":" + bestChoice.lineNumber + ")").foreground('blue'); + } + JHW.stdout.puts("\n\n" + output); + _ref = this.results; + _results = []; + for (_i = 0, _len = _ref.length; _i < _len; _i++) { + result = _ref[_i]; + output = result.message.foreground('red'); + if (result.lineNumber) { + output += (" (line ~" + (bestChoice.lineNumber + result.lineNumber) + ")").foreground('red').bright(); + } + JHW.stdout.puts(" " + output); + _results.push(JHW.stdout.puts((" " + result.line).foreground('yellow'))); + } + return _results; + }; + HeadlessReporterResult.findSpecLine = function(splitName) { + var bestChoice, file, index, lastLine, line, lineNumber, lines, newLineNumberInfo, _i, _len, _ref; + bestChoice = { + accuracy: 0, + file: null, + lineNumber: null + }; + _ref = HeadlessReporterResult.specLineNumbers; + for (file in _ref) { + lines = _ref[file]; + index = 0; + lineNumber = 0; + while (newLineNumberInfo = lines[splitName[index]]) { + if (newLineNumberInfo.length === 0) { + lineNumber = newLineNumberInfo[0]; + } else { + lastLine = null; + for (_i = 0, _len = newLineNumberInfo.length; _i < _len; _i++) { + line = newLineNumberInfo[_i]; + lastLine = line; + if (line > lineNumber) { + break; + } + } + lineNumber = lastLine; + } + index++; + } + if (index > bestChoice.accuracy) { + bestChoice = { + accuracy: index, + file: file, + lineNumber: lineNumber + }; + } + } + return bestChoice; + }; + return HeadlessReporterResult; + })(); +}).call(this); diff --git a/jasmine/intense.coffee b/jasmine/intense.coffee new file mode 100644 index 0000000..ddbcff0 --- /dev/null +++ b/jasmine/intense.coffee @@ -0,0 +1,20 @@ +window.Intense = { + colors: + black: 0 + red: 1 + green: 2 + yellow: 3 + blue: 4 + magenta: 5 + cyan: 6 + white: 7 + methods: + foreground: (color) -> + "\033[3#{Intense.colors[color]}m#{this}\033[0m" + bright: -> + "\033[1m#{this}\033[0m" +} + +for method, code of Intense.methods + String.prototype[method] = code + diff --git a/jasmine/intense.js b/jasmine/intense.js new file mode 100644 index 0000000..a393ca1 --- /dev/null +++ b/jasmine/intense.js @@ -0,0 +1,28 @@ +(function() { + var code, method, _ref; + window.Intense = { + colors: { + black: 0, + red: 1, + green: 2, + yellow: 3, + blue: 4, + magenta: 5, + cyan: 6, + white: 7 + }, + methods: { + foreground: function(color) { + return "\033[3" + Intense.colors[color] + "m" + this + "\033[0m"; + }, + bright: function() { + return "\033[1m" + this + "\033[0m"; + } + } + }; + _ref = Intense.methods; + for (method in _ref) { + code = _ref[method]; + String.prototype[method] = code; + } +}).call(this); diff --git a/jasmine/jasmine-extensions.coffee b/jasmine/jasmine-extensions.coffee new file mode 100644 index 0000000..f7e8ce6 --- /dev/null +++ b/jasmine/jasmine-extensions.coffee @@ -0,0 +1,86 @@ +if !jasmine? + throw new Error("jasmine not laoded!") + +if window.JHW + # Jasmine extensions + getSplitName = (parts) -> + parts.push(String(@description).replace(/[\n\r]/g, ' ')) + parts + + jasmine.Suite.prototype.getSuiteSplitName = -> + this.getSplitName(if @parentSuite then @parentSuite.getSuiteSplitName() else []) + + jasmine.Spec.prototype.getSpecSplitName = -> + this.getSplitName(@suite.getSuiteSplitName()) + + jasmine.Suite.prototype.getSplitName = getSplitName + jasmine.Spec.prototype.getSplitName = getSplitName + + jasmine.Spec.prototype.getJHWSpecInformation = -> + parts = this.getSpecSplitName() + specLineInfo = HeadlessReporterResult.findSpecLine(parts) + if specLineInfo.file + parts.push("#{specLineInfo.file}:#{specLineInfo.lineNumber}") + else + parts.push('') + parts.join("||") + + jasmine.Spec.prototype.fail = (e) -> + if e and e.sourceURL and window.CoffeeScriptToFilename + filename = e.sourceURL.split('/').pop() + if realFilename = window.CoffeeScriptToFilename[filename] + e = { + name: e.name, + message: e.message, + lineNumber: "~" + String(e.line), + sourceURL: realFilename + } + + expectationResult = new jasmine.ExpectationResult({ + passed: false, + message: if e then jasmine.util.formatException(e) else 'Exception', + trace: { stack: e.stack } + }) + @results_.addResult(expectationResult) + + jasmine.NestedResults.isValidSpecLine = (line) -> + line.match(/^\s*expect/) != null || line.match(/^\s*return\s*expect/) != null + + jasmine.NestedResults.parseFunction = (func) -> + lines = [] + lineCount = 0 + for line in func.split("\n") + if jasmine.NestedResults.isValidSpecLine(line) + line = line.replace(/^\s*/, '').replace(/\s*$/, '').replace(/^return\s*/, '') + lines.push([line, lineCount]) + lineCount += 1 + lines + + jasmine.NestedResults.parseAndStore = (func) -> + if !jasmine.NestedResults.ParsedFunctions[func] + jasmine.NestedResults.ParsedFunctions[func] = jasmine.NestedResults.parseFunction(func) + jasmine.NestedResults.ParsedFunctions[func] + + jasmine.NestedResults.ParsedFunctions = [] + + if !jasmine.WaitsBlock.prototype._execute + jasmine.WaitsBlock.prototype._execute = jasmine.WaitsBlock.prototype.execute + jasmine.WaitsForBlock.prototype._execute = jasmine.WaitsForBlock.prototype.execute + + pauseAndRun = (onComplete) -> + JHW.timerPause() + this._execute -> + JHW.timerDone() + onComplete() + + jasmine.WaitsBlock.prototype.execute = pauseAndRun + jasmine.WaitsForBlock.prototype.execute = pauseAndRun + + jasmine.NestedResults.prototype.addResult_ = jasmine.NestedResults.prototype.addResult + jasmine.NestedResults.prototype.addResult = (result) -> + result.expectations = [] + # always three up? + + result.expectations = jasmine.NestedResults.parseAndStore(arguments.callee.caller.caller.caller.toString()) + + this.addResult_(result) diff --git a/jasmine/jasmine-extensions.js b/jasmine/jasmine-extensions.js new file mode 100644 index 0000000..d7a64e0 --- /dev/null +++ b/jasmine/jasmine-extensions.js @@ -0,0 +1,97 @@ +(function() { + var getSplitName, pauseAndRun; + if (!(typeof jasmine !== "undefined" && jasmine !== null)) { + throw new Error("jasmine not laoded!"); + } + if (window.JHW) { + getSplitName = function(parts) { + parts.push(String(this.description).replace(/[\n\r]/g, ' ')); + return parts; + }; + jasmine.Suite.prototype.getSuiteSplitName = function() { + return this.getSplitName(this.parentSuite ? this.parentSuite.getSuiteSplitName() : []); + }; + jasmine.Spec.prototype.getSpecSplitName = function() { + return this.getSplitName(this.suite.getSuiteSplitName()); + }; + jasmine.Suite.prototype.getSplitName = getSplitName; + jasmine.Spec.prototype.getSplitName = getSplitName; + jasmine.Spec.prototype.getJHWSpecInformation = function() { + var parts, specLineInfo; + parts = this.getSpecSplitName(); + specLineInfo = HeadlessReporterResult.findSpecLine(parts); + if (specLineInfo.file) { + parts.push("" + specLineInfo.file + ":" + specLineInfo.lineNumber); + } else { + parts.push(''); + } + return parts.join("||"); + }; + jasmine.Spec.prototype.fail = function(e) { + var expectationResult, filename, realFilename; + if (e && e.sourceURL && window.CoffeeScriptToFilename) { + filename = e.sourceURL.split('/').pop(); + if (realFilename = window.CoffeeScriptToFilename[filename]) { + e = { + name: e.name, + message: e.message, + lineNumber: "~" + String(e.line), + sourceURL: realFilename + }; + } + } + expectationResult = new jasmine.ExpectationResult({ + passed: false, + message: e ? jasmine.util.formatException(e) : 'Exception', + trace: { + stack: e.stack + } + }); + return this.results_.addResult(expectationResult); + }; + jasmine.NestedResults.isValidSpecLine = function(line) { + return line.match(/^\s*expect/) !== null || line.match(/^\s*return\s*expect/) !== null; + }; + jasmine.NestedResults.parseFunction = function(func) { + var line, lineCount, lines, _i, _len, _ref; + lines = []; + lineCount = 0; + _ref = func.split("\n"); + for (_i = 0, _len = _ref.length; _i < _len; _i++) { + line = _ref[_i]; + if (jasmine.NestedResults.isValidSpecLine(line)) { + line = line.replace(/^\s*/, '').replace(/\s*$/, '').replace(/^return\s*/, ''); + lines.push([line, lineCount]); + } + lineCount += 1; + } + return lines; + }; + jasmine.NestedResults.parseAndStore = function(func) { + if (!jasmine.NestedResults.ParsedFunctions[func]) { + jasmine.NestedResults.ParsedFunctions[func] = jasmine.NestedResults.parseFunction(func); + } + return jasmine.NestedResults.ParsedFunctions[func]; + }; + jasmine.NestedResults.ParsedFunctions = []; + if (!jasmine.WaitsBlock.prototype._execute) { + jasmine.WaitsBlock.prototype._execute = jasmine.WaitsBlock.prototype.execute; + jasmine.WaitsForBlock.prototype._execute = jasmine.WaitsForBlock.prototype.execute; + pauseAndRun = function(onComplete) { + JHW.timerPause(); + return this._execute(function() { + JHW.timerDone(); + return onComplete(); + }); + }; + jasmine.WaitsBlock.prototype.execute = pauseAndRun; + jasmine.WaitsForBlock.prototype.execute = pauseAndRun; + jasmine.NestedResults.prototype.addResult_ = jasmine.NestedResults.prototype.addResult; + jasmine.NestedResults.prototype.addResult = function(result) { + result.expectations = []; + result.expectations = jasmine.NestedResults.parseAndStore(arguments.callee.caller.caller.caller.toString()); + return this.addResult_(result); + }; + } + } +}).call(this); diff --git a/jasmine/jasmine.headless-reporter.coffee b/jasmine/jasmine.headless-reporter.coffee index 8db83f4..d0a86be 100644 --- a/jasmine/jasmine.headless-reporter.coffee +++ b/jasmine/jasmine.headless-reporter.coffee @@ -1,175 +1,78 @@ if !jasmine? throw new Error("jasmine not laoded!") -if window.JHW -# Jasmine extensions - getSplitName = (parts) -> - parts.push(String(@description).replace(/[\n\r]/g, ' ')) - parts - - jasmine.Suite.prototype.getSuiteSplitName = -> - this.getSplitName(if @parentSuite then @parentSuite.getSuiteSplitName() else []) - - jasmine.Spec.prototype.getSpecSplitName = -> - this.getSplitName(@suite.getSuiteSplitName()) - - jasmine.Suite.prototype.getSplitName = getSplitName - jasmine.Spec.prototype.getSplitName = getSplitName - - jasmine.Spec.prototype.getJHWSpecInformation = -> - parts = this.getSpecSplitName() - specLineInfo = HeadlessReporterResult.findSpecLine(parts) - if specLineInfo.file - parts.push("#{specLineInfo.file}:#{specLineInfo.lineNumber}") - else - parts.push('') - parts.join("||") - - jasmine.Spec.prototype.fail = (e) -> - if e and e.sourceURL and window.CoffeeScriptToFilename - filename = e.sourceURL.split('/').pop() - if realFilename = window.CoffeeScriptToFilename[filename] - e = { - name: e.name, - message: e.message, - lineNumber: "~" + String(e.line), - sourceURL: realFilename - } - - expectationResult = new jasmine.ExpectationResult({ - passed: false, - message: if e then jasmine.util.formatException(e) else 'Exception', - trace: { stack: e.stack } - }) - @results_.addResult(expectationResult) - - jasmine.NestedResults.isValidSpecLine = (line) -> - line.match(/^\s*expect/) != null || line.match(/^\s*return\s*expect/) != null - - jasmine.NestedResults.parseFunction = (func) -> - lines = [] - lineCount = 0 - for line in func.split("\n") - if jasmine.NestedResults.isValidSpecLine(line) - line = line.replace(/^\s*/, '').replace(/\s*$/, '').replace(/^return\s*/, '') - lines.push([line, lineCount]) - lineCount += 1 - lines - - jasmine.NestedResults.parseAndStore = (func) -> - if !jasmine.NestedResults.ParsedFunctions[func] - jasmine.NestedResults.ParsedFunctions[func] = jasmine.NestedResults.parseFunction(func) - jasmine.NestedResults.ParsedFunctions[func] - - jasmine.NestedResults.ParsedFunctions = [] - - if !jasmine.WaitsBlock.prototype._execute - jasmine.WaitsBlock.prototype._execute = jasmine.WaitsBlock.prototype.execute - jasmine.WaitsForBlock.prototype._execute = jasmine.WaitsForBlock.prototype.execute - - pauseAndRun = (onComplete) -> - JHW.timerPause() - this._execute -> - JHW.timerDone() - onComplete() - - jasmine.WaitsBlock.prototype.execute = pauseAndRun - jasmine.WaitsForBlock.prototype.execute = pauseAndRun - - jasmine.NestedResults.prototype.addResult_ = jasmine.NestedResults.prototype.addResult - jasmine.NestedResults.prototype.addResult = (result) -> - result.expectations = [] - # always three up? - - result.expectations = jasmine.NestedResults.parseAndStore(arguments.callee.caller.caller.caller.toString()) - - this.addResult_(result) - -# Try to get the line number of a failed spec - class window.HeadlessReporterResult - constructor: (@name, @splitName) -> - @results = [] - addResult: (message) -> - @results.push(message) - print: -> - output = @name - bestChoice = HeadlessReporterResult.findSpecLine(@splitName) - output += " (#{bestChoice.file}:#{bestChoice.lineNumber})" if bestChoice.file - - JHW.printName(output) - for result in @results - output = result.message - if result.lineNumber - output += " (line ~#{bestChoice.lineNumber + result.lineNumber})\n #{result.line}" - JHW.printResult(output) - @findSpecLine: (splitName) -> - bestChoice = { accuracy: 0, file: null, lineNumber: null } - - for file, lines of HeadlessReporterResult.specLineNumbers - index = 0 - lineNumber = 0 - while newLineNumberInfo = lines[splitName[index]] - if newLineNumberInfo.length == 0 - lineNumber = newLineNumberInfo[0] - else - lastLine = null - for line in newLineNumberInfo - lastLine = line - break if line > lineNumber - - lineNumber = lastLine - - index++ - - if index > bestChoice.accuracy - bestChoice = { accuracy: index, file: file, lineNumber: lineNumber } - - bestChoice - # The reporter itself. - class jasmine.HeadlessReporter - constructor: (@callback = null) -> - @results = [] - @failedCount = 0 - @length = 0 - reportRunnerResults: (runner) -> - return if this.hasError() +class jasmine.HeadlessReporter + constructor: (@callback = null) -> + @results = [] + @failedCount = 0 + @length = 0 + @_hasError = false + reportRunnerResults: (runner) -> + return if this.hasError() - for result in @results - result.print() + this.callback() if @callback - this.callback() if @callback - JHW.finishSuite((new Date() - @startTime) / 1000.0, @length, @failedCount) + runtime = (new Date() - @startTime) / 1000.0 - reportRunnerStarting: (runner) -> - @startTime = new Date() + JHW.stdout.print("\n") - reportSpecResults: (spec) -> - return if this.hasError() + resultLine = this._formatResultLine(runtime) - results = spec.results() - @length++ - if results.passed() - JHW.specPassed(spec.getJHWSpecInformation()) - else - JHW.specFailed(spec.getJHWSpecInformation()) - @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) + if @failedCount == 0 + JHW.stdout.puts("PASS: #{resultLine}".foreground('green')) + else + JHW.stdout.puts("FAIL: #{resultLine}".foreground('red')) - reportSpecStarting: (spec) -> - if this.hasError() - spec.finish() - spec.suite.finish() + result.print() for result in @results - reportSuiteResults: (suite) -> - hasError: -> - JHW.hasError() + JHW.finishSuite() + + reportRunnerStarting: (runner) -> + @startTime = new Date() + JHW.stdout.puts("Running Jasmine specs...") + + 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()) + @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: -> + @_hasError == true + + _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/jasmine/jasmine.headless-reporter.js b/jasmine/jasmine.headless-reporter.js index 1a994f2..5209696 100644 --- a/jasmine/jasmine.headless-reporter.js +++ b/jasmine/jasmine.headless-reporter.js @@ -1,231 +1,93 @@ (function() { - var getSplitName, pauseAndRun; if (!(typeof jasmine !== "undefined" && jasmine !== null)) { throw new Error("jasmine not laoded!"); } - if (window.JHW) { - getSplitName = function(parts) { - parts.push(String(this.description).replace(/[\n\r]/g, ' ')); - return parts; - }; - jasmine.Suite.prototype.getSuiteSplitName = function() { - return this.getSplitName(this.parentSuite ? this.parentSuite.getSuiteSplitName() : []); - }; - jasmine.Spec.prototype.getSpecSplitName = function() { - return this.getSplitName(this.suite.getSuiteSplitName()); - }; - jasmine.Suite.prototype.getSplitName = getSplitName; - jasmine.Spec.prototype.getSplitName = getSplitName; - jasmine.Spec.prototype.getJHWSpecInformation = function() { - var parts, specLineInfo; - parts = this.getSpecSplitName(); - specLineInfo = HeadlessReporterResult.findSpecLine(parts); - if (specLineInfo.file) { - parts.push("" + specLineInfo.file + ":" + specLineInfo.lineNumber); - } else { - parts.push(''); - } - return parts.join("||"); - }; - jasmine.Spec.prototype.fail = function(e) { - var expectationResult, filename, realFilename; - if (e && e.sourceURL && window.CoffeeScriptToFilename) { - filename = e.sourceURL.split('/').pop(); - if (realFilename = window.CoffeeScriptToFilename[filename]) { - e = { - name: e.name, - message: e.message, - lineNumber: "~" + String(e.line), - sourceURL: realFilename - }; - } - } - expectationResult = new jasmine.ExpectationResult({ - passed: false, - message: e ? jasmine.util.formatException(e) : 'Exception', - trace: { - stack: e.stack - } - }); - return this.results_.addResult(expectationResult); - }; - jasmine.NestedResults.isValidSpecLine = function(line) { - return line.match(/^\s*expect/) !== null || line.match(/^\s*return\s*expect/) !== null; - }; - jasmine.NestedResults.parseFunction = function(func) { - var line, lineCount, lines, _i, _len, _ref; - lines = []; - lineCount = 0; - _ref = func.split("\n"); - for (_i = 0, _len = _ref.length; _i < _len; _i++) { - line = _ref[_i]; - if (jasmine.NestedResults.isValidSpecLine(line)) { - line = line.replace(/^\s*/, '').replace(/\s*$/, '').replace(/^return\s*/, ''); - lines.push([line, lineCount]); - } - lineCount += 1; - } - return lines; - }; - jasmine.NestedResults.parseAndStore = function(func) { - if (!jasmine.NestedResults.ParsedFunctions[func]) { - jasmine.NestedResults.ParsedFunctions[func] = jasmine.NestedResults.parseFunction(func); - } - return jasmine.NestedResults.ParsedFunctions[func]; - }; - jasmine.NestedResults.ParsedFunctions = []; - if (!jasmine.WaitsBlock.prototype._execute) { - jasmine.WaitsBlock.prototype._execute = jasmine.WaitsBlock.prototype.execute; - jasmine.WaitsForBlock.prototype._execute = jasmine.WaitsForBlock.prototype.execute; - pauseAndRun = function(onComplete) { - JHW.timerPause(); - return this._execute(function() { - JHW.timerDone(); - return onComplete(); - }); - }; - jasmine.WaitsBlock.prototype.execute = pauseAndRun; - jasmine.WaitsForBlock.prototype.execute = pauseAndRun; - jasmine.NestedResults.prototype.addResult_ = jasmine.NestedResults.prototype.addResult; - jasmine.NestedResults.prototype.addResult = function(result) { - result.expectations = []; - result.expectations = jasmine.NestedResults.parseAndStore(arguments.callee.caller.caller.caller.toString()); - return this.addResult_(result); - }; + jasmine.HeadlessReporter = (function() { + function HeadlessReporter(callback) { + this.callback = callback != null ? callback : null; + this.results = []; + this.failedCount = 0; + this.length = 0; + this._hasError = false; } - window.HeadlessReporterResult = (function() { - function HeadlessReporterResult(name, splitName) { - this.name = name; - this.splitName = splitName; - this.results = []; + HeadlessReporter.prototype.reportRunnerResults = function(runner) { + var result, resultLine, runtime, _i, _len, _ref; + if (this.hasError()) { + return; } - HeadlessReporterResult.prototype.addResult = function(message) { - return this.results.push(message); - }; - HeadlessReporterResult.prototype.print = function() { - var bestChoice, output, result, _i, _len, _ref, _results; - output = this.name; - bestChoice = HeadlessReporterResult.findSpecLine(this.splitName); - if (bestChoice.file) { - output += " (" + bestChoice.file + ":" + bestChoice.lineNumber + ")"; - } - JHW.printName(output); - _ref = this.results; - _results = []; + 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')); + } + _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("Running Jasmine specs..."); + }; + 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()); + 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]; - output = result.message; - if (result.lineNumber) { - output += " (line ~" + (bestChoice.lineNumber + result.lineNumber) + ")\n " + result.line; - } - _results.push(JHW.printResult(output)); - } - return _results; - }; - HeadlessReporterResult.findSpecLine = function(splitName) { - var bestChoice, file, index, lastLine, line, lineNumber, lines, newLineNumberInfo, _i, _len, _ref; - bestChoice = { - accuracy: 0, - file: null, - lineNumber: null - }; - _ref = HeadlessReporterResult.specLineNumbers; - for (file in _ref) { - lines = _ref[file]; - index = 0; - lineNumber = 0; - while (newLineNumberInfo = lines[splitName[index]]) { - if (newLineNumberInfo.length === 0) { - lineNumber = newLineNumberInfo[0]; - } else { - lastLine = null; - for (_i = 0, _len = newLineNumberInfo.length; _i < _len; _i++) { - line = newLineNumberInfo[_i]; - lastLine = line; - if (line > lineNumber) { - break; - } - } - lineNumber = lastLine; + if (result.type === 'expect' && !result.passed_) { + if (foundLine = result.expectations[testCount - 1]) { + result.line = foundLine[0], result.lineNumber = foundLine[1]; } - index++; - } - if (index > bestChoice.accuracy) { - bestChoice = { - accuracy: index, - file: file, - lineNumber: lineNumber - }; + failureResult.addResult(result); } + testCount += 1; } - return bestChoice; - }; - return HeadlessReporterResult; - })(); - jasmine.HeadlessReporter = (function() { - function HeadlessReporter(callback) { - this.callback = callback != null ? callback : null; - this.results = []; - this.failedCount = 0; - this.length = 0; + return this.results.push(failureResult); } - HeadlessReporter.prototype.reportRunnerResults = function(runner) { - var result, _i, _len, _ref; - if (this.hasError()) { - return; - } - _ref = this.results; - for (_i = 0, _len = _ref.length; _i < _len; _i++) { - result = _ref[_i]; - result.print(); - } - if (this.callback) { - this.callback(); - } - return JHW.finishSuite((new Date() - this.startTime) / 1000.0, this.length, this.failedCount); - }; - HeadlessReporter.prototype.reportRunnerStarting = function(runner) { - return this.startTime = new Date(); - }; - 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()) { - return JHW.specPassed(spec.getJHWSpecInformation()); - } else { - JHW.specFailed(spec.getJHWSpecInformation()); - 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.hasError(); - }; - return HeadlessReporter; - })(); - } + }; + HeadlessReporter.prototype.reportSpecStarting = function(spec) { + if (this.hasError()) { + spec.finish(); + return spec.suite.finish(); + } + }; + HeadlessReporter.prototype.reportSuiteResults = function(suite) {}; + HeadlessReporter.prototype.hasError = function() { + return this._hasError === true; + }; + 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(' '); + }; + return HeadlessReporter; + })(); }).call(this); diff --git a/lib/jasmine/files_list.rb b/lib/jasmine/files_list.rb index 72757cd..bbd8ace 100644 --- a/lib/jasmine/files_list.rb +++ b/lib/jasmine/files_list.rb @@ -10,6 +10,9 @@ module Jasmine File.join(Jasmine::Core.path, "jasmine.js"), File.join(Jasmine::Core.path, "jasmine-html.js"), File.join(Jasmine::Core.path, "jasmine.css"), + Jasmine::Headless.root.join('jasmine/jasmine-extensions.js').to_s, + Jasmine::Headless.root.join('jasmine/intense.js').to_s, + Jasmine::Headless.root.join('jasmine/headless_reporter_result.js').to_s, Jasmine::Headless.root.join('jasmine/jasmine.headless-reporter.js').to_s, Jasmine::Headless.root.join('js-lib/jsDump.js').to_s, Jasmine::Headless.root.join('js-lib/beautify-html.js').to_s diff --git a/skel/template.html.erb b/skel/template.html.erb index d44a535..ef8c453 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.headless-reporter_spec.coffee index f70203e..edc5099 100644 --- a/spec/javascripts/jasmine.headless-reporter_spec.coffee +++ b/spec/javascripts/jasmine.headless-reporter_spec.coffee @@ -30,7 +30,7 @@ describe 'jasmine.HeadlessReporter', -> reporter.reportSpecStarting(spec) - expect(spec.finish).toHaveBeenCalled() + expect(spec.finish).not.toHaveBeenCalled() expect(suite.finish).toHaveBeenCalled() describe 'jasmine.Suite.prototype.getSuiteSplitName', -> From 54e5d5c9d50a238133a7a646d3b9daeabef03f88 Mon Sep 17 00:00:00 2001 From: John Bintz Date: Tue, 25 Oct 2011 11:25:02 -0400 Subject: [PATCH 02/12] more breakage --- ext/jasmine-webkit-specrunner/Runner.cpp | 15 +-------------- ext/jasmine-webkit-specrunner/Runner.h | 10 +++------- jasmine/prolog.coffee | 0 jasmine/prolog.js | 3 +++ 4 files changed, 7 insertions(+), 21 deletions(-) create mode 100644 jasmine/prolog.coffee create mode 100644 jasmine/prolog.js diff --git a/ext/jasmine-webkit-specrunner/Runner.cpp b/ext/jasmine-webkit-specrunner/Runner.cpp index 19a8a74..985f54d 100644 --- a/ext/jasmine-webkit-specrunner/Runner.cpp +++ b/ext/jasmine-webkit-specrunner/Runner.cpp @@ -74,7 +74,6 @@ bool Runner::hasElement(const char *select) { } void Runner::setColors(bool colors) { - consoleOutput.showColors = colors; } void Runner::reportFile(const QString &file) { @@ -108,27 +107,15 @@ void Runner::print(const QString &fh, const QString &content) { void Runner::errorLog(const QString &msg, int lineNumber, const QString &sourceID) { - consoleOutput.errorLog(msg, lineNumber, sourceID); - reportFileOutput.errorLog(msg, lineNumber, sourceID); - hasErrors = true; m_runs = 0; m_ticker.start(); } -void Runner::internalLog(const QString ¬e, const QString &msg) { - consoleOutput.internalLog(note, msg); - reportFileOutput.internalLog(note, msg); -} - -void Runner::usedConsole() -{ - usedConsole = true; -} +void Runner::internalLog(const QString ¬e, const QString &msg) {} void Runner::leavePageAttempt(const QString &msg) { - consoleOutput.internalLog("error", msg); m_page.oneFalseConfirm(); hasErrors = true; } diff --git a/ext/jasmine-webkit-specrunner/Runner.h b/ext/jasmine-webkit-specrunner/Runner.h index fdc9cc2..a93ae2f 100644 --- a/ext/jasmine-webkit-specrunner/Runner.h +++ b/ext/jasmine-webkit-specrunner/Runner.h @@ -25,9 +25,7 @@ class Runner: public QObject { void reportFile(const QString &file); void addFile(const QString &spec); void go(); - public slots: - void log(const QString &msg); - bool hasError(); + public slots: void leavePageAttempt(const QString &msg); void timerPause(); void timerDone(); @@ -35,8 +33,8 @@ class Runner: public QObject { void print(const QString &fh, const QString &content); void finishSuite(); - private slots: - void watch(bool ok); + private slots: + void watch(bool ok); void errorLog(const QString &msg, int lineNumber, const QString &sourceID); void internalLog(const QString ¬e, const QString &msg); void addJHW(); @@ -54,8 +52,6 @@ class Runner: public QObject { QQueue runnerFiles; QStack failedSpecs; - ReportFileOutput reportFileOutput; - QString reportFileName; void loadSpec(); diff --git a/jasmine/prolog.coffee b/jasmine/prolog.coffee new file mode 100644 index 0000000..e69de29 diff --git a/jasmine/prolog.js b/jasmine/prolog.js new file mode 100644 index 0000000..f5e757a --- /dev/null +++ b/jasmine/prolog.js @@ -0,0 +1,3 @@ +(function() { + +}).call(this); From 7db116fb4565268c2e1ec431404f8dbf2bd82527 Mon Sep 17 00:00:00 2001 From: John Bintz Date: Tue, 25 Oct 2011 11:25:28 -0400 Subject: [PATCH 03/12] more breakage --- ext/jasmine-webkit-specrunner/Page.cpp | 37 +++++++++-------- jasmine/prolog.coffee | 55 +++++++++++++++++++++++++ lib/jasmine/headless.rb | 2 +- skel/template.html.erb | 57 +------------------------- 4 files changed, 76 insertions(+), 75 deletions(-) diff --git a/ext/jasmine-webkit-specrunner/Page.cpp b/ext/jasmine-webkit-specrunner/Page.cpp index f532c9c..caba8e5 100644 --- a/ext/jasmine-webkit-specrunner/Page.cpp +++ b/ext/jasmine-webkit-specrunner/Page.cpp @@ -4,26 +4,27 @@ #include "Page.h" - Page::Page() : QWebPage(), confirmResult(true) {} +Page::Page() : QWebPage(), confirmResult(true) {} - void Page::javaScriptConsoleMessage(const QString &message, int lineNumber, const QString &sourceID) { - emit consoleLog(message, lineNumber, sourceID); - } +void Page::javaScriptConsoleMessage(const QString &message, int lineNumber, const QString &sourceID) { + emit consoleLog(message, lineNumber, sourceID); +} - bool Page::javaScriptConfirm(QWebFrame*, const QString&) { - if (confirmResult) { - emit internalLog("TODO", "jasmine-headless-webkit can't handle confirm() yet! You should mock window.confirm for now. Returning true."); - return true; - } else { - confirmResult = true; - return false; - } +bool Page::javaScriptConfirm(QWebFrame*, const QString&) { + if (confirmResult) { + emit internalLog("TODO", "jasmine-headless-webkit can't handle confirm() yet! You should mock window.confirm for now. Returning true."); + return true; + } else { + confirmResult = true; + return false; } +} - void Page::javaScriptAlert(QWebFrame*, const QString &msg) { - emit internalLog("alert", msg); - } +void Page::javaScriptAlert(QWebFrame*, const QString &msg) { + emit internalLog("alert", msg); +} + +void Page::oneFalseConfirm() { + confirmResult = false; +} - void Page::oneFalseConfirm() { - confirmResult = false; - } diff --git a/jasmine/prolog.coffee b/jasmine/prolog.coffee index e69de29..ee21d7c 100644 --- a/jasmine/prolog.coffee +++ b/jasmine/prolog.coffee @@ -0,0 +1,55 @@ +if window.JHW + window.console = + log: (data) -> + if typeof(jQuery) != 'undefined' && data instanceof jQuery + JHW.log(style_html($("
").append(data).html(), { indent_size: 2 })) + else + useJsDump = true + + try + if typeof data.toJSON == 'function' + JHW.log("JSON: #{JSON.stringify(data, null, 2)}") + useJsDump = false + catch e + + if useJsDump + dump = jsDump.doParse(data) + if dump.indexOf("\n") == -1 + 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 + + window.onbeforeunload = (e) -> + JHW.leavePageAttempt() + + JHW.stderr.puts('The code tried to leave the test page. Check for unhandled form submits and link clicks.') + + if e = e || window.event + e.returnValue = "leaving" + + return "leaving" + + window.confirm = (message) -> + JHW.stderr.puts("jasmine-headless-webkit can't handle confirm() yet! You should mock window.confirm. Returning true.") + true + + window.alert = (message) -> + JHW.stderr.puts(message) + + JHW.error = (message, sourceUrl, lineNumber) -> + + + for handle in [ 'stdout', 'stderr', 'report' ] + JHW[handle] = + print: (content) -> JHW.print(handle, content) + puts: (content) -> JHW.print(handle, content + "\n") + + JHW.log = (msg) -> + JHW.usedConsole() + JHW.stdout.puts(msg) + diff --git a/lib/jasmine/headless.rb b/lib/jasmine/headless.rb index eb2f5fb..b35ff93 100644 --- a/lib/jasmine/headless.rb +++ b/lib/jasmine/headless.rb @@ -16,7 +16,7 @@ module Jasmine::Headless class << self def root - @root ||= Pathname.new(File.expand_path('../../..', __FILE__)) + @root ||= Pathname(File.expand_path('../../..', __FILE__)) end end end diff --git a/skel/template.html.erb b/skel/template.html.erb index ef8c453..cc5ecb1 100644 --- a/skel/template.html.erb +++ b/skel/template.html.erb @@ -3,62 +3,7 @@ Jasmine Test Runner - Generated by jasmine-headless-webkit - + "); - QVERIFY(internalLogCalled); - } - - void PageTest::testJavaScriptConfirmWithoutLog() { - connect(&page, SIGNAL(internalLog(QString, QString)), this, SLOT(internalLog(QString, QString))); - internalLogCalled = false; - - page.oneFalseConfirm(); - page.mainFrame()->setHtml(""); - QVERIFY(!internalLogCalled); - } - - void PageTest::testJavaScriptConsoleMessage() { - connect(&page, SIGNAL(consoleLog(QString, int, QString)), this, SLOT(consoleLog(QString, int, QString))); - consoleLogCalled = false; - - page.mainFrame()->setHtml(""); - QVERIFY(consoleLogCalled); - } - -QTEST_MAIN(PageTest); - diff --git a/ext/jasmine-webkit-specrunner/_old/Page_test.h b/ext/jasmine-webkit-specrunner/_old/Page_test.h deleted file mode 100644 index dcd7872..0000000 --- a/ext/jasmine-webkit-specrunner/_old/Page_test.h +++ /dev/null @@ -1,27 +0,0 @@ -#ifndef JHW_TEST_PAGE -#define JHW_TEST_PAGE - -#include - -#include "Page.h" - - class PageTest : public QObject { - Q_OBJECT - public: - PageTest(); - - private: - bool internalLogCalled; - bool consoleLogCalled; - Page page; - - private slots: - void internalLog(const QString ¬e, const QString &msg); - void consoleLog(const QString &message, int lineNumber, const QString &source); - void testJavaScriptConfirmWithLog(); - void testJavaScriptConfirmWithoutLog(); - void testJavaScriptConsoleMessage(); - }; - -#endif - diff --git a/ext/jasmine-webkit-specrunner/_old/Page_test.pro b/ext/jasmine-webkit-specrunner/_old/Page_test.pro deleted file mode 100644 index 9482e83..0000000 --- a/ext/jasmine-webkit-specrunner/_old/Page_test.pro +++ /dev/null @@ -1,6 +0,0 @@ -include(common.pri) -include(test.pri) - -SOURCES += Page_test.cpp -HEADERS += Page_test.h - diff --git a/ext/jasmine-webkit-specrunner/test.pri b/ext/jasmine-webkit-specrunner/test.pri deleted file mode 100644 index 4804421..0000000 --- a/ext/jasmine-webkit-specrunner/test.pri +++ /dev/null @@ -1,3 +0,0 @@ -TARGET = jhw-test -QT += testlib - diff --git a/ext/jasmine-webkit-specrunner/test.rb b/ext/jasmine-webkit-specrunner/test.rb deleted file mode 100644 index 0caf700..0000000 --- a/ext/jasmine-webkit-specrunner/test.rb +++ /dev/null @@ -1,31 +0,0 @@ -#!/usr/bin/env ruby - -require 'fileutils' - -system %{make clean} - -$: << File.expand_path("../../../lib", __FILE__) -require 'qt/qmake' - -result = 0 - -Dir['*_test.pro'].each do |test| - FileUtils.rm_f('jhw-test') - - Qt::Qmake.make!('jasmine-headless-webkit', test) - - if File.file?('jhw-test') - system %{./jhw-test} - if $?.exitstatus != 0 - result = 1 - break - end - else - result = 1 - break - end -end - -Qt::Qmake.make!('jasmine-headless-webkit', 'specrunner.pro') - -exit result diff --git a/jasmine/jasmine.headless-reporter.coffee b/jasmine/jasmine.headless-reporter.coffee index 22fd83f..ac3c0cb 100644 --- a/jasmine/jasmine.headless-reporter.coffee +++ b/jasmine/jasmine.headless-reporter.coffee @@ -7,7 +7,7 @@ class jasmine.HeadlessReporter @results = [] @failedCount = 0 @length = 0 - @_hasError = false + reportRunnerResults: (runner) -> return if this.hasError() diff --git a/jasmine/jasmine.headless-reporter.js b/jasmine/jasmine.headless-reporter.js index 1adb21a..9027453 100644 --- a/jasmine/jasmine.headless-reporter.js +++ b/jasmine/jasmine.headless-reporter.js @@ -8,7 +8,6 @@ this.results = []; this.failedCount = 0; this.length = 0; - this._hasError = false; } HeadlessReporter.prototype.reportRunnerResults = function(runner) { var result, resultLine, runtime, _i, _len, _ref; diff --git a/spec/javascripts/jasmine.headless-reporter_spec.coffee b/spec/javascripts/jasmine.headless-reporter_spec.coffee index edc5099..f70203e 100644 --- a/spec/javascripts/jasmine.headless-reporter_spec.coffee +++ b/spec/javascripts/jasmine.headless-reporter_spec.coffee @@ -30,7 +30,7 @@ describe 'jasmine.HeadlessReporter', -> reporter.reportSpecStarting(spec) - expect(spec.finish).not.toHaveBeenCalled() + expect(spec.finish).toHaveBeenCalled() expect(suite.finish).toHaveBeenCalled() describe 'jasmine.Suite.prototype.getSuiteSplitName', -> From 298e8c2d3d55298a5eba9b93ec29af575bb4db9f Mon Sep 17 00:00:00 2001 From: John Bintz Date: Tue, 25 Oct 2011 22:22:29 -0400 Subject: [PATCH 06/12] last set of changes --- ext/jasmine-webkit-specrunner/Page.cpp | 5 ++ ext/jasmine-webkit-specrunner/Page.h | 2 + ext/jasmine-webkit-specrunner/Runner.cpp | 49 ++++++++++--------- ext/jasmine-webkit-specrunner/Runner.h | 14 +++--- jasmine/headless_reporter_result.coffee | 5 +- jasmine/jasmine.headless-reporter.coffee | 9 +++- jasmine/jasmine.headless-reporter.js | 7 ++- jasmine/prolog.coffee | 23 +++++---- jasmine/prolog.js | 20 ++++---- .../headless_reporter_result_spec.coffee | 14 ++++++ spec/lib/jasmine/files_list_spec.rb | 3 ++ 11 files changed, 95 insertions(+), 56 deletions(-) create mode 100644 spec/javascripts/headless_reporter_result_spec.coffee diff --git a/ext/jasmine-webkit-specrunner/Page.cpp b/ext/jasmine-webkit-specrunner/Page.cpp index 0c6103b..b3f6c3d 100644 --- a/ext/jasmine-webkit-specrunner/Page.cpp +++ b/ext/jasmine-webkit-specrunner/Page.cpp @@ -9,3 +9,8 @@ Page::Page() : QWebPage() {} void Page::javaScriptConsoleMessage(const QString & message, int lineNumber, const QString & sourceID) { emit handleError(message, lineNumber, sourceID); } + +void Page::javaScriptAlert(QWebFrame *, const QString &) {} +bool Page::javaScriptConfirm(QWebFrame *, const QString &) { + return false; +} diff --git a/ext/jasmine-webkit-specrunner/Page.h b/ext/jasmine-webkit-specrunner/Page.h index 227ea1a..74c6f77 100644 --- a/ext/jasmine-webkit-specrunner/Page.h +++ b/ext/jasmine-webkit-specrunner/Page.h @@ -10,6 +10,8 @@ class Page: public QWebPage { Page(); protected: void javaScriptConsoleMessage(const QString & message, int lineNumber, const QString & sourceID); + void javaScriptAlert(QWebFrame *, const QString &); + bool javaScriptConfirm(QWebFrame *, const QString &); signals: void handleError(const QString & message, int lineNumber, const QString & sourceID); }; diff --git a/ext/jasmine-webkit-specrunner/Runner.cpp b/ext/jasmine-webkit-specrunner/Runner.cpp index 0a67f8c..82d225b 100644 --- a/ext/jasmine-webkit-specrunner/Runner.cpp +++ b/ext/jasmine-webkit-specrunner/Runner.cpp @@ -12,20 +12,19 @@ using namespace std; Runner::Runner() : QObject() - , m_runs(0) + , runs(0) , hasErrors(false) , usedConsole(false) , isFinished(false) - , didFail(false) , useColors(false) { - m_page.settings()->enablePersistentStorage(); - m_ticker.setInterval(TIMER_TICK); + page.settings()->enablePersistentStorage(); + ticker.setInterval(TIMER_TICK); - connect(&m_ticker, SIGNAL(timeout()), this, SLOT(timerEvent())); - connect(&m_page, SIGNAL(loadFinished(bool)), this, SLOT(watch(bool))); - connect(&m_page, SIGNAL(handleError(const QString &, int, const QString &)), this, SLOT(handleError(const QString &, int, const QString &))); - connect(m_page.mainFrame(), SIGNAL(javaScriptWindowObjectCleared()), this, SLOT(addJHW())); + connect(&ticker, SIGNAL(timeout()), this, SLOT(timerEvent())); + connect(&page, SIGNAL(loadFinished(bool)), this, SLOT(watch(bool))); + connect(&page, SIGNAL(handleError(const QString &, int, const QString &)), this, SLOT(handleError(const QString &, int, const QString &))); + connect(page.mainFrame(), SIGNAL(javaScriptWindowObjectCleared()), this, SLOT(addJHW())); } void Runner::addFile(const QString &spec) { @@ -33,14 +32,14 @@ void Runner::addFile(const QString &spec) { } void Runner::go() { - m_ticker.stop(); - m_page.setPreferredContentsSize(QSize(1024, 600)); + ticker.stop(); + page.setPreferredContentsSize(QSize(1024, 600)); addJHW(); loadSpec(); } void Runner::addJHW() { - m_page.mainFrame()->addToJavaScriptWindowObject("JHW", this); + page.mainFrame()->addToJavaScriptWindowObject("JHW", this); } void Runner::handleError(const QString &message, int lineNumber, const QString &sourceID) { @@ -55,7 +54,7 @@ void Runner::handleError(const QString &message, int lineNumber, const QString & QString command("JHW._handleError(\"" + messageEscaped + "\", " + QString(ss.str().c_str()) + ", \"" + sourceIDEscaped + "\"); false;"); - m_page.mainFrame()->evaluateJavaScript(command); + page.mainFrame()->evaluateJavaScript(command); hasErrors = true; } @@ -72,20 +71,20 @@ void Runner::loadSpec() ts = new QTextStream(outputFile); } - m_page.mainFrame()->load(runnerFiles.dequeue()); - m_ticker.start(); + page.mainFrame()->load(runnerFiles.dequeue()); + ticker.start(); } void Runner::watch(bool ok) { if (!ok) { - std::cerr << "Can't load " << qPrintable(m_page.mainFrame()->url().toString()) << ", the file may be broken." << std::endl; + std::cerr << "Can't load " << qPrintable(page.mainFrame()->url().toString()) << ", the file may be broken." << std::endl; std::cerr << "Out of curiosity, did your tests try to submit a form and you haven't prevented that?" << std::endl; std::cerr << "Try running your tests in your browser with the Jasmine server and see what happens." << std::endl; QApplication::instance()->exit(1); return; } - m_page.mainFrame()->evaluateJavaScript(QString("JHW._setColors(") + (useColors ? QString("true") : QString("false")) + QString("); false;")); + page.mainFrame()->evaluateJavaScript(QString("JHW._setColors(") + (useColors ? QString("true") : QString("false")) + QString("); false;")); } void Runner::setColors(bool colors) { @@ -96,16 +95,20 @@ void Runner::hasUsedConsole() { usedConsole = true; } +void Runner::hasError() { + hasErrors = true; +} + void Runner::reportFile(const QString &file) { reportFileName = file; } void Runner::timerPause() { - m_ticker.stop(); + ticker.stop(); } void Runner::timerDone() { - m_ticker.start(); + ticker.start(); } void Runner::print(const QString &fh, const QString &content) { @@ -130,9 +133,9 @@ void Runner::finishSuite() { } void Runner::timerEvent() { - ++m_runs; + ++runs; - if (hasErrors && m_runs > 2) + if (hasErrors && runs > 2) QApplication::instance()->exit(1); if (isFinished) { @@ -141,7 +144,7 @@ void Runner::timerEvent() { } int exitCode = 0; - if (didFail || hasErrors) { + if (hasErrors) { exitCode = 1; } else { if (usedConsole) { @@ -167,8 +170,8 @@ void Runner::timerEvent() { } } - if (m_runs > MAX_LOOPS) { - std::cout << "WARNING: too many runs and the test is still not finished!" << std::endl; + if (runs > MAX_LOOPS) { + std::cerr << "WARNING: too many runs and the test is still not finished!" << std::endl; QApplication::instance()->exit(1); } } diff --git a/ext/jasmine-webkit-specrunner/Runner.h b/ext/jasmine-webkit-specrunner/Runner.h index 1a98d1d..25126c7 100644 --- a/ext/jasmine-webkit-specrunner/Runner.h +++ b/ext/jasmine-webkit-specrunner/Runner.h @@ -23,28 +23,28 @@ class Runner: public QObject { void reportFile(const QString &file); void addFile(const QString &spec); void go(); + public slots: void timerPause(); void timerDone(); - void hasUsedConsole(); - + void hasError(); void print(const QString &fh, const QString &content); - void finishSuite(); + private slots: void watch(bool ok); void addJHW(); void timerEvent(); void handleError(const QString & message, int lineNumber, const QString & sourceID); + private: - Page m_page; - QTimer m_ticker; - int m_runs; + Page page; + QTimer ticker; + int runs; bool hasErrors; bool usedConsole; bool isFinished; - bool didFail; bool useColors; QQueue runnerFiles; diff --git a/jasmine/headless_reporter_result.coffee b/jasmine/headless_reporter_result.coffee index fbf296f..5fdc4a3 100644 --- a/jasmine/headless_reporter_result.coffee +++ b/jasmine/headless_reporter_result.coffee @@ -2,8 +2,10 @@ class window.HeadlessReporterResult constructor: (@name, @splitName) -> @results = [] + addResult: (message) -> @results.push(message) + print: -> output = @name.foreground('red') bestChoice = HeadlessReporterResult.findSpecLine(@splitName) @@ -16,6 +18,7 @@ class window.HeadlessReporterResult output += " (line ~#{bestChoice.lineNumber + result.lineNumber})".foreground('red').bright() JHW.stdout.puts(" " + output) JHW.stdout.puts(" #{result.line}".foreground('yellow')) + @findSpecLine: (splitName) -> bestChoice = { accuracy: 0, file: null, lineNumber: null } @@ -37,5 +40,5 @@ class window.HeadlessReporterResult if index > bestChoice.accuracy bestChoice = { accuracy: index, file: file, lineNumber: lineNumber } - + bestChoice diff --git a/jasmine/jasmine.headless-reporter.coffee b/jasmine/jasmine.headless-reporter.coffee index ac3c0cb..2a8dd2b 100644 --- a/jasmine/jasmine.headless-reporter.coffee +++ b/jasmine/jasmine.headless-reporter.coffee @@ -24,18 +24,22 @@ class jasmine.HeadlessReporter 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("Running Jasmine specs...") + 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')) @@ -43,9 +47,12 @@ class jasmine.HeadlessReporter 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] diff --git a/jasmine/jasmine.headless-reporter.js b/jasmine/jasmine.headless-reporter.js index 9027453..c0a7272 100644 --- a/jasmine/jasmine.headless-reporter.js +++ b/jasmine/jasmine.headless-reporter.js @@ -10,7 +10,7 @@ this.length = 0; } HeadlessReporter.prototype.reportRunnerResults = function(runner) { - var result, resultLine, runtime, _i, _len, _ref; + var output, result, resultLine, runtime, _i, _len, _ref; if (this.hasError()) { return; } @@ -25,6 +25,8 @@ } 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]; @@ -34,7 +36,7 @@ }; HeadlessReporter.prototype.reportRunnerStarting = function(runner) { this.startTime = new Date(); - return JHW.stdout.puts("Running Jasmine specs..."); + return JHW.stdout.puts("\nRunning Jasmine specs...".bright()); }; HeadlessReporter.prototype.reportSpecResults = function(spec) { var failureResult, foundLine, result, results, testCount, _i, _len, _ref; @@ -49,6 +51,7 @@ } 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/jasmine/prolog.coffee b/jasmine/prolog.coffee index 837a564..5c0de20 100644 --- a/jasmine/prolog.coffee +++ b/jasmine/prolog.coffee @@ -25,21 +25,16 @@ if window.JHW data window.onbeforeunload = (e) -> - JHW.leavePageAttempt() - JHW.stderr.puts('The code tried to leave the test page. Check for unhandled form submits and link clicks.') - - if e = e || window.event - e.returnValue = "leaving" - - return "leaving" + JHW.hasError() + return false window.confirm = (message) -> - JHW.stderr.puts("jasmine-headless-webkit can't handle confirm() yet! You should mock window.confirm. Returning true.") + JHW.stderr.puts("#{"[confirm]".foreground('red')} jasmine-headless-webkit can't handle confirm() yet! You should mock window.confirm. Returning true.") true window.alert = (message) -> - JHW.stderr.puts(message) + JHW.stderr.puts("[alert] ".foreground('red') + message) JHW._hasErrors = false @@ -48,8 +43,8 @@ if window.JHW JHW._hasErrors = true false - JHW._setColors = (what) -> - Intense.useColors = what + JHW._setColors = (useColors) -> + Intense.useColors = useColors createHandle = (handle) -> JHW[handle] = @@ -58,7 +53,11 @@ if window.JHW createHandle(handle) for handle in [ 'stdout', 'stderr', 'report' ] + JHW._usedConsole = false + JHW.log = (msg) -> - JHW.usedConsole() + JHW.hasUsedConsole() + JHW.report.puts("CONSOLE||#{msg}") + JHW._usedConsole = true JHW.stdout.puts(msg) diff --git a/jasmine/prolog.js b/jasmine/prolog.js index e480a96..8f12c70 100644 --- a/jasmine/prolog.js +++ b/jasmine/prolog.js @@ -37,19 +37,16 @@ } }; window.onbeforeunload = function(e) { - JHW.leavePageAttempt(); JHW.stderr.puts('The code tried to leave the test page. Check for unhandled form submits and link clicks.'); - if (e = e || window.event) { - e.returnValue = "leaving"; - } - return "leaving"; + JHW.hasError(); + return false; }; window.confirm = function(message) { - JHW.stderr.puts("jasmine-headless-webkit can't handle confirm() yet! You should mock window.confirm. Returning true."); + JHW.stderr.puts("" + ("[confirm]".foreground('red')) + " jasmine-headless-webkit can't handle confirm() yet! You should mock window.confirm. Returning true."); return true; }; window.alert = function(message) { - return JHW.stderr.puts(message); + return JHW.stderr.puts("[alert] ".foreground('red') + message); }; JHW._hasErrors = false; JHW._handleError = function(message, lineNumber, sourceURL) { @@ -57,8 +54,8 @@ JHW._hasErrors = true; return false; }; - JHW._setColors = function(what) { - return Intense.useColors = what; + JHW._setColors = function(useColors) { + return Intense.useColors = useColors; }; createHandle = function(handle) { return JHW[handle] = { @@ -75,8 +72,11 @@ handle = _ref[_i]; createHandle(handle); } + JHW._usedConsole = false; JHW.log = function(msg) { - JHW.usedConsole(); + JHW.hasUsedConsole(); + JHW.report.puts("CONSOLE||" + msg); + JHW._usedConsole = true; return JHW.stdout.puts(msg); }; } diff --git a/spec/javascripts/headless_reporter_result_spec.coffee b/spec/javascripts/headless_reporter_result_spec.coffee new file mode 100644 index 0000000..2c2d501 --- /dev/null +++ b/spec/javascripts/headless_reporter_result_spec.coffee @@ -0,0 +1,14 @@ +describe 'HeadlessReporterResult', -> + result = null + name = "name" + splitName = "splitName" + message = 'message' + + beforeEach -> + result = new HeadlessReporterResult(name, splitName) + + describe '#addResult', -> + it 'should add a message', -> + result.addResult(message) + + expect(result.results).toEqual([ message ]) diff --git a/spec/lib/jasmine/files_list_spec.rb b/spec/lib/jasmine/files_list_spec.rb index 4aefbc7..fbcc084 100644 --- a/spec/lib/jasmine/files_list_spec.rb +++ b/spec/lib/jasmine/files_list_spec.rb @@ -14,6 +14,9 @@ describe Jasmine::FilesList do File.join(Jasmine::Core.path, "jasmine.js"), File.join(Jasmine::Core.path, "jasmine-html.js"), File.join(Jasmine::Core.path, "jasmine.css"), + File.expand_path('jasmine/jasmine-extensions.js'), + File.expand_path('jasmine/intense.js'), + File.expand_path('jasmine/headless_reporter_result.js'), File.expand_path('jasmine/jasmine.headless-reporter.js'), File.expand_path('js-lib/jsDump.js'), File.expand_path('js-lib/beautify-html.js'), From 69d865c0507b497d324d5a449bc42938846f8cc6 Mon Sep 17 00:00:00 2001 From: John Bintz Date: Wed, 26 Oct 2011 08:45:23 -0400 Subject: [PATCH 07/12] rearrange the furniture some more --- Guardfile | 3 +- lib/jasmine/files_list.rb | 49 +++++++++---------- skel/template.html.erb | 2 +- spec/javascripts/support/jasmine.yml | 2 +- spec/lib/jasmine/files_list_spec.rb | 12 ++--- .../headless_reporter_result.coffee | 4 +- .../assets/coffeescripts}/intense.coffee | 0 .../coffeescripts}/jasmine-extensions.coffee | 0 .../jasmine.headless-reporter.coffee | 0 .../assets/coffeescripts}/prolog.coffee | 1 + .../assets/javascripts}/beautify-html.js | 0 .../javascripts}/headless_reporter_result.js | 2 +- .../assets/javascripts}/intense.js | 0 .../assets/javascripts}/jasmine-extensions.js | 0 .../javascripts}/jasmine.headless-reporter.js | 0 .../assets/javascripts}/jsDump.js | 0 .../assets/javascripts}/prolog.js | 1 + 17 files changed, 39 insertions(+), 37 deletions(-) rename {jasmine => vendor/assets/coffeescripts}/headless_reporter_result.coffee (93%) rename {jasmine => vendor/assets/coffeescripts}/intense.coffee (100%) rename {jasmine => vendor/assets/coffeescripts}/jasmine-extensions.coffee (100%) rename {jasmine => vendor/assets/coffeescripts}/jasmine.headless-reporter.coffee (100%) rename {jasmine => vendor/assets/coffeescripts}/prolog.coffee (98%) rename {js-lib => vendor/assets/javascripts}/beautify-html.js (100%) rename {jasmine => vendor/assets/javascripts}/headless_reporter_result.js (95%) rename {jasmine => vendor/assets/javascripts}/intense.js (100%) rename {jasmine => vendor/assets/javascripts}/jasmine-extensions.js (100%) rename {jasmine => vendor/assets/javascripts}/jasmine.headless-reporter.js (100%) rename {js-lib => vendor/assets/javascripts}/jsDump.js (100%) rename {jasmine => vendor/assets/javascripts}/prolog.js (98%) diff --git a/Guardfile b/Guardfile index 1a2ca0d..38c2dc6 100644 --- a/Guardfile +++ b/Guardfile @@ -3,6 +3,8 @@ # watch('file/path') { `command(s)` } # +guard 'coffeescript', :input => 'vendor/assets/coffeescripts', :output => 'vendor/assets/javascripts' + guard 'shell' do watch(%r{ext/jasmine-webkit-specrunner/.*\.(cpp|h|pro|pri)}) { |m| if !m[0]['moc_'] @@ -32,4 +34,3 @@ end compile -guard 'coffeescript', :input => 'jasmine' diff --git a/lib/jasmine/files_list.rb b/lib/jasmine/files_list.rb index bbd8ace..1d1e216 100644 --- a/lib/jasmine/files_list.rb +++ b/lib/jasmine/files_list.rb @@ -6,17 +6,30 @@ module Jasmine class FilesList attr_reader :files, :spec_files, :filtered_files, :spec_outside_scope + class << self + def find_vendored_asset_paths(*names) + require 'rubygems' + + raise StandardError.new("A newer version of Rubygems is required to use vendored assets. Please upgrade.") if !Gem::Specification.respond_to?(:map) + all_spec_files.find_all do |file| + names.any? { |name| file["/#{name}.js"] } + end + end + + def all_spec_files + @all_spec_files ||= Gem::Specification.map { |spec| spec.files.find_all { |file| + file["vendor/assets/javascripts"] + }.compact.collect { |file| File.join(spec.gem_dir, file) } }.flatten + end + end + DEFAULT_FILES = [ File.join(Jasmine::Core.path, "jasmine.js"), File.join(Jasmine::Core.path, "jasmine-html.js"), - File.join(Jasmine::Core.path, "jasmine.css"), - Jasmine::Headless.root.join('jasmine/jasmine-extensions.js').to_s, - Jasmine::Headless.root.join('jasmine/intense.js').to_s, - Jasmine::Headless.root.join('jasmine/headless_reporter_result.js').to_s, - Jasmine::Headless.root.join('jasmine/jasmine.headless-reporter.js').to_s, - Jasmine::Headless.root.join('js-lib/jsDump.js').to_s, - Jasmine::Headless.root.join('js-lib/beautify-html.js').to_s - ] + File.join(Jasmine::Core.path, "jasmine.css") + ] + %w{jasmine-extensions intense headless_reporter_result jasmine.headless-reporter jsDump beautify-html}.collect { |name| + Jasmine::Headless.root.join("vendor/assets/javascripts/#{name}.js").to_s + } PLEASE_WAIT_IM_WORKING_TIME = 2 @@ -75,13 +88,10 @@ module Jasmine cache = Jasmine::Headless::CoffeeScriptCache.new(file) source = cache.handle if cache.cached? - %{ - S + %{ - } + } else %{} end @@ -161,19 +171,6 @@ module Jasmine def expanded_dir(path) Dir[path].collect { |file| File.expand_path(file) } end - - def self.find_vendored_asset_path(name) - require 'rubygems' - - raise StandardError.new("A newer version of Rubygems is required to use vendored assets. Please upgrade.") if !Gem::Specification.respond_to?(:map) - all_spec_files.find_all { |file| file["vendor/assets/javascripts/#{name}.js"] } - end - - def self.all_spec_files - @all_spec_files ||= Gem::Specification.map { |spec| spec.files.find_all { |file| - file["vendor/assets/javascripts"] - }.compact.collect { |file| File.join(spec.gem_dir, file) } }.flatten - end end end diff --git a/skel/template.html.erb b/skel/template.html.erb index cc5ecb1..7b7e363 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") %> } else %{} diff --git a/vendor/assets/coffeescripts/prolog.coffee b/vendor/assets/coffeescripts/prolog.coffee index 0144ed0..b22c572 100644 --- a/vendor/assets/coffeescripts/prolog.coffee +++ b/vendor/assets/coffeescripts/prolog.coffee @@ -62,3 +62,5 @@ if window.JHW JHW.stdout.puts(msg) window.CoffeeScriptToFilename = {} +window.CSTF = window.CoffeeScriptToFilename + diff --git a/vendor/assets/javascripts/prolog.js b/vendor/assets/javascripts/prolog.js index 5851336..2e70ab2 100644 --- a/vendor/assets/javascripts/prolog.js +++ b/vendor/assets/javascripts/prolog.js @@ -81,4 +81,5 @@ }; } window.CoffeeScriptToFilename = {}; + window.CSTF = window.CoffeeScriptToFilename; }).call(this); From 7b91fc5a76ef61797491cd692cbe4131204a5f9d Mon Sep 17 00:00:00 2001 From: John Bintz Date: Wed, 26 Oct 2011 20:05:05 -0400 Subject: [PATCH 09/12] 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); From 3a559fb0d5b0dfd08bd9d019000335125f1e352b Mon Sep 17 00:00:00 2001 From: John Bintz Date: Wed, 26 Oct 2011 22:20:51 -0400 Subject: [PATCH 10/12] more cleaning --- .../coffeescripts/jasmine.headless-reporter.coffee | 5 ----- vendor/assets/javascripts/jasmine.headless-reporter.js | 9 --------- 2 files changed, 14 deletions(-) delete mode 100644 vendor/assets/coffeescripts/jasmine.headless-reporter.coffee delete mode 100644 vendor/assets/javascripts/jasmine.headless-reporter.js diff --git a/vendor/assets/coffeescripts/jasmine.headless-reporter.coffee b/vendor/assets/coffeescripts/jasmine.headless-reporter.coffee deleted file mode 100644 index 349ba69..0000000 --- a/vendor/assets/coffeescripts/jasmine.headless-reporter.coffee +++ /dev/null @@ -1,5 +0,0 @@ -if !jasmine? - throw new Error("jasmine not laoded!") - -# The reporter itself. -class jasmine.HeadlessReporter diff --git a/vendor/assets/javascripts/jasmine.headless-reporter.js b/vendor/assets/javascripts/jasmine.headless-reporter.js deleted file mode 100644 index 871018c..0000000 --- a/vendor/assets/javascripts/jasmine.headless-reporter.js +++ /dev/null @@ -1,9 +0,0 @@ -(function() { - if (!(typeof jasmine !== "undefined" && jasmine !== null)) { - throw new Error("jasmine not laoded!"); - } - jasmine.HeadlessReporter = (function() { - function HeadlessReporter() {} - return HeadlessReporter; - })(); -}).call(this); From 5ca065728dea0d93d849f316c126340952ac6bf5 Mon Sep 17 00:00:00 2001 From: John Bintz Date: Sat, 5 Nov 2011 14:19:41 -0400 Subject: [PATCH 11/12] 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."); From 495fd1900ea9cb41c13c8b377deb4965337f9baf Mon Sep 17 00:00:00 2001 From: John Bintz Date: Thu, 10 Nov 2011 11:18:55 -0500 Subject: [PATCH 12/12] nuke the cpu detection --- lib/jasmine/headless/version.rb | 2 +- lib/qt/qmake.rb | 20 +------------------- spec/lib/qt/qmake_spec.rb | 11 ----------- 3 files changed, 2 insertions(+), 31 deletions(-) diff --git a/lib/jasmine/headless/version.rb b/lib/jasmine/headless/version.rb index 1844491..f611b97 100644 --- a/lib/jasmine/headless/version.rb +++ b/lib/jasmine/headless/version.rb @@ -1,5 +1,5 @@ module Jasmine module Headless - VERSION = "0.7.3" + VERSION = "0.8.0" end end diff --git a/lib/qt/qmake.rb b/lib/qt/qmake.rb index a0012f0..b4a3116 100644 --- a/lib/qt/qmake.rb +++ b/lib/qt/qmake.rb @@ -2,12 +2,6 @@ require 'rbconfig' require 'rubygems' require 'rubygems/version' -begin - require 'facter' -rescue LoadError - warn 'Including Facter allows for detection of # of cpus, resulting in faster compilations.' -end - module Qt class NotInstalledError < StandardError; end class Qmake @@ -45,11 +39,7 @@ module Qt system command(project_file) - system %{make #{make_options}} - end - - def make_options - "-j#{number_of_cpus}" + system %{make} end # @@ -103,14 +93,6 @@ module Qt end.compact.join(" ") end - def number_of_cpus - if defined?(Facter) - Facter.sp_number_processors rescue Facter.processorcount - else - 1 - end - end - def get_exe_path(command) path = %x{which #{command}}.strip path = nil if path == '' diff --git a/spec/lib/qt/qmake_spec.rb b/spec/lib/qt/qmake_spec.rb index 45b61c4..8b7c02f 100644 --- a/spec/lib/qt/qmake_spec.rb +++ b/spec/lib/qt/qmake_spec.rb @@ -138,16 +138,5 @@ describe Qt::Qmake do end end end - - describe '.make_options' do - let(:cpu_count) { 3 } - subject { Qt::Qmake.make_options } - - before do - Qt::Qmake.stubs(:number_of_cpus).returns(cpu_count) - end - - it { should == "-j#{cpu_count}" } - end end