From 1b6ac99ea2b558706d0419597f46452378be2184 Mon Sep 17 00:00:00 2001 From: Iuri Matias Date: Fri, 8 Jun 2018 12:30:44 -0400 Subject: [PATCH] remove listeners to avoid leaks --- lib/tests/test.js | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/lib/tests/test.js b/lib/tests/test.js index 0e883686..ac1a219f 100644 --- a/lib/tests/test.js +++ b/lib/tests/test.js @@ -33,6 +33,7 @@ class Test { this.contracts = {}; this.events = new Events(); this.ready = true; + this.error = false; this.builtContracts = {}; this.compiledContracts = {}; @@ -111,13 +112,19 @@ class Test { } onReady(callback) { + const self = this; if (this.ready) { return callback(); } + if (this.error) { + return callback(this.error); + } this.events.once('ready', () => { + self.events.removeListener('deployError', () => {}); callback(); }); this.events.once('deployError', (err) => { + self.events.removeListener('ready', () => {}); callback(err); }); } @@ -180,9 +187,11 @@ class Test { self._deploy(options, (err, accounts) => { if (err) { self.events.emit('deployError', err); + self.error = err; return next(err); } self.ready = true; + self.error = false; self.events.emit('ready'); next(null, accounts); });