Skip to content

Commit f8eb89c

Browse files
committed
including mocha tests
1 parent 4febbcf commit f8eb89c

File tree

2 files changed

+36
-3
lines changed

2 files changed

+36
-3
lines changed

bin/test.js

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ function printHelp() {
1919
console.log('');
2020
console.log(' -f <file> Parse and test the specified file');
2121
console.log(' -d <path> Parse each file in the specified path');
22+
console.log(' -m <path> Run mocha tests on the specified path');
2223
console.log(' -r Use recursivity with the specified path');
2324
console.log(' -e Eval the specified input and shows AST');
2425
console.log(' -v Enable verbose mode and show debug');
@@ -40,7 +41,8 @@ var options = {
4041
path: null,
4142
recursive: false,
4243
evalCode: false,
43-
aspShort: false
44+
aspShort: false,
45+
mocha: false
4446
};
4547

4648
var args = process.argv.slice(2); // Trim 'node' and the script path.
@@ -87,6 +89,11 @@ while (args.length > 0 && isOption(args[0])) {
8789
options.path = args[0];
8890
break;
8991

92+
case '-m':
93+
nextArg();
94+
options.mocha = args[0];
95+
break;
96+
9097
case '-r':
9198
options.recusive = true;
9299
break;
@@ -111,7 +118,7 @@ if ( args.length > 0 ) {
111118
abort('Too many arguments.');
112119
}
113120
}
114-
if ( !options.filename && !options.path && !options.evalCode ) {
121+
if ( !options.filename && !options.path && !options.evalCode && !options.mocha ) {
115122
abort('Expecting a filename or a path.');
116123
}
117124

@@ -184,6 +191,32 @@ function test(filename) {
184191
}
185192
}
186193

194+
if (options.mocha) {
195+
var Mocha = require('mocha'), path = require('path');
196+
197+
// Instantiate a Mocha instance.
198+
var mocha = new Mocha();
199+
200+
// Add each .js file to the mocha instance
201+
fs.readdirSync(options.mocha).filter(function(file){
202+
// Only keep the .js files
203+
return file.substr(-3) === '.js';
204+
}).forEach(function(file){
205+
mocha.addFile(
206+
path.join(options.mocha, file)
207+
);
208+
});
209+
210+
// Run the tests.
211+
mocha.run(function(failures){
212+
if (failures) {
213+
process.on('exit', function () {
214+
process.exit(failures); // exit with non-zero status if there were failures
215+
});
216+
}
217+
});
218+
}
219+
187220
// run tests
188221
console.log('\n*** START TESTING ***\n');
189222
if (options.evalCode) {

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"scripts": {
77
"bench": "node --expose-gc bin/bench.js",
88
"test": "node --stack-size=5000 bin/test.js -r -d test/",
9-
"cover": "node --stack-size=5000 node_modules/istanbul/lib/cli.js cover -x \"**/bin/**\" bin/test.js -- -r -d test/ ",
9+
"cover": "node --stack-size=5000 node_modules/istanbul/lib/cli.js cover -x \"**/bin/**\" bin/test.js -- -r -d test/ -m test/functional",
1010
"mocha": "node node_modules/mocha/bin/mocha test/functional --stack-size=5000"
1111
},
1212
"repository": {

0 commit comments

Comments
 (0)