Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

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

  • Loading branch information...
commit 332ef8572fae038083b7a7a5ea9bd24daddd788b 2 parents 1512c10 + 9ad5f65
@kusor kusor authored
Showing with 114 additions and 7 deletions.
  1. +1 −0  README.md
  2. +5 −7 package.json
  3. +108 −0 test.js
View
1  README.md
@@ -75,3 +75,4 @@ this is very useful for CI systems and such.
support for running TAP tests.
More docs coming soon, hopefully.
+
View
12 package.json
@@ -7,7 +7,6 @@
, "dependencies" :
{ "tap-global-harness" : "0.x"
, "tap-runner" : "0.x >=0.0.6"
- , "tap-test" : "0.x"
, "tap-harness" : "0.x"
, "tap-results" : "0.x"
, "tap-consumer" : "0.x"
@@ -22,14 +21,12 @@
, "tap-harness"
, "tap-producer"
, "tap-results"
- , "tap-test"
, "yamlish"
]
, "keywords" :
- [
- "assert",
- "test",
- "tap"
+ [ "assert"
+ , "test"
+ , "tap"
]
, "contributors" :
[
@@ -38,7 +35,8 @@
]
, "license": {
"type": "MIT",
- "url": "https://github.com/isaacs/tap-assert/raw/master/LICENSE"
+ "url": "https://github.com/isaacs/node-tap/raw/master/LICENSE"
}
, "repository" : "git://github.com/isaacs/node-tap.git"
, "scripts" : { "test" : "bin/tap.js test" } }
+
View
108 test.js
@@ -0,0 +1,108 @@
+// This is a very simple test framework that leverages the tap framework
+// to run tests and output tap-parseable results.
+
+module.exports = Test
+
+var assert = require("tap-assert")
+ , inherits = require("inherits")
+ , Results = require("tap-results")
+
+// tests are also test harnesses
+inherits(Test, require("tap-harness"))
+
+function Test (harness, name, conf) {
+ //console.error("test ctor")
+ if (!(this instanceof Test)) return new Test(harness, name, conf)
+
+ Test.super.call(this, Test)
+
+ conf.name = name || conf.name || "(anonymous)"
+ this.conf = conf
+
+ this.harness = harness
+ this.harness.add(this)
+}
+
+// it's taking too long!
+Test.prototype.timeout = function () {
+ // detect false alarms
+ if (this._ended) return
+ this.fail("Timeout!")
+ this.end()
+}
+
+Test.prototype.clear = function () {
+ this._started = false
+ this._ended = false
+ this._plan = null
+ this._bailedOut = false
+ this._testCount = 0
+ this.results = new Results()
+}
+
+// this gets called if a test throws ever
+Test.prototype.threw = function (ex) {
+ //console.error("threw!", ex.stack)
+ this.fail(ex.name + ": " + ex.message, { error: ex, thrown: true })
+ // may emit further failing tests if the plan is not completed
+ //console.error("end, because it threw")
+ this.end()
+}
+
+Test.prototype.comment = function (m) {
+ if (typeof m !== "string") {
+ return this.fail("Test.comment argument must be a string")
+ }
+ this.result("\n" + m.trim())
+}
+
+Test.prototype.result = function (res) {
+ this.results.add(res)
+ this._testCount ++
+ this.emit("result", res)
+ if (this._plan === this._testCount) {
+ process.nextTick(this._endNice.bind(this))
+ }
+}
+
+Test.prototype._endNice = function () {
+ if (!this._ended) this.end()
+}
+
+// parasitic
+// Who says you can't do multiple inheritance in js?
+Object.getOwnPropertyNames(assert).forEach(function (k) {
+ if (k === "prototype" || k === "name") return
+ var d = Object.getOwnPropertyDescriptor(assert, k)
+ , v = d.value
+ if (!v) return
+ d.value = assertParasite(v)
+ Object.defineProperty(Test.prototype, k, d)
+})
+
+function assertParasite (fn) { return function _testAssert () {
+ //console.error("_testAssert", fn.name, arguments)
+ if (this._bailedOut) return
+ var res = fn.apply(assert, arguments)
+ this.result(res)
+}}
+
+// a few tweaks on the EE emit function, because
+// we want to catch all thrown errors and bubble up "bailout"
+Test.prototype.emit = (function (em) { return function (t) {
+ // bailouts bubble until handled
+ if (t === "bailout" &&
+ this.listeners(t).length === 0 &&
+ this.harness) {
+ return this.harness.bailout(arguments[1])
+ }
+
+ if (t === "error") return em.apply(this, arguments)
+ try {
+ em.apply(this, arguments)
+ } catch (ex) {
+ // any exceptions in a test are a failure
+ //console.error("caught!", ex.stack)
+ this.threw(ex)
+ }
+}})(Test.super.prototype.emit)
Please sign in to comment.
Something went wrong with that request. Please try again.