@@ -20,9 +20,8 @@ module.exports = function () {
20
20
21
21
nextTick ( function next ( ) {
22
22
var t = getNextTest ( results ) ;
23
- if ( ! t && results . running ) return ;
24
- if ( ! t ) return results . close ( ) ;
25
- t . run ( ) ;
23
+ if ( t ) t . run ( ) ;
24
+ else results . close ( ) ;
26
25
} ) ;
27
26
28
27
return output ;
@@ -34,52 +33,26 @@ function Results (stream) {
34
33
this . pass = 0 ;
35
34
this . stream = stream ;
36
35
this . tests = [ ] ;
37
- this . running = 0 ;
38
36
}
39
37
40
- Results . prototype . push = function ( t , parentT ) {
38
+ Results . prototype . push = function ( t ) {
39
+ var self = this ;
40
+ self . tests . push ( t ) ;
41
+ self . _watch ( t ) ;
42
+ t . once ( 'end' , function ( ) {
43
+ var nt = getNextTest ( self ) ;
44
+ if ( nt ) nt . run ( ) ;
45
+ else self . close ( ) ;
46
+ } ) ;
47
+ } ;
48
+
49
+ Results . prototype . _watch = function ( t ) {
41
50
var self = this ;
42
51
var write = function ( s ) { self . stream . queue ( s ) } ;
43
52
t . once ( 'prerun' , function ( ) {
44
- if ( self . only && self . only !== t . name && ! parentT ) {
45
- var nt = getNextTest ( self ) ;
46
- if ( nt ) nt . run ( )
47
- else self . close ( ) ;
48
- return ;
49
- }
50
-
51
- self . running ++ ;
52
53
write ( '# ' + t . name + '\n' ) ;
53
54
} ) ;
54
- if ( parentT ) {
55
- var ix = self . tests . indexOf ( parentT ) ;
56
- if ( ix >= 0 ) self . tests . splice ( ix , 0 , t ) ;
57
- }
58
- else self . tests . push ( t ) ;
59
-
60
- var plan ;
61
- t . on ( 'plan' , function ( n ) { plan = n } ) ;
62
-
63
- var subtests = 0 ;
64
-
65
- t . on ( 'test' , function ( st ) {
66
- subtests ++ ;
67
- st . on ( 'end' , function ( ) {
68
- subtests -- ;
69
- if ( subtests === 1 ) nextTick ( function ( ) { st . run ( ) } ) ;
70
- else if ( subtests === 0 && ! t . ended ) {
71
- t . end ( ) ;
72
- }
73
- } ) ;
74
- self . push ( st , t ) ;
75
- if ( subtests === 1 ) {
76
- if ( plan === undefined ) st . run ( ) ;
77
- else nextTick ( function ( ) {
78
- st . run ( ) ;
79
- } ) ;
80
- }
81
- } ) ;
82
-
55
+
83
56
t . on ( 'result' , function ( res ) {
84
57
if ( typeof res === 'string' ) {
85
58
write ( '# ' + res + '\n' ) ;
@@ -91,27 +64,9 @@ Results.prototype.push = function (t, parentT) {
91
64
if ( res . ok ) self . pass ++
92
65
else self . fail ++
93
66
} ) ;
94
-
95
- t . once ( 'end' , function ( ) {
96
- if ( t . _skip ) {
97
- var nt = getNextTest ( self ) ;
98
- if ( nt ) nt . run ( ) ;
99
- else self . close ( ) ;
100
- return ;
101
- }
102
-
103
- self . running -- ;
104
- if ( subtests !== 0 ) return ;
105
-
106
- if ( self . running === 0 && self . tests . length ) {
107
- var nt = getNextTest ( self ) ;
108
- if ( nt ) nt . run ( ) ;
109
- else self . close ( ) ;
110
- }
111
- else if ( self . running === 0 ) {
112
- self . close ( ) ;
113
- }
114
- } ) ;
67
+
68
+ t . on ( 'test' , function ( st ) { self . _watch ( st ) } ) ;
69
+ t . on ( 'next' , function ( st ) { st . run ( ) } ) ;
115
70
} ;
116
71
117
72
Results . prototype . close = function ( ) {
0 commit comments