From e03389e93873fde58369a04084f1a8d154b301ca Mon Sep 17 00:00:00 2001 From: John Bintz Date: Mon, 12 Dec 2011 12:22:32 -0500 Subject: [PATCH 01/45] start splitting the reporters out --- ext/jasmine-webkit-specrunner/Runner.cpp | 3 +- lib/jasmine/headless/files_list.rb | 4 +- skel/template.html.erb | 1 + .../headless_reporter_result_spec.coffee | 28 +++- spec/javascripts/helpers/spec_helper.coffee | 2 + .../jasmine-extensions_spec.coffee | 80 +++++++++++ ...asmine.HeadlessConsoleReporter_spec.coffee | 124 ++++------------- .../jasmine.HeadlessReporter_spec.coffee | 27 ++++ spec/javascripts/support/jasmine.yml | 11 +- spec/lib/jasmine/headless/files_list_spec.rb | 2 + .../jasmine.HeadlessConsoleReporter.coffee | 106 ++++++--------- .../jasmine.HeadlessFileReporter.coffee | 17 +++ .../jasmine.HeadlessReporter.coffee | 48 +++++++ .../jasmine.HeadlessConsoleReporter.js | 125 ++++++++---------- .../jasmine.HeadlessFileReporter.js | 36 +++++ .../javascripts/jasmine.HeadlessReporter.js | 62 +++++++++ 16 files changed, 422 insertions(+), 254 deletions(-) create mode 100644 spec/javascripts/helpers/spec_helper.coffee create mode 100644 spec/javascripts/jasmine-extensions_spec.coffee create mode 100644 spec/javascripts/jasmine.HeadlessReporter_spec.coffee create mode 100644 vendor/assets/coffeescripts/jasmine.HeadlessFileReporter.coffee create mode 100644 vendor/assets/coffeescripts/jasmine.HeadlessReporter.coffee create mode 100644 vendor/assets/javascripts/jasmine.HeadlessFileReporter.js create mode 100644 vendor/assets/javascripts/jasmine.HeadlessReporter.js 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; + + })(); -- 2.45.2 From 5743227de6445435ec33b503cf4e2dfec4ab9418 Mon Sep 17 00:00:00 2001 From: John Bintz Date: Mon, 12 Dec 2011 14:54:53 -0500 Subject: [PATCH 02/45] have runner define report files as a queue --- ext/jasmine-webkit-specrunner/Runner.cpp | 27 +++++++++++++----------- ext/jasmine-webkit-specrunner/Runner.h | 3 ++- 2 files changed, 17 insertions(+), 13 deletions(-) diff --git a/ext/jasmine-webkit-specrunner/Runner.cpp b/ext/jasmine-webkit-specrunner/Runner.cpp index 641edf9..3ea407a 100644 --- a/ext/jasmine-webkit-specrunner/Runner.cpp +++ b/ext/jasmine-webkit-specrunner/Runner.cpp @@ -62,14 +62,10 @@ void Runner::handleError(const QString &message, int lineNumber, const QString & void Runner::loadSpec() { - if (reportFileName.isEmpty()) { - outputFile = 0; - ts = 0; - } else { - outputFile = new QFile(reportFileName); + if (!reportFileName.isEmpty()) { + QFile *outputFile = new QFile(reportFileName); outputFile->open(QIODevice::WriteOnly); - - ts = new QTextStream(outputFile); + outputFiles.enqueue(outputFile); } page.mainFrame()->load(runnerFiles.dequeue()); @@ -131,9 +127,14 @@ void Runner::print(const QString &fh, const QString &content) { std::cerr.flush(); } - if (fh == "report" && outputFile) { - *ts << qPrintable(content); - ts->flush(); + if (fh == "report") { + QListIterator iterator(outputFiles); + + while (iterator.hasNext()) { + QTextStream ts(iterator.next()); + ts << qPrintable(content); + ts.flush(); + } } } @@ -149,8 +150,10 @@ void Runner::timerEvent() { QApplication::instance()->exit(1); if (isFinished && runs > 2) { - if (outputFile) { - outputFile->close(); + QListIterator iterator(outputFiles); + + while (iterator.hasNext()) { + iterator.next()->close(); } int exitCode = 0; diff --git a/ext/jasmine-webkit-specrunner/Runner.h b/ext/jasmine-webkit-specrunner/Runner.h index 03e2c53..f49d5fc 100644 --- a/ext/jasmine-webkit-specrunner/Runner.h +++ b/ext/jasmine-webkit-specrunner/Runner.h @@ -56,8 +56,9 @@ class Runner: public QObject { void loadSpec(); + QQueue outputFiles; + QFile *outputFile; - QTextStream *ts; }; #endif -- 2.45.2 From 4c7a1f860d3c3036a4efaa7cf260cb85e66c5eb4 Mon Sep 17 00:00:00 2001 From: Ville Lautanala Date: Fri, 16 Dec 2011 14:21:06 +0200 Subject: [PATCH 03/45] Parse and run ERB tags inside YAML config --- lib/jasmine/headless/runner.rb | 3 ++- spec/lib/jasmine/headless/runner_spec.rb | 6 +++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/lib/jasmine/headless/runner.rb b/lib/jasmine/headless/runner.rb index 1337123..85763c8 100644 --- a/lib/jasmine/headless/runner.rb +++ b/lib/jasmine/headless/runner.rb @@ -4,6 +4,7 @@ require 'coffee-script' require 'rainbow' require 'yaml' +require 'erb' require 'sprockets' @@ -112,7 +113,7 @@ module Jasmine def jasmine_config_data raise JasmineConfigNotFound.new("Jasmine config not found. I tried #{@options[:jasmine_config]}.") if !File.file?(@options[:jasmine_config]) - YAML.load_file(@options[:jasmine_config]) + YAML.load(ERB.new(File.read(@options[:jasmine_config])).result(binding)) end end end diff --git a/spec/lib/jasmine/headless/runner_spec.rb b/spec/lib/jasmine/headless/runner_spec.rb index 6c2787c..d6e4cd2 100644 --- a/spec/lib/jasmine/headless/runner_spec.rb +++ b/spec/lib/jasmine/headless/runner_spec.rb @@ -37,13 +37,17 @@ describe Jasmine::Headless::Runner do context 'file exists' do before do File.open(Jasmine::Headless::Runner::RUNNER, 'w') - File.open(config_filename, 'w') { |fh| fh.print YAML.dump('test' => 'hello') } + File.open(config_filename, 'w') { |fh| fh.print YAML.dump('test' => 'hello', 'erb' => '<%= "erb" %>') } end it 'should load the jasmine config' do runner.jasmine_config['test'].should == 'hello' runner.jasmine_config['spec_dir'].should == 'spec/javascripts' end + + it 'should execute ERB in the config file' do + runner.jasmine_config['erb'].should == 'erb' + end end context 'file does not exist' do -- 2.45.2 From e38963ed42099695c9624417eef1938589e5832e Mon Sep 17 00:00:00 2001 From: John Bintz Date: Sat, 24 Dec 2011 09:53:52 -0500 Subject: [PATCH 04/45] try loading bundler too --- lib/jasmine/headless/files_list.rb | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/lib/jasmine/headless/files_list.rb b/lib/jasmine/headless/files_list.rb index f22414e..a92ced8 100644 --- a/lib/jasmine/headless/files_list.rb +++ b/lib/jasmine/headless/files_list.rb @@ -39,14 +39,26 @@ module Jasmine::Headless def reset! @asset_paths = nil - # register haml-sprockets if it's available... - %w{haml-sprockets}.each do |library| + # register haml-sprockets and handlebars_assets if it's available... + %w{haml-sprockets handlebars_assets}.each do |library| begin require library rescue LoadError end end + begin + require 'bundler' + + envs = [ :default ] + %w{JHW_ENV RAILS_ENV RACK_ENV RAILS_GROUPS}.each do |env| + envs << ENV[env].to_sym if ENV[env] + end + + Bundler.require(*envs) + rescue LoadError + end + # ...and unregister ones we don't want/need Sprockets.instance_eval do EXCLUDED_FORMATS.each do |extension| @@ -175,12 +187,16 @@ module Jasmine::Headless def to_html(files) alert_time = Time.now + PLEASE_WAIT_IM_WORKING_TIME + p self.class.extension_filter + files.collect do |file| if alert_time && alert_time < Time.now puts "Rebuilding cache, please wait..." alert_time = nil end + p file + sprockets_environment.find_asset(file, :bundle => false).body end.compact.reject(&:empty?) end -- 2.45.2 From ac9a9cf23b250366bed4aa8a675bea5b1f47197b Mon Sep 17 00:00:00 2001 From: John Bintz Date: Sat, 24 Dec 2011 09:53:52 -0500 Subject: [PATCH 05/45] try loading bundler too --- lib/jasmine/headless/files_list.rb | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/lib/jasmine/headless/files_list.rb b/lib/jasmine/headless/files_list.rb index d12725e..8539f04 100644 --- a/lib/jasmine/headless/files_list.rb +++ b/lib/jasmine/headless/files_list.rb @@ -39,14 +39,26 @@ module Jasmine::Headless def reset! @asset_paths = nil - # register haml-sprockets if it's available... - %w{haml-sprockets}.each do |library| + # register haml-sprockets and handlebars_assets if it's available... + %w{haml-sprockets handlebars_assets}.each do |library| begin require library rescue LoadError end end + begin + require 'bundler' + + envs = [ :default ] + %w{JHW_ENV RAILS_ENV RACK_ENV RAILS_GROUPS}.each do |env| + envs << ENV[env].to_sym if ENV[env] + end + + Bundler.require(*envs) + rescue LoadError + end + # ...and unregister ones we don't want/need Sprockets.instance_eval do EXCLUDED_FORMATS.each do |extension| @@ -173,12 +185,16 @@ module Jasmine::Headless def to_html(files) alert_time = Time.now + PLEASE_WAIT_IM_WORKING_TIME + p self.class.extension_filter + files.collect do |file| if alert_time && alert_time < Time.now puts "Rebuilding cache, please wait..." alert_time = nil end + p file + sprockets_environment.find_asset(file, :bundle => false).body end.compact.reject(&:empty?) end -- 2.45.2 From dd86eb404e9c29f0362f4dede2ef90dc18432e0c Mon Sep 17 00:00:00 2001 From: John Bintz Date: Sat, 24 Dec 2011 09:55:21 -0500 Subject: [PATCH 06/45] remove debugging --- lib/jasmine/headless/files_list.rb | 4 ---- 1 file changed, 4 deletions(-) diff --git a/lib/jasmine/headless/files_list.rb b/lib/jasmine/headless/files_list.rb index 8539f04..f49ac2e 100644 --- a/lib/jasmine/headless/files_list.rb +++ b/lib/jasmine/headless/files_list.rb @@ -185,16 +185,12 @@ module Jasmine::Headless def to_html(files) alert_time = Time.now + PLEASE_WAIT_IM_WORKING_TIME - p self.class.extension_filter - files.collect do |file| if alert_time && alert_time < Time.now puts "Rebuilding cache, please wait..." alert_time = nil end - p file - sprockets_environment.find_asset(file, :bundle => false).body end.compact.reject(&:empty?) end -- 2.45.2 From 9dafb8389298ed45231cbe6f64e088738e0086cf Mon Sep 17 00:00:00 2001 From: John Bintz Date: Thu, 29 Dec 2011 09:32:27 -0500 Subject: [PATCH 07/45] things in a weird state... --- lib/jasmine/headless/files_list.rb | 13 +++---- lib/jasmine/headless/options.rb | 42 +++++++++++++++++++++-- spec/lib/jasmine/headless/options_spec.rb | 39 +++++++++++++++++++++ 3 files changed, 83 insertions(+), 11 deletions(-) diff --git a/lib/jasmine/headless/files_list.rb b/lib/jasmine/headless/files_list.rb index f49ac2e..f4f066b 100644 --- a/lib/jasmine/headless/files_list.rb +++ b/lib/jasmine/headless/files_list.rb @@ -47,16 +47,13 @@ module Jasmine::Headless end end - begin - require 'bundler' + if ENV['JHW_ENV'] + begin + require 'bundler' - envs = [ :default ] - %w{JHW_ENV RAILS_ENV RACK_ENV RAILS_GROUPS}.each do |env| - envs << ENV[env].to_sym if ENV[env] + Bundler.require(ENV['JHW_ENV'].to_sym) + rescue LoadError end - - Bundler.require(*envs) - rescue LoadError end # ...and unregister ones we don't want/need diff --git a/lib/jasmine/headless/options.rb b/lib/jasmine/headless/options.rb index d62da56..a228dd6 100644 --- a/lib/jasmine/headless/options.rb +++ b/lib/jasmine/headless/options.rb @@ -17,7 +17,10 @@ module Jasmine :do_list => false, :full_run => true, :enable_cache => true, - :files => [] + :files => [], + :reporters => [ + [ 'HeadlessConsoleReporter' ] + ] } DEFAULTS_FILE = File.join(Dir.pwd, '.jasmine-headless-webkit') @@ -64,6 +67,10 @@ module Jasmine @options[:do_list] = true when '--seed' @options[:seed] = arg.to_i + when '--format', '-f' + add_reporter(arg) + when '--out' + @options[:reporters].last << arg end end @@ -80,18 +87,47 @@ module Jasmine [ '--colors', '-c', GetoptLong::NO_ARGUMENT ], [ '--no-colors', GetoptLong::NO_ARGUMENT ], [ '--cache', GetoptLong::NO_ARGUMENT ], - [ '--no-t stcache', GetoptLong::NO_ARGUMENT ], + [ '--no-cache', GetoptLong::NO_ARGUMENT ], [ '--keep', GetoptLong::NO_ARGUMENT ], [ '--runner-out', GetoptLong::REQUIRED_ARGUMENT ], [ '--report', GetoptLong::REQUIRED_ARGUMENT ], [ '--jasmine-config', '-j', GetoptLong::REQUIRED_ARGUMENT ], [ '--no-full-run', GetoptLong::NO_ARGUMENT ], [ '--list', '-l', GetoptLong::NO_ARGUMENT ], - [ '--seed', GetoptLong::REQUIRED_ARGUMENT ] + [ '--seed', GetoptLong::REQUIRED_ARGUMENT ], + [ '--format', '-f', GetoptLong::REQUIRED_ARGUMENT ], + [ '--out', GetoptLong::REQUIRED_ARGUMENT ] ) command_line_args.each { |*args| process_option(*args) } end + + def reporters + file_index = 0 + + @options[:reporters].collect do |reporter, file| + output = [ reporter ] + if file + output << "report:#{file_index}" + output << file + file_index += 1 + else + output << "stdout" + end + + output + end + end + + private + def add_reporter(name) + if !@added_reporter + @options[:reporters] = [] + @added_reporter = true + end + + @options[:reporters] << [ name ] + end end end end diff --git a/spec/lib/jasmine/headless/options_spec.rb b/spec/lib/jasmine/headless/options_spec.rb index 237423d..8494681 100644 --- a/spec/lib/jasmine/headless/options_spec.rb +++ b/spec/lib/jasmine/headless/options_spec.rb @@ -110,6 +110,45 @@ describe Jasmine::Headless::Options do end end + let(:test_reporter) { 'TestReporter' } + let(:file) { 'file' } + + context 'no reporters' do + it 'should have the default reporter' do + options[:reporters].should == [ [ 'HeadlessConsoleReporter' ] ] + end + end + + context 'one reporter' do + context 'stdout' do + before do + ARGV.replace([ "--format", test_reporter ]) + end + + it 'should have the new reporter on stdout' do + options[:reporters].should == [ [ test_reporter ] ] + + options.reporters.should == [ [ test_reporter, 'stdout' ] ] + end + end + + context 'file' do + before do + ARGV.replace([ "--format", test_reporter, '--out', file ]) + end + + it 'should have the new reporter on stdout' do + options[:reporters].should == [ [ test_reporter, file ] ] + + options.reporters.should == [ [ test_reporter, 'report:0', file ] ] + end + end + end + + context 'two reporters' do + + end + after do ARGV.replace(@argv) end -- 2.45.2 From 0adf3a41b6f696fc1e35a6d70d3cc93a09bff567 Mon Sep 17 00:00:00 2001 From: John Bintz Date: Thu, 29 Dec 2011 18:37:23 -0500 Subject: [PATCH 08/45] a whole ton of reporters work --- Gemfile | 5 + Guardfile | 7 +- Rakefile | 1 + ext/jasmine-webkit-specrunner/Runner.cpp | 36 +++--- ext/jasmine-webkit-specrunner/Runner.h | 14 ++- ext/jasmine-webkit-specrunner/specrunner.cpp | 20 ++-- features/bin/failure.feature | 7 ++ features/bin/filtered_run/both_runs.feature | 18 +++ features/bin/filtered_run/no_full_run.feature | 14 +++ features/bin/reporters.feature | 0 features/bin/success.feature | 20 ++++ features/bin/success_with_js_error.feature | 5 + features/bin/tries_to_leave_page.feature | 7 ++ features/bin/try_to_click_a_button.feature | 7 ++ features/bin/with_coffeescript_error.feature | 7 ++ features/bin/with_console_log.feature | 7 ++ features/reporters.feature | 24 ++++ features/steps/given/no_existing_file.rb | 4 + .../steps/given/options/i_have_defaults.rb | 4 + .../steps/given/options/i_have_reporters.rb | 10 ++ .../steps/then/bin/exit_status_should_be.rb | 3 + .../then/reporting/report_does_not_exist.rb | 4 + .../then/reporting/report_should_exist.rb | 3 + .../then/reporting/report_should_have.rb | 7 ++ .../then/reporting/report_should_have_seed.rb | 4 + .../runner/it_should_include_report_file.rb | 4 + .../it_should_not_include_report_file.rb | 3 + .../then/templates/it_should_use_reporter.rb | 6 + features/steps/when/i_get_runner.rb | 4 + features/steps/when/i_get_template_writer.rb | 4 + features/steps/when/i_run_executable.rb | 4 + features/support/env.rb | 2 + lib/jasmine/headless/files_list.rb | 10 +- lib/jasmine/headless/options.rb | 26 ++++- lib/jasmine/headless/report.rb | 7 +- lib/jasmine/headless/report_message.rb | 1 + .../headless/report_message/console.rb | 6 +- lib/jasmine/headless/report_message/seed.rb | 14 +++ lib/jasmine/headless/report_message/spec.rb | 8 +- lib/jasmine/headless/runner.rb | 44 ++++---- lib/jasmine/headless/template_writer.rb | 30 ++++- skel/template.html.erb | 5 +- spec/bin/jasmine-headless-webkit_spec.rb | 106 ------------------ .../jasmine.HeadlessTAPReporter_spec.coffee | 19 ++++ spec/lib/jasmine/headless/files_list_spec.rb | 1 + spec/lib/jasmine/headless/options_spec.rb | 46 +++++++- .../headless/report_message/seed_spec.rb | 18 +++ spec/lib/jasmine/headless/report_spec.rb | 16 +++ spec/lib/jasmine/headless/runner_spec.rb | 73 ++++++++++-- .../jasmine/headless/template_writer_spec.rb | 62 +++++----- spec/skel/template.html.erb_spec.rb | 8 ++ .../jasmine.HeadlessConsoleReporter.coffee | 23 ++-- .../jasmine.HeadlessFileReporter.coffee | 11 +- .../jasmine.HeadlessReporter.coffee | 12 +- .../jasmine.HeadlessTAPReporter.coffee | 26 +++++ vendor/assets/coffeescripts/prolog.coffee | 22 ++-- .../jasmine.HeadlessConsoleReporter.js | 22 ++-- .../jasmine.HeadlessFileReporter.js | 11 +- .../javascripts/jasmine.HeadlessReporter.js | 21 +++- .../jasmine.HeadlessTAPReporter.js | 40 +++++++ vendor/assets/javascripts/prolog.js | 36 ++---- 61 files changed, 689 insertions(+), 300 deletions(-) create mode 100644 features/bin/failure.feature create mode 100644 features/bin/filtered_run/both_runs.feature create mode 100644 features/bin/filtered_run/no_full_run.feature create mode 100644 features/bin/reporters.feature create mode 100644 features/bin/success.feature create mode 100644 features/bin/success_with_js_error.feature create mode 100644 features/bin/tries_to_leave_page.feature create mode 100644 features/bin/try_to_click_a_button.feature create mode 100644 features/bin/with_coffeescript_error.feature create mode 100644 features/bin/with_console_log.feature create mode 100644 features/reporters.feature create mode 100644 features/steps/given/no_existing_file.rb create mode 100644 features/steps/given/options/i_have_defaults.rb create mode 100644 features/steps/given/options/i_have_reporters.rb create mode 100644 features/steps/then/bin/exit_status_should_be.rb create mode 100644 features/steps/then/reporting/report_does_not_exist.rb create mode 100644 features/steps/then/reporting/report_should_exist.rb create mode 100644 features/steps/then/reporting/report_should_have.rb create mode 100644 features/steps/then/reporting/report_should_have_seed.rb create mode 100644 features/steps/then/runner/it_should_include_report_file.rb create mode 100644 features/steps/then/runner/it_should_not_include_report_file.rb create mode 100644 features/steps/then/templates/it_should_use_reporter.rb create mode 100644 features/steps/when/i_get_runner.rb create mode 100644 features/steps/when/i_get_template_writer.rb create mode 100644 features/steps/when/i_run_executable.rb create mode 100644 features/support/env.rb create mode 100644 lib/jasmine/headless/report_message/seed.rb create mode 100644 spec/javascripts/jasmine.HeadlessTAPReporter_spec.coffee create mode 100644 spec/lib/jasmine/headless/report_message/seed_spec.rb create mode 100644 spec/skel/template.html.erb_spec.rb create mode 100644 vendor/assets/coffeescripts/jasmine.HeadlessTAPReporter.coffee create mode 100644 vendor/assets/javascripts/jasmine.HeadlessTAPReporter.js diff --git a/Gemfile b/Gemfile index f04a59b..ec3e2e7 100644 --- a/Gemfile +++ b/Gemfile @@ -6,15 +6,20 @@ gemspec gem 'rspec' gem 'fakefs', :require => nil gem 'guard' + gem 'guard-rspec' gem 'guard-shell' gem 'guard-coffeescript' +gem 'guard-cucumber' + gem 'growl' gem 'rake', '0.8.7' gem 'mocha', '0.9.12' gem 'guard-jasmine-headless-webkit', :git => 'git://github.com/johnbintz/guard-jasmine-headless-webkit.git' gem 'facter' +gem 'cucumber' + gem 'jquery-rails' gem 'ejs' diff --git a/Guardfile b/Guardfile index 38c2dc6..620fcd4 100644 --- a/Guardfile +++ b/Guardfile @@ -22,13 +22,18 @@ guard 'rspec', :version => 2, :all_on_start => false do watch('spec/spec_helper.rb') { "spec" } end +guard 'cucumber', :cli => '-r features --format pretty' do + watch(%r{^features/.+\.feature$}) + watch(%r{^features/support/.+$}) { 'features' } + watch(%r{^features/steps/(.+)_steps\.rb$}) { 'features' } +end + guard 'jasmine-headless-webkit', :all_on_start => false do watch(%r{^spec/javascripts/.+_spec\.coffee}) watch(%r{^jasmine/(.+)\.coffee$}) { |m| "spec/javascripts/#{m[1]}_spec.coffee" } end def compile - #system %{cd ext/jasmine-webkit-specrunner && ruby test.rb && ruby extconf.rb} system %{cd ext/jasmine-webkit-specrunner && ruby extconf.rb} end diff --git a/Rakefile b/Rakefile index 6f33603..a9c6eb5 100644 --- a/Rakefile +++ b/Rakefile @@ -30,6 +30,7 @@ namespace :spec do task :platforms do rvm_bundle rvm_bundle "exec rspec spec" + rvm_bundle "exec cucumber" raise SpecError.new if $?.exitstatus != 0 end end diff --git a/ext/jasmine-webkit-specrunner/Runner.cpp b/ext/jasmine-webkit-specrunner/Runner.cpp index 3ea407a..c5332e6 100644 --- a/ext/jasmine-webkit-specrunner/Runner.cpp +++ b/ext/jasmine-webkit-specrunner/Runner.cpp @@ -62,8 +62,10 @@ void Runner::handleError(const QString &message, int lineNumber, const QString & void Runner::loadSpec() { - if (!reportFileName.isEmpty()) { - QFile *outputFile = new QFile(reportFileName); + QVectorIterator iterator(reportFiles); + + while (iterator.hasNext()) { + QFile *outputFile = new QFile(iterator.next()); outputFile->open(QIODevice::WriteOnly); outputFiles.enqueue(outputFile); } @@ -100,8 +102,8 @@ void Runner::hasSpecFailure() { _hasSpecFailure = true; } -void Runner::reportFile(const QString &file) { - reportFileName = file; +void Runner::setReportFiles(QStack &files) { + reportFiles = files; } void Runner::timerPause() { @@ -116,6 +118,14 @@ void Runner::ping() { runs = 0; } +void Runner::setSeed(QString s) { + seed = s; +} + +QString Runner::getSeed() { + return seed; +} + void Runner::print(const QString &fh, const QString &content) { if (fh == "stdout") { std::cout << qPrintable(content); @@ -127,14 +137,12 @@ void Runner::print(const QString &fh, const QString &content) { std::cerr.flush(); } - if (fh == "report") { - QListIterator iterator(outputFiles); + if (fh.contains("report")) { + int index = (int)fh.split(":").last().toUInt(); - while (iterator.hasNext()) { - QTextStream ts(iterator.next()); - ts << qPrintable(content); - ts.flush(); - } + QTextStream ts(outputFiles.at(index)); + ts << qPrintable(content); + ts.flush(); } } @@ -150,10 +158,8 @@ void Runner::timerEvent() { QApplication::instance()->exit(1); if (isFinished && runs > 2) { - QListIterator iterator(outputFiles); - - while (iterator.hasNext()) { - iterator.next()->close(); + while (!outputFiles.isEmpty()) { + outputFiles.dequeue()->close(); } int exitCode = 0; diff --git a/ext/jasmine-webkit-specrunner/Runner.h b/ext/jasmine-webkit-specrunner/Runner.h index f49d5fc..8b65a46 100644 --- a/ext/jasmine-webkit-specrunner/Runner.h +++ b/ext/jasmine-webkit-specrunner/Runner.h @@ -20,7 +20,9 @@ class Runner: public QObject { Runner(); void setColors(bool colors); - void reportFile(const QString &file); + void setReportFiles(QStack &files); + void setSeed(QString s); + void addFile(const QString &spec); void go(); @@ -30,6 +32,9 @@ class Runner: public QObject { void hasUsedConsole(); void hasError(); void hasSpecFailure(); + + QString getSeed(); + void print(const QString &fh, const QString &content); void finishSuite(); void ping(); @@ -50,15 +55,14 @@ class Runner: public QObject { bool isFinished; bool useColors; - QQueue runnerFiles; + QString seed; - QString reportFileName; + QQueue runnerFiles; + QStack reportFiles; void loadSpec(); QQueue outputFiles; - - QFile *outputFile; }; #endif diff --git a/ext/jasmine-webkit-specrunner/specrunner.cpp b/ext/jasmine-webkit-specrunner/specrunner.cpp index c0e969f..22d94ac 100644 --- a/ext/jasmine-webkit-specrunner/specrunner.cpp +++ b/ext/jasmine-webkit-specrunner/specrunner.cpp @@ -29,34 +29,40 @@ int main(int argc, char** argv) { - char *reporter = NULL; - char showColors = false; + bool showColors = false; + QString seed; + + QStack reporterFiles; int c, index; - while ((c = getopt(argc, argv, "cr:")) != -1) { + while ((c = getopt(argc, argv, "cr:s:")) != -1) { switch(c) { case 'c': showColors = true; break; case 'r': - reporter = optarg; + reporterFiles.push(QString(optarg)); + break; + case 's': + seed = QString(optarg); break; } } if (optind == argc) { std::cerr << "Run Jasmine's SpecRunner headlessly" << std::endl << std::endl; - std::cerr << " specrunner [-c] [-r ] specrunner.html ..." << std::endl; + std::cerr << " specrunner [-c] [-s seed] [-r report file ...] specrunner.html ..." << std::endl; return 1; } QApplication app(argc, argv); app.setApplicationName("jasmine-headless-webkit"); Runner runner; - runner.setColors(showColors); - runner.reportFile(reporter); + runner.setColors(showColors); + runner.setReportFiles(reporterFiles); + runner.setSeed(seed); for (index = optind; index < argc; index++) { runner.addFile(QString::fromLocal8Bit(argv[index])); diff --git a/features/bin/failure.feature b/features/bin/failure.feature new file mode 100644 index 0000000..aa59fdc --- /dev/null +++ b/features/bin/failure.feature @@ -0,0 +1,7 @@ +Feature: Bin - Failure + Scenario: Run a failing test + Given there is no existing "spec/report.txt" file + When I run `bin/jasmine-headless-webkit -j spec/jasmine/failure/failure.yml --format HeadlessFileReporter --out spec/report.txt` + Then the exit status should be 1 + And the report file "spec/report.txt" should have 1 total, 1 failure, no console usage + diff --git a/features/bin/filtered_run/both_runs.feature b/features/bin/filtered_run/both_runs.feature new file mode 100644 index 0000000..e23156c --- /dev/null +++ b/features/bin/filtered_run/both_runs.feature @@ -0,0 +1,18 @@ +Feature: Bin - Filtered Run - Both Runs + Background: + Given there is no existing "spec/report.txt" file + + Scenario: Run one and fail + When I run `bin/jasmine-headless-webkit -j spec/jasmine/filtered_failure/filtered_failure.yml --format HeadlessFileReporter --out spec/report.txt ./spec/jasmine/filtered_failure/failure_spec.js` + Then the exit status should be 1 + And the report file "spec/report.txt" should have 1 total, 1 failure, no console usage + + Scenario: Run both and succeed + When I run `bin/jasmine-headless-webkit -j spec/jasmine/filtered_success/filtered_success.yml --format HeadlessFileReporter --out spec/report.txt ./spec/jasmine/filtered_success/success_one_spec.js` + Then the exit status should be 0 + And the report file "spec/report.txt" should have 2 total, 0 failures, no console usage + + Scenario: Run both with console.log + When I run `bin/jasmine-headless-webkit -j spec/jasmine/filtered_success_with_console/filtered_success.yml --format HeadlessFileReporter --out spec/report.txt ./spec/jasmine/filtered_success_with_console/success_one_spec.js` + Then the exit status should be 2 + And the report file "spec/report.txt" should have 2 total, 0 failures, yes console usage diff --git a/features/bin/filtered_run/no_full_run.feature b/features/bin/filtered_run/no_full_run.feature new file mode 100644 index 0000000..a16553e --- /dev/null +++ b/features/bin/filtered_run/no_full_run.feature @@ -0,0 +1,14 @@ +Feature: Bin - No Full Run + Background: + Given there is no existing "spec/report.txt" file + + Scenario: Only run the filtered run + When I run `bin/jasmine-headless-webkit -j spec/jasmine/filtered_success/filtered_success.yml --format HeadlessFileReporter --out spec/report.txt --no-full-run ./spec/jasmine/filtered_success/success_one_spec.js` + Then the exit status should be 0 + And the report file "spec/report.txt" should have 1 total, 0 failure, no console usage + + Scenario: Use a file outside of the normal test run + When I run `bin/jasmine-headless-webkit -j spec/jasmine/filtered_success/filtered_success.yml --format HeadlessFileReporter --out spec/report.txt ./spec/jasmine/filtered_success/success_other_file.js` + Then the exit status should be 0 + And the report file "spec/report.txt" should have 1 total, 0 failure, no console usage + diff --git a/features/bin/reporters.feature b/features/bin/reporters.feature new file mode 100644 index 0000000..e69de29 diff --git a/features/bin/success.feature b/features/bin/success.feature new file mode 100644 index 0000000..50d0a79 --- /dev/null +++ b/features/bin/success.feature @@ -0,0 +1,20 @@ +Feature: Bin - Success + Scenario: Run a successful test + Given there is no existing "spec/report.txt" file + When I run `bin/jasmine-headless-webkit --seed 1234 -j spec/jasmine/success/success.yml --format HeadlessFileReporter --out spec/report.txt` + Then the exit status should be 0 + And the report file "spec/report.txt" should have 1 total, 0 failures, no console usage + And the report file "spec/report.txt" should have seed 1234 + + Scenario: Run a successful test with legacy file reporting + Given there is no existing "spec/report.txt" file + When I run `bin/jasmine-headless-webkit -j spec/jasmine/success/success.yml --report spec/report.txt` + Then the exit status should be 0 + And the report file "spec/report.txt" should have 1 total, 0 failures, no console usage + + Scenario: Run a successful test with shortened format definition + Given there is no existing "spec/report.txt" file + When I run `bin/jasmine-headless-webkit -j spec/jasmine/success/success.yml --format HeadlessFileReporter:spec/report.txt` + Then the exit status should be 0 + And the report file "spec/report.txt" should have 1 total, 0 failures, no console usage + diff --git a/features/bin/success_with_js_error.feature b/features/bin/success_with_js_error.feature new file mode 100644 index 0000000..0cb3da4 --- /dev/null +++ b/features/bin/success_with_js_error.feature @@ -0,0 +1,5 @@ +Feature: Bin - Success with JS Error + Scenario: Succeed + Given there is no existing "spec/report.txt" file + When I run `bin/jasmine-headless-webkit -j spec/jasmine/success_with_error/success_with_error.yml --format HeadlessFileReporter --out spec/report.txt` + Then the exit status should be 1 diff --git a/features/bin/tries_to_leave_page.feature b/features/bin/tries_to_leave_page.feature new file mode 100644 index 0000000..3334159 --- /dev/null +++ b/features/bin/tries_to_leave_page.feature @@ -0,0 +1,7 @@ +Feature: Bin - Try to Leave Page + Scenario: Fail on trying to leave the page + Given there is no existing "spec/report.txt" file + When I run `bin/jasmine-headless-webkit -j spec/jasmine/leave_page/leave_page.yml --format HeadlessFileReporter --out spec/report.txt` + Then the exit status should be 1 + And the report file "spec/report.txt" should exist + diff --git a/features/bin/try_to_click_a_button.feature b/features/bin/try_to_click_a_button.feature new file mode 100644 index 0000000..91ff051 --- /dev/null +++ b/features/bin/try_to_click_a_button.feature @@ -0,0 +1,7 @@ +Feature: Bin - Try to Click A Button + Scenario: Don't leave page when clicking a button + Given there is no existing "spec/report.txt" file + When I run `bin/jasmine-headless-webkit -j spec/jasmine/click_button/click_button.yml --format HeadlessFileReporter --out spec/report.txt` + Then the exit status should be 0 + And the report file "spec/report.txt" should have 0 total, 0 failures, no console usage + diff --git a/features/bin/with_coffeescript_error.feature b/features/bin/with_coffeescript_error.feature new file mode 100644 index 0000000..7b03252 --- /dev/null +++ b/features/bin/with_coffeescript_error.feature @@ -0,0 +1,7 @@ +Feature: Bin - With CoffeeScript error + Scenario: Fail on CoffeeScript error + Given there is no existing "spec/report.txt" file + When I run `bin/jasmine-headless-webkit -j spec/jasmine/coffeescript_error/coffeescript_error.yml --format HeadlessFileReporter --out spec/report.txt` + Then the exit status should be 1 + And the report file "spec/report.txt" should not exist + diff --git a/features/bin/with_console_log.feature b/features/bin/with_console_log.feature new file mode 100644 index 0000000..47ce1e8 --- /dev/null +++ b/features/bin/with_console_log.feature @@ -0,0 +1,7 @@ +Feature: Bin - With console.log + Scenario: Run a successful test that uses console.log + Given there is no existing "spec/report.txt" file + When I run `bin/jasmine-headless-webkit -j spec/jasmine/console_log/console_log.yml --format HeadlessFileReporter --out spec/report.txt` + Then the exit status should be 2 + And the report file "spec/report.txt" should have 1 total, 0 failures, yes console usage + diff --git a/features/reporters.feature b/features/reporters.feature new file mode 100644 index 0000000..fe10131 --- /dev/null +++ b/features/reporters.feature @@ -0,0 +1,24 @@ +Feature: Reporters + In order to allow for multiple types of output + I should be able to + Manage reporters and decide which ones to use + + Scenario: Use default reporters + Given I have the default runner options + When I get a runner + And I get a template writer + Then the template should use the "HeadlessConsoleReporter" reporter to "stdout" + And the command to run the runner should not include a report file + + Scenario: Use a file reporter + Given I have the default runner options + And I have the following reporters: + | Name | File | + | ConsoleReporter | | + | FileReporter | file | + When I get a runner + And I get a template writer + Then the template should use the "ConsoleReporter" reporter to "stdout" + And the template should use the "FileReporter" reporter to "report:0" + And the command to run the runner should include the report file "file" + diff --git a/features/steps/given/no_existing_file.rb b/features/steps/given/no_existing_file.rb new file mode 100644 index 0000000..04a8b15 --- /dev/null +++ b/features/steps/given/no_existing_file.rb @@ -0,0 +1,4 @@ +Given /^there is no existing "([^"]*)" file$/ do |file| + FileUtils.rm_rf file +end + diff --git a/features/steps/given/options/i_have_defaults.rb b/features/steps/given/options/i_have_defaults.rb new file mode 100644 index 0000000..03e7971 --- /dev/null +++ b/features/steps/given/options/i_have_defaults.rb @@ -0,0 +1,4 @@ +Given /^I have the default runner options$/ do + @options = Jasmine::Headless::Options.new +end + diff --git a/features/steps/given/options/i_have_reporters.rb b/features/steps/given/options/i_have_reporters.rb new file mode 100644 index 0000000..60ffb68 --- /dev/null +++ b/features/steps/given/options/i_have_reporters.rb @@ -0,0 +1,10 @@ +Given /^I have the following reporters:$/ do |table| + @options[:reporters] = [] + + table.hashes.each do |hash| + reporter = [ hash['Name'] ] + reporter << hash['File'] if !hash['File'].empty? + + @options[:reporters] << reporter + end +end diff --git a/features/steps/then/bin/exit_status_should_be.rb b/features/steps/then/bin/exit_status_should_be.rb new file mode 100644 index 0000000..0e6992c --- /dev/null +++ b/features/steps/then/bin/exit_status_should_be.rb @@ -0,0 +1,3 @@ +Then /^the exit status should be (\d+)$/ do |exitstatus| + $?.exitstatus.should == exitstatus.to_i +end diff --git a/features/steps/then/reporting/report_does_not_exist.rb b/features/steps/then/reporting/report_does_not_exist.rb new file mode 100644 index 0000000..2cff304 --- /dev/null +++ b/features/steps/then/reporting/report_does_not_exist.rb @@ -0,0 +1,4 @@ +Then /^the report file "([^"]*)" should not exist$/ do |file| + File.file?(file).should be_false +end + diff --git a/features/steps/then/reporting/report_should_exist.rb b/features/steps/then/reporting/report_should_exist.rb new file mode 100644 index 0000000..d7b5859 --- /dev/null +++ b/features/steps/then/reporting/report_should_exist.rb @@ -0,0 +1,3 @@ +Then /^the report file "([^"]*)" should exist$/ do |file| + File.file?(file).should be_true +end diff --git a/features/steps/then/reporting/report_should_have.rb b/features/steps/then/reporting/report_should_have.rb new file mode 100644 index 0000000..ef2ad58 --- /dev/null +++ b/features/steps/then/reporting/report_should_have.rb @@ -0,0 +1,7 @@ +Then /^the report file "(.*)" should have (\d+) total, (\d+) failures?, (no|yes) console usage$/ do |file, total, failures, console_usage| + report = Jasmine::Headless::Report.load(file) + + report.total.should == total.to_i + report.failed.should == failures.to_i + report.has_used_console?.should == (console_usage == 'yes') +end diff --git a/features/steps/then/reporting/report_should_have_seed.rb b/features/steps/then/reporting/report_should_have_seed.rb new file mode 100644 index 0000000..ec905a3 --- /dev/null +++ b/features/steps/then/reporting/report_should_have_seed.rb @@ -0,0 +1,4 @@ +Then /^the report file "([^"]*)" should have seed (\d+)$/ do |file, seed| + report = Jasmine::Headless::Report.load(file) + report.seed.should == seed.to_i +end diff --git a/features/steps/then/runner/it_should_include_report_file.rb b/features/steps/then/runner/it_should_include_report_file.rb new file mode 100644 index 0000000..0dd465a --- /dev/null +++ b/features/steps/then/runner/it_should_include_report_file.rb @@ -0,0 +1,4 @@ +Then /^the command to run the runner should include the report file "([^"]*)"$/ do |file| + @runner.jasmine_command.should include("-r #{file}") +end + diff --git a/features/steps/then/runner/it_should_not_include_report_file.rb b/features/steps/then/runner/it_should_not_include_report_file.rb new file mode 100644 index 0000000..28a7417 --- /dev/null +++ b/features/steps/then/runner/it_should_not_include_report_file.rb @@ -0,0 +1,3 @@ +Then /^the command to run the runner should not include a report file$/ do + @runner.jasmine_command.should_not include('-r') +end diff --git a/features/steps/then/templates/it_should_use_reporter.rb b/features/steps/then/templates/it_should_use_reporter.rb new file mode 100644 index 0000000..5e9e99e --- /dev/null +++ b/features/steps/then/templates/it_should_use_reporter.rb @@ -0,0 +1,6 @@ +Then /^the template should use the "([^"]*)" reporter to "([^"]*)"$/ do |reporter, target| + output = @template_writer.render + + output.should include(%{jasmine.#{reporter}("#{target}")}) +end + diff --git a/features/steps/when/i_get_runner.rb b/features/steps/when/i_get_runner.rb new file mode 100644 index 0000000..ed1b2e6 --- /dev/null +++ b/features/steps/when/i_get_runner.rb @@ -0,0 +1,4 @@ +When /^I get a runner$/ do + @runner = Jasmine::Headless::Runner.new(@options) +end + diff --git a/features/steps/when/i_get_template_writer.rb b/features/steps/when/i_get_template_writer.rb new file mode 100644 index 0000000..77c1e2c --- /dev/null +++ b/features/steps/when/i_get_template_writer.rb @@ -0,0 +1,4 @@ +When /^I get a template writer$/ do + @template_writer = Jasmine::Headless::TemplateWriter.new(@runner) +end + diff --git a/features/steps/when/i_run_executable.rb b/features/steps/when/i_run_executable.rb new file mode 100644 index 0000000..553ef51 --- /dev/null +++ b/features/steps/when/i_run_executable.rb @@ -0,0 +1,4 @@ +When /^I run `(.*)`$/ do |command| + system command +end + diff --git a/features/support/env.rb b/features/support/env.rb new file mode 100644 index 0000000..db7b786 --- /dev/null +++ b/features/support/env.rb @@ -0,0 +1,2 @@ +require 'jasmine-headless-webkit' + diff --git a/lib/jasmine/headless/files_list.rb b/lib/jasmine/headless/files_list.rb index e819ac2..5a5a9eb 100644 --- a/lib/jasmine/headless/files_list.rb +++ b/lib/jasmine/headless/files_list.rb @@ -72,7 +72,9 @@ module Jasmine::Headless def default_files %w{jasmine.js jasmine-html jasmine.css jasmine-extensions intense headless_reporter_result jasmine.HeadlessReporter - jasmine.HeadlessFileReporter jasmine.HeadlessConsoleReporter jsDump beautify-html} + jasmine.HeadlessFileReporter jasmine.HeadlessConsoleReporter + jasmine.HeadlessTAPReporter + jsDump beautify-html} end def extension_filter @@ -84,7 +86,7 @@ module Jasmine::Headless PLEASE_WAIT_IM_WORKING_TIME = 2 - attr_reader :required_files, :potential_files_to_filter + attr_reader :options, :required_files, :potential_files_to_filter def initialize(options = {}) @options = options @@ -184,16 +186,12 @@ module Jasmine::Headless def to_html(files) alert_time = Time.now + PLEASE_WAIT_IM_WORKING_TIME - p self.class.extension_filter - files.collect do |file| if alert_time && alert_time < Time.now puts "Rebuilding cache, please wait..." alert_time = nil end - p file - sprockets_environment.find_asset(file, :bundle => false).body end.compact.reject(&:empty?) end diff --git a/lib/jasmine/headless/options.rb b/lib/jasmine/headless/options.rb index a228dd6..7f85f2c 100644 --- a/lib/jasmine/headless/options.rb +++ b/lib/jasmine/headless/options.rb @@ -13,7 +13,6 @@ module Jasmine :remove_html_file => true, :runner_output_filename => false, :jasmine_config => 'spec/javascripts/support/jasmine.yml', - :report => false, :do_list => false, :full_run => true, :enable_cache => true, @@ -26,6 +25,8 @@ module Jasmine DEFAULTS_FILE = File.join(Dir.pwd, '.jasmine-headless-webkit') GLOBAL_DEFAULTS_FILE = File.expand_path('~/.jasmine-headless-webkit') + REPORT_DEPRECATED_MESSAGE = "--report is deprecated. Use --format HeadlessFileReporter --out " + def self.from_command_line options = new options.process_command_line_args @@ -56,7 +57,10 @@ module Jasmine when '--keep' @options[:remove_html_file] = false when '--report' - @options[:report] = arg + warn REPORT_DEPRECATED_MESSAGE + + add_reporter('HeadlessFileReporter', arg) + add_reporter('HeadlessConsoleReporter') when '--runner-out' @options[:runner_output_filename] = arg when '--jasmine-config', '-j' @@ -70,7 +74,7 @@ module Jasmine when '--format', '-f' add_reporter(arg) when '--out' - @options[:reporters].last << arg + add_reporter_file(arg) end end @@ -119,14 +123,28 @@ module Jasmine end end + def file_reporters + reporters.find_all { |reporter| reporter[1]["report:"] } + end + private - def add_reporter(name) + def add_reporter(name, file = nil) if !@added_reporter @options[:reporters] = [] @added_reporter = true end + if (parts = name.split(':')).length == 2 + name, file = parts + end + @options[:reporters] << [ name ] + + add_reporter_file(file) if file + end + + def add_reporter_file(file) + @options[:reporters].last << file end end end diff --git a/lib/jasmine/headless/report.rb b/lib/jasmine/headless/report.rb index d620b73..3da241c 100644 --- a/lib/jasmine/headless/report.rb +++ b/lib/jasmine/headless/report.rb @@ -60,8 +60,13 @@ module Jasmine::Headless }.collect(&:filename).uniq.compact end - private + def seed + if seed = report.find { |entry| entry.respond_to?(:seed) } + seed.seed + end + end + private def last_total @report.reverse.find { |entry| entry.respond_to?(:total) } end diff --git a/lib/jasmine/headless/report_message.rb b/lib/jasmine/headless/report_message.rb index 218ba17..83505a4 100644 --- a/lib/jasmine/headless/report_message.rb +++ b/lib/jasmine/headless/report_message.rb @@ -6,6 +6,7 @@ module Jasmine::Headless autoload :Console, 'jasmine/headless/report_message/console' autoload :Error, 'jasmine/headless/report_message/error' autoload :Total, 'jasmine/headless/report_message/total' + autoload :Seed, 'jasmine/headless/report_message/seed' end end diff --git a/lib/jasmine/headless/report_message/console.rb b/lib/jasmine/headless/report_message/console.rb index 25c64ef..2fb8e85 100644 --- a/lib/jasmine/headless/report_message/console.rb +++ b/lib/jasmine/headless/report_message/console.rb @@ -1,9 +1,7 @@ module Jasmine::Headless::ReportMessage class Console - class << self - def new_from_parts(parts) - new(parts.first) - end + def self.new_from_parts(parts) + new(parts.first) end attr_reader :message diff --git a/lib/jasmine/headless/report_message/seed.rb b/lib/jasmine/headless/report_message/seed.rb new file mode 100644 index 0000000..a2f53f2 --- /dev/null +++ b/lib/jasmine/headless/report_message/seed.rb @@ -0,0 +1,14 @@ +module Jasmine::Headless::ReportMessage + class Seed + def self.new_from_parts(parts) + new(parts.first) + end + + attr_reader :seed + + def initialize(seed) + @seed = seed.to_i + end + end +end + diff --git a/lib/jasmine/headless/report_message/spec.rb b/lib/jasmine/headless/report_message/spec.rb index 63c5b54..218dabd 100644 --- a/lib/jasmine/headless/report_message/spec.rb +++ b/lib/jasmine/headless/report_message/spec.rb @@ -1,11 +1,9 @@ module Jasmine::Headless::ReportMessage class Spec - class << self - def new_from_parts(parts) - file_info = parts.pop + def self.new_from_parts(parts) + file_info = parts.pop - new(parts.join(' '), file_info) - end + new(parts.join(' '), file_info) end attr_reader :statement, :file_info diff --git a/lib/jasmine/headless/runner.rb b/lib/jasmine/headless/runner.rb index 85763c8..946fe71 100644 --- a/lib/jasmine/headless/runner.rb +++ b/lib/jasmine/headless/runner.rb @@ -34,14 +34,6 @@ module Jasmine end def initialize(options) - if !File.file?(RUNNER) - $stderr.puts "No runner found, attempting to compile..." - Dir.chdir RUNNER_DIR do - system %{ruby extconf.rb} - end - raise NoRunnerError if !File.file?(RUNNER) - end - @options = options end @@ -60,25 +52,25 @@ module Jasmine end def jasmine_command(*targets) - [ - RUNNER, - @options[:colors] ? '-c' : nil, - @options[:report] ? "-r #{@options[:report]}" : nil, - *targets - ].compact.join(" ") + command = [ RUNNER ] + + command << "-s #{options[:seed]}" + command << '-c' if options[:colors] + + options.file_reporters.each do |reporter, identifier, file| + command << "-r #{file}" + end + + command += targets + + command.compact.join(' ') end def run Jasmine::Headless::CacheableAction.enabled = @options[:enable_cache] FilesList.reset! - files_list = Jasmine::Headless::FilesList.new( - :config => jasmine_config, - :only => @options[:files], - :seed => @options[:seed] - ) - - @_targets = template_writer.write!(files_list) + @_targets = template_writer.write run_targets = @_targets.dup @@ -90,8 +82,6 @@ module Jasmine system jasmine_command(run_targets) - puts "\nTest ordering seed: --seed #{@options[:seed]}" - @_status = $?.exitstatus ensure if @_targets && !runner_filename && (@options[:remove_html_file] || (@_status == 0)) @@ -109,6 +99,14 @@ module Jasmine end end + def files_list + @files_list ||= Jasmine::Headless::FilesList.new( + :config => jasmine_config, + :only => @options[:files], + :seed => @options[:seed] + ) + end + private def jasmine_config_data raise JasmineConfigNotFound.new("Jasmine config not found. I tried #{@options[:jasmine_config]}.") if !File.file?(@options[:jasmine_config]) diff --git a/lib/jasmine/headless/template_writer.rb b/lib/jasmine/headless/template_writer.rb index 7d41161..1592265 100644 --- a/lib/jasmine/headless/template_writer.rb +++ b/lib/jasmine/headless/template_writer.rb @@ -1,24 +1,30 @@ require 'multi_json' require 'erb' require 'tempfile' +require 'forwardable' module Jasmine::Headless class TemplateWriter attr_reader :runner + extend Forwardable + + def_delegators :runner, :files_list, :options + def_delegators :options, :reporters + def initialize(runner) @runner = runner end - def write!(files_list) + def write output = [ [ all_tests_filename, files_list.files_to_html ] ] - output.unshift([filtered_tests_filename , files_list.filtered_files_to_html ]) if files_list.filtered? + output.unshift([filtered_tests_filename, files_list.filtered_files_to_html ]) if files_list.filtered? output.each do |name, files| - File.open(name, 'w') { |fh| fh.print template_for(files, files_list.spec_file_line_numbers) } + File.open(name, 'w') { |fh| fh.print template_for(files) } end output.collect(&:first) @@ -32,8 +38,24 @@ module Jasmine::Headless all_tests_filename.gsub(%r{\.html$}, '.filter.html') end + def render + template_for(all_files) + end + + def all_files + files_list.files_to_html + end + + def jhw_reporters + reporters.collect do |reporter, output| + %{jasmine.getEnv().addReporter(new jasmine.#{reporter}("#{output}"));} + end.join("\n") + end + private - def template_for(files, spec_lines) + def template_for(files) + spec_lines = files_list.spec_file_line_numbers + ERB.new(Jasmine::Headless.root.join('skel/template.html.erb').read).result(binding) end end diff --git a/skel/template.html.erb b/skel/template.html.erb index 10e5307..c02247b 100644 --- a/skel/template.html.erb +++ b/skel/template.html.erb @@ -12,7 +12,7 @@ <%= files.join("\n") %> diff --git a/vendor/assets/javascripts/intense.coffee b/vendor/assets/javascripts/intense.coffee index 0e6abfd..f344f78 100644 --- a/vendor/assets/javascripts/intense.coffee +++ b/vendor/assets/javascripts/intense.coffee @@ -11,16 +11,16 @@ window.Intense = { methods: foreground: (color) -> if Intense.useColors - "\x33[3#{Intense.colors[color]}m#{this}\x33[0m" + '\x1b' + "[3#{Intense.colors[color]}m#{this}" + '\x1b' + "[0m" else this bright: -> if Intense.useColors - "\x33[1m#{this}\x33[0m" + '\x1b' + "[1m#{this}" + '\x1b' + "[0m" else this useColors: true - moveBack: (count = 1) -> "\x33[#{count}D" + moveBack: (count = 1) -> '\x1b' + "[#{count}D" } for method, code of Intense.methods -- 2.45.2 From 30e1ff8e51ada9071ae4a17c61c148d200c90a80 Mon Sep 17 00:00:00 2001 From: John Bintz Date: Mon, 23 Apr 2012 11:08:17 -0400 Subject: [PATCH 43/45] bump version --- .gitignore | 1 + lib/jasmine/headless/version.rb | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 54583c8..280bfd5 100644 --- a/.gitignore +++ b/.gitignore @@ -16,3 +16,4 @@ _site/ jhw.*.html coverage/ tmp/ +cache dir/ diff --git a/lib/jasmine/headless/version.rb b/lib/jasmine/headless/version.rb index 437ce0e..2960da5 100644 --- a/lib/jasmine/headless/version.rb +++ b/lib/jasmine/headless/version.rb @@ -1,5 +1,5 @@ module Jasmine module Headless - VERSION = "0.9.0.rc1" + VERSION = "0.9.0.rc.2" end end -- 2.45.2 From aa1d989a90c7ebc2d5ac372f2228fbbbcd335fb0 Mon Sep 17 00:00:00 2001 From: John Bintz Date: Mon, 30 Jul 2012 11:15:32 -0400 Subject: [PATCH 44/45] message about looking for new maintainer --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 1df0ad5..18a02b2 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,5 @@ +_I am looking for a new maintainer for this project. Please contact me via GitHub if you're interested._ + # Jasmine Headless WebKit runner Run your specs at sonic boom speed! No pesky reload button or page rendering slowdowns! -- 2.45.2 From 16fb1a72143df5f7b435fc6e24f90cf8a3032341 Mon Sep 17 00:00:00 2001 From: Lukas Beaton Date: Wed, 21 Nov 2012 14:49:31 -0500 Subject: [PATCH 45/45] adds handlebars assets --- 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 d12725e..d4d1cff 100644 --- a/lib/jasmine/headless/files_list.rb +++ b/lib/jasmine/headless/files_list.rb @@ -40,7 +40,7 @@ module Jasmine::Headless @asset_paths = nil # register haml-sprockets if it's available... - %w{haml-sprockets}.each do |library| + %w{haml-sprockets handlebars_assets}.each do |library| begin require library rescue LoadError -- 2.45.2