@@ -119,7 +119,7 @@ if (options.watch) {
119
119
msg ( 'bin' , 'argv' , args ) ;
120
120
msg ( 'bin' , 'options' , { reporter : options . reporter . name , matcher : options . matcher } ) ;
121
121
122
- if ( args . length === 0 ) {
122
+ if ( args . length === 0 || options . watch ) {
123
123
msg ( 'bin' , 'discovering' , 'folder structure' ) ;
124
124
root = fs . readdirSync ( '.' ) ;
125
125
@@ -132,7 +132,14 @@ if (args.length === 0) {
132
132
}
133
133
msg ( 'bin' , 'discovered' , "./" + testFolder ) ;
134
134
135
- args = paths ( testFolder ) ;
135
+ if ( args . length === 0 ) {
136
+ args = paths ( testFolder ) ;
137
+
138
+ if ( options . watch ) {
139
+ args = args . concat ( paths ( 'lib' ) ,
140
+ paths ( 'src' ) ) ;
141
+ }
142
+ }
136
143
}
137
144
138
145
if ( ! options . watch ) {
@@ -171,7 +178,6 @@ if (! options.watch) {
171
178
} ) ;
172
179
} ) ;
173
180
} else {
174
- msg ( 'watcher' , 'watching files in' , process . cwd ( ) + '/' ) ;
175
181
//
176
182
// Watch mode
177
183
//
@@ -229,7 +235,7 @@ if (! options.watch) {
229
235
function cursorRestore ( ) { esc ( "0G" ) }
230
236
function cursorHide ( ) { esc ( "?25l" ) }
231
237
function cursorShow ( ) { esc ( "?25h" ) }
232
- function cleanup ( ) { eraseLine ( ) , cursorShow ( ) , print ( '\n' ) }
238
+ function cleanup ( ) { eraseLine ( ) , cursorShow ( ) , clearInterval ( timer ) , print ( '\n' ) }
233
239
234
240
//
235
241
// Called when a file has been modified.
@@ -238,10 +244,10 @@ if (! options.watch) {
238
244
function changed ( file ) {
239
245
status = { honored : 0 , broken : 0 , errored : 0 , pending : 0 } ;
240
246
241
- msg ( 'watcher' , 'detected change in' , file + '.js' ) ;
247
+ msg ( 'watcher' , 'detected change in' , file ) ;
242
248
243
- file = ( / - ( t e s t | s p e c ) $ / . test ( file ) ? path . join ( testFolder , file )
244
- : path . join ( testFolder , file + '-' + testFolder ) ) + '.js' ;
249
+ file = ( / - ( t e s t | s p e c ) \. j s $ / . test ( file ) ? path . join ( testFolder , file )
250
+ : path . join ( testFolder , file + '-' + testFolder ) ) ;
245
251
246
252
try {
247
253
fs . statSync ( file ) ;
@@ -268,16 +274,18 @@ if (! options.watch) {
268
274
} ) ;
269
275
}
270
276
277
+ msg ( 'watcher' , 'watching' , args ) ;
278
+
271
279
//
272
- // Watch all relevant files in lib/ and src/ ,
280
+ // Watch all relevant files,
273
281
// and call `changed()` on change.
274
282
//
275
- [ ] . concat ( paths ( 'lib' ) , paths ( 'src' ) , paths ( testFolder ) ) . forEach ( function ( p ) {
283
+ args . forEach ( function ( p ) {
276
284
fs . watchFile ( p , function ( current , previous ) {
277
285
if ( new ( Date ) ( current . mtime ) . valueOf ( ) ===
278
286
new ( Date ) ( previous . mtime ) . valueOf ( ) ) { return }
279
287
else {
280
- changed ( path . basename ( p , '.js' ) ) ;
288
+ changed ( p ) ;
281
289
}
282
290
} ) ;
283
291
} ) ;
@@ -298,7 +306,7 @@ function runSuites(suites, callback) {
298
306
( function run ( suites , callback ) {
299
307
var suite = suites . shift ( ) ;
300
308
if ( suite ) {
301
- msg ( 'runner' , "running" , suite . subject + ' ' , true ) ;
309
+ msg ( 'runner' , "running" , suite . subject + ' ' , options . watch ? false : true ) ;
302
310
suite . run ( options , function ( result ) {
303
311
Object . keys ( result ) . forEach ( function ( k ) {
304
312
results [ k ] += result [ k ] ;
0 commit comments