Skip to content

Commit

Permalink
avoid max listeners warnings, test passes
Browse files Browse the repository at this point in the history
  • Loading branch information
James Halliday committed Dec 21, 2012
1 parent 4058f75 commit 2f8a822
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [];
Expand All @@ -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);
Expand Down

0 comments on commit 2f8a822

Please sign in to comment.