Permalink
Browse files

GH-18: Merged tap-results, git history included.

  • Loading branch information...
2 parents 9757dfc + b4329b7 commit 7a941818f3d23a1ae02ba31c9a8931bc56be40a3 @kusor kusor committed Nov 17, 2011
Showing with 69 additions and 3 deletions.
  1. +1 −3 package.json
  2. +68 −0 results.js
View
@@ -5,16 +5,14 @@
, "bin" : "bin/tap.js"
, "main" : "lib/main.js"
, "dependencies" :
- { "tap-results" : "0.x"
- , "tap-consumer" : "0.x"
+ { "tap-consumer" : "0.x"
, "inherits" : "*"
, "yamlish" : "*"
, "slide": "*"
}
, "bundledDependencies" :
[ "inherits"
, "tap-consumer"
- , "tap-results"
, "yamlish"
]
, "keywords" :
View
@@ -0,0 +1,68 @@
+// A class for counting up results in a test harness.
+
+module.exports = Results
+
+var inherits = require("inherits")
+ , EventEmitter = require("events").EventEmitter
+
+inherits(Results, EventEmitter)
+
+function Results (r) {
+ //console.error("result constructor", r)
+ this.ok = true
+ this.addSet(r)
+}
+
+Results.prototype.addSet = function (r) {
+ //console.error("add set of results", r)
+ r = r || {ok: true}
+ ; [ "todo"
+ , "todoPass"
+ , "todoFail"
+ , "skip"
+ , "skipPass"
+ , "skipFail"
+ , "pass"
+ , "passTotal"
+ , "fail"
+ , "failTotal"
+ , "tests"
+ , "testsTotal" ].forEach(function (k) {
+ this[k] = (this[k] || 0) + (r[k] || 0)
+ //console.error([k, this[k]])
+ }, this)
+
+ this.ok = this.ok && r.ok && true
+ this.bailedOut = this.bailedOut || r.bailedOut || false
+ this.list = (this.list || []).concat(r.list || [])
+ this.emit("set", this.list)
+ //console.error("after addSet", this)
+}
+
+Results.prototype.add = function (r, addToList) {
+ //console.error("add result", r)
+ var pf = r.ok ? "pass" : "fail"
+ , PF = r.ok ? "Pass" : "Fail"
+
+ this.testsTotal ++
+ this[pf + "Total"] ++
+
+ if (r.skip) {
+ this["skip" + PF] ++
+ this.skip ++
+ } else if (r.todo) {
+ this["todo" + PF] ++
+ this.todo ++
+ } else {
+ this.tests ++
+ this[pf] ++
+ }
+
+ if (r.bailout || typeof r.bailout === "string") this.bailedOut = true
+ this.ok = !!(this.ok && r.ok)
+
+ if (addToList === false) return
+ this.list = this.list || []
+ this.list.push(r)
+ this.emit("result", r)
+}

0 comments on commit 7a94181

Please sign in to comment.