@@ -141,17 +141,21 @@ const startApp = Effect.fn("startApp")(function* (input: {
141141 ] ;
142142
143143 if ( input . surface === "web" ) {
144- const [ webPort = "" ] = input . ports ;
145- const serverPort = yield * net . reserveLoopbackPort ( ) ;
144+ // e2e opens the app at this host, so the web server is told to bind exactly it. Left to its
145+ // default, `localhost`, it binds ::1 alone on machines that resolve the name to IPv6 first.
146+ const [ host = "" , webPort = "" ] = input . ports ;
147+ const origin = `http://${ host } :${ webPort } ` ;
148+ const serverPort = String ( yield * net . reserveLoopbackPort ( ) ) ;
146149 const token = yield * ( yield * SecureRandom . SecureRandom ) . uuidV4 ( ) ;
147- const runner = yield * start ( {
150+ const ports = [ "--port" , serverPort , "--dev-url" , origin ] ;
151+ const webEnv = { ...env , T3CODE_PORT_OFFSET : String ( Number ( webPort ) - BASE_WEB_PORT ) } ;
152+ const server = yield * start ( {
148153 cwd : checkout ,
149154 command : node ,
150- args : devRunner ( "dev" , [ "--port" , String ( serverPort ) ] ) ,
155+ args : devRunner ( "dev:server " , ports ) ,
151156 env : {
152- ...env ,
153- T3CODE_PORT_OFFSET : String ( Number ( webPort ) - BASE_WEB_PORT ) ,
154- T3CODE_DEV_ALLOWED_ORIGINS : `http://127.0.0.1:${ webPort } ` ,
157+ ...webEnv ,
158+ T3CODE_DEV_ALLOWED_ORIGINS : origin ,
155159 // Makes the startup pairing link reusable, so every test can sign in with it.
156160 T3CODE_DEV_AUTH_TOKEN : `${ token } ${ token } ` . replaceAll ( "-" , "" ) ,
157161 } ,
@@ -165,7 +169,32 @@ const startApp = Effect.fn("startApp")(function* (input: {
165169 . pipe ( Effect . ignore ) ;
166170 } ,
167171 } ) ;
168- return yield * runner . exitCode ;
172+ const web = yield * start ( {
173+ cwd : checkout ,
174+ command : node ,
175+ args : devRunner ( "dev:web" , [ ...ports , "--" , "--host" , host ] ) ,
176+ env : webEnv ,
177+ onLine : Console . log ,
178+ } ) ;
179+ // A web server that came up on another loopback address would leave e2e waiting out its
180+ // whole startup timeout; say so at once instead.
181+ const boundElsewhere = Effect . gen ( function * ( ) {
182+ const elsewhere = host === "::1" ? "127.0.0.1" : "::1" ;
183+ if ( yield * net . hasListenerOnHost ( Number ( webPort ) , host ) ) return yield * Effect . never ;
184+ if ( ! ( yield * net . hasListenerOnHost ( Number ( webPort ) , elsewhere ) ) ) {
185+ return yield * new ScenarioError ( { message : "The web server is not listening yet." } ) ;
186+ }
187+ yield * Console . error (
188+ `The web server listens on ${ elsewhere } :${ webPort } , not on ${ host } : it ignored --host.` ,
189+ ) ;
190+ return 1 ;
191+ } ) . pipe (
192+ Effect . retry ( {
193+ schedule : Schedule . spaced ( "1 second" ) ,
194+ while : ( error ) => error . _tag === "ScenarioError" ,
195+ } ) ,
196+ ) ;
197+ return yield * Effect . raceAll ( [ server . exitCode , web . exitCode , boundElsewhere ] ) ;
169198 }
170199
171200 // The device is another machine: the server listens on every interface, and Metro serves the
@@ -212,7 +241,9 @@ const command = Command.make(
212241 ) ,
213242 home : Argument . String ( "t3-home" ) . pipe ( Argument . withDescription ( "T3 home to recreate." ) ) ,
214243 ports : Argument . String ( "port" ) . pipe (
215- Argument . withDescription ( "web: <web-port>. mobile: <server-port> <metro-port> <host>." ) ,
244+ Argument . withDescription (
245+ "web: <host> <web-port>. mobile: <server-port> <metro-port> <host>." ,
246+ ) ,
216247 Argument . variadic ( ) ,
217248 ) ,
218249 } ,
0 commit comments