Permalink
Browse files

End tests if they hit the plan count

  • Loading branch information...
1 parent 9e3d7e2 commit 4f3c94779ad530cc218a501ca23307c93efaa185 @isaacs isaacs committed Apr 5, 2011
Showing with 38 additions and 0 deletions.
  1. +5 −0 lib/test.js
  2. +33 −0 test/timeout.js
View
@@ -44,6 +44,11 @@ Test.prototype.result = function (res) {
this.results.add(res)
this._testCount ++
this.emit("result", res)
+ if (this._plan === this._testCount) {
+ process.nextTick(function () {
+ if (!this._ended) this.end()
+ }.bind(this))
+ }
}
// parasitic
View
@@ -0,0 +1,33 @@
+var tap = require("../")
+
+tap.test("timeout test with plan only", function (t) {
+ console.error("timeout test")
+ t.plan(2)
+ console.error("t.plan="+t._plan)
+ setTimeout(function () {
+ console.error("a assert")
+ t.ok(true, "a")
+ }, 1000)
+ setTimeout(function () {
+ console.error("b assert")
+ t.ok(true, "b")
+ }, 1000)
+})
+
+tap.test("timeout test with plan and end", function (t) {
+ console.error("timeout test")
+ t.plan(2)
+
+ var tc = 2
+ console.error("t.plan="+t._plan)
+ setTimeout(function () {
+ console.error("a assert")
+ t.ok(true, "a")
+ if (-- tc === 0) t.end()
+ }, 1000)
+ setTimeout(function () {
+ console.error("b assert")
+ t.ok(true, "b")
+ if (-- tc === 0) t.end()
+ }, 1000)
+})

0 comments on commit 4f3c947

Please sign in to comment.