@@ -24,26 +24,24 @@ Results.prototype.createStream = function () {
2424 var self = this ;
2525 var output = resumer ( ) ;
2626 output . queue ( 'TAP version 13\n' ) ;
27-
28- nextTick ( function ( ) {
29- var t = getNextTest ( self ) ;
30- if ( t ) t . run ( )
31- else self . emit ( 'done' )
27+
28+ nextTick ( function next ( ) {
29+ var t ;
30+ while ( t = getNextTest ( self ) ) {
31+ t . run ( ) ;
32+ if ( ! t . ended ) return t . once ( 'end' , function ( ) { nextTick ( next ) ; } ) ;
33+ }
34+ self . emit ( 'done' ) ;
3235 } ) ;
3336 self . _stream . pipe ( output ) ;
34-
37+
3538 return output ;
3639} ;
3740
3841Results . prototype . push = function ( t ) {
3942 var self = this ;
4043 self . tests . push ( t ) ;
4144 self . _watch ( t ) ;
42- t . once ( 'end' , function ( ) {
43- var nt = getNextTest ( self ) ;
44- if ( nt ) nt . run ( )
45- else self . emit ( 'done' )
46- } ) ;
4745} ;
4846
4947Results . prototype . only = function ( name ) {
@@ -69,7 +67,7 @@ Results.prototype._watch = function (t) {
6967 }
7068 write ( encodeResult ( res , self . count + 1 ) ) ;
7169 self . count ++ ;
72-
70+
7371 if ( res . ok ) self . pass ++
7472 else self . fail ++
7573 } ) ;
@@ -82,35 +80,35 @@ Results.prototype.close = function () {
8280 if ( self . closed ) self . _stream . emit ( 'error' , new Error ( 'ALREADY CLOSED' ) ) ;
8381 self . closed = true ;
8482 var write = function ( s ) { self . _stream . queue ( s ) } ;
85-
83+
8684 write ( '\n1..' + self . count + '\n' ) ;
8785 write ( '# tests ' + self . count + '\n' ) ;
8886 write ( '# pass ' + self . pass + '\n' ) ;
8987 if ( self . fail ) write ( '# fail ' + self . fail + '\n' )
9088 else write ( '\n# ok\n' )
91-
89+
9290 self . _stream . queue ( null ) ;
9391} ;
9492
9593function encodeResult ( res , count ) {
9694 var output = '' ;
9795 output += ( res . ok ? 'ok ' : 'not ok ' ) + count ;
9896 output += res . name ? ' ' + res . name . toString ( ) . replace ( / \s + / g, ' ' ) : '' ;
99-
97+
10098 if ( res . skip ) output += ' # SKIP' ;
10199 else if ( res . todo ) output += ' # TODO' ;
102-
100+
103101 output += '\n' ;
104102 if ( res . ok ) return output ;
105-
103+
106104 var outer = ' ' ;
107105 var inner = outer + ' ' ;
108106 output += outer + '---\n' ;
109107 output += inner + 'operator: ' + res . operator + '\n' ;
110-
108+
111109 var ex = json . stringify ( res . expected , getSerialize ( ) ) || '' ;
112110 var ac = json . stringify ( res . actual , getSerialize ( ) ) || '' ;
113-
111+
114112 if ( Math . max ( ex . length , ac . length ) > 65 ) {
115113 output += inner + 'expected:\n' + inner + ' ' + ex + '\n' ;
116114 output += inner + 'actual:\n' + inner + ' ' + ac + '\n' ;
@@ -130,14 +128,14 @@ function encodeResult (res, count) {
130128 output += inner + lines [ i ] + '\n' ;
131129 }
132130 }
133-
131+
134132 output += outer + '...\n' ;
135133 return output ;
136134}
137135
138136function getSerialize ( ) {
139137 var seen = [ ] ;
140-
138+
141139 return function ( key , value ) {
142140 var ret = value ;
143141 if ( typeof value === 'object' && value ) {
@@ -148,7 +146,7 @@ function getSerialize () {
148146 break ;
149147 }
150148 }
151-
149+
152150 if ( found ) ret = '[Circular]'
153151 else seen . push ( value )
154152 }
0 commit comments