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
+18 -6
View File
@@ -3,6 +3,9 @@
exports = module.exports = {
SettingsError: SettingsError,
initialize: initialize,
uninitialize: uninitialize,
getEmailDnsRecords: getEmailDnsRecords,
getAutoupdatePattern: getAutoupdatePattern,
@@ -56,7 +59,7 @@ exports = module.exports = {
APPSTORE_CONFIG_KEY: 'appstore_config',
MAIL_CONFIG_KEY: 'mail_config',
events: new (require('events').EventEmitter)()
events: null
};
var assert = require('assert'),
@@ -102,11 +105,6 @@ var gDefaults = (function () {
return result;
})();
if (config.TEST) {
// avoid noisy warnings during npm test
exports.events.setMaxListeners(100);
}
function SettingsError(reason, errorOrMessage) {
assert.strictEqual(typeof reason, 'string');
assert(errorOrMessage instanceof Error || typeof errorOrMessage === 'string' || typeof errorOrMessage === 'undefined');
@@ -131,6 +129,20 @@ SettingsError.EXTERNAL_ERROR = 'External Error';
SettingsError.NOT_FOUND = 'Not Found';
SettingsError.BAD_FIELD = 'Bad Field';
function initialize(callback) {
assert.strictEqual(typeof callback, 'function');
exports.events = new (require('events').EventEmitter)();
callback();
}
function uninitialize(callback) {
assert.strictEqual(typeof callback, 'function');
exports.events = null;
callback();
}
function getEmailDnsRecords(callback) {
assert.strictEqual(typeof callback, 'function');