Skip to content

Commit 263fdb6

Browse files
committed
support specifying file or folder when running tests
1 parent ec6fc4d commit 263fdb6

File tree

3 files changed

+35
-19
lines changed

3 files changed

+35
-19
lines changed

lib/cmd.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -136,14 +136,13 @@ class Cmd {
136136

137137
test() {
138138
program
139-
.command('test')
139+
.command('test [file]')
140140
.description('run tests')
141-
.action(function () {
141+
.action(function (file) {
142142
embark.initConfig('development', {
143143
embarkConfig: 'embark.json', interceptLogs: false
144144
});
145-
embark.runTests();
146-
//shelljs.exec('mocha test');
145+
embark.runTests(file);
147146
});
148147
}
149148

lib/core/run_tests.js

Lines changed: 30 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,41 @@
11

22
module.exports = {
3-
run: function() {
3+
run: function(filepath) {
44
var Mocha = require('mocha'),
55
fs = require('fs'),
66
path = require('path');
77

88
var mocha = new Mocha();
99

10-
var testDir = 'test/';
11-
12-
// Add each .js file to the mocha instance
13-
fs.readdirSync(testDir).filter(function(file){
14-
// Only keep the .js files
15-
// TODO: make this a configuration in embark.json
16-
return file.substr(-3) === '.js';
17-
}).forEach(function(file){
18-
mocha.addFile(
19-
path.join(testDir, file)
20-
);
21-
});
10+
if (filepath) {
11+
if (filepath.substr(-1) === '/') {
12+
// Add each .js file to the mocha instance
13+
fs.readdirSync(filepath).filter(function(file){
14+
// Only keep the .js files
15+
// TODO: make this a configuration in embark.json
16+
return file.substr(-3) === '.js';
17+
}).forEach(function(file){
18+
mocha.addFile(
19+
path.join(filepath, file)
20+
);
21+
});
22+
} else {
23+
mocha.addFile(filepath);
24+
}
25+
} else {
26+
var testDir = 'test/';
27+
28+
// Add each .js file to the mocha instance
29+
fs.readdirSync(testDir).filter(function(file){
30+
// Only keep the .js files
31+
// TODO: make this a configuration in embark.json
32+
return file.substr(-3) === '.js';
33+
}).forEach(function(file){
34+
mocha.addFile(
35+
path.join(testDir, file)
36+
);
37+
});
38+
}
2239

2340
let Test = require('./test.js');
2441

lib/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -195,9 +195,9 @@ class Embark {
195195
}
196196
}
197197

198-
runTests() {
198+
runTests(file) {
199199
let RunTests = require('./core/run_tests.js');
200-
RunTests.run();
200+
RunTests.run(file);
201201
}
202202

203203
}

0 commit comments

Comments
 (0)