From b6a64c5b1dfd1f8b5c823d1daeb0d2393cad58c5 Mon Sep 17 00:00:00 2001 From: hysios Date: Wed, 8 Feb 2012 21:54:34 +0800 Subject: [PATCH 01/20] feature: add jst template file have cache --- lib/jasmine/headless.rb | 19 +--------------- lib/jasmine/headless/jst_template.rb | 16 ++++++++++++- lib/jasmine/headless/jst_template_cache.rb | 26 ++++++++++++++++++++++ 3 files changed, 42 insertions(+), 19 deletions(-) create mode 100644 lib/jasmine/headless/jst_template_cache.rb diff --git a/lib/jasmine/headless.rb b/lib/jasmine/headless.rb index 0a60efa..33ee28c 100644 --- a/lib/jasmine/headless.rb +++ b/lib/jasmine/headless.rb @@ -24,6 +24,7 @@ module Jasmine autoload :CoffeeTemplate, 'jasmine/headless/coffee_template' autoload :JSTemplate, 'jasmine/headless/js_template' + autoload :JSTTemplateCache, 'jasmine/headless/jst_template_cache' autoload :JSTTemplate, 'jasmine/headless/jst_template' autoload :CSSTemplate, 'jasmine/headless/css_template' autoload :NilTemplate, 'jasmine/headless/nil_template' @@ -35,24 +36,6 @@ module Jasmine def root @root ||= Pathname(File.expand_path('../../..', __FILE__)) end - - def warn(message) - output.puts message if show_warnings? - end - - def show_warnings=(show) - @show_warnings = show - end - - def show_warnings? - @show_warnings = true if @show_warnings.nil? - - @show_warnings - end - - def output - $stdout - end end end end diff --git a/lib/jasmine/headless/jst_template.rb b/lib/jasmine/headless/jst_template.rb index b6d8f1c..9ef20b2 100644 --- a/lib/jasmine/headless/jst_template.rb +++ b/lib/jasmine/headless/jst_template.rb @@ -8,7 +8,21 @@ module Jasmine::Headless alert_bad_format(file) return '' end - %{} + begin + data = super + cache = Jasmine::Headless::JSTTemplateCache.new(file, data) + + source = cache.handle + if cache.cached? + %{ + } + else + %{} + end + rescue StandardError => e + puts "[%s] Error in compiling file: %s" % [ 'jst'.color(:red), file.color(:yellow) ] + raise e + end end end end diff --git a/lib/jasmine/headless/jst_template_cache.rb b/lib/jasmine/headless/jst_template_cache.rb new file mode 100644 index 0000000..ff7dcdc --- /dev/null +++ b/lib/jasmine/headless/jst_template_cache.rb @@ -0,0 +1,26 @@ +require 'sprockets/jst_processor' +require 'digest/sha1' +require 'fileutils' + +module Jasmine + module Headless + class JSTTemplateCache < CacheableAction + + def initialize(file, data) + @file = file + @data = data + end + + class << self + def cache_type + "jst_template" + end + end + + def action + @data + end + end + end +end + -- 2.45.2 From 0a63582366fe5a2fe7c48b74b29de5da811b8689 Mon Sep 17 00:00:00 2001 From: hysios hu Date: Thu, 20 Sep 2012 14:01:41 +0800 Subject: [PATCH 02/20] update headless --- lib/jasmine/headless.rb | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/lib/jasmine/headless.rb b/lib/jasmine/headless.rb index 33ee28c..4503e8e 100644 --- a/lib/jasmine/headless.rb +++ b/lib/jasmine/headless.rb @@ -36,9 +36,26 @@ module Jasmine def root @root ||= Pathname(File.expand_path('../../..', __FILE__)) end + + def warn(message) + output.puts message if show_warnings? + end + + def show_warnings=(show) + @show_warnings = show + end + + def show_warnings? + @show_warnings = true if @show_warnings.nil? + + @show_warnings + end + + def output + $stdout + end end end end require 'jasmine/headless/errors' - -- 2.45.2 From 167318eef1ef36e855cc82c55e9bd895d385e81d Mon Sep 17 00:00:00 2001 From: hysios hu Date: Thu, 20 Sep 2012 14:13:35 +0800 Subject: [PATCH 03/20] add junit xml report --- lib/jasmine/headless/files_list.rb | 2 +- skel/template.html.erb | 2 +- .../javascripts/jasmine.junit_reporter.js | 200 ++++++++++++++++++ 3 files changed, 202 insertions(+), 2 deletions(-) create mode 100644 vendor/assets/javascripts/jasmine.junit_reporter.js diff --git a/lib/jasmine/headless/files_list.rb b/lib/jasmine/headless/files_list.rb index aad2d62..3338bae 100644 --- a/lib/jasmine/headless/files_list.rb +++ b/lib/jasmine/headless/files_list.rb @@ -57,7 +57,7 @@ module Jasmine::Headless %w{jasmine.js jasmine-html jasmine.css jasmine-extensions intense headless_reporter_result jasmine.HeadlessReporter jasmine.HeadlessReporter.ConsoleBase - jsDump beautify-html} + jsDump beautify-html jasmine.junit_reporter} end def extension_filter diff --git a/skel/template.html.erb b/skel/template.html.erb index 644dde9..94c2e2a 100644 --- a/skel/template.html.erb +++ b/skel/template.html.erb @@ -68,7 +68,7 @@ checker(); }); } - + jasmine.getEnv().addReporter(new jasmine.JUnitXmlReporter()); jasmine.getEnv().execute(); } diff --git a/vendor/assets/javascripts/jasmine.junit_reporter.js b/vendor/assets/javascripts/jasmine.junit_reporter.js new file mode 100644 index 0000000..1aa69ee --- /dev/null +++ b/vendor/assets/javascripts/jasmine.junit_reporter.js @@ -0,0 +1,200 @@ +(function() { + + if (! jasmine) { + throw new Exception("jasmine library does not exist in global namespace!"); + } + + function elapsed(startTime, endTime) { + return (endTime - startTime)/1000; + } + + function ISODateString(d) { + function pad(n) { return n < 10 ? '0'+n : n; } + + return d.getFullYear() + '-' + + pad(d.getMonth()+1) + '-' + + pad(d.getDate()) + 'T' + + pad(d.getHours()) + ':' + + pad(d.getMinutes()) + ':' + + pad(d.getSeconds()); + } + + function trim(str) { + return str.replace(/^\s+/, "" ).replace(/\s+$/, "" ); + } + + function escapeInvalidXmlChars(str) { + return str.replace(/\&/g, "&") + .replace(//g, ">") + .replace(/\"/g, """) + .replace(/\'/g, "'"); + } + + /** + * Generates JUnit XML for the given spec run. + * Allows the test results to be used in java based CI + * systems like CruiseControl and Hudson. + * + * @param {string} savePath where to save the files + * @param {boolean} consolidate whether to save nested describes within the + * same file as their parent; default: true + * @param {boolean} useDotNotation whether to separate suite names with + * dots rather than spaces (ie "Class.init" not + * "Class init"); default: true + */ + var JUnitXmlReporter = function(savePath, consolidate, useDotNotation) { + this.savePath = savePath || ''; + this.consolidate = consolidate === jasmine.undefined ? true : consolidate; + this.useDotNotation = useDotNotation === jasmine.undefined ? true : useDotNotation; + }; + JUnitXmlReporter.finished_at = null; // will be updated after all files have been written + + JUnitXmlReporter.prototype = { + reportSpecStarting: function(spec) { + spec.startTime = new Date(); + + if (!spec.suite.startTime) { + spec.suite.startTime = spec.startTime; + } + }, + + reportSpecResults: function(spec) { + var results = spec.results(); + spec.didFail = !results.passed(); + spec.duration = elapsed(spec.startTime, new Date()); + spec.output = ''; + + var failure = ""; + var failures = 0; + var resultItems = results.getItems(); + for (var i = 0; i < resultItems.length; i++) { + var result = resultItems[i]; + + if (result.type == 'expect' && result.passed && !result.passed()) { + failures += 1; + failure += (failures + ": " + escapeInvalidXmlChars(result.message) + " "); + } + } + if (failure) { + spec.output += "" + trim(failure) + ""; + } + spec.output += ""; + }, + + reportSuiteResults: function(suite) { + var results = suite.results(); + var specs = suite.specs(); + var specOutput = ""; + // for JUnit results, let's only include directly failed tests (not nested suites') + var failedCount = 0; + + suite.status = results.passed() ? 'Passed.' : 'Failed.'; + if (results.totalCount === 0) { // todo: change this to check results.skipped + suite.status = 'Skipped.'; + } + + // if a suite has no (active?) specs, reportSpecStarting is never called + // and thus the suite has no startTime -- account for that here + suite.startTime = suite.startTime || new Date(); + suite.duration = elapsed(suite.startTime, new Date()); + + for (var i = 0; i < specs.length; i++) { + failedCount += specs[i].didFail ? 1 : 0; + specOutput += "\n " + specs[i].output; + } + suite.output = '\n'; + suite.output += specOutput; + suite.output += "\n"; + }, + + reportRunnerResults: function(runner) { + var suites = runner.suites(); + for (var i = 0; i < suites.length; i++) { + var suite = suites[i]; + var fileName = 'TEST-' + this.getFullName(suite, true) + '.xml'; + var output = ''; + // if we are consolidating, only write out top-level suites + if (this.consolidate && suite.parentSuite) { + continue; + } + else if (this.consolidate) { + output += "\n"; + output += this.getNestedOutput(suite); + output += "\n"; + this.writeFile(this.savePath + fileName, output); + } + else { + output += suite.output; + this.writeFile(this.savePath + fileName, output); + } + } + // When all done, make it known on JUnitXmlReporter + JUnitXmlReporter.finished_at = (new Date()).getTime(); + }, + + getNestedOutput: function(suite) { + var output = suite.output; + for (var i = 0; i < suite.suites().length; i++) { + output += this.getNestedOutput(suite.suites()[i]); + } + return output; + }, + + writeFile: function(filename, text) { + // Rhino + try { + var out = new java.io.BufferedWriter(new java.io.FileWriter(filename)); + out.write(text); + out.close(); + return; + } catch (e) {} + // PhantomJS, via a method injected by phantomjs-testrunner.js + try { + __phantom_writeFile(filename, text); + return; + } catch (f) {} + // Node.js + try { + var fs = require("fs"); + var fd = fs.openSync(filename, "w"); + fs.writeSync(fd, text, 0); + fs.closeSync(fd); + return; + } catch (g) {} + }, + + getFullName: function(suite, isFilename) { + var fullName; + if (this.useDotNotation) { + fullName = suite.description; + for (var parentSuite = suite.parentSuite; parentSuite; parentSuite = parentSuite.parentSuite) { + fullName = parentSuite.description + '.' + fullName; + } + } + else { + fullName = suite.getFullName(); + } + + // Either remove or escape invalid XML characters + if (isFilename) { + return fullName.replace(/[^\w]/g, ""); + } + return escapeInvalidXmlChars(fullName); + }, + + log: function(str) { + var console = jasmine.getGlobal().console; + + if (console && console.log) { + console.log(str); + } + } + }; + + // export public + jasmine.JUnitXmlReporter = JUnitXmlReporter; +})(); \ No newline at end of file -- 2.45.2 From c25adfcfbb17910a2de41b95e6693a34158b78f0 Mon Sep 17 00:00:00 2001 From: hysios hu Date: Thu, 20 Sep 2012 14:24:01 +0800 Subject: [PATCH 04/20] change junit file name --- .../javascripts/jasmine.junit_reporter.js | 200 ------------------ 1 file changed, 200 deletions(-) delete mode 100644 vendor/assets/javascripts/jasmine.junit_reporter.js diff --git a/vendor/assets/javascripts/jasmine.junit_reporter.js b/vendor/assets/javascripts/jasmine.junit_reporter.js deleted file mode 100644 index 1aa69ee..0000000 --- a/vendor/assets/javascripts/jasmine.junit_reporter.js +++ /dev/null @@ -1,200 +0,0 @@ -(function() { - - if (! jasmine) { - throw new Exception("jasmine library does not exist in global namespace!"); - } - - function elapsed(startTime, endTime) { - return (endTime - startTime)/1000; - } - - function ISODateString(d) { - function pad(n) { return n < 10 ? '0'+n : n; } - - return d.getFullYear() + '-' + - pad(d.getMonth()+1) + '-' + - pad(d.getDate()) + 'T' + - pad(d.getHours()) + ':' + - pad(d.getMinutes()) + ':' + - pad(d.getSeconds()); - } - - function trim(str) { - return str.replace(/^\s+/, "" ).replace(/\s+$/, "" ); - } - - function escapeInvalidXmlChars(str) { - return str.replace(/\&/g, "&") - .replace(//g, ">") - .replace(/\"/g, """) - .replace(/\'/g, "'"); - } - - /** - * Generates JUnit XML for the given spec run. - * Allows the test results to be used in java based CI - * systems like CruiseControl and Hudson. - * - * @param {string} savePath where to save the files - * @param {boolean} consolidate whether to save nested describes within the - * same file as their parent; default: true - * @param {boolean} useDotNotation whether to separate suite names with - * dots rather than spaces (ie "Class.init" not - * "Class init"); default: true - */ - var JUnitXmlReporter = function(savePath, consolidate, useDotNotation) { - this.savePath = savePath || ''; - this.consolidate = consolidate === jasmine.undefined ? true : consolidate; - this.useDotNotation = useDotNotation === jasmine.undefined ? true : useDotNotation; - }; - JUnitXmlReporter.finished_at = null; // will be updated after all files have been written - - JUnitXmlReporter.prototype = { - reportSpecStarting: function(spec) { - spec.startTime = new Date(); - - if (!spec.suite.startTime) { - spec.suite.startTime = spec.startTime; - } - }, - - reportSpecResults: function(spec) { - var results = spec.results(); - spec.didFail = !results.passed(); - spec.duration = elapsed(spec.startTime, new Date()); - spec.output = ''; - - var failure = ""; - var failures = 0; - var resultItems = results.getItems(); - for (var i = 0; i < resultItems.length; i++) { - var result = resultItems[i]; - - if (result.type == 'expect' && result.passed && !result.passed()) { - failures += 1; - failure += (failures + ": " + escapeInvalidXmlChars(result.message) + " "); - } - } - if (failure) { - spec.output += "" + trim(failure) + ""; - } - spec.output += ""; - }, - - reportSuiteResults: function(suite) { - var results = suite.results(); - var specs = suite.specs(); - var specOutput = ""; - // for JUnit results, let's only include directly failed tests (not nested suites') - var failedCount = 0; - - suite.status = results.passed() ? 'Passed.' : 'Failed.'; - if (results.totalCount === 0) { // todo: change this to check results.skipped - suite.status = 'Skipped.'; - } - - // if a suite has no (active?) specs, reportSpecStarting is never called - // and thus the suite has no startTime -- account for that here - suite.startTime = suite.startTime || new Date(); - suite.duration = elapsed(suite.startTime, new Date()); - - for (var i = 0; i < specs.length; i++) { - failedCount += specs[i].didFail ? 1 : 0; - specOutput += "\n " + specs[i].output; - } - suite.output = '\n'; - suite.output += specOutput; - suite.output += "\n"; - }, - - reportRunnerResults: function(runner) { - var suites = runner.suites(); - for (var i = 0; i < suites.length; i++) { - var suite = suites[i]; - var fileName = 'TEST-' + this.getFullName(suite, true) + '.xml'; - var output = ''; - // if we are consolidating, only write out top-level suites - if (this.consolidate && suite.parentSuite) { - continue; - } - else if (this.consolidate) { - output += "\n"; - output += this.getNestedOutput(suite); - output += "\n"; - this.writeFile(this.savePath + fileName, output); - } - else { - output += suite.output; - this.writeFile(this.savePath + fileName, output); - } - } - // When all done, make it known on JUnitXmlReporter - JUnitXmlReporter.finished_at = (new Date()).getTime(); - }, - - getNestedOutput: function(suite) { - var output = suite.output; - for (var i = 0; i < suite.suites().length; i++) { - output += this.getNestedOutput(suite.suites()[i]); - } - return output; - }, - - writeFile: function(filename, text) { - // Rhino - try { - var out = new java.io.BufferedWriter(new java.io.FileWriter(filename)); - out.write(text); - out.close(); - return; - } catch (e) {} - // PhantomJS, via a method injected by phantomjs-testrunner.js - try { - __phantom_writeFile(filename, text); - return; - } catch (f) {} - // Node.js - try { - var fs = require("fs"); - var fd = fs.openSync(filename, "w"); - fs.writeSync(fd, text, 0); - fs.closeSync(fd); - return; - } catch (g) {} - }, - - getFullName: function(suite, isFilename) { - var fullName; - if (this.useDotNotation) { - fullName = suite.description; - for (var parentSuite = suite.parentSuite; parentSuite; parentSuite = parentSuite.parentSuite) { - fullName = parentSuite.description + '.' + fullName; - } - } - else { - fullName = suite.getFullName(); - } - - // Either remove or escape invalid XML characters - if (isFilename) { - return fullName.replace(/[^\w]/g, ""); - } - return escapeInvalidXmlChars(fullName); - }, - - log: function(str) { - var console = jasmine.getGlobal().console; - - if (console && console.log) { - console.log(str); - } - } - }; - - // export public - jasmine.JUnitXmlReporter = JUnitXmlReporter; -})(); \ No newline at end of file -- 2.45.2 From 8ffb807aca603ee1ffd9a6223199cc6605aaad53 Mon Sep 17 00:00:00 2001 From: hysios hu Date: Thu, 20 Sep 2012 14:24:10 +0800 Subject: [PATCH 05/20] change junit file name --- .../javascripts/jasmine.JUnitReporter.js | 200 ++++++++++++++++++ 1 file changed, 200 insertions(+) create mode 100644 vendor/assets/javascripts/jasmine.JUnitReporter.js diff --git a/vendor/assets/javascripts/jasmine.JUnitReporter.js b/vendor/assets/javascripts/jasmine.JUnitReporter.js new file mode 100644 index 0000000..1aa69ee --- /dev/null +++ b/vendor/assets/javascripts/jasmine.JUnitReporter.js @@ -0,0 +1,200 @@ +(function() { + + if (! jasmine) { + throw new Exception("jasmine library does not exist in global namespace!"); + } + + function elapsed(startTime, endTime) { + return (endTime - startTime)/1000; + } + + function ISODateString(d) { + function pad(n) { return n < 10 ? '0'+n : n; } + + return d.getFullYear() + '-' + + pad(d.getMonth()+1) + '-' + + pad(d.getDate()) + 'T' + + pad(d.getHours()) + ':' + + pad(d.getMinutes()) + ':' + + pad(d.getSeconds()); + } + + function trim(str) { + return str.replace(/^\s+/, "" ).replace(/\s+$/, "" ); + } + + function escapeInvalidXmlChars(str) { + return str.replace(/\&/g, "&") + .replace(//g, ">") + .replace(/\"/g, """) + .replace(/\'/g, "'"); + } + + /** + * Generates JUnit XML for the given spec run. + * Allows the test results to be used in java based CI + * systems like CruiseControl and Hudson. + * + * @param {string} savePath where to save the files + * @param {boolean} consolidate whether to save nested describes within the + * same file as their parent; default: true + * @param {boolean} useDotNotation whether to separate suite names with + * dots rather than spaces (ie "Class.init" not + * "Class init"); default: true + */ + var JUnitXmlReporter = function(savePath, consolidate, useDotNotation) { + this.savePath = savePath || ''; + this.consolidate = consolidate === jasmine.undefined ? true : consolidate; + this.useDotNotation = useDotNotation === jasmine.undefined ? true : useDotNotation; + }; + JUnitXmlReporter.finished_at = null; // will be updated after all files have been written + + JUnitXmlReporter.prototype = { + reportSpecStarting: function(spec) { + spec.startTime = new Date(); + + if (!spec.suite.startTime) { + spec.suite.startTime = spec.startTime; + } + }, + + reportSpecResults: function(spec) { + var results = spec.results(); + spec.didFail = !results.passed(); + spec.duration = elapsed(spec.startTime, new Date()); + spec.output = ''; + + var failure = ""; + var failures = 0; + var resultItems = results.getItems(); + for (var i = 0; i < resultItems.length; i++) { + var result = resultItems[i]; + + if (result.type == 'expect' && result.passed && !result.passed()) { + failures += 1; + failure += (failures + ": " + escapeInvalidXmlChars(result.message) + " "); + } + } + if (failure) { + spec.output += "" + trim(failure) + ""; + } + spec.output += ""; + }, + + reportSuiteResults: function(suite) { + var results = suite.results(); + var specs = suite.specs(); + var specOutput = ""; + // for JUnit results, let's only include directly failed tests (not nested suites') + var failedCount = 0; + + suite.status = results.passed() ? 'Passed.' : 'Failed.'; + if (results.totalCount === 0) { // todo: change this to check results.skipped + suite.status = 'Skipped.'; + } + + // if a suite has no (active?) specs, reportSpecStarting is never called + // and thus the suite has no startTime -- account for that here + suite.startTime = suite.startTime || new Date(); + suite.duration = elapsed(suite.startTime, new Date()); + + for (var i = 0; i < specs.length; i++) { + failedCount += specs[i].didFail ? 1 : 0; + specOutput += "\n " + specs[i].output; + } + suite.output = '\n'; + suite.output += specOutput; + suite.output += "\n"; + }, + + reportRunnerResults: function(runner) { + var suites = runner.suites(); + for (var i = 0; i < suites.length; i++) { + var suite = suites[i]; + var fileName = 'TEST-' + this.getFullName(suite, true) + '.xml'; + var output = ''; + // if we are consolidating, only write out top-level suites + if (this.consolidate && suite.parentSuite) { + continue; + } + else if (this.consolidate) { + output += "\n"; + output += this.getNestedOutput(suite); + output += "\n"; + this.writeFile(this.savePath + fileName, output); + } + else { + output += suite.output; + this.writeFile(this.savePath + fileName, output); + } + } + // When all done, make it known on JUnitXmlReporter + JUnitXmlReporter.finished_at = (new Date()).getTime(); + }, + + getNestedOutput: function(suite) { + var output = suite.output; + for (var i = 0; i < suite.suites().length; i++) { + output += this.getNestedOutput(suite.suites()[i]); + } + return output; + }, + + writeFile: function(filename, text) { + // Rhino + try { + var out = new java.io.BufferedWriter(new java.io.FileWriter(filename)); + out.write(text); + out.close(); + return; + } catch (e) {} + // PhantomJS, via a method injected by phantomjs-testrunner.js + try { + __phantom_writeFile(filename, text); + return; + } catch (f) {} + // Node.js + try { + var fs = require("fs"); + var fd = fs.openSync(filename, "w"); + fs.writeSync(fd, text, 0); + fs.closeSync(fd); + return; + } catch (g) {} + }, + + getFullName: function(suite, isFilename) { + var fullName; + if (this.useDotNotation) { + fullName = suite.description; + for (var parentSuite = suite.parentSuite; parentSuite; parentSuite = parentSuite.parentSuite) { + fullName = parentSuite.description + '.' + fullName; + } + } + else { + fullName = suite.getFullName(); + } + + // Either remove or escape invalid XML characters + if (isFilename) { + return fullName.replace(/[^\w]/g, ""); + } + return escapeInvalidXmlChars(fullName); + }, + + log: function(str) { + var console = jasmine.getGlobal().console; + + if (console && console.log) { + console.log(str); + } + } + }; + + // export public + jasmine.JUnitXmlReporter = JUnitXmlReporter; +})(); \ No newline at end of file -- 2.45.2 From 2a429cc5753be70c10d50de5d8570214cc38b2cc Mon Sep 17 00:00:00 2001 From: hysios hu Date: Thu, 20 Sep 2012 14:26:57 +0800 Subject: [PATCH 06/20] change junit file name --- lib/jasmine/headless/files_list.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/jasmine/headless/files_list.rb b/lib/jasmine/headless/files_list.rb index 3338bae..c188993 100644 --- a/lib/jasmine/headless/files_list.rb +++ b/lib/jasmine/headless/files_list.rb @@ -57,7 +57,7 @@ module Jasmine::Headless %w{jasmine.js jasmine-html jasmine.css jasmine-extensions intense headless_reporter_result jasmine.HeadlessReporter jasmine.HeadlessReporter.ConsoleBase - jsDump beautify-html jasmine.junit_reporter} + jsDump beautify-html jasmine.JUnitReporter} end def extension_filter -- 2.45.2 From 38ecb0e18511db3f2eea11ee9528cd6d52f72853 Mon Sep 17 00:00:00 2001 From: hysios hu Date: Thu, 20 Sep 2012 14:50:00 +0800 Subject: [PATCH 07/20] remove files_list JUnitReporter.js --- lib/jasmine/headless/files_list.rb | 2 +- .../javascripts/jasmine.JUnitReporter.js | 200 ------------------ 2 files changed, 1 insertion(+), 201 deletions(-) delete mode 100644 vendor/assets/javascripts/jasmine.JUnitReporter.js diff --git a/lib/jasmine/headless/files_list.rb b/lib/jasmine/headless/files_list.rb index c188993..aad2d62 100644 --- a/lib/jasmine/headless/files_list.rb +++ b/lib/jasmine/headless/files_list.rb @@ -57,7 +57,7 @@ module Jasmine::Headless %w{jasmine.js jasmine-html jasmine.css jasmine-extensions intense headless_reporter_result jasmine.HeadlessReporter jasmine.HeadlessReporter.ConsoleBase - jsDump beautify-html jasmine.JUnitReporter} + jsDump beautify-html} end def extension_filter diff --git a/vendor/assets/javascripts/jasmine.JUnitReporter.js b/vendor/assets/javascripts/jasmine.JUnitReporter.js deleted file mode 100644 index 1aa69ee..0000000 --- a/vendor/assets/javascripts/jasmine.JUnitReporter.js +++ /dev/null @@ -1,200 +0,0 @@ -(function() { - - if (! jasmine) { - throw new Exception("jasmine library does not exist in global namespace!"); - } - - function elapsed(startTime, endTime) { - return (endTime - startTime)/1000; - } - - function ISODateString(d) { - function pad(n) { return n < 10 ? '0'+n : n; } - - return d.getFullYear() + '-' + - pad(d.getMonth()+1) + '-' + - pad(d.getDate()) + 'T' + - pad(d.getHours()) + ':' + - pad(d.getMinutes()) + ':' + - pad(d.getSeconds()); - } - - function trim(str) { - return str.replace(/^\s+/, "" ).replace(/\s+$/, "" ); - } - - function escapeInvalidXmlChars(str) { - return str.replace(/\&/g, "&") - .replace(//g, ">") - .replace(/\"/g, """) - .replace(/\'/g, "'"); - } - - /** - * Generates JUnit XML for the given spec run. - * Allows the test results to be used in java based CI - * systems like CruiseControl and Hudson. - * - * @param {string} savePath where to save the files - * @param {boolean} consolidate whether to save nested describes within the - * same file as their parent; default: true - * @param {boolean} useDotNotation whether to separate suite names with - * dots rather than spaces (ie "Class.init" not - * "Class init"); default: true - */ - var JUnitXmlReporter = function(savePath, consolidate, useDotNotation) { - this.savePath = savePath || ''; - this.consolidate = consolidate === jasmine.undefined ? true : consolidate; - this.useDotNotation = useDotNotation === jasmine.undefined ? true : useDotNotation; - }; - JUnitXmlReporter.finished_at = null; // will be updated after all files have been written - - JUnitXmlReporter.prototype = { - reportSpecStarting: function(spec) { - spec.startTime = new Date(); - - if (!spec.suite.startTime) { - spec.suite.startTime = spec.startTime; - } - }, - - reportSpecResults: function(spec) { - var results = spec.results(); - spec.didFail = !results.passed(); - spec.duration = elapsed(spec.startTime, new Date()); - spec.output = ''; - - var failure = ""; - var failures = 0; - var resultItems = results.getItems(); - for (var i = 0; i < resultItems.length; i++) { - var result = resultItems[i]; - - if (result.type == 'expect' && result.passed && !result.passed()) { - failures += 1; - failure += (failures + ": " + escapeInvalidXmlChars(result.message) + " "); - } - } - if (failure) { - spec.output += "" + trim(failure) + ""; - } - spec.output += ""; - }, - - reportSuiteResults: function(suite) { - var results = suite.results(); - var specs = suite.specs(); - var specOutput = ""; - // for JUnit results, let's only include directly failed tests (not nested suites') - var failedCount = 0; - - suite.status = results.passed() ? 'Passed.' : 'Failed.'; - if (results.totalCount === 0) { // todo: change this to check results.skipped - suite.status = 'Skipped.'; - } - - // if a suite has no (active?) specs, reportSpecStarting is never called - // and thus the suite has no startTime -- account for that here - suite.startTime = suite.startTime || new Date(); - suite.duration = elapsed(suite.startTime, new Date()); - - for (var i = 0; i < specs.length; i++) { - failedCount += specs[i].didFail ? 1 : 0; - specOutput += "\n " + specs[i].output; - } - suite.output = '\n'; - suite.output += specOutput; - suite.output += "\n"; - }, - - reportRunnerResults: function(runner) { - var suites = runner.suites(); - for (var i = 0; i < suites.length; i++) { - var suite = suites[i]; - var fileName = 'TEST-' + this.getFullName(suite, true) + '.xml'; - var output = ''; - // if we are consolidating, only write out top-level suites - if (this.consolidate && suite.parentSuite) { - continue; - } - else if (this.consolidate) { - output += "\n"; - output += this.getNestedOutput(suite); - output += "\n"; - this.writeFile(this.savePath + fileName, output); - } - else { - output += suite.output; - this.writeFile(this.savePath + fileName, output); - } - } - // When all done, make it known on JUnitXmlReporter - JUnitXmlReporter.finished_at = (new Date()).getTime(); - }, - - getNestedOutput: function(suite) { - var output = suite.output; - for (var i = 0; i < suite.suites().length; i++) { - output += this.getNestedOutput(suite.suites()[i]); - } - return output; - }, - - writeFile: function(filename, text) { - // Rhino - try { - var out = new java.io.BufferedWriter(new java.io.FileWriter(filename)); - out.write(text); - out.close(); - return; - } catch (e) {} - // PhantomJS, via a method injected by phantomjs-testrunner.js - try { - __phantom_writeFile(filename, text); - return; - } catch (f) {} - // Node.js - try { - var fs = require("fs"); - var fd = fs.openSync(filename, "w"); - fs.writeSync(fd, text, 0); - fs.closeSync(fd); - return; - } catch (g) {} - }, - - getFullName: function(suite, isFilename) { - var fullName; - if (this.useDotNotation) { - fullName = suite.description; - for (var parentSuite = suite.parentSuite; parentSuite; parentSuite = parentSuite.parentSuite) { - fullName = parentSuite.description + '.' + fullName; - } - } - else { - fullName = suite.getFullName(); - } - - // Either remove or escape invalid XML characters - if (isFilename) { - return fullName.replace(/[^\w]/g, ""); - } - return escapeInvalidXmlChars(fullName); - }, - - log: function(str) { - var console = jasmine.getGlobal().console; - - if (console && console.log) { - console.log(str); - } - } - }; - - // export public - jasmine.JUnitXmlReporter = JUnitXmlReporter; -})(); \ No newline at end of file -- 2.45.2 From 9fa31807bf0b9331705e65d3740af47f5be94c42 Mon Sep 17 00:00:00 2001 From: hysios hu Date: Thu, 20 Sep 2012 14:59:52 +0800 Subject: [PATCH 08/20] remove template modify --- skel/template.html.erb | 1 - 1 file changed, 1 deletion(-) diff --git a/skel/template.html.erb b/skel/template.html.erb index 94c2e2a..7525bc1 100644 --- a/skel/template.html.erb +++ b/skel/template.html.erb @@ -68,7 +68,6 @@ checker(); }); } - jasmine.getEnv().addReporter(new jasmine.JUnitXmlReporter()); jasmine.getEnv().execute(); } -- 2.45.2 From d60a95efaf2924a5f1c936e6ad18e8efa1437f88 Mon Sep 17 00:00:00 2001 From: hysios hu Date: Fri, 21 Sep 2012 17:33:46 +0800 Subject: [PATCH 09/20] add display filename in load_spec --- ext/jasmine-webkit-specrunner/Runner.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/ext/jasmine-webkit-specrunner/Runner.cpp b/ext/jasmine-webkit-specrunner/Runner.cpp index 66943a5..e1663a7 100644 --- a/ext/jasmine-webkit-specrunner/Runner.cpp +++ b/ext/jasmine-webkit-specrunner/Runner.cpp @@ -66,7 +66,8 @@ void Runner::loadSpec() QVectorIterator iterator(reportFiles); while (iterator.hasNext()) { - QFile *outputFile = new QFile(iterator.next()); + QString fileName = iterator.next(); + QFile *outputFile = new QFile(fileName); outputFile->open(QIODevice::WriteOnly); outputFiles.enqueue(outputFile); } -- 2.45.2 From c0014ae2b7a7a5a3881cb2fbd99b2f52b90dddde Mon Sep 17 00:00:00 2001 From: hysios hu Date: Fri, 21 Sep 2012 18:07:19 +0800 Subject: [PATCH 10/20] add print --- ext/jasmine-webkit-specrunner/Runner.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/ext/jasmine-webkit-specrunner/Runner.cpp b/ext/jasmine-webkit-specrunner/Runner.cpp index e1663a7..52f410e 100644 --- a/ext/jasmine-webkit-specrunner/Runner.cpp +++ b/ext/jasmine-webkit-specrunner/Runner.cpp @@ -67,6 +67,7 @@ void Runner::loadSpec() while (iterator.hasNext()) { QString fileName = iterator.next(); + std::cout << qPrintable(fileName); QFile *outputFile = new QFile(fileName); outputFile->open(QIODevice::WriteOnly); outputFiles.enqueue(outputFile); -- 2.45.2 From 453271ad333fe2a8992d779da91d6c4490b7f7eb Mon Sep 17 00:00:00 2001 From: hysios hu Date: Sun, 23 Sep 2012 11:07:43 +0800 Subject: [PATCH 11/20] add Print debug log --- ext/jasmine-webkit-specrunner/Runner.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/ext/jasmine-webkit-specrunner/Runner.cpp b/ext/jasmine-webkit-specrunner/Runner.cpp index 52f410e..2c63ea5 100644 --- a/ext/jasmine-webkit-specrunner/Runner.cpp +++ b/ext/jasmine-webkit-specrunner/Runner.cpp @@ -154,6 +154,8 @@ void Runner::print(const QString &fh, const QString &content) { int index = (int)fh.split(":").last().toUInt(); QTextStream ts(outputFiles.at(index)); + while (!outputFiles.isEmpty()) + std::cout << qPrintable(outputFiles.dequeue()) << endl; ts << qPrintable(content); ts.flush(); } -- 2.45.2 From f2126b288559e74d7ff78e18508e568fc724d931 Mon Sep 17 00:00:00 2001 From: hysios hu Date: Sun, 23 Sep 2012 16:40:16 +0800 Subject: [PATCH 12/20] fix std:endl --- ext/jasmine-webkit-specrunner/Runner.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ext/jasmine-webkit-specrunner/Runner.cpp b/ext/jasmine-webkit-specrunner/Runner.cpp index 2c63ea5..b7414d0 100644 --- a/ext/jasmine-webkit-specrunner/Runner.cpp +++ b/ext/jasmine-webkit-specrunner/Runner.cpp @@ -155,7 +155,7 @@ void Runner::print(const QString &fh, const QString &content) { QTextStream ts(outputFiles.at(index)); while (!outputFiles.isEmpty()) - std::cout << qPrintable(outputFiles.dequeue()) << endl; + std::cout << qPrintable(outputFiles.dequeue()) << std::endl; ts << qPrintable(content); ts.flush(); } -- 2.45.2 From fd383be5acc490ecbc6e5e306012de8a61f105ec Mon Sep 17 00:00:00 2001 From: hysios hu Date: Sun, 23 Sep 2012 16:54:25 +0800 Subject: [PATCH 13/20] print outoutFile Name --- ext/jasmine-webkit-specrunner/Runner.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/ext/jasmine-webkit-specrunner/Runner.cpp b/ext/jasmine-webkit-specrunner/Runner.cpp index b7414d0..7c3d77d 100644 --- a/ext/jasmine-webkit-specrunner/Runner.cpp +++ b/ext/jasmine-webkit-specrunner/Runner.cpp @@ -154,8 +154,10 @@ void Runner::print(const QString &fh, const QString &content) { int index = (int)fh.split(":").last().toUInt(); QTextStream ts(outputFiles.at(index)); - while (!outputFiles.isEmpty()) - std::cout << qPrintable(outputFiles.dequeue()) << std::endl; + while (!outputFiles.isEmpty()){ + QFile *outputFile = outputFiles.dequeue(); + std::cout << qPrintable(outputFile->fileName()) << std::endl; + } ts << qPrintable(content); ts.flush(); } -- 2.45.2 From d65348a05146cfd60f1dc5940820388ad267c20c Mon Sep 17 00:00:00 2001 From: hysios hu Date: Sun, 23 Sep 2012 17:08:51 +0800 Subject: [PATCH 14/20] add a deboug print --- ext/jasmine-webkit-specrunner/Runner.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ext/jasmine-webkit-specrunner/Runner.cpp b/ext/jasmine-webkit-specrunner/Runner.cpp index 7c3d77d..655a95c 100644 --- a/ext/jasmine-webkit-specrunner/Runner.cpp +++ b/ext/jasmine-webkit-specrunner/Runner.cpp @@ -152,7 +152,7 @@ void Runner::print(const QString &fh, const QString &content) { if (fh.contains("report")) { int index = (int)fh.split(":").last().toUInt(); - + std::cout << qPrintable("report"); QTextStream ts(outputFiles.at(index)); while (!outputFiles.isEmpty()){ QFile *outputFile = outputFiles.dequeue(); -- 2.45.2 From f96b931285ff8ab5e76efc343493d831a8d08738 Mon Sep 17 00:00:00 2001 From: hysios hu Date: Sun, 23 Sep 2012 17:27:03 +0800 Subject: [PATCH 15/20] Runner::print --- ext/jasmine-webkit-specrunner/Runner.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/ext/jasmine-webkit-specrunner/Runner.cpp b/ext/jasmine-webkit-specrunner/Runner.cpp index 655a95c..4eb083f 100644 --- a/ext/jasmine-webkit-specrunner/Runner.cpp +++ b/ext/jasmine-webkit-specrunner/Runner.cpp @@ -140,6 +140,7 @@ bool Runner::isQuiet() { } void Runner::print(const QString &fh, const QString &content) { + std::cout << qPrintable("Runner::report"); if (fh == "stdout") { std::cout << qPrintable(content); std::cout.flush(); @@ -152,7 +153,7 @@ void Runner::print(const QString &fh, const QString &content) { if (fh.contains("report")) { int index = (int)fh.split(":").last().toUInt(); - std::cout << qPrintable("report"); + QTextStream ts(outputFiles.at(index)); while (!outputFiles.isEmpty()){ QFile *outputFile = outputFiles.dequeue(); -- 2.45.2 From 9a47cdd6c8adf716f6e5399e97ea766b32f51de6 Mon Sep 17 00:00:00 2001 From: hysios hu Date: Sun, 23 Sep 2012 17:33:27 +0800 Subject: [PATCH 16/20] add print fh --- ext/jasmine-webkit-specrunner/Runner.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ext/jasmine-webkit-specrunner/Runner.cpp b/ext/jasmine-webkit-specrunner/Runner.cpp index 4eb083f..bb5c5ea 100644 --- a/ext/jasmine-webkit-specrunner/Runner.cpp +++ b/ext/jasmine-webkit-specrunner/Runner.cpp @@ -140,7 +140,6 @@ bool Runner::isQuiet() { } void Runner::print(const QString &fh, const QString &content) { - std::cout << qPrintable("Runner::report"); if (fh == "stdout") { std::cout << qPrintable(content); std::cout.flush(); @@ -150,6 +149,7 @@ void Runner::print(const QString &fh, const QString &content) { std::cerr << qPrintable(content); std::cerr.flush(); } + std::cout << qPrintable("Runner::report" + fh); if (fh.contains("report")) { int index = (int)fh.split(":").last().toUInt(); -- 2.45.2 From 065e69b09f7d2bdae30a9d2700ca61e8830d26f4 Mon Sep 17 00:00:00 2001 From: hysios hu Date: Sun, 23 Sep 2012 18:08:56 +0800 Subject: [PATCH 17/20] fix a bug --- ext/jasmine-webkit-specrunner/Runner.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ext/jasmine-webkit-specrunner/Runner.cpp b/ext/jasmine-webkit-specrunner/Runner.cpp index bb5c5ea..2de6505 100644 --- a/ext/jasmine-webkit-specrunner/Runner.cpp +++ b/ext/jasmine-webkit-specrunner/Runner.cpp @@ -149,7 +149,7 @@ void Runner::print(const QString &fh, const QString &content) { std::cerr << qPrintable(content); std::cerr.flush(); } - std::cout << qPrintable("Runner::report" + fh); + std::cout << qPrintable("Runner::report " + fh); if (fh.contains("report")) { int index = (int)fh.split(":").last().toUInt(); -- 2.45.2 From 1079c71369d9e0f07c875063db4ee37be74521af Mon Sep 17 00:00:00 2001 From: hysios hu Date: Sun, 23 Sep 2012 18:17:50 +0800 Subject: [PATCH 18/20] add printFile function --- ext/jasmine-webkit-specrunner/Runner.cpp | 8 ++++++++ ext/jasmine-webkit-specrunner/Runner.h | 1 + 2 files changed, 9 insertions(+) diff --git a/ext/jasmine-webkit-specrunner/Runner.cpp b/ext/jasmine-webkit-specrunner/Runner.cpp index 2de6505..b0dfc06 100644 --- a/ext/jasmine-webkit-specrunner/Runner.cpp +++ b/ext/jasmine-webkit-specrunner/Runner.cpp @@ -164,6 +164,14 @@ void Runner::print(const QString &fh, const QString &content) { } } +void Runner::printFile(const QString &fileName, const QString &content) { + QFile *outputFile = new QFile(fileName); + outputFile->open(QIODevice::WriteOnly); + QTextStream ts(outputFile); + ts << qPrintable(content); + ts.flush(); +} + void Runner::finishSuite() { isFinished = true; runs = 0; diff --git a/ext/jasmine-webkit-specrunner/Runner.h b/ext/jasmine-webkit-specrunner/Runner.h index 3f1f01b..024e362 100644 --- a/ext/jasmine-webkit-specrunner/Runner.h +++ b/ext/jasmine-webkit-specrunner/Runner.h @@ -40,6 +40,7 @@ class Runner: public QObject { QString getSeed(); void print(const QString &fh, const QString &content); + void printFile(const QString &fileName, const QString &content); void finishSuite(); void ping(); -- 2.45.2 From d3a87a7fc69c7b868bba091589335a73a99e5a11 Mon Sep 17 00:00:00 2001 From: hysios hu Date: Tue, 25 Sep 2012 16:12:50 +0800 Subject: [PATCH 19/20] remove debug log --- ext/jasmine-webkit-specrunner/Runner.cpp | 6 ------ 1 file changed, 6 deletions(-) diff --git a/ext/jasmine-webkit-specrunner/Runner.cpp b/ext/jasmine-webkit-specrunner/Runner.cpp index b0dfc06..fb455ef 100644 --- a/ext/jasmine-webkit-specrunner/Runner.cpp +++ b/ext/jasmine-webkit-specrunner/Runner.cpp @@ -67,7 +67,6 @@ void Runner::loadSpec() while (iterator.hasNext()) { QString fileName = iterator.next(); - std::cout << qPrintable(fileName); QFile *outputFile = new QFile(fileName); outputFile->open(QIODevice::WriteOnly); outputFiles.enqueue(outputFile); @@ -149,16 +148,11 @@ void Runner::print(const QString &fh, const QString &content) { std::cerr << qPrintable(content); std::cerr.flush(); } - std::cout << qPrintable("Runner::report " + fh); if (fh.contains("report")) { int index = (int)fh.split(":").last().toUInt(); QTextStream ts(outputFiles.at(index)); - while (!outputFiles.isEmpty()){ - QFile *outputFile = outputFiles.dequeue(); - std::cout << qPrintable(outputFile->fileName()) << std::endl; - } ts << qPrintable(content); ts.flush(); } -- 2.45.2 From 1b959250a0dd3f5e6b862fe27e42baf4dea3732c Mon Sep 17 00:00:00 2001 From: hysios hu Date: Tue, 25 Sep 2012 16:22:22 +0800 Subject: [PATCH 20/20] use file to default output dir --- lib/jasmine/headless/template_writer.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/jasmine/headless/template_writer.rb b/lib/jasmine/headless/template_writer.rb index 81562a5..487b613 100644 --- a/lib/jasmine/headless/template_writer.rb +++ b/lib/jasmine/headless/template_writer.rb @@ -49,7 +49,8 @@ module Jasmine::Headless end def jhw_reporters - reporters.collect do |reporter, output| + reporters.collect do |reporter, report, output| + output = output || "spec/reports" %{jasmine.getEnv().addReporter(new jasmine.HeadlessReporter.#{reporter}("#{output}"));} end.join("\n") end -- 2.45.2