From 2d1a37d63b4c7cf7ce4ccd697807857e6aea2db5 Mon Sep 17 00:00:00 2001 From: Jonathan Rainville Date: Fri, 1 Jun 2018 13:44:49 -0400 Subject: [PATCH] conflict in pakcgae lock --- lib/contracts/contract_deployer.js | 4 ++ lib/i18n/i18n.js | 2 +- lib/tests/run_tests.js | 72 +++++++++++++++++------------- lib/tests/test.js | 18 +++++--- package.json | 1 + 5 files changed, 59 insertions(+), 38 deletions(-) diff --git a/lib/contracts/contract_deployer.js b/lib/contracts/contract_deployer.js index 234769540..e1cc8f652 100644 --- a/lib/contracts/contract_deployer.js +++ b/lib/contracts/contract_deployer.js @@ -98,6 +98,10 @@ class ContractDeployer { return next(); } + // TODO find a better way to do that + if (process.env.isTest) { + return self.contractToDeploy(contract, params, next); + } // TODO: this should be a plugin API instead, if not existing, it should by default deploy the contract self.events.request("deploy:contract:shouldDeploy", contract, function(trackedContract) { if (!trackedContract) { diff --git a/lib/i18n/i18n.js b/lib/i18n/i18n.js index aa52a03ff..ebe6562cb 100644 --- a/lib/i18n/i18n.js +++ b/lib/i18n/i18n.js @@ -7,7 +7,7 @@ const supported_languages = ['en', 'pt', 'fr']; i18n.configure({ locales: supported_languages, register: global, - //updateFiles: false, + updateFiles: false, directory: path.join(__dirname, 'locales') }); diff --git a/lib/tests/run_tests.js b/lib/tests/run_tests.js index b12361ef5..bd435bd92 100644 --- a/lib/tests/run_tests.js +++ b/lib/tests/run_tests.js @@ -22,28 +22,13 @@ function getFilesFromDir(filePath, cb) { module.exports = { run: function (filePath) { - const mocha = new Mocha(); + process.env.isTest = true; + let failures = 0; if (!filePath) { filePath = 'test/'; } async.waterfall([ - function getFiles(next) { - if (filePath.substr(-1) !== '/') { - mocha.addFile(filePath); - return next(); - } - getFilesFromDir(filePath, (err, files) => { - if (err) { - console.error('Error while reading the directory'); - return next(err); - } - files.forEach(file => { - mocha.addFile(file); - }); - next(); - }); - }, function setupGlobalNamespace(next) { // TODO put default config const test = new Test(); @@ -53,31 +38,56 @@ module.exports = { // TODO: this global here might not be necessary at all global.web3 = global.embark.web3; - mocha.suite.beforeEach('Wait for deploy', (done) => { - test.onReady(() => { - done(); - }); - }); global.contract = function (describeName, callback) { return Mocha.describe(describeName, callback); }; + console.info('Compiling contracts'.cyan); test.init(next); + }, + function getFiles(next) { + if (filePath.substr(-1) !== '/') { + return next(null, [filePath]); + } + getFilesFromDir(filePath, (err, files) => { + if (err) { + console.error('Error while reading the directory'); + return next(err); + } + next(null, files); + }); + }, + function executeForAllFiles(files, next) { + async.eachLimit(files, 1, (file, eachCb) => { + const mocha = new Mocha(); + mocha.addFile(file); + + mocha.suite.timeout(0); + mocha.suite.beforeEach('Wait for deploy', (done) => { + global.embark.onReady(() => { + done(); + }); + }); + + mocha.run(function(fails) { + failures += fails; + // Mocha prints the error already + eachCb(); + }); + }, next); } ], (err) => { if (err) { console.error(err); process.exit(1); } - // Run the tests. - mocha.run(function (failures) { - // Clean contracts folder for next test run - fs.remove('.embark/contracts', (_err) => { - process.on('exit', function () { - process.exit(failures); // exit with non-zero status if there were failures - }); - process.exit(); - }); + if (failures) { + console.error(`Total number of failures: ${failures}`.red); + } + + // Clean contracts folder for next test run + fs.remove('.embark/contracts', (_err) => { + process.exit(failures); }); }); } diff --git a/lib/tests/test.js b/lib/tests/test.js index 3ac0b2d47..5269d84bb 100644 --- a/lib/tests/test.js +++ b/lib/tests/test.js @@ -5,6 +5,7 @@ const Web3 = require('web3'); const utils = require('../utils/utils'); const constants = require('../constants'); const Events = require('../core/events'); +const cloneDeep = require('clone-deep'); function getSimulator() { try { @@ -63,7 +64,9 @@ class Test { } init(callback) { + const self = this; this.engine.contractsManager.build(() => { + self.builtContracts = cloneDeep(self.engine.contractsManager.contracts); callback(); }); } @@ -88,11 +91,14 @@ class Test { this.simOptions = this.options.simulatorOptions || {}; this.ready = false; + // Reset contracts + this.engine.contractsManager.contracts = cloneDeep(this.builtContracts); + this._deploy(options, (err, accounts) => { this.ready = true; this.events.emit('ready'); if (err) { - console.error(err); + console.error(err.red); return callback(err); } callback(null, accounts); @@ -131,11 +137,11 @@ class Test { }); }, function createContractObject(next) { - async.each(Object.keys(self.contracts), (contractName, eachCb) => { - if (!self.engine.contractsManager.contracts[contractName]) { - throw new Error(__('No contract with the name %s', contractName)); - } + async.each(Object.keys(self.engine.contractsManager.contracts), (contractName, eachCb) => { const contract = self.engine.contractsManager.contracts[contractName]; + if (!self.contracts[contractName]) { + self.contracts[contractName] = {}; + } Object.assign(self.contracts[contractName], new self.web3.eth.Contract(contract.abiDefinition, contract.address, {from: self.web3.eth.defaultAccount, gas: 6000000})); eachCb(); @@ -144,7 +150,7 @@ class Test { ], function (err) { if (err) { console.log(__('terminating due to error')); - throw new Error(err); + return callback(err); } callback(); }); diff --git a/package.json b/package.json index 9872b897d..e6ffb76b4 100644 --- a/package.json +++ b/package.json @@ -33,6 +33,7 @@ "bip39": "^2.5.0", "blessed": "^0.1.81", "chokidar": "^2.0.3", + "clone-deep": "^4.0.0", "colors": "^1.1.2", "commander": "^2.15.1", "css-loader": "^0.28.11",