@@ -177,24 +177,33 @@ export class XCodeSimctlSimulator extends IPhoneSimulatorNameGetter implements I
177177 return this . deviceLogChildProcess ;
178178 }
179179
180- private getDeviceToRun ( ) : IDevice {
181- let devices = this . simctl . getDevices ( ) ,
182- sdkVersion = options . sdkVersion || options . sdk ;
180+ private getDeviceToRun ( device ?: any ) : IDevice {
181+ let devices = _ . sortBy ( this . simctl . getDevices ( ) , ( device ) => device . runtimeVersion ) ,
182+ sdkVersion = options . sdkVersion || options . sdk ,
183+ deviceIdOrName = options . device ;
184+
185+ if ( device && ( device . sdkVersion || device . sdk ) ) {
186+ sdkVersion = device . sdkVersion || device . sdk ;
187+ }
188+
189+ if ( device && device . id ) {
190+ deviceIdOrName = device . id ;
191+ }
183192
184193 let result = _ . find ( devices , ( device : IDevice ) => {
185- if ( sdkVersion && ! options . device ) {
194+ if ( sdkVersion && ! deviceIdOrName ) {
186195 return device . runtimeVersion === sdkVersion ;
187196 }
188197
189- if ( options . device && ! sdkVersion ) {
190- return device . name === options . device || device . id === options . device ;
198+ if ( deviceIdOrName && ! sdkVersion ) {
199+ return device . name === deviceIdOrName || device . id === deviceIdOrName ;
191200 }
192201
193- if ( options . device && sdkVersion ) {
194- return device . runtimeVersion === sdkVersion && ( device . name === options . device || device . id === options . device ) ;
202+ if ( deviceIdOrName && sdkVersion ) {
203+ return device . runtimeVersion === sdkVersion && ( device . name === deviceIdOrName || device . id === deviceIdOrName ) ;
195204 }
196205
197- if ( ! sdkVersion && ! options . device ) {
206+ if ( ! sdkVersion && ! deviceIdOrName ) {
198207 return this . isDeviceBooted ( device ) ;
199208 }
200209 } ) ;
@@ -204,8 +213,7 @@ export class XCodeSimctlSimulator extends IPhoneSimulatorNameGetter implements I
204213 }
205214
206215 if ( ! result ) {
207- let sortedDevices = _ . sortBy ( devices , ( device ) => device . runtimeVersion ) ;
208- result = _ . last ( sortedDevices ) ;
216+ result = _ . last ( devices ) ;
209217 }
210218
211219 return result ;
@@ -226,7 +234,9 @@ export class XCodeSimctlSimulator extends IPhoneSimulatorNameGetter implements I
226234 }
227235
228236 public startSimulator ( device ?: IDevice ) : void {
229- device = device || this . getDeviceToRun ( ) ;
237+ if ( ! device || ! device . runtimeVersion || ! device . fullId ) {
238+ device = this . getDeviceToRun ( device ) ;
239+ }
230240
231241 // In case the id is undefined, skip verification - we'll start default simulator.
232242 if ( device . id ) {
@@ -273,7 +283,7 @@ export class XCodeSimctlSimulator extends IPhoneSimulatorNameGetter implements I
273283
274284 private verifyDevice ( device : IDevice ) : void {
275285 const availableDevices = this . getDevices ( ) ;
276- if ( ! _ . find ( availableDevices , { id : device . id } ) ) {
286+ if ( ! _ . find ( availableDevices , { id : device . id } ) && ! _ . find ( availableDevices , { name : device . id } ) ) {
277287 errors . fail ( `No simulator image available for device identifier '${ device . id } '.` ) ;
278288 }
279289 }
0 commit comments