Create/destroy event listeners

mocha loads all the tests in same process. This means that when
we start a new test, the old state still persists. For event
listeners, this means that they get multiple duplicate event handlers.
This commit is contained in:
Girish Ramakrishnan
2017-02-07 10:30:52 -08:00
parent 4bb864e2ac
commit b91674799b
7 changed files with 99 additions and 41 deletions
+14 -2
View File
@@ -4,7 +4,10 @@ exports = module.exports = {
initialize: initialize,
uninitialize: uninitialize,
events: new (require('events').EventEmitter)(),
start: start,
events: null,
EVENT_READY: 'ready'
};
@@ -34,6 +37,15 @@ var gPlatformReadyTimer = null;
var NOOP_CALLBACK = function (error) { if (error) debug(error); };
function initialize(callback) {
assert.strictEqual(typeof callback, 'function');
exports.events = new (require('events').EventEmitter)();
return callback();
}
function start(callback) {
assert.strictEqual(typeof callback, 'function');
if (process.env.BOX_ENV === 'test' && !process.env.TEST_CREATE_INFRA) return callback();
debug('initializing addon infrastructure');
@@ -87,7 +99,7 @@ function uninitialize(callback) {
clearTimeout(gPlatformReadyTimer);
gPlatformReadyTimer = null;
// TODO: unregister event listeners
exports.events = null;
callback();
}