@@ -10,6 +10,7 @@ import { run } from "../run.js";
1010import readYAML from "../lib/readYAML.js" ;
1111import { createTestServer } from "../createTestServer.js" ;
1212
13+ const DEFAULT_PORT = 3000 ;
1314const pkg = JSON . parse ( await readFile ( new URL ( "../package.json" , import . meta. url ) ) ) ;
1415
1516function parseFlags ( flags ) {
@@ -43,6 +44,13 @@ yargs( process.argv.slice( 2 ) )
4344 description : "Path to a YAML configuration file. " +
4445 "Use this to avoid passing options via the command line."
4546 } )
47+ . option ( "base-url" , {
48+ alias : "u" ,
49+ type : "string" ,
50+ description : "Base URL for the test server. " +
51+ "Expected to always start and end with a slash (/). " +
52+ "Defaults to \"/test/\"."
53+ } )
4654 . option ( "flag" , {
4755 alias : "f" ,
4856 type : "array" ,
@@ -60,10 +68,10 @@ yargs( process.argv.slice( 2 ) )
6068 type : "array" ,
6169 choices : browsers ,
6270 description :
63- "Run tests in a specific browser." +
64- "Pass multiple browsers by repeating the option." +
65- "If using BrowserStack, specify browsers using --browserstack." ,
66- default : [ "chrome" ]
71+ "Run tests in a specific browser. " +
72+ "Pass multiple browsers by repeating the option. " +
73+ "If using BrowserStack, specify browsers using --browserstack. " +
74+ "Defaults to Chrome."
6775 } )
6876 . option ( "middleware" , {
6977 alias : "mw" ,
@@ -108,7 +116,7 @@ yargs( process.argv.slice( 2 ) )
108116 . option ( "verbose" , {
109117 alias : "v" ,
110118 type : "boolean" ,
111- description : "Log additional information."
119+ description : "Log additional information, including all test server requests ."
112120 } )
113121 . option ( "browserstack" , {
114122 type : "array" ,
@@ -143,6 +151,7 @@ yargs( process.argv.slice( 2 ) )
143151 ...( argv . isolatedFlag ?? [ ] )
144152 ] ;
145153 const middleware = await parseMiddleware ( config , argv ) ;
154+
146155 return run ( { ...config , ...argv , flag, isolatedFlag, middleware } ) ;
147156 }
148157 } )
@@ -156,17 +165,22 @@ yargs( process.argv.slice( 2 ) )
156165 description : "Path to a YAML configuration file. " +
157166 "Use this to avoid passing options via the command line."
158167 } )
168+ . option ( "base-url" , {
169+ alias : "u" ,
170+ type : "string" ,
171+ description : "Base URL for the test server. " +
172+ "Expected to always start and end with a slash (/). " +
173+ "Defaults to \"/test/\"."
174+ } )
159175 . option ( "port" , {
160176 alias : "p" ,
161177 type : "number" ,
162- description : "Port to listen on." ,
163- default : 3000
178+ description : "Port to listen on. Defaults to 3000."
164179 } )
165180 . option ( "quiet" , {
166181 alias : "q" ,
167182 type : "boolean" ,
168- description : "Whether to log requests to the console." ,
169- default : true
183+ description : "Whether to log requests to the console. Default: false."
170184 } )
171185 . option ( "middleware" , {
172186 alias : "mw" ,
@@ -176,7 +190,7 @@ yargs( process.argv.slice( 2 ) )
176190 "Pass multiple by repeating the option."
177191 } ) ;
178192 } ,
179- handler : async ( { configFile, quiet, ...argv } ) => {
193+ handler : async ( { baseUrl , configFile, quiet, ...argv } ) => {
180194 console . log ( "Starting server..." ) ;
181195 const config = await readYAML ( configFile ) ;
182196 const middleware = await parseMiddleware ( config , argv ) ;
@@ -186,10 +200,11 @@ yargs( process.argv.slice( 2 ) )
186200 * Note: this server does not support middleware.
187201 * To add middleware, use createTestServer directly.
188202 */
189- const app = await createTestServer ( { middleware, quiet } ) ;
203+ const app = await createTestServer ( { baseUrl , middleware, quiet } ) ;
190204
191- return app . listen ( { ...config , ...argv , host : "0.0.0.0" } , function ( ) {
192- console . log ( `Open tests at http://localhost:${ argv . port } /` ) ;
205+ const port = argv . port ?? config . port ?? DEFAULT_PORT ;
206+ return app . listen ( { port, host : "0.0.0.0" } , function ( ) {
207+ console . log ( `Open tests at http://localhost:${ port } /` ) ;
193208 } ) ;
194209 }
195210 } )
0 commit comments