@@ -47,12 +47,11 @@ export class XcodeBuild {
4747
4848 /**
4949 * @param {import('appium-xcode').XcodeVersion } xcodeVersion
50- * @param {any } device
51- * // TODO: make args typed
52- * @param {import('@appium/types').StringRecord } [args={}]
53- * @param {import('@appium/types').AppiumLogger? } [log=null]
50+ * @param {import('./types').AppleDevice } device
51+ * @param {import('./types').XcodeBuildArgs } args
52+ * @param {import('@appium/types').AppiumLogger | null } [log=null]
5453 */
55- constructor ( xcodeVersion , device , args = { } , log = null ) {
54+ constructor ( xcodeVersion , device , args , log = null ) {
5655 this . xcodeVersion = xcodeVersion ;
5756
5857 this . device = device ;
@@ -110,13 +109,19 @@ export class XcodeBuild {
110109 this . noSessionProxy = noSessionProxy ;
111110
112111 if ( this . useXctestrunFile ) {
113- const deviveInfo = {
114- isRealDevice : this . realDevice ,
112+ /** @type {import('./utils').DeviceInfo } */
113+ const deviceInfo = {
114+ isRealDevice : ! ! this . realDevice ,
115115 udid : this . device . udid ,
116- platformVersion : this . platformVersion ,
117- platformName : this . platformName
116+ platformVersion : this . platformVersion || '' ,
117+ platformName : this . platformName || ''
118118 } ;
119- this . xctestrunFilePath = await setXctestrunFile ( deviveInfo , this . iosSdkVersion , this . bootstrapPath , this . wdaRemotePort ) ;
119+ this . xctestrunFilePath = await setXctestrunFile (
120+ deviceInfo ,
121+ this . iosSdkVersion || '' ,
122+ this . bootstrapPath ,
123+ this . wdaRemotePort || 8100
124+ ) ;
120125 return ;
121126 }
122127
@@ -200,8 +205,8 @@ export class XcodeBuild {
200205 * @returns {Promise<void> }
201206 */
202207 async cleanProject ( ) {
203- const libScheme = isTvOS ( this . platformName ) ? LIB_SCHEME_TV : LIB_SCHEME_IOS ;
204- const runnerScheme = isTvOS ( this . platformName ) ? RUNNER_SCHEME_TV : RUNNER_SCHEME_IOS ;
208+ const libScheme = isTvOS ( this . platformName || '' ) ? LIB_SCHEME_TV : LIB_SCHEME_IOS ;
209+ const runnerScheme = isTvOS ( this . platformName || '' ) ? RUNNER_SCHEME_TV : RUNNER_SCHEME_IOS ;
205210
206211 for ( const scheme of [ libScheme , runnerScheme ] ) {
207212 this . log . debug ( `Cleaning the project scheme '${ scheme } ' to make sure there are no leftovers from previous installs` ) ;
@@ -249,22 +254,24 @@ export class XcodeBuild {
249254 if ( this . useXctestrunFile && this . xctestrunFilePath ) {
250255 args . push ( '-xctestrun' , this . xctestrunFilePath ) ;
251256 } else {
252- const runnerScheme = isTvOS ( this . platformName ) ? RUNNER_SCHEME_TV : RUNNER_SCHEME_IOS ;
257+ const runnerScheme = isTvOS ( this . platformName || '' ) ? RUNNER_SCHEME_TV : RUNNER_SCHEME_IOS ;
253258 args . push ( '-project' , this . agentPath , '-scheme' , runnerScheme ) ;
254259 if ( this . derivedDataPath ) {
255260 args . push ( '-derivedDataPath' , this . derivedDataPath ) ;
256261 }
257262 }
258263 args . push ( '-destination' , `id=${ this . device . udid } ` ) ;
259264
260- const versionMatch = new RegExp ( / ^ ( \d + ) \. ( \d + ) / ) . exec ( this . platformVersion ) ;
261- if ( versionMatch ) {
265+ let versionMatch ;
266+ if ( this . platformVersion && ( versionMatch = new RegExp ( / ^ ( \d + ) \. ( \d + ) / ) . exec ( this . platformVersion ) ) ) {
262267 args . push (
263- `${ isTvOS ( this . platformName ) ? 'TV' : 'IPHONE' } OS_DEPLOYMENT_TARGET=${ versionMatch [ 1 ] } .${ versionMatch [ 2 ] } `
268+ `${ isTvOS ( this . platformName || '' ) ? 'TV' : 'IPHONE' } OS_DEPLOYMENT_TARGET=${ versionMatch [ 1 ] } .${ versionMatch [ 2 ] } `
264269 ) ;
265270 } else {
266- this . log . warn ( `Cannot parse major and minor version numbers from platformVersion "${ this . platformVersion } ". ` +
267- 'Will build for the default platform instead' ) ;
271+ this . log . warn (
272+ `Cannot parse major and minor version numbers from platformVersion "${ this . platformVersion } ". ` +
273+ 'Will build for the default platform instead'
274+ ) ;
268275 }
269276
270277 if ( this . realDevice ) {
@@ -413,10 +420,11 @@ export class XcodeBuild {
413420 */
414421 async waitForStart ( timer ) {
415422 // try to connect once every 0.5 seconds, until `launchTimeout` is up
416- this . log . debug ( `Waiting up to ${ this . launchTimeout } ms for WebDriverAgent to start` ) ;
423+ const timeout = this . launchTimeout || 60000 ; // Default to 60 seconds if not set
424+ this . log . debug ( `Waiting up to ${ timeout } ms for WebDriverAgent to start` ) ;
417425 let currentStatus = null ;
418426 try {
419- const retries = Math . trunc ( this . launchTimeout / 500 ) ;
427+ const retries = Math . trunc ( timeout / 500 ) ;
420428 await retryInterval ( retries , 1000 , async ( ) => {
421429 if ( this . _didProcessExit ) {
422430 // there has been an error elsewhere and we need to short-circuit
@@ -448,7 +456,7 @@ export class XcodeBuild {
448456 } catch ( err ) {
449457 this . log . debug ( err . stack ) ;
450458 throw new Error (
451- `We were not able to retrieve the /status response from the WebDriverAgent server after ${ this . launchTimeout } ms timeout.` +
459+ `We were not able to retrieve the /status response from the WebDriverAgent server after ${ timeout } ms timeout.` +
452460 `Try to increase the value of 'appium:wdaLaunchTimeout' capability as a possible workaround.`
453461 ) ;
454462 }
0 commit comments