add verbose reporter

This commit is contained in:
John Bintz 2012-01-10 17:14:37 -05:00
parent 81f561282a
commit da59a48025
14 changed files with 369 additions and 240 deletions

View File

@ -72,6 +72,7 @@ module Jasmine::Headless
def default_files
%w{jasmine.js jasmine-html jasmine.css jasmine-extensions
intense headless_reporter_result jasmine.HeadlessReporter
jasmine.HeadlessReporter.ConsoleBase
jsDump beautify-html}
end

View File

@ -0,0 +1,35 @@
describe 'jasmine.HeadlessReporter.ConsoleBase', ->
reporter = null
beforeEach ->
reporter = new jasmine.HeadlessReporter.ConsoleBase()
describe '#formatResultLine', ->
context 'length = 1', ->
it 'should format', ->
reporter.length = 1
expect(reporter.formatResultLine(0)).toMatch(/test,/)
context 'length != 1', ->
it 'should format', ->
reporter.length = 2
expect(reporter.formatResultLine(0)).toMatch(/tests,/)
context 'failedCount = 1', ->
it 'should format', ->
reporter.failedCount = 1
expect(reporter.formatResultLine(0)).toMatch(/failure,/)
context 'failedCount != 1', ->
it 'should format', ->
reporter.failedCount = 0
expect(reporter.formatResultLine(0)).toMatch(/failures,/)
context 'runtime = 1', ->
it 'should format', ->
expect(reporter.formatResultLine(1)).toMatch(/sec./)
context 'runtime != 1', ->
it 'should format', ->
expect(reporter.formatResultLine(0)).toMatch(/secs./)

View File

@ -1,35 +1,3 @@
describe 'jasmine.HeadlessReporter', ->
reporter = null
beforeEach ->
reporter = new jasmine.HeadlessReporter.Console()
describe '#formatResultLine', ->
context 'length = 1', ->
it 'should format', ->
reporter.length = 1
expect(reporter.formatResultLine(0)).toMatch(/test,/)
context 'length != 1', ->
it 'should format', ->
reporter.length = 2
expect(reporter.formatResultLine(0)).toMatch(/tests,/)
context 'failedCount = 1', ->
it 'should format', ->
reporter.failedCount = 1
expect(reporter.formatResultLine(0)).toMatch(/failure,/)
context 'failedCount != 1', ->
it 'should format', ->
reporter.failedCount = 0
expect(reporter.formatResultLine(0)).toMatch(/failures,/)
context 'runtime = 1', ->
it 'should format', ->
expect(reporter.formatResultLine(1)).toMatch(/sec./)
context 'runtime != 1', ->
it 'should format', ->
expect(reporter.formatResultLine(0)).toMatch(/secs./)
describe 'jasmine.HeadlessReporter.Console', ->
describe '#reportSpecResults', ->

View File

@ -1,89 +1,8 @@
#= require jasmine.HeadlessReporter.js
#= require jasmine.HeadlessReporter.ConsoleBase
#
class jasmine.HeadlessReporter.Console extends jasmine.HeadlessReporter
constructor: (@callback = null) ->
super(@callback)
@position = 0
@positions = "|/-\\"
reportRunnerResults: (runner) ->
super()
this.print("\n")
resultLine = this.formatResultLine(this._runtime())
if @failedCount == 0
this.puts("PASS: #{resultLine}".foreground('green'))
else
this.puts("FAIL: #{resultLine}".foreground('red'))
for result in @results
this.puts(result.toString())
this.puts("\nTest ordering seed: --seed #{JHW.getSeed()}")
reportRunnerStarting: (runner) ->
super(runner)
this.puts("\nRunning Jasmine specs...".bright()) if !this.hasError()
reportSpecResults: (spec) ->
super(spec)
this._reportSpecResult(spec, {
success: (results) =>
class jasmine.HeadlessReporter.Console extends jasmine.HeadlessReporter.ConsoleBase
displaySuccess: (spec) =>
this.print('.'.foreground('green'))
failure: (results) =>
displayFailure: (spec) =>
this.print('F'.foreground('red'))
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)
})
reportSpecWaiting: ->
if !@timer
@timer = true
@first = true
this._waitRunner()
reportSpecRunning: ->
if @timer
clearTimeout(@timer)
@timer = null
this.print(Intense.moveBack())
formatResultLine: (runtime) ->
line = []
line.push(@length)
line.push((if @length == 1 then "test" else "tests") + ',')
line.push(@failedCount)
line.push((if @failedCount == 1 then "failure" else "failures") + ',')
line.push(runtime)
line.push((if runtime == 1.0 then "sec" else "secs") + '.')
line.join(' ')
_waitRunner: =>
@timer = setTimeout(
=>
if @timer
this.print(Intense.moveBack()) if !@first
this.print(@positions.substr(@position, 1).foreground('yellow'))
@position += 1
@position %= @positions.length
@first = false
this._waitRunner()
, 750
)

