support specifying file or folder when running tests

This commit is contained in:
Iuri Matias 2017-07-02 11:32:16 -04:00
parent ec6fc4d967
commit 263fdb6d8b
3 changed files with 34 additions and 18 deletions

View File

@ -136,14 +136,13 @@ class Cmd {
test() {
program
.command('test')
.command('test [file]')
.description('run tests')
.action(function () {
.action(function (file) {
embark.initConfig('development', {
embarkConfig: 'embark.json', interceptLogs: false
});
embark.runTests();
//shelljs.exec('mocha test');
embark.runTests(file);
});
}

View File

@ -1,24 +1,41 @@
module.exports = {
run: function() {
run: function(filepath) {
var Mocha = require('mocha'),
fs = require('fs'),
path = require('path');
var mocha = new Mocha();
var testDir = 'test/';
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)
);
});
// 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)
);
});
}
let Test = require('./test.js');

View File

@ -195,9 +195,9 @@ class Embark {
}
}
runTests() {
runTests(file) {
let RunTests = require('./core/run_tests.js');
RunTests.run();
RunTests.run(file);
}
}