@@ -82,18 +82,36 @@ class Params {
8282 this . startDelay = 100 ;
8383 }
8484
85- for ( const paramKey of [ "tag" , "tags" , "test" , "tests" ] ) {
86- this . testList = this . _parseTestListParam ( sourceParams , paramKey ) ;
87- }
88-
89- this . testIterationCount = this . _parseIntParam ( sourceParams , "iterationCount" , 1 ) ;
90- this . testWorstCaseCount = this . _parseIntParam ( sourceParams , "worstCaseCount" , 1 ) ;
85+ this . testList = this . _parseOneOf ( sourceParams , [ "testList" , "tag" , "tags" , "test" , "tests" ] , this . _parseTestListParam ) ;
86+ this . testIterationCount = this . _parseOneOf ( sourceParams , [ "testIterationCount" , "iterationCount" , "iterations" ] , this . _parseIntParam , 1 ) ;
87+ this . testWorstCaseCount = this . _parseOneOf ( sourceParams , [ "testWorstCaseCount" , "worstCaseCount" , "worst" ] , this . _parseIntParam , 1 ) ;
9188
9289 const unused = Array . from ( sourceParams . keys ( ) ) ;
9390 if ( unused . length > 0 )
9491 console . error ( "Got unused source params" , unused ) ;
9592 }
9693
94+ _parseOneOf ( sourceParams , paramKeys , parseFunction , ...args ) {
95+ const defaultParamKey = paramKeys [ 0 ]
96+ let result = undefined ;
97+ let parsedParamKey = undefined ;
98+ for ( const paramKey of paramKeys ) {
99+ if ( ! sourceParams . has ( paramKey ) ) {
100+ continue ;
101+ }
102+ const parseResult = parseFunction . call ( this , sourceParams , paramKey , ...args ) ;
103+ if ( parsedParamKey ) {
104+ throw new Error ( `Cannot parse ${ paramKey } , overriding previous "${ parsedParamKey } " value ${ JSON . stringify ( result ) } with ${ JSON . stringify ( parseResult ) } ` )
105+ }
106+ parsedParamKey = paramKey ;
107+ result = parseResult ;
108+ }
109+ if ( ! parsedParamKey ) {
110+ return DefaultJetStreamParams [ defaultParamKey ] ;
111+ }
112+ return result ;
113+ }
114+
97115 _parseTestListParam ( sourceParams , key ) {
98116 if ( ! sourceParams . has ( key ) )
99117 return this . testList ;
@@ -108,9 +126,6 @@ class Params {
108126 }
109127 testList = testList . map ( each => each . trim ( ) ) ;
110128 sourceParams . delete ( key ) ;
111- if ( this . testList . length > 0 && testList . length > 0 ) {
112- throw new Error ( `Overriding previous testList='${ this . testList . join ( ) } ' with ${ key } url-parameter.` ) ;
113- }
114129 return testList ;
115130 }
116131
0 commit comments