@@ -6,7 +6,7 @@ import { resolve } from "node:path";
66import { browsers } from "../flags/browsers.js" ;
77import { getPlan , listBrowsers , stopWorkers } from "../browserstack/api.js" ;
88import { buildBrowserFromString } from "../browserstack/buildBrowserFromString.js" ;
9- import { run } from "../run.js" ;
9+ import { run as runTests } from "../run.js" ;
1010import readYAML from "../lib/readYAML.js" ;
1111import { createTestServer } from "../createTestServer.js" ;
1212
@@ -19,6 +19,31 @@ function parseFlags( flags ) {
1919 . map ( ( value ) => `${ key } =${ value } ` ) ) ;
2020}
2121
22+ // Get all possible combinations of flag values.
23+ // Example: { "jquery": [ "1.12.4", "3.5.1" ], "jquery-migrate": [ "dev", "min" ] }
24+ // -> [ "jquery=1.12.4&jquery-migrate=dev", "jquery=3.5.1&jquery-migrate=dev",
25+ // "jquery=1.12.4&jquery-migrate=min", "jquery=3.5.1&jquery-migrate=min" ]
26+ function parseRuns ( runs ) {
27+ const results = [ ] ;
28+
29+ function dfs ( run , keys , startIndex ) {
30+ if ( startIndex === keys . length ) {
31+ if ( run . length > 0 ) {
32+ results . push ( run . join ( "&" ) ) ;
33+ }
34+ return ;
35+ }
36+ const key = keys [ startIndex ] ;
37+ const values = runs [ key ] ;
38+ for ( const value of values ) {
39+ dfs ( run . concat ( `${ key } =${ value } ` ) , keys , startIndex + 1 ) ;
40+ }
41+ }
42+
43+ dfs ( [ ] , Object . keys ( runs ?? [ ] ) , 0 ) ;
44+ return results ;
45+ }
46+
2247async function parseMiddleware ( config , argv ) {
2348 const middleware = await Promise . all ( [
2449 ...( config . middleware ?? [ ] ) ,
@@ -41,12 +66,15 @@ yargs( process.argv.slice( 2 ) )
4166 yargs . option ( "config-file" , {
4267 alias : "c" ,
4368 type : "string" ,
69+ example : "jtr-config.yml" ,
4470 description : "Path to a YAML configuration file. " +
45- "Use this to avoid passing options via the command line."
71+ "Use this to avoid passing options via the command line. " +
72+ "jquery-test-runner will automatically search for jtr.yml or jtr.yaml."
4673 } )
4774 . option ( "base-url" , {
4875 alias : "u" ,
4976 type : "string" ,
77+ example : "/tests/" ,
5078 description : "Base URL for the test server. " +
5179 "Expected to always start and end with a slash (/). " +
5280 "Defaults to \"/test/\"."
@@ -59,15 +87,17 @@ yargs( process.argv.slice( 2 ) )
5987 } )
6088 . option ( "flag" , {
6189 alias : "f" ,
90+ example : "module=core" ,
6291 type : "array" ,
6392 description : "Add a universal flag to be added as a query parameter " +
64- "to the test URL for all test pages."
93+ "to the test URL for all test pages. e.g. --flag module=core "
6594 } )
66- . option ( "isolated-flag" , {
67- alias : "i" ,
95+ . option ( "run" , {
6896 type : "array" ,
69- description : "Add an isolated flag to be added as a query parameter " +
70- "to the test URL for each. Each isolated flag creates a new test page."
97+ example : "module=core&esmodules=true" ,
98+ description : "Reuse the same tunnel and browser by adding more runs with " +
99+ "different flags. Each run is a separate test run. These have the same " +
100+ "format as the --flag option."
71101 } )
72102 . option ( "browser" , {
73103 alias : "b" ,
@@ -80,7 +110,7 @@ yargs( process.argv.slice( 2 ) )
80110 "Defaults to Chrome."
81111 } )
82112 . option ( "middleware" , {
83- alias : "mw " ,
113+ alias : "m " ,
84114 type : "array" ,
85115 description : "Add middleware to the test server by passing " +
86116 "the path to a module that exports a middleware factory function. " +
@@ -144,27 +174,26 @@ yargs( process.argv.slice( 2 ) )
144174 } ) ;
145175 } ,
146176 handler : async ( { configFile, ...argv } ) => {
147- console . log ( "Running tests..." ) ;
148177 const config = await readYAML ( configFile ) ;
149178 const flag = [
150179 ...parseFlags ( config . flags ) ,
151180 ...( config . flag ?? [ ] ) ,
152181 ...( argv . flag ?? [ ] )
153182 ] ;
154- const isolatedFlag = [
155- ...parseFlags ( config . isolatedFlags ) ,
156- ...( config . isolatedFlag ?? [ ] ) ,
157- ...( argv . isolatedFlag ?? [ ] )
183+ const run = [
184+ ...parseRuns ( config . runs ) ,
185+ ...( config . run ?? [ ] ) ,
186+ ...( argv . run ?? [ ] )
158187 ] ;
159188 const middleware = await parseMiddleware ( config , argv ) ;
160189
161- return run ( {
190+ return runTests ( {
162191 ...config ,
163192 testUrl : config . testUrls ,
164193 ...argv ,
165194 flag,
166- isolatedFlag ,
167- middleware
195+ middleware ,
196+ run
168197 } ) ;
169198 }
170199 } )
@@ -196,7 +225,7 @@ yargs( process.argv.slice( 2 ) )
196225 description : "Whether to log requests to the console. Default: false."
197226 } )
198227 . option ( "middleware" , {
199- alias : "mw " ,
228+ alias : "m " ,
200229 type : "array" ,
201230 description : "Add middleware to the test server by passing " +
202231 "the path to a module that exports a middleware factory function. " +
@@ -218,7 +247,7 @@ yargs( process.argv.slice( 2 ) )
218247
219248 const port = argv . port ?? config . port ?? DEFAULT_PORT ;
220249 return app . listen ( { port, host : "0.0.0.0" } , function ( ) {
221- console . log ( `Open tests at http://localhost:${ port } / ` ) ;
250+ console . log ( `Open tests at http://localhost:${ port } ${ baseUrl } ` ) ;
222251 } ) ;
223252 }
224253 } )
0 commit comments