Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

End tests if they hit the plan count

  • Loading branch information...
commit 4f3c94779ad530cc218a501ca23307c93efaa185 1 parent 9e3d7e2
@isaacs authored
Showing with 38 additions and 0 deletions.
  1. +5 −0 lib/test.js
  2. +33 −0 test/timeout.js
View
5 lib/test.js
@@ -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
33 test/timeout.js
@@ -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)
+})
Please sign in to comment.
Something went wrong with that request. Please try again.