Name: js-handler/node_modules/nodeunit/node_modules/tap/lib/tap-results.js
| 1: | // A class for counting up results in a test harness. |
| 2: | |
| 3: | module.exports = Results |
| 4: | |
| 5: | var inherits = require("inherits") |
| 6: | , EventEmitter = require("events").EventEmitter |
| 7: | |
| 8: | inherits(Results, EventEmitter) |
| 9: | |
| 10: | function Results (r) { |
| 11: | //console.error("result constructor", r) |
| 12: | this.ok = true |
| 13: | this.addSet(r) |
| 14: | } |
| 15: | |
| 16: | Results.prototype.addSet = function (r) { |
| 17: | //console.error("add set of results", r) |
| 18: | r = r || {ok: true} |
| 19: | ; [ "todo" |
| 20: | , "todoPass" |
| 21: | , "todoFail" |
| 22: | , "skip" |
| 23: | , "skipPass" |
| 24: | , "skipFail" |
| 25: | , "pass" |
| 26: | , "passTotal" |
| 27: | , "fail" |
| 28: | , "failTotal" |
| 29: | , "tests" |
| 30: | , "testsTotal" ].forEach(function (k) { |
| 31: | this[k] = (this[k] || 0) + (r[k] || 0) |
| 32: | //console.error([k, this[k]]) |
| 33: | }, this) |
| 34: | |
| 35: | this.ok = this.ok && r.ok && true |
| 36: | this.bailedOut = this.bailedOut || r.bailedOut || false |
| 37: | this.list = (this.list || []).concat(r.list || []) |
| 38: | this.emit("set", this.list) |
| 39: | //console.error("after addSet", this) |
| 40: | } |
| 41: | |
| 42: | Results.prototype.add = function (r, addToList) { |
| 43: | //console.error("add result", r) |
| 44: | var pf = r.ok ? "pass" : "fail" |
| 45: | , PF = r.ok ? "Pass" : "Fail" |
| 46: | |
| 47: | this.testsTotal ++ |
| 48: | this[pf + "Total"] ++ |
| 49: | |
| 50: | if (r.skip) { |
| 51: | this["skip" + PF] ++ |
| 52: | this.skip ++ |
| 53: | } else if (r.todo) { |
| 54: | this["todo" + PF] ++ |
| 55: | this.todo ++ |
| 56: | } else { |
| 57: | this.tests ++ |
| 58: | this[pf] ++ |
| 59: | } |
| 60: | |
| 61: | if (r.bailout || typeof r.bailout === "string") { |
| 62: | // console.error("Bailing out in result") |
| 63: | this.bailedOut = true |
| 64: | } |
| 65: | this.ok = !!(this.ok && r.ok) |
| 66: | |
| 67: | if (addToList === false) return |
| 68: | this.list = this.list || [] |
| 69: | this.list.push(r) |
| 70: | this.emit("result", r) |
| 71: | } |
