@@ -30,16 +30,27 @@ function Results (stream) {
30
30
this . fail = 0 ;
31
31
this . pass = 0 ;
32
32
this . stream = stream ;
33
- this . pending = 0 ;
33
+ this . tests = [ ] ;
34
34
}
35
35
36
36
Results . prototype . push = function ( t ) {
37
37
var self = this ;
38
38
var write = function ( s ) { self . stream . queue ( s ) } ;
39
- write ( '# ' + t . name + '\n' ) ;
40
- self . pending ++ ;
39
+ t . on ( 'run' , function ( ) {
40
+ write ( '# ' + t . name + '\n' ) ;
41
+ } ) ;
42
+
43
+ var plan ;
44
+ t . on ( 'plan' , function ( n ) { plan = n } ) ;
41
45
46
+ var subtests = 0 ;
42
47
t . on ( 'test' , function ( st ) {
48
+ subtests ++ ;
49
+ st . on ( 'end' , function ( ) {
50
+ nextTick ( function ( ) {
51
+ if ( -- subtests === 0 && ! plan ) t . emit ( 'end' ) ;
52
+ } ) ;
53
+ } ) ;
43
54
self . push ( st ) ;
44
55
} ) ;
45
56
@@ -57,7 +68,9 @@ Results.prototype.push = function (t) {
57
68
58
69
t . on ( 'end' , function ( ) {
59
70
nextTick ( function ( ) {
60
- if ( -- self . pending === 0 ) self . close ( ) ;
71
+ if ( subtests === 0 ) return ;
72
+ if ( self . tests . length === 0 ) self . close ( ) ;
73
+ else self . tests . shift ( ) . run ( ) ;
61
74
} ) ;
62
75
} ) ;
63
76
} ;
@@ -84,49 +97,47 @@ function encodeResult (res, count) {
84
97
else if ( res . todo ) output += ' # TODO' ;
85
98
86
99
output += '\n' ;
100
+ if ( res . ok ) return output ;
87
101
88
- if ( ! res . ok ) {
89
- var outer = ' ' ;
90
- var inner = outer + ' ' ;
91
- output += outer + '---\n' ;
92
- output += inner + 'operator: ' + res . operator + '\n' ;
93
-
94
- var ex = json . stringify ( res . expected , getSerialize ( ) ) || '' ;
95
- var ac = json . stringify ( res . actual , getSerialize ( ) ) || '' ;
96
-
97
- if ( Math . max ( ex . length , ac . length ) > 65 ) {
98
- output += inner + 'expected:\n' + inner + ' ' + ex + '\n' ;
99
- output += inner + 'actual:\n' + inner + ' ' + ac + '\n' ;
100
- }
101
- else {
102
- output += inner + 'expected: ' + ex + '\n' ;
103
- output += inner + 'actual: ' + ac + '\n' ;
104
- }
105
- if ( res . at ) {
106
- output += inner + 'at: ' + res . at + '\n' ;
107
- }
108
- if ( res . operator === 'error' && res . actual && res . actual . stack ) {
109
- var lines = String ( res . actual . stack ) . split ( '\n' ) ;
110
- output += inner + 'stack:\n' ;
111
- output += inner + ' ' + lines [ 0 ] + '\n' ;
112
- for ( var i = 1 ; i < lines . length ; i ++ ) {
113
- output += inner + lines [ i ] + '\n' ;
114
- }
102
+ var outer = ' ' ;
103
+ var inner = outer + ' ' ;
104
+ output += outer + '---\n' ;
105
+ output += inner + 'operator: ' + res . operator + '\n' ;
106
+
107
+ var ex = json . stringify ( res . expected , getSerialize ( ) ) || '' ;
108
+ var ac = json . stringify ( res . actual , getSerialize ( ) ) || '' ;
109
+
110
+ if ( Math . max ( ex . length , ac . length ) > 65 ) {
111
+ output += inner + 'expected:\n' + inner + ' ' + ex + '\n' ;
112
+ output += inner + 'actual:\n' + inner + ' ' + ac + '\n' ;
113
+ }
114
+ else {
115
+ output += inner + 'expected: ' + ex + '\n' ;
116
+ output += inner + 'actual: ' + ac + '\n' ;
117
+ }
118
+ if ( res . at ) {
119
+ output += inner + 'at: ' + res . at + '\n' ;
120
+ }
121
+ if ( res . operator === 'error' && res . actual && res . actual . stack ) {
122
+ var lines = String ( res . actual . stack ) . split ( '\n' ) ;
123
+ output += inner + 'stack:\n' ;
124
+ output += inner + ' ' + lines [ 0 ] + '\n' ;
125
+ for ( var i = 1 ; i < lines . length ; i ++ ) {
126
+ output += inner + lines [ i ] + '\n' ;
115
127
}
116
-
117
- output += outer + '...\n' ;
118
128
}
119
-
129
+
130
+ output += outer + '...\n' ;
120
131
return output ;
121
132
}
122
133
123
- function getSerialize ( ) {
134
+ function getSerialize ( ) {
124
135
var seen = [ ] ;
125
136
126
137
return function ( key , value ) {
127
138
var ret = value ;
128
139
if ( typeof value === 'object' && value ) {
129
- var found = false
140
+ var found = false ;
130
141
for ( var i = 0 ; i < seen . length ; i ++ ) {
131
142
if ( seen [ i ] === value ) {
132
143
found = true
0 commit comments