@@ -19,6 +19,7 @@ function printHelp() {
19
19
console . log ( '' ) ;
20
20
console . log ( ' -f <file> Parse and test the specified file' ) ;
21
21
console . log ( ' -d <path> Parse each file in the specified path' ) ;
22
+ console . log ( ' -m <path> Run mocha tests on the specified path' ) ;
22
23
console . log ( ' -r Use recursivity with the specified path' ) ;
23
24
console . log ( ' -e Eval the specified input and shows AST' ) ;
24
25
console . log ( ' -v Enable verbose mode and show debug' ) ;
@@ -40,7 +41,8 @@ var options = {
40
41
path : null ,
41
42
recursive : false ,
42
43
evalCode : false ,
43
- aspShort : false
44
+ aspShort : false ,
45
+ mocha : false
44
46
} ;
45
47
46
48
var args = process . argv . slice ( 2 ) ; // Trim 'node' and the script path.
@@ -87,6 +89,11 @@ while (args.length > 0 && isOption(args[0])) {
87
89
options . path = args [ 0 ] ;
88
90
break ;
89
91
92
+ case '-m' :
93
+ nextArg ( ) ;
94
+ options . mocha = args [ 0 ] ;
95
+ break ;
96
+
90
97
case '-r' :
91
98
options . recusive = true ;
92
99
break ;
@@ -111,7 +118,7 @@ if ( args.length > 0 ) {
111
118
abort ( 'Too many arguments.' ) ;
112
119
}
113
120
}
114
- if ( ! options . filename && ! options . path && ! options . evalCode ) {
121
+ if ( ! options . filename && ! options . path && ! options . evalCode && ! options . mocha ) {
115
122
abort ( 'Expecting a filename or a path.' ) ;
116
123
}
117
124
@@ -184,6 +191,32 @@ function test(filename) {
184
191
}
185
192
}
186
193
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
+
187
220
// run tests
188
221
console . log ( '\n*** START TESTING ***\n' ) ;
189
222
if ( options . evalCode ) {
0 commit comments