From ede4926069918bb66b7a4e1232a62ac01d2ea665 Mon Sep 17 00:00:00 2001 From: Iuri Matias Date: Fri, 8 Jun 2018 06:14:46 -0400 Subject: [PATCH 1/4] don't continue testing file if there was deploy errors; avoids unrelated errors for each 'it' --- lib/tests/run_tests.js | 4 ++-- lib/tests/test.js | 9 ++++++--- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/lib/tests/run_tests.js b/lib/tests/run_tests.js index eb31209a..0ed32c7c 100644 --- a/lib/tests/run_tests.js +++ b/lib/tests/run_tests.js @@ -83,8 +83,8 @@ module.exports = { mocha.suite.timeout(0); mocha.suite.beforeAll('Wait for deploy', (done) => { - global.embark.onReady(() => { - done(); + global.embark.onReady((err) => { + done(err); }); }); diff --git a/lib/tests/test.js b/lib/tests/test.js index 4f9d1075..bc9b5abe 100644 --- a/lib/tests/test.js +++ b/lib/tests/test.js @@ -117,6 +117,9 @@ class Test { this.events.once('ready', () => { callback(); }); + this.events.once('deployError', (err) => { + callback(err); + }); } config(options, callback) { @@ -175,12 +178,12 @@ class Test { }, function deploy(next) { self._deploy(options, (err, accounts) => { - self.ready = true; - self.events.emit('ready'); if (err) { - console.error(err.red); + self.events.emit('deployError', err); return next(err); } + self.ready = true; + self.events.emit('ready'); next(null, accounts); }); } From 2efea55d2b42217960c5c17d9d5755aa1122d20b Mon Sep 17 00:00:00 2001 From: Iuri Matias Date: Fri, 8 Jun 2018 06:17:51 -0400 Subject: [PATCH 2/4] lint is king --- lib/tests/test.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/tests/test.js b/lib/tests/test.js index bc9b5abe..0e883686 100644 --- a/lib/tests/test.js +++ b/lib/tests/test.js @@ -124,7 +124,7 @@ class Test { config(options, callback) { const self = this; - if (typeof(options) === 'function') { + if (typeof (options) === 'function') { callback = options; options = {}; } @@ -229,7 +229,7 @@ class Test { {from: self.web3.eth.defaultAccount, gas: 6000000})); self.contracts[contractName].address = contract.deployedAddress; if (self.contracts[contractName].options) { - self.contracts[contractName].options.from = self.contracts[contractName].options.from || web3.eth.defaultAccount; + self.contracts[contractName].options.from = self.contracts[contractName].options.from || self.web3.eth.defaultAccount; self.contracts[contractName].options.data = data; } eachCb(); @@ -276,7 +276,7 @@ class Test { {from: this.web3.eth.defaultAccount, gas: 6000000}); this.contracts[contractName].address = contract.address; this.contracts[contractName].options.data = contract.code; - web3.eth.getAccounts().then((accounts) => { + this.web3.eth.getAccounts().then((accounts) => { this.contracts[contractName].options.from = contract.from || accounts[0]; }); return this.contracts[contractName]; From 1b6ac99ea2b558706d0419597f46452378be2184 Mon Sep 17 00:00:00 2001 From: Iuri Matias Date: Fri, 8 Jun 2018 12:30:44 -0400 Subject: [PATCH 3/4] 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); }); From cdfa30ebd2edc9e00ca9f9a95bc2a4b10e256737 Mon Sep 17 00:00:00 2001 From: Iuri Matias Date: Fri, 8 Jun 2018 12:51:04 -0400 Subject: [PATCH 4/4] remove listeners correctly --- lib/tests/test.js | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/lib/tests/test.js b/lib/tests/test.js index ac1a219f..a6789da9 100644 --- a/lib/tests/test.js +++ b/lib/tests/test.js @@ -119,14 +119,21 @@ class Test { 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', () => {}); + + let errorCallback, readyCallback; + + errorCallback = (err) => { + self.events.removeListener('ready', readyCallback); callback(err); - }); + }; + + readyCallback = () => { + self.events.removeListener('deployError', errorCallback); + callback(); + }; + + this.events.once('ready', readyCallback); + this.events.once('deployError', errorCallback); } config(options, callback) {