View File

@ -0,0 +1,92 @@
#= require jasmine.HeadlessReporter.js
class jasmine.HeadlessReporter.ConsoleBase extends jasmine.HeadlessReporter
constructor: (@callback = null) ->
super(@callback)
@position = 0
@positions = "|/-\\"
formatResultLine: (runtime) ->
line = []
line.push(@length)
line.push((if @length == 1 then "test" else "tests") + ',')
line.push(@failedCount)
line.push((if @failedCount == 1 then "failure" else "failures") + ',')
line.push(runtime)
line.push((if runtime == 1.0 then "sec" else "secs") + '.')
line.join(' ')
reportRunnerResults: (runner) ->
super()
this.print("\n")
resultLine = this.formatResultLine(this._runtime())
if @failedCount == 0
this.puts("PASS: #{resultLine}".foreground('green'))
else
this.puts("FAIL: #{resultLine}".foreground('red'))
for result in @results
this.puts(result.toString())
this.puts("\nTest ordering seed: --seed #{JHW.getSeed()}")
reportRunnerStarting: (runner) ->
super(runner)
this.puts("\nRunning Jasmine specs...".bright()) if !this.hasError()
reportSpecWaiting: ->
if !@timer
@timer = true
@first = true
this._waitRunner()
reportSpecRunning: ->
if @timer
clearTimeout(@timer)
@timer = null
this.print(Intense.moveBack())
reportSpecResults: (spec) ->
super(spec)
this._reportSpecResult(spec, {
success: (results) =>
this.displaySuccess(spec)
failure: (results) =>
this.displayFailure(spec)
this.reportFailureResult(results, new HeadlessReporterResult(spec.getFullName(), spec.getSpecSplitName()))
})
reportFailureResult: (results, failureResult) ->
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)
_waitRunner: =>
@timer = setTimeout(
=>
if @timer
this.print(Intense.moveBack()) if !@first
this.print(@positions.substr(@position, 1).foreground('yellow'))
@position += 1
@position %= @positions.length
@first = false
this._waitRunner()
, 750
)

View File

@ -0,0 +1,26 @@
#= require jasmine.HeadlessReporter.ConsoleBase
#
class jasmine.HeadlessReporter.Verbose extends jasmine.HeadlessReporter.ConsoleBase
displaySuccess: (spec) =>
this.displaySpec(spec, 'green')
displayFailure: (spec) =>
this.displaySpec(spec, 'red')
displaySpec: (spec, color) =>
currentLastNames = (@lastNames || []).slice(0)
@lastNames = spec.getSpecSplitName()
this.puts(this.indentSpec(@lastNames, currentLastNames, color).join("\n"))
indentSpec: (current, last, color) =>
last = last.slice(0)
output = []
indent = ''
for name in current
output.push(indent + name.foreground(color)) if last.shift() != name
indent += ' '
output

View File

@ -1,3 +1,4 @@
(function() {
window.HeadlessReporterResult = (function() {
@ -74,3 +75,5 @@
return HeadlessReporterResult;
})();
}).call(this);

View File

