From 2f8a822688581fb1c506ab51921aff40429fb45c Mon Sep 17 00:00:00 2001 From: James Halliday Date: Thu, 20 Dec 2012 19:51:23 -0800 Subject: [PATCH] avoid max listeners warnings, test passes --- index.js | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index 9983a495..2c5110ba 100644 --- a/index.js +++ b/index.js @@ -12,6 +12,13 @@ var canEmitExit = typeof process !== 'undefined' && process var canExit = typeof process !== 'undefined' && process && typeof process.exit === 'function' ; +var onexit = (function () { + var stack = []; + if (canEmitExit) process.on('exit', function (code) { + for (var i = 0; i < stack.length; i++) stack[i](code); + }); + return function (cb) { stack.push(cb) }; +})(); function createHarness (conf_) { var pending = []; @@ -26,8 +33,8 @@ function createHarness (conf_) { var t = new Test(name, conf, cb); if (!conf || typeof conf !== 'object') conf = conf_ || {}; - if (conf.exit !== false && canEmitExit) { - process.on('exit', function (code) { + if (conf.exit !== false) { + onexit(function (code) { t._exit(); out.close(); if (!code && !t._ok) process.exit(1);