diff --git a/index.js b/index.js index f6a679e8..e47cf049 100644 --- a/index.js +++ b/index.js @@ -16,6 +16,11 @@ var onexit = (function () { return function (cb) { stack.push(cb) }; })(); +var nextTick = typeof setImmediate !== 'undefined' + ? setImmediate + : process.nextTick +; + exports = module.exports = createHarness(); exports.createHarness = createHarness; exports.Test = Test; @@ -71,7 +76,7 @@ function createHarness (conf_) { }); } - process.nextTick(function () { + nextTick(function () { if (!out.piped) out.pipe(createDefaultStream()); if (!began) out.begin(); began = true; @@ -117,7 +122,7 @@ function createHarness (conf_) { pending.unshift.apply(pending, unshifts); } - process.nextTick(function () { + nextTick(function () { running = false; if (pending.length) return pending.shift()(); if (count === 0 && !closed) { diff --git a/lib/test.js b/lib/test.js index 89b32606..4d1e239c 100644 --- a/lib/test.js +++ b/lib/test.js @@ -5,6 +5,11 @@ var path = require('path'); module.exports = Test; +var nextTick = typeof setImmediate !== 'undefined' + ? setImmediate + : process.nextTick +; + Test.prototype = new EventEmitter; function Test (name_, opts_, cb_) { @@ -137,7 +142,7 @@ Test.prototype._assert = function assert (ok, opts) { self.emit('result', res); if (self._plan === self.assertCount) { - process.nextTick(function () { + nextTick(function () { if (!self.ended) self.end(); }); }