@ -1,6 +1,6 @@
(function() {
var generator, getSplitName, method, pauseAndRun, _i, _len, _ref;
var __slice = Array.prototype.slice;
var generator, getSplitName, method, pauseAndRun, _i, _len, _ref,
__slice = Array.prototype.slice;
if (!(typeof jasmine !== "undefined" && jasmine !== null)) {
throw new Error("jasmine not laoded!");

View File

@ -1,115 +1,28 @@
(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; };
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.HeadlessReporter.Console = (function() {
jasmine.HeadlessReporter.Console = (function(_super) {
__extends(Console, jasmine.HeadlessReporter);
__extends(Console, _super);
function Console(callback) {
this.callback = callback != null ? callback : null;
this._waitRunner = __bind(this._waitRunner, this);
Console.__super__.constructor.call(this, this.callback);
this.position = 0;
this.positions = "|/-\\";
function Console() {
this.displayFailure = __bind(this.displayFailure, this);
this.displaySuccess = __bind(this.displaySuccess, this);
Console.__super__.constructor.apply(this, arguments);
}
Console.prototype.reportRunnerResults = function(runner) {
var result, resultLine, _i, _len, _ref;
Console.__super__.reportRunnerResults.call(this);
this.print("\n");
resultLine = this.formatResultLine(this._runtime());
if (this.failedCount === 0) {
this.puts(("PASS: " + resultLine).foreground('green'));
} else {
this.puts(("FAIL: " + resultLine).foreground('red'));
}
_ref = this.results;
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
result = _ref[_i];
this.puts(result.toString());
}
return this.puts("\nTest ordering seed: --seed " + (JHW.getSeed()));
Console.prototype.displaySuccess = function(spec) {
return this.print('.'.foreground('green'));
};
Console.prototype.reportRunnerStarting = function(runner) {
Console.__super__.reportRunnerStarting.call(this, runner);
if (!this.hasError()) {
return this.puts("\nRunning Jasmine specs...".bright());
}
};
Console.prototype.reportSpecResults = function(spec) {
var _this = this;
Console.__super__.reportSpecResults.call(this, spec);
return this._reportSpecResult(spec, {
success: function(results) {
return _this.print('.'.foreground('green'));
},
failure: function(results) {
var failureResult, foundLine, result, testCount, _i, _len, _ref;
_this.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);
}
testCount += 1;
}
return _this.results.push(failureResult);
}
});
};
Console.prototype.reportSpecWaiting = function() {
if (!this.timer) {
this.timer = true;
this.first = true;
return this._waitRunner();
}
};
Console.prototype.reportSpecRunning = function() {
if (this.timer) {
clearTimeout(this.timer);
this.timer = null;
return this.print(Intense.moveBack());
}
};
Console.prototype.formatResultLine = function(runtime) {
var line;
line = [];
line.push(this.length);
line.push((this.length === 1 ? "test" : "tests") + ',');
line.push(this.failedCount);
line.push((this.failedCount === 1 ? "failure" : "failures") + ',');
line.push(runtime);
line.push((runtime === 1.0 ? "sec" : "secs") + '.');
return line.join(' ');
};
Console.prototype._waitRunner = function() {
var _this = this;
return this.timer = setTimeout(function() {
if (_this.timer) {
if (!_this.first) _this.print(Intense.moveBack());
_this.print(_this.positions.substr(_this.position, 1).foreground('yellow'));
_this.position += 1;
_this.position %= _this.positions.length;
_this.first = false;
return _this._waitRunner();
}
}, 750);
Console.prototype.displayFailure = function(spec) {
return this.print('F'.foreground('red'));
};
return Console;
})();
})(jasmine.HeadlessReporter.ConsoleBase);
}).call(this);

View File

@ -0,0 +1,120 @@
(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.HeadlessReporter.ConsoleBase = (function(_super) {
__extends(ConsoleBase, _super);
function ConsoleBase(callback) {
this.callback = callback != null ? callback : null;
this._waitRunner = __bind(this._waitRunner, this);
ConsoleBase.__super__.constructor.call(this, this.callback);
this.position = 0;
this.positions = "|/-\\";
}
ConsoleBase.prototype.formatResultLine = function(runtime) {
var line;
line = [];
line.push(this.length);
line.push((this.length === 1 ? "test" : "tests") + ',');
line.push(this.failedCount);
line.push((this.failedCount === 1 ? "failure" : "failures") + ',');
line.push(runtime);
line.push((runtime === 1.0 ? "sec" : "secs") + '.');
return line.join(' ');
};
ConsoleBase.prototype.reportRunnerResults = function(runner) {
var result, resultLine, _i, _len, _ref;
ConsoleBase.__super__.reportRunnerResults.call(this);
this.print("\n");
resultLine = this.formatResultLine(this._runtime());
if (this.failedCount === 0) {
this.puts(("PASS: " + resultLine).foreground('green'));
} else {
this.puts(("FAIL: " + resultLine).foreground('red'));
}
_ref = this.results;
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
result = _ref[_i];
this.puts(result.toString());
}
return this.puts("\nTest ordering seed: --seed " + (JHW.getSeed()));
};
ConsoleBase.prototype.reportRunnerStarting = function(runner) {
ConsoleBase.__super__.reportRunnerStarting.call(this, runner);
if (!this.hasError()) {
return this.puts("\nRunning Jasmine specs...".bright());
}
};
ConsoleBase.prototype.reportSpecWaiting = function() {
if (!this.timer) {
this.timer = true;
this.first = true;
return this._waitRunner();
}
};
ConsoleBase.prototype.reportSpecRunning = function() {
if (this.timer) {
clearTimeout(this.timer);
this.timer = null;
return this.print(Intense.moveBack());
}
};
ConsoleBase.prototype.reportSpecResults = function(spec) {
var _this = this;
ConsoleBase.__super__.reportSpecResults.call(this, spec);
return this._reportSpecResult(spec, {
success: function(results) {
return _this.displaySuccess(spec);
},
failure: function(results) {
_this.displayFailure(spec);
return _this.reportFailureResult(results, new HeadlessReporterResult(spec.getFullName(), spec.getSpecSplitName()));
}
});
};
ConsoleBase.prototype.reportFailureResult = function(results, failureResult) {
var foundLine, result, testCount, _i, _len, _ref;
testCount = 1;
_ref = results.getItems();
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
result = _ref[_i];
if (result.type === 'expect' && !result.passed_) {
if (foundLine = result.expectations[testCount - 1]) {
result.line = foundLine[0], result.lineNumber = foundLine[1];
}
failureResult.addResult(result);
}
testCount += 1;
}
return this.results.push(failureResult);
};
ConsoleBase.prototype._waitRunner = function() {
var _this = this;
return this.timer = setTimeout(function() {
if (_this.timer) {
if (!_this.first) _this.print(Intense.moveBack());
_this.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 ConsoleBase;
})(jasmine.HeadlessReporter);
}).call(this);

View File

@ -1,9 +1,10 @@
(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; };
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.HeadlessReporter.File = (function() {
jasmine.HeadlessReporter.File = (function(_super) {
__extends(File, jasmine.HeadlessReporter);
__extends(File, _super);
function File() {
File.__super__.constructor.apply(this, arguments);
@ -36,6 +37,6 @@
return File;
})();
})(jasmine.HeadlessReporter);
}).call(this);

