@@ -20,10 +20,43 @@ function Results () {
20
20
this . tests = [ ] ;
21
21
}
22
22
23
- Results . prototype . createStream = function ( ) {
23
+ Results . prototype . createStream = function ( opts ) {
24
+ if ( ! opts ) opts = { } ;
24
25
var self = this ;
25
- var output = resumer ( ) ;
26
- output . queue ( 'TAP version 13\n' ) ;
26
+ var output , testId = 0 ;
27
+ if ( opts . objectMode ) {
28
+ output = through ( ) ;
29
+ self . on ( '_push' , function ontest ( t , extra ) {
30
+ if ( ! extra ) extra = { } ;
31
+ var id = testId ++ ;
32
+ var row = {
33
+ type : 'test' ,
34
+ name : t . name ,
35
+ id : id
36
+ } ;
37
+ if ( extra . parent ) {
38
+ row . parent = extra . parent ;
39
+ }
40
+ output . queue ( row ) ;
41
+ t . on ( 'test' , function ( st ) {
42
+ ontest ( st , { parent : id } ) ;
43
+ } ) ;
44
+ t . on ( 'result' , function ( res ) {
45
+ res . test = id ;
46
+ res . type = 'assert' ;
47
+ output . queue ( res ) ;
48
+ } ) ;
49
+ t . on ( 'end' , function ( ) {
50
+ output . queue ( { type : 'end' , test : id } ) ;
51
+ } ) ;
52
+ } ) ;
53
+ self . on ( 'done' , function ( ) { output . queue ( null ) } ) ;
54
+ }
55
+ else {
56
+ output = resumer ( ) ;
57
+ output . queue ( 'TAP version 13\n' ) ;
58
+ self . _stream . pipe ( output ) ;
59
+ }
27
60
28
61
nextTick ( function next ( ) {
29
62
var t ;
@@ -33,7 +66,6 @@ Results.prototype.createStream = function () {
33
66
}
34
67
self . emit ( 'done' ) ;
35
68
} ) ;
36
- self . _stream . pipe ( output ) ;
37
69
38
70
return output ;
39
71
} ;
@@ -42,6 +74,7 @@ Results.prototype.push = function (t) {
42
74
var self = this ;
43
75
self . tests . push ( t ) ;
44
76
self . _watch ( t ) ;
77
+ self . emit ( '_push' , t ) ;
45
78
} ;
46
79
47
80
Results . prototype . only = function ( name ) {
@@ -154,7 +187,7 @@ function getSerialize () {
154
187
} ;
155
188
}
156
189
157
- function getNextTest ( results ) {
190
+ function getNextTest ( results ) {
158
191
if ( ! results . _only ) {
159
192
return results . tests . shift ( ) ;
160
193
}
0 commit comments