@@ -17,13 +17,80 @@ var yamlIndicators = /:|-|\?/;
17
17
var nextTick = typeof setImmediate !== 'undefined'
18
18
? setImmediate
19
19
: process . nextTick ;
20
- module . exports = Results ;
21
- inherits ( Results , EventEmitter ) ;
22
20
23
21
function coalesceWhiteSpaces ( str ) {
24
22
return $replace ( String ( str ) , / \s + / g, ' ' ) ;
25
23
}
26
24
25
+ function getNextTest ( results ) {
26
+ if ( ! results . _only ) {
27
+ return $shift ( results . tests ) ;
28
+ }
29
+
30
+ do {
31
+ var t = $shift ( results . tests ) ;
32
+ if ( t && results . _only === t ) {
33
+ return t ;
34
+ }
35
+ } while ( results . tests . length !== 0 ) ;
36
+
37
+ return void undefined ;
38
+ }
39
+
40
+ function invalidYaml ( str ) {
41
+ return $exec ( yamlIndicators , str ) !== null ;
42
+ }
43
+
44
+ function encodeResult ( res , count ) {
45
+ var output = '' ;
46
+ output += ( res . ok ? 'ok ' : 'not ok ' ) + count ;
47
+ output += res . name ? ' ' + coalesceWhiteSpaces ( res . name ) : '' ;
48
+
49
+ if ( res . skip ) {
50
+ output += ' # SKIP' + ( typeof res . skip === 'string' ? ' ' + coalesceWhiteSpaces ( res . skip ) : '' ) ;
51
+ } else if ( res . todo ) {
52
+ output += ' # TODO' + ( typeof res . todo === 'string' ? ' ' + coalesceWhiteSpaces ( res . todo ) : '' ) ;
53
+ }
54
+
55
+ output += '\n' ;
56
+ if ( res . ok ) { return output ; }
57
+
58
+ var outer = ' ' ;
59
+ var inner = outer + ' ' ;
60
+ output += outer + '---\n' ;
61
+ output += inner + 'operator: ' + res . operator + '\n' ;
62
+
63
+ if ( has ( res , 'expected' ) || has ( res , 'actual' ) ) {
64
+ var ex = inspect ( res . expected , { depth : res . objectPrintDepth } ) ;
65
+ var ac = inspect ( res . actual , { depth : res . objectPrintDepth } ) ;
66
+
67
+ if ( Math . max ( ex . length , ac . length ) > 65 || invalidYaml ( ex ) || invalidYaml ( ac ) ) {
68
+ output += inner + 'expected: |-\n' + inner + ' ' + ex + '\n' ;
69
+ output += inner + 'actual: |-\n' + inner + ' ' + ac + '\n' ;
70
+ } else {
71
+ output += inner + 'expected: ' + ex + '\n' ;
72
+ output += inner + 'actual: ' + ac + '\n' ;
73
+ }
74
+ }
75
+ if ( res . at ) {
76
+ output += inner + 'at: ' + res . at + '\n' ;
77
+ }
78
+
79
+ var actualStack = res . actual && ( typeof res . actual === 'object' || typeof res . actual === 'function' ) ? res . actual . stack : undefined ;
80
+ var errorStack = res . error && res . error . stack ;
81
+ var stack = defined ( actualStack , errorStack ) ;
82
+ if ( stack ) {
83
+ var lines = $split ( String ( stack ) , '\n' ) ;
84
+ output += inner + 'stack: |-\n' ;
85
+ for ( var i = 0 ; i < lines . length ; i ++ ) {
86
+ output += inner + ' ' + lines [ i ] + '\n' ;
87
+ }
88
+ }
89
+
90
+ output += outer + '...\n' ;
91
+ return output ;
92
+ }
93
+
27
94
function Results ( ) {
28
95
if ( ! ( this instanceof Results ) ) { return new Results ( ) ; }
29
96
this . count = 0 ;
@@ -36,6 +103,8 @@ function Results() {
36
103
this . _isRunning = false ;
37
104
}
38
105
106
+ inherits ( Results , EventEmitter ) ;
107
+
39
108
Results . prototype . createStream = function ( opts ) {
40
109
if ( ! opts ) { opts = { } ; }
41
110
var self = this ;
@@ -160,71 +229,4 @@ Results.prototype.close = function () {
160
229
self . _stream . queue ( null ) ;
161
230
} ;
162
231
163
- function encodeResult ( res , count ) {
164
- var output = '' ;
165
- output += ( res . ok ? 'ok ' : 'not ok ' ) + count ;
166
- output += res . name ? ' ' + coalesceWhiteSpaces ( res . name ) : '' ;
167
-
168
- if ( res . skip ) {
169
- output += ' # SKIP' + ( typeof res . skip === 'string' ? ' ' + coalesceWhiteSpaces ( res . skip ) : '' ) ;
170
- } else if ( res . todo ) {
171
- output += ' # TODO' + ( typeof res . todo === 'string' ? ' ' + coalesceWhiteSpaces ( res . todo ) : '' ) ;
172
- }
173
-
174
- output += '\n' ;
175
- if ( res . ok ) { return output ; }
176
-
177
- var outer = ' ' ;
178
- var inner = outer + ' ' ;
179
- output += outer + '---\n' ;
180
- output += inner + 'operator: ' + res . operator + '\n' ;
181
-
182
- if ( has ( res , 'expected' ) || has ( res , 'actual' ) ) {
183
- var ex = inspect ( res . expected , { depth : res . objectPrintDepth } ) ;
184
- var ac = inspect ( res . actual , { depth : res . objectPrintDepth } ) ;
185
-
186
- if ( Math . max ( ex . length , ac . length ) > 65 || invalidYaml ( ex ) || invalidYaml ( ac ) ) {
187
- output += inner + 'expected: |-\n' + inner + ' ' + ex + '\n' ;
188
- output += inner + 'actual: |-\n' + inner + ' ' + ac + '\n' ;
189
- } else {
190
- output += inner + 'expected: ' + ex + '\n' ;
191
- output += inner + 'actual: ' + ac + '\n' ;
192
- }
193
- }
194
- if ( res . at ) {
195
- output += inner + 'at: ' + res . at + '\n' ;
196
- }
197
-
198
- var actualStack = res . actual && ( typeof res . actual === 'object' || typeof res . actual === 'function' ) ? res . actual . stack : undefined ;
199
- var errorStack = res . error && res . error . stack ;
200
- var stack = defined ( actualStack , errorStack ) ;
201
- if ( stack ) {
202
- var lines = $split ( String ( stack ) , '\n' ) ;
203
- output += inner + 'stack: |-\n' ;
204
- for ( var i = 0 ; i < lines . length ; i ++ ) {
205
- output += inner + ' ' + lines [ i ] + '\n' ;
206
- }
207
- }
208
-
209
- output += outer + '...\n' ;
210
- return output ;
211
- }
212
-
213
- function getNextTest ( results ) {
214
- if ( ! results . _only ) {
215
- return $shift ( results . tests ) ;
216
- }
217
-
218
- do {
219
- var t = $shift ( results . tests ) ;
220
- if ( t && results . _only === t ) {
221
- return t ;
222
- }
223
- } while ( results . tests . length !== 0 ) ;
224
-
225
- return void undefined ;
226
- }
227
-
228
- function invalidYaml ( str ) {
229
- return $exec ( yamlIndicators , str ) !== null ;
230
- }
232
+ module . exports = Results ;
0 commit comments