@@ -160,76 +160,79 @@ export async function dismissFirstRunPrompts(opts: {
160160 ) ;
161161 }
162162
163- const deadline = timing . now ( ) + timeoutMs ;
164- let promptsDismissed = false ;
165- let uiSeen = false ;
166- while ( timing . now ( ) < deadline ) {
167- const search = await findFirstRunPromptLabel ( {
168- simulatorId : opts . simulatorId ,
169- labels : dismissals . labels ,
170- cwd : opts . cwd ,
171- logPath : opts . logPath ,
172- executor,
173- axePath,
174- axeEnv,
175- } ) ;
176-
177- if ( search . status === 'unavailable' ) {
178- await appendLifecycleLog (
179- opts . logPath ,
180- `First-run prompt preflight: UI unavailable; retrying (exit ${ search . exitCode } )` ,
181- ) ;
182- await timing . sleep ( 500 ) ;
183- continue ;
184- }
163+ try {
164+ const deadline = timing . now ( ) + timeoutMs ;
165+ let promptsDismissed = false ;
166+ let uiSeen = false ;
167+ while ( timing . now ( ) < deadline ) {
168+ const search = await findFirstRunPromptLabel ( {
169+ simulatorId : opts . simulatorId ,
170+ labels : dismissals . labels ,
171+ cwd : opts . cwd ,
172+ logPath : opts . logPath ,
173+ executor,
174+ axePath,
175+ axeEnv,
176+ } ) ;
177+
178+ if ( search . status === 'unavailable' ) {
179+ await appendLifecycleLog (
180+ opts . logPath ,
181+ `First-run prompt preflight: UI unavailable; retrying (exit ${ search . exitCode } )` ,
182+ ) ;
183+ await timing . sleep ( 500 ) ;
184+ continue ;
185+ }
185186
186- if ( search . status === 'not-found' ) {
187- if ( search . hasElements ) {
188- uiSeen = true ;
187+ if ( search . status === 'not-found' ) {
188+ if ( search . hasElements ) {
189+ uiSeen = true ;
190+ }
191+ if ( uiSeen ) {
192+ promptsDismissed = true ;
193+ break ;
194+ }
195+ await timing . sleep ( 500 ) ;
196+ continue ;
189197 }
190- if ( uiSeen ) {
191- promptsDismissed = true ;
192- break ;
198+
199+ uiSeen = true ;
200+ const { label } = search ;
201+ opts . onEvent ?.( `dismissing first-run prompt '${ label } '` ) ;
202+ await appendLifecycleLog ( opts . logPath , `Dismissing first-run prompt label: ${ label } ` ) ;
203+ const tap = await executor ( {
204+ command : axePath ,
205+ args : [ 'tap' , '--label' , label , '--element-type' , 'Button' , '--udid' , opts . simulatorId ] ,
206+ cwd : opts . cwd ,
207+ logPath : opts . logPath ,
208+ env : axeEnv ,
209+ } ) ;
210+ if ( tap . exitCode !== 0 ) {
211+ throw new Error (
212+ `${ opts . config . name } : failed to dismiss first-run prompt '${ label } ' (exit ${ tap . exitCode } ); see ${ opts . logPath } ` ,
213+ ) ;
193214 }
194215 await timing . sleep ( 500 ) ;
195- continue ;
196216 }
197217
198- uiSeen = true ;
199- const { label } = search ;
200- opts . onEvent ?.( `dismissing first-run prompt '${ label } '` ) ;
201- await appendLifecycleLog ( opts . logPath , `Dismissing first-run prompt label: ${ label } ` ) ;
202- const tap = await executor ( {
203- command : axePath ,
204- args : [ 'tap' , '--label' , label , '--element-type' , 'Button' , '--udid' , opts . simulatorId ] ,
218+ if ( ! promptsDismissed ) {
219+ throw new Error (
220+ `${ opts . config . name } : timed out during first-run prompt preflight; see ${ opts . logPath } ` ,
221+ ) ;
222+ }
223+
224+ await appendLifecycleLog ( opts . logPath , 'First-run prompt preflight: complete' ) ;
225+ } finally {
226+ const terminate = await executor ( {
227+ command : 'xcrun' ,
228+ args : [ 'simctl' , 'terminate' , opts . simulatorId , bundleId ] ,
205229 cwd : opts . cwd ,
206230 logPath : opts . logPath ,
207- env : axeEnv ,
208231 } ) ;
209- if ( tap . exitCode !== 0 ) {
232+ if ( terminate . exitCode !== 0 ) {
210233 throw new Error (
211- `${ opts . config . name } : failed to dismiss first-run prompt ' ${ label } ' (exit ${ tap . exitCode } ); see ${ opts . logPath } ` ,
234+ `${ opts . config . name } : failed to terminate app after first-run prompt preflight (exit ${ terminate . exitCode } ); see ${ opts . logPath } ` ,
212235 ) ;
213236 }
214- await timing . sleep ( 500 ) ;
215- }
216-
217- if ( ! promptsDismissed ) {
218- throw new Error (
219- `${ opts . config . name } : timed out during first-run prompt preflight; see ${ opts . logPath } ` ,
220- ) ;
221- }
222-
223- const terminate = await executor ( {
224- command : 'xcrun' ,
225- args : [ 'simctl' , 'terminate' , opts . simulatorId , bundleId ] ,
226- cwd : opts . cwd ,
227- logPath : opts . logPath ,
228- } ) ;
229- if ( terminate . exitCode !== 0 ) {
230- throw new Error (
231- `${ opts . config . name } : failed to terminate app after first-run prompt preflight (exit ${ terminate . exitCode } ); see ${ opts . logPath } ` ,
232- ) ;
233237 }
234- await appendLifecycleLog ( opts . logPath , 'First-run prompt preflight: complete' ) ;
235238}
0 commit comments