diff --git a/ext/jasmine-webkit-specrunner/Runner.cpp b/ext/jasmine-webkit-specrunner/Runner.cpp index e5e03a5..641edf9 100644 --- a/ext/jasmine-webkit-specrunner/Runner.cpp +++ b/ext/jasmine-webkit-specrunner/Runner.cpp @@ -139,6 +139,7 @@ void Runner::print(const QString &fh, const QString &content) { void Runner::finishSuite() { isFinished = true; + runs = 0; } void Runner::timerEvent() { @@ -147,7 +148,7 @@ void Runner::timerEvent() { if (hasErrors && runs > 2) QApplication::instance()->exit(1); - if (isFinished) { + if (isFinished && runs > 2) { if (outputFile) { outputFile->close(); } diff --git a/lib/jasmine/headless/files_list.rb b/lib/jasmine/headless/files_list.rb index d12725e..f22414e 100644 --- a/lib/jasmine/headless/files_list.rb +++ b/lib/jasmine/headless/files_list.rb @@ -61,7 +61,9 @@ module Jasmine::Headless end def default_files - %w{jasmine.js jasmine-html jasmine.css jasmine-extensions intense headless_reporter_result jasmine.HeadlessConsoleReporter jsDump beautify-html} + %w{jasmine.js jasmine-html jasmine.css jasmine-extensions + intense headless_reporter_result jasmine.HeadlessReporter + jasmine.HeadlessFileReporter jasmine.HeadlessConsoleReporter jsDump beautify-html} end def extension_filter diff --git a/skel/template.html.erb b/skel/template.html.erb index 0f240a4..10e5307 100644 --- a/skel/template.html.erb +++ b/skel/template.html.erb @@ -24,6 +24,7 @@ if (window.JHW) { jasmine.getEnv().addReporter(new jasmine.HeadlessConsoleReporter()); + jasmine.getEnv().addReporter(new jasmine.HeadlessFileReporter()); } else { types = [ 'HtmlReporter', 'TrivialReporter' ]; diff --git a/spec/javascripts/headless_reporter_result_spec.coffee b/spec/javascripts/headless_reporter_result_spec.coffee index 2c2d501..f5f6fff 100644 --- a/spec/javascripts/headless_reporter_result_spec.coffee +++ b/spec/javascripts/headless_reporter_result_spec.coffee @@ -4,11 +4,27 @@ describe 'HeadlessReporterResult', -> splitName = "splitName" message = 'message' - beforeEach -> - result = new HeadlessReporterResult(name, splitName) + context 'no lines', -> + beforeEach -> + result = new HeadlessReporterResult(name, splitName) - describe '#addResult', -> - it 'should add a message', -> - result.addResult(message) + describe '#addResult', -> + it 'should add a message', -> + result.addResult(message) + + expect(result.results).toEqual([ message ]) + + context 'with lines', -> + beforeEach -> + HeadlessReporterResult.specLineNumbers = { + 'one': { + 'name': [ 1 ], + 'of': [ 2, 9 ], + 'test': [ 3, 10 ], + 'other': [ 7 ] + } + } + it 'should find the best spec lines', -> + expect(HeadlessReporterResult.findSpecLine([ 'name', 'of', 'test' ]).lineNumber).toEqual(3) + expect(HeadlessReporterResult.findSpecLine([ 'other', 'of', 'test' ]).lineNumber).toEqual(10) - expect(result.results).toEqual([ message ]) diff --git a/spec/javascripts/helpers/spec_helper.coffee b/spec/javascripts/helpers/spec_helper.coffee new file mode 100644 index 0000000..4905362 --- /dev/null +++ b/spec/javascripts/helpers/spec_helper.coffee @@ -0,0 +1,2 @@ +window.context = window.describe + diff --git a/spec/javascripts/jasmine-extensions_spec.coffee b/spec/javascripts/jasmine-extensions_spec.coffee new file mode 100644 index 0000000..8ed17fd --- /dev/null +++ b/spec/javascripts/jasmine-extensions_spec.coffee @@ -0,0 +1,80 @@ +describe 'jasmine.Suite.prototype.getSuiteSplitName', -> + it 'should flatten the description', -> + suite = new jasmine.Suite({}); + suite.description = "hello\ngoodbye\n"; + expect(suite.getSuiteSplitName()).toEqual([ "hello goodbye " ]) + + it 'should not fail on missing description', -> + suite = new jasmine.Suite({}); + suite.description = 1; + expect(suite.getSuiteSplitName()).toEqual([ "1" ]) + +describe 'jasmine.Spec.prototype.getSuiteSplitName', -> + it 'should flatten the description', -> + spec = new jasmine.Spec({}, {}); + spec.suite = { + getSuiteSplitName: -> [] + } + spec.description = "hello\ngoodbye\n"; + expect(spec.getSpecSplitName()).toEqual([ "hello goodbye " ]) + + it 'should not fail on missing description', -> + spec = new jasmine.Spec({}, {}); + spec.suite = { + getSuiteSplitName: -> [] + } + spec.description = 1 + expect(spec.getSpecSplitName()).toEqual([ "1" ]) + +describe 'jasmine.Spec.prototype.getJHWSpecInformation', -> + it 'should append null when there is no file information', -> + spec = new jasmine.Spec({}, {}) + spyOn(spec, 'getSpecSplitName').andReturn(["one"]) + spyOn(HeadlessReporterResult, 'findSpecLine').andReturn({}) + expect(spec.getJHWSpecInformation()).toEqual("one||") + +describe 'jasmine.WaitsBlock and jasmine.WaitsForBlock', -> + beforeEach -> + it 'should notify JHW of waiting', -> + waits(5500) + runs -> + expect(true).toEqual(true) + + it 'should notify JHW of waiting for something', -> + value = false + + setTimeout( + -> + value = true + , 5000 + ) + + waitsFor( + -> + value + , "Nope" + 5500 + ) + + runs -> + expect(true).toEqual(true) + +describe 'jasmine.NestedResults.isValidSpecLine', -> + it 'should check the lines', -> + expect(jasmine.NestedResults.isValidSpecLine('yes')).toEqual(false) + expect(jasmine.NestedResults.isValidSpecLine('expect')).toEqual(true) + expect(jasmine.NestedResults.isValidSpecLine(' expect')).toEqual(true) + expect(jasmine.NestedResults.isValidSpecLine('return expect')).toEqual(true) + expect(jasmine.NestedResults.isValidSpecLine(' return expect')).toEqual(true) + +describe 'jasmine.nestedResults.parseFunction', -> + it 'should parse the function', -> + expect(jasmine.NestedResults.parseFunction(""" +test +expect("cat") + return expect("dog") + """)).toEqual([ + [ 'expect("cat")', 1 ], + [ 'expect("dog")', 2 ] + ]) + diff --git a/spec/javascripts/jasmine.HeadlessConsoleReporter_spec.coffee b/spec/javascripts/jasmine.HeadlessConsoleReporter_spec.coffee index 6696b95..31a4a78 100644 --- a/spec/javascripts/jasmine.HeadlessConsoleReporter_spec.coffee +++ b/spec/javascripts/jasmine.HeadlessConsoleReporter_spec.coffee @@ -1,16 +1,4 @@ describe 'HeadlessReporterResult', -> - beforeEach -> - HeadlessReporterResult.specLineNumbers = { - 'one': { - 'name': [ 1 ], - 'of': [ 2, 9 ], - 'test': [ 3, 10 ], - 'other': [ 7 ] - } - } - it 'should find the best spec lines', -> - expect(HeadlessReporterResult.findSpecLine([ 'name', 'of', 'test' ]).lineNumber).toEqual(3) - expect(HeadlessReporterResult.findSpecLine([ 'other', 'of', 'test' ]).lineNumber).toEqual(10) describe 'jasmine.HeadlessConsoleReporter', -> reporter = null @@ -18,98 +6,32 @@ describe 'jasmine.HeadlessConsoleReporter', -> beforeEach -> reporter = new jasmine.HeadlessConsoleReporter() - it 'should stop running specs if there are errors reported', -> - # otherwise it gets really confusing! + describe '#formatResultLine', -> + context 'length = 1', -> + it 'should format', -> + reporter.length = 1 + expect(reporter.formatResultLine(0)).toMatch(/test,/) - suite = { finish: -> null } - spec = new jasmine.Spec("env", suite, "test") + context 'length != 1', -> + it 'should format', -> + reporter.length = 2 + expect(reporter.formatResultLine(0)).toMatch(/tests,/) - spyOn(reporter, 'hasError').andReturn(true) - spyOn(spec, 'finish') - spyOn(suite, 'finish') + context 'failedCount = 1', -> + it 'should format', -> + reporter.failedCount = 1 + expect(reporter.formatResultLine(0)).toMatch(/failure,/) - reporter.reportSpecStarting(spec) - - expect(spec.finish).toHaveBeenCalled() - expect(suite.finish).toHaveBeenCalled() + context 'failedCount != 1', -> + it 'should format', -> + reporter.failedCount = 0 + expect(reporter.formatResultLine(0)).toMatch(/failures,/) -describe 'jasmine.Suite.prototype.getSuiteSplitName', -> - it 'should flatten the description', -> - suite = new jasmine.Suite({}); - suite.description = "hello\ngoodbye\n"; - expect(suite.getSuiteSplitName()).toEqual([ "hello goodbye " ]) + context 'runtime = 1', -> + it 'should format', -> + expect(reporter.formatResultLine(1)).toMatch(/sec./) - it 'should not fail on missing description', -> - suite = new jasmine.Suite({}); - suite.description = 1; - expect(suite.getSuiteSplitName()).toEqual([ "1" ]) - -describe 'jasmine.Spec.prototype.getSuiteSplitName', -> - it 'should flatten the description', -> - spec = new jasmine.Spec({}, {}); - spec.suite = { - getSuiteSplitName: -> [] - } - spec.description = "hello\ngoodbye\n"; - expect(spec.getSpecSplitName()).toEqual([ "hello goodbye " ]) - - it 'should not fail on missing description', -> - spec = new jasmine.Spec({}, {}); - spec.suite = { - getSuiteSplitName: -> [] - } - spec.description = 1 - expect(spec.getSpecSplitName()).toEqual([ "1" ]) - -describe 'jasmine.Spec.prototype.getJHWSpecInformation', -> - it 'should append null when there is no file information', -> - spec = new jasmine.Spec({}, {}) - spyOn(spec, 'getSpecSplitName').andReturn(["one"]) - spyOn(HeadlessReporterResult, 'findSpecLine').andReturn({}) - expect(spec.getJHWSpecInformation()).toEqual("one||") - -describe 'jasmine.WaitsBlock and jasmine.WaitsForBlock', -> - beforeEach -> - it 'should notify JHW of waiting', -> - waits(5500) - runs -> - expect(true).toEqual(true) - - it 'should notify JHW of waiting for something', -> - value = false - - setTimeout( - -> - value = true - , 5000 - ) - - waitsFor( - -> - value - , "Nope" - 5500 - ) - - runs -> - expect(true).toEqual(true) - -describe 'jasmine.NestedResults.isValidSpecLine', -> - it 'should check the lines', -> - expect(jasmine.NestedResults.isValidSpecLine('yes')).toEqual(false) - expect(jasmine.NestedResults.isValidSpecLine('expect')).toEqual(true) - expect(jasmine.NestedResults.isValidSpecLine(' expect')).toEqual(true) - expect(jasmine.NestedResults.isValidSpecLine('return expect')).toEqual(true) - expect(jasmine.NestedResults.isValidSpecLine(' return expect')).toEqual(true) - -describe 'jasmine.nestedResults.parseFunction', -> - it 'should parse the function', -> - expect(jasmine.NestedResults.parseFunction(""" -test -expect("cat") - return expect("dog") - """)).toEqual([ - [ 'expect("cat")', 1 ], - [ 'expect("dog")', 2 ] - ]) + context 'runtime != 1', -> + it 'should format', -> + expect(reporter.formatResultLine(0)).toMatch(/secs./) diff --git a/spec/javascripts/jasmine.HeadlessReporter_spec.coffee b/spec/javascripts/jasmine.HeadlessReporter_spec.coffee new file mode 100644 index 0000000..8a31685 --- /dev/null +++ b/spec/javascripts/jasmine.HeadlessReporter_spec.coffee @@ -0,0 +1,27 @@ +describe 'jasmine.HeadlessReporter', -> + reporter = null + + beforeEach -> + reporter = new jasmine.HeadlessReporter() + + it 'should stop running specs if there are errors reported', -> + # otherwise it gets really confusing! + + suite = { finish: -> null } + spec = new jasmine.Spec("env", suite, "test") + + spyOn(reporter, 'hasError').andReturn(true) + spyOn(spec, 'finish') + spyOn(suite, 'finish') + + reporter.reportSpecStarting(spec) + + expect(spec.finish).toHaveBeenCalled() + expect(suite.finish).toHaveBeenCalled() + + describe '#reportRunnerStarting', -> + it 'should start getting time', -> + expect(reporter.startTime).not.toBeDefined() + reporter.reportRunnerStarting("runner") + expect(reporter.startTime).toBeDefined() + diff --git a/spec/javascripts/support/jasmine.yml b/spec/javascripts/support/jasmine.yml index fdbbc4c..7f26a68 100644 --- a/spec/javascripts/support/jasmine.yml +++ b/spec/javascripts/support/jasmine.yml @@ -1,8 +1,9 @@ src_files: - - 'spec/javascripts/support/jquery-1.6.2.min.js' - - 'vendor/assets/coffeescripts/*.coffee' + - '**/*' -spec_files: [ 'spec/javascripts/*_spec.coffee' ] -src_dir: . -spec_dir: . +spec_files: [ '**/*_spec.coffee' ] +src_dir: vendor/assets/javascripts +spec_dir: spec/javascripts +helpers: + - 'helpers/**.*' diff --git a/spec/lib/jasmine/headless/files_list_spec.rb b/spec/lib/jasmine/headless/files_list_spec.rb index d69b34b..9254fbe 100644 --- a/spec/lib/jasmine/headless/files_list_spec.rb +++ b/spec/lib/jasmine/headless/files_list_spec.rb @@ -14,6 +14,8 @@ describe Jasmine::Headless::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.HeadlessReporter.js'), + File.expand_path('vendor/assets/javascripts/jasmine.HeadlessFileReporter.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 index 01ab8c4..c925c57 100644 --- a/vendor/assets/coffeescripts/jasmine.HeadlessConsoleReporter.coffee +++ b/vendor/assets/coffeescripts/jasmine.HeadlessConsoleReporter.coffee @@ -1,33 +1,23 @@ -if !jasmine? - throw new Error("jasmine not loaded!") - -class jasmine.HeadlessConsoleReporter +#= require jasmine.HeadlessReporter.js +# +class jasmine.HeadlessConsoleReporter extends jasmine.HeadlessReporter constructor: (@callback = null) -> - @results = [] - @failedCount = 0 - @length = 0 - @timer = null + super(@callback) + @position = 0 @positions = "|/-\\" reportRunnerResults: (runner) -> - return if this.hasError() - - runtime = (new Date() - @startTime) / 1000.0 + super() JHW.stdout.print("\n") - resultLine = this._formatResultLine(runtime) + resultLine = this.formatResultLine(this._runtime()) if @failedCount == 0 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) for result in @results JHW.stdout.puts(result.toString()) @@ -35,63 +25,37 @@ class jasmine.HeadlessConsoleReporter if window.JHW window.onbeforeunload = null - JHW.finishSuite() - reportRunnerStarting: (runner) -> - @startTime = new Date() + super(runner) JHW.stdout.puts("\nRunning Jasmine specs...".bright()) if !this.hasError() reportSpecResults: (spec) -> - return if this.hasError() - JHW.ping() + super(spec) - results = spec.results() + this._reportSpecResult(spec, { + success: (results) => + JHW.stdout.print('.'.foreground('green')) + failure: (results) => + JHW.stdout.print('F'.foreground('red')) - @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()) + failureResult = new HeadlessReporterResult(spec.getFullName(), spec.getSpecSplitName()) + testCount = 1 - @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() + 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) + }) reportSpecWaiting: -> - runner = null - if !@timer @timer = true - first = true + @first = true - runner = => - @timer = setTimeout( - => - if @timer - JHW.stdout.print(Intense.moveBack()) if !first - JHW.stdout.print(@positions.substr(@position, 1).foreground('yellow')) - @position += 1 - @position %= @positions.length - first = false - runner() - , 750 - ) - runner() + this._waitRunner() reportSpecRunning: -> if @timer @@ -99,11 +63,7 @@ class jasmine.HeadlessConsoleReporter @timer = null JHW.stdout.print(Intense.moveBack()) - reportSuiteResults: (suite) -> - hasError: -> - JHW._hasErrors - - _formatResultLine: (runtime) -> + formatResultLine: (runtime) -> line = [] line.push(@length) line.push((if @length == 1 then "test" else "tests") + ',') @@ -116,3 +76,15 @@ class jasmine.HeadlessConsoleReporter line.join(' ') + _waitRunner: => + @timer = setTimeout( + => + if @timer + JHW.stdout.print(Intense.moveBack()) if !@first + JHW.stdout.print(@positions.substr(@position, 1).foreground('yellow')) + @position += 1 + @position %= @positions.length + @first = false + this._waitRunner() + , 750 + ) diff --git a/vendor/assets/coffeescripts/jasmine.HeadlessFileReporter.coffee b/vendor/assets/coffeescripts/jasmine.HeadlessFileReporter.coffee new file mode 100644 index 0000000..862343f --- /dev/null +++ b/vendor/assets/coffeescripts/jasmine.HeadlessFileReporter.coffee @@ -0,0 +1,17 @@ +class jasmine.HeadlessFileReporter extends jasmine.HeadlessReporter + reportRunnerResults: (runner) -> + super(runner) + + output = "TOTAL||#{@length}||#{@failedCount}||#{this._runtime()}||#{if JHW._hasErrors then "T" else "F"}" + + JHW.report.puts(output) + + reportSpecResults: (spec) -> + super(spec) + + this._reportSpecResult(spec, { + success: (results) => + JHW.report.puts("PASS||" + spec.getJHWSpecInformation()) + failure: (results) => + JHW.report.puts("FAIL||" + spec.getJHWSpecInformation()) + }) diff --git a/vendor/assets/coffeescripts/jasmine.HeadlessReporter.coffee b/vendor/assets/coffeescripts/jasmine.HeadlessReporter.coffee new file mode 100644 index 0000000..4205e1b --- /dev/null +++ b/vendor/assets/coffeescripts/jasmine.HeadlessReporter.coffee @@ -0,0 +1,48 @@ +if !jasmine? + throw new Error("jasmine not loaded!") + +class jasmine.HeadlessReporter + constructor: (@callback = null) -> + @results = [] + @failedCount = 0 + @length = 0 + @timer = null + + hasError: -> + JHW._hasErrors + + reportSpecStarting: (spec) -> + if this.hasError() + spec.finish() + spec.suite.finish() + + reportSuiteResults: (suite) -> + + reportRunnerStarting: (runner) -> + @startTime = new Date() + + reportRunnerResults: (runner) -> + return if this.hasError() + + if @failedCount != 0 + JHW.hasSpecFailure() + + JHW.finishSuite() + + reportSpecResults: (spec) -> + return if this.hasError() + JHW.ping() + + _reportSpecResult: (spec, options) -> + results = spec.results() + + @length++ + + if results.passed() + options.success(results, spec) + else + @failedCount++ + options.failure(results, spec) + + _runtime: -> + (new Date() - @startTime) / 1000.0 diff --git a/vendor/assets/javascripts/jasmine.HeadlessConsoleReporter.js b/vendor/assets/javascripts/jasmine.HeadlessConsoleReporter.js index c276b3a..7584e24 100644 --- a/vendor/assets/javascripts/jasmine.HeadlessConsoleReporter.js +++ b/vendor/assets/javascripts/jasmine.HeadlessConsoleReporter.js @@ -1,107 +1,76 @@ - - if (!(typeof jasmine !== "undefined" && jasmine !== null)) { - throw new Error("jasmine not loaded!"); - } +(function() { + var __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; }, __hasProp = Object.prototype.hasOwnProperty, __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor; child.__super__ = parent.prototype; return child; }; jasmine.HeadlessConsoleReporter = (function() { + __extends(HeadlessConsoleReporter, jasmine.HeadlessReporter); + function HeadlessConsoleReporter(callback) { this.callback = callback != null ? callback : null; - this.results = []; - this.failedCount = 0; - this.length = 0; - this.timer = null; + this._waitRunner = __bind(this._waitRunner, this); + HeadlessConsoleReporter.__super__.constructor.call(this, this.callback); this.position = 0; this.positions = "|/-\\"; } HeadlessConsoleReporter.prototype.reportRunnerResults = function(runner) { - var output, result, resultLine, runtime, _i, _len, _ref; - if (this.hasError()) return; - runtime = (new Date() - this.startTime) / 1000.0; + var result, resultLine, _i, _len, _ref; + HeadlessConsoleReporter.__super__.reportRunnerResults.call(this); JHW.stdout.print("\n"); - resultLine = this._formatResultLine(runtime); + resultLine = this.formatResultLine(this._runtime()); if (this.failedCount === 0) { 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); _ref = this.results; for (_i = 0, _len = _ref.length; _i < _len; _i++) { result = _ref[_i]; JHW.stdout.puts(result.toString()); } - if (window.JHW) window.onbeforeunload = null; - return JHW.finishSuite(); + if (window.JHW) return window.onbeforeunload = null; }; HeadlessConsoleReporter.prototype.reportRunnerStarting = function(runner) { - this.startTime = new Date(); + HeadlessConsoleReporter.__super__.reportRunnerStarting.call(this, runner); if (!this.hasError()) { 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; - JHW.ping(); - 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]; - if (result.type === 'expect' && !result.passed_) { - if (foundLine = result.expectations[testCount - 1]) { - result.line = foundLine[0], result.lineNumber = foundLine[1]; + var _this = this; + HeadlessConsoleReporter.__super__.reportSpecResults.call(this, spec); + return this._reportSpecResult(spec, { + success: function(results) { + return JHW.stdout.print('.'.foreground('green')); + }, + failure: function(results) { + var failureResult, foundLine, result, testCount, _i, _len, _ref; + JHW.stdout.print('F'.foreground('red')); + 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); } - failureResult.addResult(result); + testCount += 1; } - testCount += 1; + return _this.results.push(failureResult); } - return this.results.push(failureResult); - } - }; - - HeadlessConsoleReporter.prototype.reportSpecStarting = function(spec) { - if (this.hasError()) { - spec.finish(); - return spec.suite.finish(); - } + }); }; HeadlessConsoleReporter.prototype.reportSpecWaiting = function() { - var first, runner; - var _this = this; - runner = null; if (!this.timer) { this.timer = true; - first = true; - runner = function() { - return _this.timer = setTimeout(function() { - if (_this.timer) { - if (!first) JHW.stdout.print(Intense.moveBack()); - JHW.stdout.print(_this.positions.substr(_this.position, 1).foreground('yellow')); - _this.position += 1; - _this.position %= _this.positions.length; - first = false; - return runner(); - } - }, 750); - }; - return runner(); + this.first = true; + return this._waitRunner(); } }; @@ -113,13 +82,7 @@ } }; - HeadlessConsoleReporter.prototype.reportSuiteResults = function(suite) {}; - - HeadlessConsoleReporter.prototype.hasError = function() { - return JHW._hasErrors; - }; - - HeadlessConsoleReporter.prototype._formatResultLine = function(runtime) { + HeadlessConsoleReporter.prototype.formatResultLine = function(runtime) { var line; line = []; line.push(this.length); @@ -131,6 +94,22 @@ return line.join(' '); }; + HeadlessConsoleReporter.prototype._waitRunner = function() { + var _this = this; + return this.timer = setTimeout(function() { + if (_this.timer) { + if (!_this.first) JHW.stdout.print(Intense.moveBack()); + JHW.stdout.print(_this.positions.substr(_this.position, 1).foreground('yellow')); + _this.position += 1; + _this.position %= _this.positions.length; + _this.first = false; + return _this._waitRunner(); + } + }, 750); + }; + return HeadlessConsoleReporter; })(); + +}).call(this); diff --git a/vendor/assets/javascripts/jasmine.HeadlessFileReporter.js b/vendor/assets/javascripts/jasmine.HeadlessFileReporter.js new file mode 100644 index 0000000..e0165bf --- /dev/null +++ b/vendor/assets/javascripts/jasmine.HeadlessFileReporter.js @@ -0,0 +1,36 @@ +(function() { + var __hasProp = Object.prototype.hasOwnProperty, __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor; child.__super__ = parent.prototype; return child; }; + + jasmine.HeadlessFileReporter = (function() { + + __extends(HeadlessFileReporter, jasmine.HeadlessReporter); + + function HeadlessFileReporter() { + HeadlessFileReporter.__super__.constructor.apply(this, arguments); + } + + HeadlessFileReporter.prototype.reportRunnerResults = function(runner) { + var output; + HeadlessFileReporter.__super__.reportRunnerResults.call(this, runner); + output = "TOTAL||" + this.length + "||" + this.failedCount + "||" + (this._runtime()) + "||" + (JHW._hasErrors ? "T" : "F"); + return JHW.report.puts(output); + }; + + HeadlessFileReporter.prototype.reportSpecResults = function(spec) { + var _this = this; + HeadlessFileReporter.__super__.reportSpecResults.call(this, spec); + return this._reportSpecResult(spec, { + success: function(results) { + return JHW.report.puts("PASS||" + spec.getJHWSpecInformation()); + }, + failure: function(results) { + return JHW.report.puts("FAIL||" + spec.getJHWSpecInformation()); + } + }); + }; + + return HeadlessFileReporter; + + })(); + +}).call(this); diff --git a/vendor/assets/javascripts/jasmine.HeadlessReporter.js b/vendor/assets/javascripts/jasmine.HeadlessReporter.js new file mode 100644 index 0000000..5a2d33c --- /dev/null +++ b/vendor/assets/javascripts/jasmine.HeadlessReporter.js @@ -0,0 +1,62 @@ + + if (!(typeof jasmine !== "undefined" && jasmine !== null)) { + throw new Error("jasmine not loaded!"); + } + + jasmine.HeadlessReporter = (function() { + + function HeadlessReporter(callback) { + this.callback = callback != null ? callback : null; + this.results = []; + this.failedCount = 0; + this.length = 0; + this.timer = null; + } + + HeadlessReporter.prototype.hasError = function() { + return JHW._hasErrors; + }; + + HeadlessReporter.prototype.reportSpecStarting = function(spec) { + if (this.hasError()) { + spec.finish(); + return spec.suite.finish(); + } + }; + + HeadlessReporter.prototype.reportSuiteResults = function(suite) {}; + + HeadlessReporter.prototype.reportRunnerStarting = function(runner) { + return this.startTime = new Date(); + }; + + HeadlessReporter.prototype.reportRunnerResults = function(runner) { + if (this.hasError()) return; + if (this.failedCount !== 0) JHW.hasSpecFailure(); + return JHW.finishSuite(); + }; + + HeadlessReporter.prototype.reportSpecResults = function(spec) { + if (this.hasError()) return; + return JHW.ping(); + }; + + HeadlessReporter.prototype._reportSpecResult = function(spec, options) { + var results; + results = spec.results(); + this.length++; + if (results.passed()) { + return options.success(results, spec); + } else { + this.failedCount++; + return options.failure(results, spec); + } + }; + + HeadlessReporter.prototype._runtime = function() { + return (new Date() - this.startTime) / 1000.0; + }; + + return HeadlessReporter; + + })();