View File

@ -1,9 +1,10 @@
(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; };
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.HeadlessReporter.Tap = (function() {
jasmine.HeadlessReporter.Tap = (function(_super) {
__extends(Tap, jasmine.HeadlessReporter);
__extends(Tap, _super);
function Tap(outputTarget) {
this.outputTarget = outputTarget != null ? outputTarget : null;
@ -18,8 +19,8 @@
};
Tap.prototype.reportSpecResults = function(spec) {
var description, index;
var _this = this;
var description, index,
_this = this;
Tap.__super__.reportSpecResults.call(this, spec);
index = this.output.length + 1;
description = spec.getSpecSplitName().join(' ');
@ -35,6 +36,6 @@
return Tap;
})();
})(jasmine.HeadlessReporter);
}).call(this);

View File

@ -0,0 +1,50 @@
(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.HeadlessReporter.Verbose = (function(_super) {
__extends(Verbose, _super);
function Verbose() {
this.indentSpec = __bind(this.indentSpec, this);
this.displaySpec = __bind(this.displaySpec, this);
this.displayFailure = __bind(this.displayFailure, this);
this.displaySuccess = __bind(this.displaySuccess, this);
Verbose.__super__.constructor.apply(this, arguments);
}
Verbose.prototype.displaySuccess = function(spec) {
return this.displaySpec(spec, 'green');
};
Verbose.prototype.displayFailure = function(spec) {
return this.displaySpec(spec, 'red');
};
Verbose.prototype.displaySpec = function(spec, color) {
var currentLastNames;
currentLastNames = (this.lastNames || []).slice(0);
this.lastNames = spec.getSpecSplitName();
return this.puts(this.indentSpec(this.lastNames, currentLastNames, color).join("\n"));
};
Verbose.prototype.indentSpec = function(current, last, color) {
var indent, name, output, _i, _len;
last = last.slice(0);
output = [];
indent = '';
for (_i = 0, _len = current.length; _i < _len; _i++) {
name = current[_i];
if (last.shift() !== name) output.push(indent + name.foreground(color));
indent += ' ';
}
return output;
};
return Verbose;
})(jasmine.HeadlessReporter.ConsoleBase);
}).call(this);

View File

@ -1,5 +1,6 @@
(function() {
var puts;
if (window.JHW) {
window.console = {
log: function(data) {
@ -43,9 +44,7 @@
e = e || window.event;
JHW.hasError();
puts("The code tried to leave the test page. Check for unhandled form submits and link clicks.");
if (e) {
e.returnValue = 'string';
}
if (e) e.returnValue = 'string';
return 'string';
};
JHW._hasErrors = false;
@ -75,14 +74,15 @@
_ref = jasmine.getEnv().reporter.subReporters_;
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
reporter = _ref[_i];
if (reporter.consoleLogUsed != null) {
reporter.consoleLogUsed(msg);
}
if (reporter.consoleLogUsed != null) reporter.consoleLogUsed(msg);
}
JHW._usedConsole = true;
return puts(msg);
};
}
window.CoffeeScriptToFilename = {};
window.CSTF = window.CoffeeScriptToFilename;
}).call(this);