diff --git a/bin/vows b/bin/vows index 065f32a..2694549 100755 --- a/bin/vows +++ b/bin/vows @@ -47,6 +47,7 @@ var help = [ " -r PATTERN Only run tests matching the PATTERN regexp", " --json Use JSON reporter", " --spec Use Spec reporter", + " --tap Use TAP reporter", " --dot-matrix Use Dot-Matrix reporter", " --xunit Use xUnit reporter", " --cover-plain Print plain coverage map if detected", @@ -107,6 +108,9 @@ while (arg = argv.shift()) { case 'spec': _reporter = require('../lib/vows/reporters/spec'); break; + case 'tap': + _reporter = require('../lib/vows/reporters/tap'); + break; case 'dot-matrix': _reporter = require('../lib/vows/reporters/dot-matrix'); break; diff --git a/lib/vows/reporters/tap.js b/lib/vows/reporters/tap.js new file mode 100644 index 0000000..35785d4 --- /dev/null +++ b/lib/vows/reporters/tap.js @@ -0,0 +1,100 @@ +var options = { + tail: "\n" +}; +var console = require("vows/lib/vows/console"); +var stylize = console.stylize; +var puts = console.puts(options); + +// +// TAP Reporter +// + +this.name = "tap"; +this.setSTream = function setStream(s) { + options.stream = s; +} + +var __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; }; +var TapInterface = (function() { + function TapInterface() { + this.genOutput_ = __bind(this.genOutput_, this); + this.testCount = __bind(this.testCount, this); + this.bailOut = __bind(this.bailOut, this); + this.skip = __bind(this.skip, this); + this.notOk = __bind(this.notOk, this); + this.ok = __bind(this.ok, this); + this.count_ = 0; + } + + TapInterface.prototype.ok = function(description) { + return this.genOutput_("ok", ++this.count_, "- " + description); + }; + + TapInterface.prototype.notOk = function(description) { + return this.genOutput_("not ok", ++this.count_, "- " + description); + }; + + TapInterface.prototype.skip = function(description) { + return this.genOutput_("ok", ++this.count_, "# SKIP " + description); + }; + + TapInterface.prototype.bailOut = function(reason) { + return "Bail out!" + (reason != null ? " " + reason : ""); + }; + + TapInterface.prototype.testCount = function() { + return "1.." + this.count_; + }; + + TapInterface.prototype.genOutput_ = function(status, testNumber, description) { + return "" + status + " " + testNumber + " " + description; + }; + + return TapInterface; +})(); + +var tap = new TapInterface(); + +this.report = function report(data) { + var type = data[0]; + var event = data[1]; + switch (type) { + case "subject": + puts("# " + stylize(event, "bold")); + break; + case "context": + puts("# " + event); + break; + case "vow": + switch (event.status) { + case "honored": + puts(tap.ok(event.title)); + break; + case "pending": + puts(tap.skip(event.title)); + break; + case "broken": + puts(tap.notOk(event.title + "\n# " + event.exception)); + break; + case "errored": + puts(tap.notOk(event.title)); + puts(tap.bailOut(event.exception)); + break; + } + break; + case "end": + puts("\n"); + break; + case "finish": + puts(tap.testCount()); + break; + case "error": + puts("#> Errored"); + puts("# " + JSON.stringify(data)); + break; + } +} + +this.print = function print(str) { + require("util").print(str); +}