@@ -16,9 +16,8 @@ module.exports = function (test) {
16
16
17
17
nextTick ( function next ( ) {
18
18
var t = results . tests . shift ( ) ;
19
- if ( ! t && results . subtests ) return ;
19
+ if ( ! t && results . running ) return ;
20
20
if ( ! t ) return results . close ( ) ;
21
- t . on ( 'end' , next ) ;
22
21
t . run ( ) ;
23
22
} ) ;
24
23
@@ -31,13 +30,14 @@ function Results (stream) {
31
30
this . pass = 0 ;
32
31
this . stream = stream ;
33
32
this . tests = [ ] ;
34
- this . subtests = 0 ;
33
+ this . running = 0 ;
35
34
}
36
35
37
36
Results . prototype . push = function ( t , parentT ) {
38
37
var self = this ;
39
38
var write = function ( s ) { self . stream . queue ( s ) } ;
40
39
t . on ( 'prerun' , function ( ) {
40
+ self . running ++ ;
41
41
write ( '# ' + t . name + '\n' ) ;
42
42
} ) ;
43
43
if ( parentT ) {
@@ -52,10 +52,9 @@ Results.prototype.push = function (t, parentT) {
52
52
var subtests = 0 ;
53
53
t . on ( 'test' , function ( st ) {
54
54
subtests ++ ;
55
- self . subtests ++ ;
56
55
st . on ( 'end' , function ( ) {
56
+ self . running -- ;
57
57
subtests -- ;
58
- self . subtests -- ;
59
58
if ( subtests === 0 && ! plan ) t . emit ( 'end' ) ;
60
59
nextTick ( function ( ) { onend . call ( t ) } ) ;
61
60
} ) ;
@@ -79,16 +78,14 @@ Results.prototype.push = function (t, parentT) {
79
78
function onend ( ) {
80
79
if ( this . ended ) return ;
81
80
if ( subtests !== 0 ) return ;
82
- if ( ! plan && self . tests . length === 0 ) {
83
- nextTick ( function ( ) {
84
- if ( ! plan && self . tests . length === 0 ) {
85
- self . close ( ) ;
86
- }
87
- } ) ;
81
+ self . running -- ;
82
+
83
+ if ( ! self . running && self . tests . length === 0 ) {
84
+ self . close ( ) ;
88
85
}
89
- else if ( ! plan && self . tests . length ) {
86
+ else if ( ! self . running ) {
90
87
var t = self . tests . shift ( ) ;
91
- nextTick ( function ( ) { t . run ( ) } ) ;
88
+ t . run ( ) ;
92
89
}
93
90
}
94
91
} ;
0 commit comments