@@ -104,28 +104,25 @@ program
104
104
"for that browser, on a matching OS."
105
105
)
106
106
. option ( "--run-id <id>" , "A unique identifier for the run in BrowserStack." )
107
- . action ( async ( { configFile, ...options } ) => {
107
+ . action ( async ( { configFile, ...argv } ) => {
108
108
const config = await readYAML ( configFile ) ;
109
- const flag = [
109
+ const options = {
110
+ baseUrl : "/test/" ,
111
+ ...config ,
112
+ testUrl : config . testUrls ,
113
+ ...argv
114
+ } ;
115
+ options . flag = [
110
116
...parseFlags ( config . flags ) ,
111
- ...( config . flag ?? [ ] ) ,
112
117
...( options . flag ?? [ ] )
113
118
] ;
114
- const run = [
119
+ options . run = [
115
120
...parseRuns ( config . runs ) ,
116
- ...( config . run ?? [ ] ) ,
117
121
...( options . run ?? [ ] )
118
122
] ;
119
- const middleware = await parseMiddleware ( config , options ) ;
123
+ options . middleware = await parseMiddleware ( options ) ;
120
124
121
- return runTests ( {
122
- ...config ,
123
- testUrl : config . testUrls ,
124
- ...options ,
125
- flag,
126
- middleware,
127
- run
128
- } ) ;
125
+ return runTests ( options ) ;
129
126
} ) ;
130
127
131
128
// Define the serve command
@@ -156,22 +153,26 @@ program
156
153
"passing the path to a module that exports a middleware factory function. " +
157
154
"Pass multiple by repeating the option."
158
155
)
159
- . action ( async ( { configFile, quiet , ...options } ) => {
156
+ . action ( async ( { configFile, ...argv } ) => {
160
157
console . log ( "Starting server..." ) ;
161
158
const config = await readYAML ( configFile ) ;
162
- const middleware = await parseMiddleware ( config , options ) ;
163
- const baseUrl = config . baseUrl ?? options . baseUrl ?? "/test/" ;
159
+ const options = {
160
+ baseUrl : "/test/" ,
161
+ port : DEFAULT_PORT ,
162
+ ...config ,
163
+ ...argv
164
+ } ;
165
+ options . middleware = await parseMiddleware ( options ) ;
164
166
165
167
/**
166
168
* Run a simple server for loading tests in a browser.
167
169
* Note: this server does not support middleware.
168
170
* To add middleware, use createTestServer directly.
169
171
*/
170
- const app = await createTestServer ( { baseUrl , middleware , quiet } ) ;
172
+ const app = await createTestServer ( options ) ;
171
173
172
- const port = options . port ?? config . port ?? DEFAULT_PORT ;
173
- return app . listen ( { port, host : "0.0.0.0" } , function ( ) {
174
- console . log ( `Open tests at http://localhost:${ port } ${ baseUrl } ` ) ;
174
+ return app . listen ( { port : options . port , host : "0.0.0.0" } , function ( ) {
175
+ console . log ( `Open tests at http://localhost:${ options . port } ${ options . baseUrl } ` ) ;
175
176
} ) ;
176
177
} ) ;
177
178
@@ -249,13 +250,15 @@ function parseRuns( runs ) {
249
250
return results ;
250
251
}
251
252
252
- async function parseMiddleware ( config , options ) {
253
+ async function parseMiddleware ( options ) {
253
254
const middleware = await Promise . all (
254
- [ ... ( config . middleware ?? [ ] ) , ... ( options . middleware ?? [ ] ) ] . map (
255
+ ( options . middleware ?? [ ] ) . map (
255
256
async ( mw ) => {
256
- const module = await import (
257
- pathToFileURL ( resolve ( process . cwd ( ) , mw ) ) . toString ( )
258
- ) ;
257
+ const filepath = pathToFileURL ( resolve ( process . cwd ( ) , mw ) ) . toString ( ) ;
258
+ if ( options . verbose ) {
259
+ console . log ( `Loading middleware from ${ filepath } ...` ) ;
260
+ }
261
+ const module = await import ( filepath ) ;
259
262
return module . default ;
260
263
}
261
264
)
0 commit comments