44// This code is governed by the BSD License found in the LICENSE file.
55
66var args = require ( 'minimist' ) ( process . argv . slice ( 2 ) , {
7- default : {
8- runner : 'node' ,
9- reporter : 'simple' ,
10- threads : 4 ,
11- } ,
127 alias : {
138 consoleCommand : 'e' ,
149 consolePrintCommand : 'p' ,
1510 runner : 'r' ,
1611 reporter : 'R' ,
1712 threads : 't' ,
18- batch : 'b'
13+ batch : 'b' ,
14+ config : 'c'
1915 }
2016} ) ;
2117
@@ -28,68 +24,58 @@ var fs = require('fs');
2824var path = require ( 'path' ) ;
2925var jss = require ( 'JSONStream' ) . stringify ( ) ;
3026var Tributary = require ( 'stream-bifurcate' )
31-
3227var scenarios = require ( '../lib/scenarios' ) ;
3328var readFile = _ . wrapCallback ( fs . readFile ) ;
3429var DEFAULT_BATCH_SIZE = 75 ;
30+ var t262 = require ( '../index' ) ;
3531
36- if ( args . config ) {
37- require ( path . join ( process . cwd ( ) , args . config ) ) ;
38- }
39-
40- var t262 = require ( '../index' )
41- console . log ( t262 . config ) ;
42-
43- console . log ( )
44-
45- var Runner = loadRunner ( ) ;
46- console . log ( Runner ) ;
32+ if ( args . config ) require ( path . join ( process . cwd ( ) , args . config ) ) ;
33+ t262 . useConfig ( args ) ;
4734
48- // default to console runner if passing console command
49- if ( args . consoleCommand && args . runner === 'node' ) {
50- args . runner = 'console' ;
51- }
35+ var Runner = t262 . loadRunner ( ) ;
5236
53- // apply default batch size
54- if ( args . batch === true ) args . batch = DEFAULT_BATCH_SIZE ;
37+ // apply defaults
38+ if ( t262 . config . batch === true ) t262 . config . batch = DEFAULT_BATCH_SIZE ;
39+ if ( ! t262 . config . threads ) t262 . config . threads = 4 ;
40+ if ( ! t262 . config . reporter ) t262 . config . reporter = 'simple' ;
5541
5642var start = Date . now ( ) ;
5743
58- var files = _ ( args . _ . map ( globStream ) ) . merge ( ) ;
44+ var files = _ ( t262 . config . _ . map ( globStream ) ) . merge ( ) ;
5945var contents = files . fork ( ) . map ( readFile ) . sequence ( ) ;
6046var tests = contents . zip ( files . fork ( ) ) . map ( function ( d ) {
6147 return parser . parseFile ( { contents : d [ 0 ] . toString ( 'utf8' ) , file : d [ 1 ] } ) ;
6248} ) ;
63- var getScenarios = scenarios ( args ) ;
49+ var getScenarios = scenarios ( t262 . config ) ;
6450var scenarios = tests . flatMap ( scenarioStream ) ;
65- if ( args . batch ) scenarios = _ ( scenarios ) . batch ( args . batch ) ;
51+ if ( t262 . config . batch ) scenarios = _ ( scenarios ) . batch ( t262 . config . batch ) ;
6652
6753var trb = scenarios . pipe ( new Tributary ( ) ) ;
6854var results = _ ( function ( push ) {
69- for ( var i = 0 ; i < args . threads ; i ++ ) push ( null , run ( trb . fork ( ) ) ) ;
55+ for ( var i = 0 ; i < t262 . config . threads ; i ++ ) push ( null , run ( trb . fork ( ) ) ) ;
7056 push ( null , _ . nil ) ;
7157} ) . merge ( ) ;
7258
7359results . on ( 'end' , function ( ) {
7460 console . log ( "Took " + ( ( Date . now ( ) - start ) / 1000 ) + " seconds" ) ;
7561} )
7662
77- if ( args . reporter === 'json' ) {
63+ if ( t262 . config . reporter === 'json' ) {
7864 results . pipe ( jss ) . pipe ( process . stdout ) ;
79- } else if ( args . reporter === 'tap' ) {
65+ } else if ( t262 . config . reporter === 'tap' ) {
8066 results . pipe ( tapify ) . pipe ( process . stdout ) ;
81- } else if ( args . reporter === 'simple' ) {
67+ } else if ( t262 . config . reporter === 'simple' ) {
8268 results . pipe ( simpleReporter ) ;
8369}
8470
8571// takes a test collateral stream.
8672// Returns test results stream.
8773function run ( tests ) {
88- var runner = new Runner ( args ) ;
74+ var runner = new Runner ( t262 . config ) ;
8975
9076 return _ ( tests ) . map ( function ( test ) {
9177 return _ ( function ( push ) {
92- if ( args . batch ) {
78+ if ( t262 . config . batch ) {
9379 runner . runBatch ( test , function ( ) {
9480 test . forEach ( function ( t ) {
9581 push ( null , t ) ;
@@ -129,15 +115,3 @@ function scenarioStream(test) {
129115 push ( null , _ . nil ) ;
130116 } )
131117}
132-
133- // Load the runner
134- function loadRunner ( ) {
135- if ( t262 . config . runner ) return t262 . config . runner ;
136-
137- try {
138- return require ( '../lib/runners/' + args . runner ) ;
139- } catch ( e ) {
140- if ( e . code === 'MODULE_NOT_FOUND' ) throw new Error ( 'Runner ' + args . runner + ' not found.' ) ;
141- throw e ;
142- }
143- }
0 commit comments