@@ -5,38 +5,8 @@ var nodeunit = require('nodeunit'),
5
5
path = require ( 'path' ) ,
6
6
AssertionError = require ( 'assert' ) . AssertionError ;
7
7
8
- var optimist = require ( 'optimist' )
9
- . usage ( 'Run the jsdom test suite' )
10
- . alias ( 's' , 'suites' )
11
- . string ( 's' )
12
- . describe ( 's' , 'suites that you want to run. ie: -s level1/core,1/html,html' )
13
- . alias ( 'f' , 'fail-fast' )
14
- . describe ( 'f' , 'stop on the first failed test' )
15
- . alias ( 'h' , 'help' )
16
- . describe ( 'h' , 'show the help' )
17
- . alias ( 't' , 'tests' )
18
- . describe ( 't' , 'choose the test cases to run. ie: -t jquery' )
19
- . alias ( 'd' , 'debug' )
20
- . describe ( 'd' , 'run in node\'s interactive debugger mode' )
21
- . alias ( 'p' , 'parser' )
22
- . describe ( 'p' , 'the HTML parser to use (e.g. html5); default is htmlparser' )
23
- . alias ( 'v' , 'verbose' )
24
- . describe ( 'v' , 'show all tests that are being run' ) ;
8
+ var argv = require ( './runner-options' ) ;
25
9
26
- var argv = optimist . argv ;
27
- if ( argv . help ) {
28
- optimist . showHelp ( ) ;
29
- process . exit ( ) ;
30
- }
31
-
32
-
33
- var totalTests = 0 ;
34
- var failedTests = 0 ;
35
- var passedTests = 0 ;
36
- var modules = { } ;
37
- var currentModule = "" ;
38
- var moduleIndex = 0 ;
39
- var start = new Date ( ) . getTime ( ) ;
40
10
var fileFilter = [ ] ;
41
11
var testFilter = [ ] ;
42
12
@@ -51,28 +21,6 @@ if (argv.tests) {
51
21
testFilter = argv . tests . replace ( / \s / g, '' ) . split ( ',' ) ;
52
22
}
53
23
54
- var assert = require ( 'nodeunit/lib/assert' ) ;
55
- require ( 'nodeunit/lib/assert' ) . equal = function equal ( actual , expected , message ) {
56
- if ( actual != expected ) {
57
- if ( actual && actual . nodeType ) {
58
- actual = actual . toString ( ) ;
59
- }
60
-
61
- if ( expected && expected . nodeType ) {
62
- expected = expected . toString ( ) ;
63
- }
64
-
65
- assert . fail ( actual , expected , message , '==' , assert . equal ) ;
66
- }
67
- } ;
68
-
69
- assert . domSame = function ( actual , expected , message ) {
70
- if ( expected != actual ) {
71
- assert . equal ( expected . nodeType , actual . nodeType ) ;
72
- assert . equal ( expected . nodeValue , actual . nodeValue ) ;
73
- }
74
- } ;
75
-
76
24
var files = [
77
25
"level1/core.js" ,
78
26
"level1/html.js" ,
@@ -155,148 +103,5 @@ if (argv.parser) {
155
103
browser . setDefaultParser ( argv . parser ) ;
156
104
}
157
105
158
- nodeunit . runModules ( modulesToRun , {
159
- moduleStart : function ( name ) {
160
- currentModule = name . replace ( '.js' , '' ) ;
161
- console . log ( "running" , name , currentModule ) ;
162
- modules [ currentModule ] = {
163
- total : 0 ,
164
- fail : 0 ,
165
- pass : 0
166
- } ;
167
- moduleIndex ++ ;
168
- } ,
169
- moduleDone : function ( name , assertions ) {
170
- if ( argv [ 'verbose' ] ) {
171
- console . log ( ' ' ) ;
172
- }
173
- } ,
174
- testStart : function ( test ) {
175
- modules [ currentModule ] . total ++ ;
176
- if ( argv [ 'verbose' ] ) {
177
- process . stdout . write ( ' ' + test [ 0 ] + ' ...' ) ;
178
- }
179
- } ,
180
- testDone : function ( test , assertions ) {
181
- if ( argv [ 'verbose' ] ) {
182
- console . log ( ' done' ) ;
183
- }
184
- totalTests ++ ;
185
- if ( ! assertions . failures ( ) ) {
186
- passedTests ++ ;
187
- modules [ currentModule ] . pass ++ ;
188
- }
189
- else {
190
- failedTests ++ ;
191
- modules [ currentModule ] . fail ++ ;
192
-
193
- console . log ( '✖ ' + currentModule + '/' + test ) ;
194
- assertions . forEach ( function ( a ) {
195
- if ( a . failed ( ) ) {
196
- if ( a . error instanceof AssertionError ) {
197
- a = nodeunit . utils . betterErrors ( a ) ;
198
- if ( a . message ) {
199
- console . log (
200
- 'Assertion Message: ' + assertion_message ( a . message ) + '\n' +
201
- 'expected:' , a . error . expected , 'got:' , a . error . actual
202
- ) ;
203
- }
204
- } else {
205
- if ( a . error . expected || a . error . actual ) {
206
- console . log ( '\nERROR' , a . error . expected , 'vs' , a . error . actual , '\n' ) ;
207
- }
208
-
209
- console . log ( a . error . message , a . error . stack , ( new Error ( ) ) . stack ) ;
210
- }
211
- } else {
212
- console . log ( a . message ) ;
213
- }
214
- } ) ;
215
-
216
- if ( argv [ 'fail-fast' ] ) {
217
- process . exit ( ) ;
218
- }
219
- }
220
- } ,
221
- done : function ( assertions ) {
222
- var end = new Date ( ) . getTime ( ) ;
223
- var duration = end - start ;
224
- var maxWidths = {
225
- name : 0 ,
226
- ratio : 0 ,
227
- percent : 4
228
- } ;
229
- var width = 0 ;
230
- var keys = Object . keys ( modules ) ;
231
-
232
- var calculateMax = function ( name , value ) {
233
- if ( ! maxWidths [ name ] || value . length > maxWidths [ name ] ) {
234
- maxWidths [ name ] = value . length ;
235
- }
236
-
237
- width = 2 ;
238
- Object . keys ( maxWidths ) . forEach ( function ( v ) {
239
- width += maxWidths [ v ] + 2 ;
240
- } ) ;
241
- }
242
-
243
- var pad = function ( name , value , rightJustified ) {
244
- var ret = '' ;
245
- var padding = '' ;
246
-
247
- var amount = maxWidths [ name ] - value . length ;
248
- while ( amount -- ) {
249
- padding += " " ;
250
- }
251
-
252
- if ( rightJustified ) {
253
- return ' ' + padding + value + ' ' ;
254
- } else {
255
- return ' ' + value + padding + ' ' ;
256
- }
257
- }
258
-
259
- // First pass, calculate the max widths
260
- keys . forEach ( function ( v ) {
261
- var module = modules [ v ] ;
262
- var ratio = module . pass + '/' + module . total ;
263
- var percentage = Math . floor ( ( module . pass / module . total ) * 100 ) + '%' ;
264
- modules [ v ] . ratio = ratio ;
265
- modules [ v ] . percentage = percentage ;
266
- calculateMax ( 'name' , v ) ;
267
- calculateMax ( 'ratio' , ratio ) ;
268
- calculateMax ( 'percentage' , percentage ) ;
269
- } ) ;
270
-
271
- var caps = '' ;
272
- var gen = width ;
273
-
274
- while ( gen -- ) {
275
- caps += '-' ;
276
- }
277
-
278
- console . log ( '' ) ;
279
- Object . keys ( modules ) . forEach ( function ( v ) {
280
- var module = modules [ v ] ;
281
- process . stdout . write ( pad ( 'name' , v , false ) ) ;
282
- process . stdout . write ( pad ( 'ratio' , module . ratio , true ) ) ;
283
- process . stdout . write ( pad ( 'percentage' , module . percentage , true ) ) ;
284
- process . stdout . write ( '\n' ) ;
285
- } ) ;
286
- console . log ( caps ) ;
287
- var ratio = failedTests + '/' + totalTests ;
288
- var percent = 0 ;
289
- if ( totalTests === 0 ) {
290
- percent = '100%' ;
291
- } else {
292
- percent = Math . floor ( ( passedTests / totalTests ) * 100 ) + '%' ;
293
- }
294
- console . log ( 'TOTALS: %s failed; %s success' , ratio , percent ) ;
295
- console . log ( 'TIME: %dms' , duration ) ;
296
-
297
- if ( passedTests !== totalTests ) {
298
- process . exit ( 1 ) ;
299
- }
300
-
301
- }
302
- } ) ;
106
+ var runner = require ( './runner-core' ) ( modulesToRun ) ;
107
+ require ( './runner-display' ) ( runner , argv ) ;
0 commit comments