mirror of https://github.com/embarklabs/embark.git
always deploy contracts when in tests and make all test work
This commit is contained in:
parent
0ab151500d
commit
a112f18d93
|
@ -99,6 +99,10 @@ class Deploy {
|
|||
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) {
|
||||
|
|
|
@ -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')
|
||||
});
|
||||
|
||||
|
|
|
@ -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);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
});
|
||||
|
|
|
@ -2409,6 +2409,22 @@
|
|||
"resolved": "https://registry.npmjs.org/clone-buffer/-/clone-buffer-1.0.0.tgz",
|
||||
"integrity": "sha1-4+JbIHrE5wGvch4staFnksrD3Fg="
|
||||
},
|
||||
"clone-deep": {
|
||||
"version": "4.0.0",
|
||||
"resolved": "https://registry.npmjs.org/clone-deep/-/clone-deep-4.0.0.tgz",
|
||||
"integrity": "sha512-aNJ5/7Bz2IYBb7nIj34TLGk78lBXpXUgV9qsLngtTvJ9+scsZNnlU0OX2S2N4ax/sUQt7sDBkXiGjGJEmNbXOQ==",
|
||||
"requires": {
|
||||
"kind-of": "6.0.2",
|
||||
"shallow-clone": "3.0.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"kind-of": {
|
||||
"version": "6.0.2",
|
||||
"resolved": "https://registry.npmjs.org/kind-of/-/kind-of-6.0.2.tgz",
|
||||
"integrity": "sha512-s5kLOcnH0XqDO+FvuaLX8DDjZ18CGFk7VygH40QoKPUQhW4e2rvM0rwUq0t8IQDOwYSeLK01U90OjzBTme2QqA=="
|
||||
}
|
||||
}
|
||||
},
|
||||
"clone-response": {
|
||||
"version": "1.0.2",
|
||||
"resolved": "https://registry.npmjs.org/clone-response/-/clone-response-1.0.2.tgz",
|
||||
|
@ -11274,6 +11290,21 @@
|
|||
"nan": "2.9.2"
|
||||
}
|
||||
},
|
||||
"shallow-clone": {
|
||||
"version": "3.0.0",
|
||||
"resolved": "https://registry.npmjs.org/shallow-clone/-/shallow-clone-3.0.0.tgz",
|
||||
"integrity": "sha512-Drg+nOI+ofeuslBf0nulyWLZhK1BZprqNvPJaiB4VvES+9gC6GG+qOVAfuO12zVSgxq9SKevcme7S3uDT6Be8w==",
|
||||
"requires": {
|
||||
"kind-of": "6.0.2"
|
||||
},
|
||||
"dependencies": {
|
||||
"kind-of": {
|
||||
"version": "6.0.2",
|
||||
"resolved": "https://registry.npmjs.org/kind-of/-/kind-of-6.0.2.tgz",
|
||||
"integrity": "sha512-s5kLOcnH0XqDO+FvuaLX8DDjZ18CGFk7VygH40QoKPUQhW4e2rvM0rwUq0t8IQDOwYSeLK01U90OjzBTme2QqA=="
|
||||
}
|
||||
}
|
||||
},
|
||||
"shallow-copy": {
|
||||
"version": "0.0.1",
|
||||
"resolved": "https://registry.npmjs.org/shallow-copy/-/shallow-copy-0.0.1.tgz",
|
||||
|
|
|
@ -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",
|
||||
|
|
Loading…
Reference in New Issue