@@ -39,6 +39,21 @@ var getTestArgs = function (name_, opts_, cb_) {
3939 return { name : name , opts : opts , cb : cb } ;
4040} ;
4141
42+ var runProgeny = function ( ) {
43+ var self = this ;
44+ if ( this . _progeny . length ) {
45+ var t = this . _progeny . shift ( ) ;
46+ t . on ( 'end' , function ( ) { runProgeny . call ( self ) } ) ;
47+ nextTick ( function ( ) {
48+ t . run ( ) ;
49+ } ) ;
50+ return ;
51+ }
52+ if ( this . calledEnd || this . _plan ) {
53+ this . _end ( ) ;
54+ }
55+ } ;
56+
4257function Test ( name_ , opts_ , cb_ ) {
4358 if ( ! ( this instanceof Test ) ) {
4459 return new Test ( name_ , opts_ , cb_ ) ;
@@ -107,7 +122,7 @@ Test.prototype.test = function (name, opts, cb) {
107122 } ) ;
108123
109124 if ( ! this . _pendingAsserts ( ) ) {
110- this . _runProgeny ( ) ;
125+ runProgeny . call ( this ) ;
111126 }
112127} ;
113128
@@ -123,14 +138,14 @@ Test.prototype.plan = function (n) {
123138 this . emit ( 'plan' , n ) ;
124139} ;
125140
126- Test . prototype . timeoutAfter = function ( ms ) {
141+ Test . prototype . timeoutAfter = function ( ms ) {
127142 if ( ! ms ) throw new Error ( 'timeoutAfter requires a timespan' ) ;
128143 var self = this ;
129- var timeout = safeSetTimeout ( function ( ) {
144+ var timeout = safeSetTimeout ( function ( ) {
130145 self . fail ( 'test timed out after ' + ms + 'ms' ) ;
131146 self . end ( ) ;
132147 } , ms ) ;
133- this . once ( 'end' , function ( ) {
148+ this . once ( 'end' , function ( ) {
134149 safeClearTimeout ( timeout ) ;
135150 } ) ;
136151}
@@ -144,7 +159,7 @@ Test.prototype.end = function (err) {
144159 this . fail ( '.end() called twice' ) ;
145160 }
146161 this . calledEnd = true ;
147- this . _runProgeny ( ) ;
162+ runProgeny . call ( this ) ;
148163} ;
149164
150165Test . prototype . _end = function ( err ) {
@@ -160,21 +175,6 @@ Test.prototype._end = function (err) {
160175 this . ended = true ;
161176} ;
162177
163- Test . prototype . _runProgeny = function ( ) {
164- var self = this ;
165- if ( this . _progeny . length ) {
166- var t = this . _progeny . shift ( ) ;
167- t . on ( 'end' , function ( ) { self . _runProgeny ( ) } ) ;
168- nextTick ( function ( ) {
169- t . run ( ) ;
170- } ) ;
171- return ;
172- }
173- if ( this . calledEnd || this . _plan ) {
174- this . _end ( ) ;
175- }
176- } ;
177-
178178Test . prototype . _exit = function ( ) {
179179 if ( this . _plan !== undefined &&
180180 ! this . _planError && this . assertCount !== this . _plan ) {
@@ -296,7 +296,7 @@ Test.prototype._assert = function assert (ok, opts) {
296296 if ( extra . exiting ) {
297297 self . _end ( ) ;
298298 } else {
299- self . _runProgeny ( ) ;
299+ runProgeny . call ( self ) ;
300300 }
301301 }
302302
0 commit comments