2018-01-12 23:36:29 +00:00
|
|
|
var utils = require('../utils/utils.js');
|
2017-07-02 04:27:14 +00:00
|
|
|
|
|
|
|
module.exports = {
|
2017-07-02 15:32:16 +00:00
|
|
|
run: function(filepath) {
|
2017-07-02 04:27:14 +00:00
|
|
|
var Mocha = require('mocha'),
|
|
|
|
fs = require('fs'),
|
|
|
|
path = require('path');
|
|
|
|
|
|
|
|
var mocha = new Mocha();
|
|
|
|
|
2017-07-02 15:32:16 +00:00
|
|
|
if (filepath) {
|
|
|
|
if (filepath.substr(-1) === '/') {
|
|
|
|
// Add each .js file to the mocha instance
|
|
|
|
fs.readdirSync(filepath).filter(function(file){
|
|
|
|
// Only keep the .js files
|
|
|
|
// TODO: make this a configuration in embark.json
|
|
|
|
return file.substr(-3) === '.js';
|
|
|
|
}).forEach(function(file){
|
|
|
|
mocha.addFile(
|
|
|
|
path.join(filepath, file)
|
|
|
|
);
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
mocha.addFile(filepath);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
var testDir = 'test/';
|
|
|
|
|
|
|
|
// Add each .js file to the mocha instance
|
|
|
|
fs.readdirSync(testDir).filter(function(file){
|
|
|
|
// Only keep the .js files
|
|
|
|
// TODO: make this a configuration in embark.json
|
|
|
|
return file.substr(-3) === '.js';
|
|
|
|
}).forEach(function(file){
|
|
|
|
mocha.addFile(
|
|
|
|
path.join(testDir, file)
|
|
|
|
);
|
|
|
|
});
|
|
|
|
}
|
2017-07-02 04:27:14 +00:00
|
|
|
|
|
|
|
let Test = require('./test.js');
|
|
|
|
|
|
|
|
global.assert = require('assert');
|
|
|
|
|
2018-01-12 23:36:29 +00:00
|
|
|
let configOptions = {
|
|
|
|
gasPrice: 1
|
|
|
|
};
|
2017-12-22 18:07:43 +00:00
|
|
|
global.config = function(config) {
|
2018-01-12 23:36:29 +00:00
|
|
|
configOptions = utils.recursiveMerge(configOptions, config);
|
2017-12-22 18:07:43 +00:00
|
|
|
};
|
2017-07-02 04:27:14 +00:00
|
|
|
// TODO: check how to pass the options
|
|
|
|
//global.EmbarkSpec = new Test(options);
|
|
|
|
global.EmbarkSpec = new Test({});
|
|
|
|
global.web3 = global.EmbarkSpec.web3;
|
|
|
|
|
2017-07-03 22:15:43 +00:00
|
|
|
global.contract = function(describeName, callback) {
|
|
|
|
return Mocha.describe(describeName, callback);
|
|
|
|
};
|
|
|
|
|
2017-07-02 04:27:14 +00:00
|
|
|
// Run the tests.
|
|
|
|
let runner = mocha.run(function(failures){
|
|
|
|
process.on('exit', function () {
|
|
|
|
process.exit(failures); // exit with non-zero status if there were failures
|
|
|
|
});
|
|
|
|
process.exit();
|
|
|
|
});
|
|
|
|
|
|
|
|
runner.on('suite', function() {
|
|
|
|
global.assert = require('assert');
|
2017-12-22 18:07:43 +00:00
|
|
|
global.EmbarkSpec = new Test({simulatorOptions: configOptions});
|
2017-07-02 04:27:14 +00:00
|
|
|
global.web3 = global.EmbarkSpec.web3;
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
2017-07-02 22:03:14 +00:00
|
|
|
};
|