@@ -6,7 +6,7 @@ import { resolve } from "node:path";
6
6
import { browsers } from "../flags/browsers.js" ;
7
7
import { getPlan , listBrowsers , stopWorkers } from "../browserstack/api.js" ;
8
8
import { buildBrowserFromString } from "../browserstack/buildBrowserFromString.js" ;
9
- import { run } from "../run.js" ;
9
+ import { run as runTests } from "../run.js" ;
10
10
import readYAML from "../lib/readYAML.js" ;
11
11
import { createTestServer } from "../createTestServer.js" ;
12
12
@@ -19,6 +19,31 @@ function parseFlags( flags ) {
19
19
. map ( ( value ) => `${ key } =${ value } ` ) ) ;
20
20
}
21
21
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
+
22
47
async function parseMiddleware ( config , argv ) {
23
48
const middleware = await Promise . all ( [
24
49
...( config . middleware ?? [ ] ) ,
@@ -41,12 +66,15 @@ yargs( process.argv.slice( 2 ) )
41
66
yargs . option ( "config-file" , {
42
67
alias : "c" ,
43
68
type : "string" ,
69
+ example : "jtr-config.yml" ,
44
70
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."
46
73
} )
47
74
. option ( "base-url" , {
48
75
alias : "u" ,
49
76
type : "string" ,
77
+ example : "/tests/" ,
50
78
description : "Base URL for the test server. " +
51
79
"Expected to always start and end with a slash (/). " +
52
80
"Defaults to \"/test/\"."
@@ -59,15 +87,17 @@ yargs( process.argv.slice( 2 ) )
59
87
} )
60
88
. option ( "flag" , {
61
89
alias : "f" ,
90
+ example : "module=core" ,
62
91
type : "array" ,
63
92
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 "
65
94
} )
66
- . option ( "isolated-flag" , {
67
- alias : "i" ,
95
+ . option ( "run" , {
68
96
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."
71
101
} )
72
102
. option ( "browser" , {
73
103
alias : "b" ,
@@ -80,7 +110,7 @@ yargs( process.argv.slice( 2 ) )
80
110
"Defaults to Chrome."
81
111
} )
82
112
. option ( "middleware" , {
83
- alias : "mw " ,
113
+ alias : "m " ,
84
114
type : "array" ,
85
115
description : "Add middleware to the test server by passing " +
86
116
"the path to a module that exports a middleware factory function. " +
@@ -144,27 +174,26 @@ yargs( process.argv.slice( 2 ) )
144
174
} ) ;
145
175
} ,
146
176
handler : async ( { configFile, ...argv } ) => {
147
- console . log ( "Running tests..." ) ;
148
177
const config = await readYAML ( configFile ) ;
149
178
const flag = [
150
179
...parseFlags ( config . flags ) ,
151
180
...( config . flag ?? [ ] ) ,
152
181
...( argv . flag ?? [ ] )
153
182
] ;
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 ?? [ ] )
158
187
] ;
159
188
const middleware = await parseMiddleware ( config , argv ) ;
160
189
161
- return run ( {
190
+ return runTests ( {
162
191
...config ,
163
192
testUrl : config . testUrls ,
164
193
...argv ,
165
194
flag,
166
- isolatedFlag ,
167
- middleware
195
+ middleware ,
196
+ run
168
197
} ) ;
169
198
}
170
199
} )
@@ -196,7 +225,7 @@ yargs( process.argv.slice( 2 ) )
196
225
description : "Whether to log requests to the console. Default: false."
197
226
} )
198
227
. option ( "middleware" , {
199
- alias : "mw " ,
228
+ alias : "m " ,
200
229
type : "array" ,
201
230
description : "Add middleware to the test server by passing " +
202
231
"the path to a module that exports a middleware factory function. " +
@@ -218,7 +247,7 @@ yargs( process.argv.slice( 2 ) )
218
247
219
248
const port = argv . port ?? config . port ?? DEFAULT_PORT ;
220
249
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 } ` ) ;
222
251
} ) ;
223
252
}
224
253
} )
0 commit comments