From ea179376e2771b6ea2349a84b96f6c0a9113a511 Mon Sep 17 00:00:00 2001 From: Kory Nunn Date: Mon, 11 Jan 2016 10:31:50 +1000 Subject: [PATCH] [Fix] Resolves issue where tests would not attempt to complete --- lib/results.js | 14 +++++++++++--- package.json | 1 + test/async.js | 37 +++++++++++++++++++++++++++++++++++++ 3 files changed, 49 insertions(+), 3 deletions(-) create mode 100644 test/async.js diff --git a/lib/results.js b/lib/results.js index 56fdc4ba..077855ec 100644 --- a/lib/results.js +++ b/lib/results.js @@ -5,6 +5,7 @@ var through = require('through'); var resumer = require('resumer'); var inspect = require('object-inspect'); var bind = require('function-bind'); +var debounce = require('debounce'); var has = require('has'); var regexpTest = bind.call(Function.call, RegExp.prototype.test); var yamlIndicators = /\:|\-|\?/; @@ -65,6 +66,14 @@ Results.prototype.createStream = function (opts) { self._stream.pipe(output); } + self._end(); + + return output; +}; + +Results.prototype._end = debounce(function () { + var self = this; + nextTick(function next() { var t; while (t = getNextTest(self)) { @@ -73,15 +82,14 @@ Results.prototype.createStream = function (opts) { } self.emit('done'); }); - - return output; -}; +}, 1); Results.prototype.push = function (t) { var self = this; self.tests.push(t); self._watch(t); self.emit('_push', t); + self._end(); }; Results.prototype.only = function (t) { diff --git a/package.json b/package.json index fb6d83d3..81ed442c 100644 --- a/package.json +++ b/package.json @@ -9,6 +9,7 @@ "test": "test" }, "dependencies": { + "debounce": "~1.0.0", "deep-equal": "~1.0.1", "defined": "~1.0.0", "for-each": "~0.3.3", diff --git a/test/async.js b/test/async.js new file mode 100644 index 00000000..d9167652 --- /dev/null +++ b/test/async.js @@ -0,0 +1,37 @@ +var tape = require('../'); +var tap = require('tap'); + +tap.test('async test calls', function (tt) { + tt.plan(1); + + var test = tape.createHarness(); + var tc = tap.createConsumer(); + + test.createStream().pipe(tc); + + function run1(callback){ + test('first', function (t) { + t.plan(1); + + t.pass(); + + setTimeout(callback, 10); + }); + } + + function run2(callback){ + test('second', function (t) { + t.plan(1); + + t.pass(); + + setTimeout(callback, 10); + }); + } + + run1(function(){ + run2(function(){ + tt.pass(); + }); + }); +});