@@ -177,24 +177,33 @@ export class XCodeSimctlSimulator extends IPhoneSimulatorNameGetter implements I
177
177
return this . deviceLogChildProcess ;
178
178
}
179
179
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
+ }
183
192
184
193
let result = _ . find ( devices , ( device : IDevice ) => {
185
- if ( sdkVersion && ! options . device ) {
194
+ if ( sdkVersion && ! deviceIdOrName ) {
186
195
return device . runtimeVersion === sdkVersion ;
187
196
}
188
197
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 ;
191
200
}
192
201
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 ) ;
195
204
}
196
205
197
- if ( ! sdkVersion && ! options . device ) {
206
+ if ( ! sdkVersion && ! deviceIdOrName ) {
198
207
return this . isDeviceBooted ( device ) ;
199
208
}
200
209
} ) ;
@@ -204,8 +213,7 @@ export class XCodeSimctlSimulator extends IPhoneSimulatorNameGetter implements I
204
213
}
205
214
206
215
if ( ! result ) {
207
- let sortedDevices = _ . sortBy ( devices , ( device ) => device . runtimeVersion ) ;
208
- result = _ . last ( sortedDevices ) ;
216
+ result = _ . last ( devices ) ;
209
217
}
210
218
211
219
return result ;
@@ -226,7 +234,9 @@ export class XCodeSimctlSimulator extends IPhoneSimulatorNameGetter implements I
226
234
}
227
235
228
236
public startSimulator ( device ?: IDevice ) : void {
229
- device = device || this . getDeviceToRun ( ) ;
237
+ if ( ! device || ! device . runtimeVersion || ! device . fullId ) {
238
+ device = this . getDeviceToRun ( device ) ;
239
+ }
230
240
231
241
// In case the id is undefined, skip verification - we'll start default simulator.
232
242
if ( device . id ) {
@@ -273,7 +283,7 @@ export class XCodeSimctlSimulator extends IPhoneSimulatorNameGetter implements I
273
283
274
284
private verifyDevice ( device : IDevice ) : void {
275
285
const availableDevices = this . getDevices ( ) ;
276
- if ( ! _ . find ( availableDevices , { id : device . id } ) ) {
286
+ if ( ! _ . find ( availableDevices , { id : device . id } ) && ! _ . find ( availableDevices , { name : device . id } ) ) {
277
287
errors . fail ( `No simulator image available for device identifier '${ device . id } '.` ) ;
278
288
}
279
289
}
0 commit comments