@@ -192,11 +192,7 @@ Api.prototype.run = function (files) {
192192 self . fileCount = files . length ;
193193 self . base = path . relative ( '.' , commonPathPrefix ( files ) ) + path . sep ;
194194
195- var tests = files . map ( self . _runFile ) ;
196-
197- // receive test count from all files and then run the tests
198- var unreportedFiles = self . fileCount ;
199-
195+ var tests = new Array ( self . fileCount ) ;
200196 return new Promise ( function ( resolve ) {
201197 function run ( ) {
202198 if ( self . options . match . length > 0 && ! self . hasExclusive ) {
@@ -205,10 +201,6 @@ Api.prototype.run = function (files) {
205201 file : undefined
206202 } ) ;
207203
208- tests . forEach ( function ( test ) {
209- // No tests will be run so tear down the child processes.
210- test . send ( 'teardown' ) ;
211- } ) ;
212204 resolve ( [ ] ) ;
213205 return ;
214206 }
@@ -238,20 +230,44 @@ Api.prototype.run = function (files) {
238230 } ) ) ;
239231 }
240232
241- tests . forEach ( function ( test ) {
233+ // receive test count from all files and then run the tests
234+ var unreportedFiles = self . fileCount ;
235+ var bailed = false ;
236+ files . every ( function ( file , index ) {
242237 var tried = false ;
243238 function tryRun ( ) {
244- if ( ! tried ) {
239+ if ( ! tried && ! bailed ) {
245240 unreportedFiles -- ;
246241 if ( unreportedFiles === 0 ) {
247242 run ( ) ;
248243 }
249244 }
250245 }
251246
252- test . on ( 'stats' , tryRun ) ;
253- test . catch ( tryRun ) ;
247+ try {
248+ var test = tests [ index ] = self . _runFile ( file ) ;
249+ test . on ( 'stats' , tryRun ) ;
250+ test . catch ( tryRun ) ;
251+ return true ;
252+ } catch ( err ) {
253+ bailed = true ;
254+ self . _handleExceptions ( {
255+ exception : err ,
256+ file : file
257+ } ) ;
258+ resolve ( [ ] ) ;
259+ return false ;
260+ }
254261 } ) ;
262+ } ) . then ( function ( results ) {
263+ if ( results . length === 0 ) {
264+ // No tests ran, make sure to tear down the child processes.
265+ tests . forEach ( function ( test ) {
266+ test . send ( 'teardown' ) ;
267+ } ) ;
268+ }
269+
270+ return results ;
255271 } ) ;
256272 } )
257273 . then ( function ( results ) {
0 commit comments