@@ -13,7 +13,13 @@ jest.mock('execa', () => {
13
13
return { sync : jest . fn ( ) } ;
14
14
} ) ;
15
15
16
- const xcrunOut = `
16
+ beforeEach ( ( ) => {
17
+ ( execa . sync as jest . Mock )
18
+ . mockReturnValueOnce ( { stdout : xcrunXcdeviceOut } )
19
+ . mockReturnValueOnce ( { stdout : xcrunSimctlOut } ) ;
20
+ } ) ;
21
+
22
+ const xcrunXcdeviceOut = `
17
23
[
18
24
{
19
25
"simulator" : true,
@@ -63,6 +69,19 @@ const xcrunOut = `
63
69
"modelName" : "iPhone SE (3rd generation)",
64
70
"name" : "iPhone SE (3rd generation)"
65
71
},
72
+ {
73
+ "simulator" : true,
74
+ "operatingSystemVersion" : "17.0 (21A328)",
75
+ "available" : true,
76
+ "platform" : "com.apple.platform.iphonesimulator",
77
+ "modelCode" : "iPhone16,2",
78
+ "identifier" : "B3D623E3-9907-4E0A-B76B-13B13A47FE92",
79
+ "architecture" : "arm64",
80
+ "modelUTI" : "com.apple.iphone-15-pro-max-1",
81
+ "modelName" : "iPhone 15 Pro Max",
82
+ "name" : "iPhone 15 Pro Max",
83
+ "ignored" : false
84
+ },
66
85
{
67
86
"simulator" : false,
68
87
"operatingSystemVersion" : "13.0.1 (22A400)",
@@ -161,9 +180,40 @@ const xcrunOut = `
161
180
]
162
181
` ;
163
182
183
+ const xcrunSimctlOut = `
184
+ {
185
+ "devices" : {
186
+ "com.apple.CoreSimulator.SimRuntime.iOS-16-2" : [
187
+ {
188
+ "lastBootedAt" : "2023-05-09T11:08:32Z",
189
+ "dataPath" : "<REPLACED_ROOT>/Library/Developer/CoreSimulator/Devices/54B1D3DE-A943-4867-BA6A-B82BFE3A7904/data",
190
+ "dataPathSize" : 4630163456,
191
+ "logPath" : "<REPLACED_ROOT>/Library/Logs/CoreSimulator/54B1D3DE-A943-4867-BA6A-B82BFE3A7904",
192
+ "udid" : "54B1D3DE-A943-4867-BA6A-B82BFE3A7904",
193
+ "isAvailable" : false,
194
+ "availabilityError" : "runtime profile not found using System match policy",
195
+ "deviceTypeIdentifier" : "com.apple.CoreSimulator.SimDeviceType.iPhone-14",
196
+ "state" : "Shutdown",
197
+ "name" : "iPhone 14"
198
+ },
199
+ {
200
+ "lastBootedAt" : "2024-01-07T15:33:06Z",
201
+ "dataPath" : "<REPLACED_ROOT>/Library/Developer/CoreSimulator/Devices/B3D623E3-9907-4E0A-B76B-13B13A47FE92/data",
202
+ "dataPathSize" : 4181225472,
203
+ "logPath" : "<REPLACED_ROOT>/Library/Logs/CoreSimulator/B3D623E3-9907-4E0A-B76B-13B13A47FE92",
204
+ "udid" : "B3D623E3-9907-4E0A-B76B-13B13A47FE92",
205
+ "isAvailable" : true,
206
+ "logPathSize" : 745472,
207
+ "deviceTypeIdentifier" : "com.apple.CoreSimulator.SimDeviceType.iPhone-15-Pro-Max",
208
+ "state" : "Shutdown",
209
+ "name" : "iPhone 15 Pro Max"
210
+ }
211
+ ]
212
+ }
213
+ }` ;
214
+
164
215
describe ( 'listDevices' , ( ) => {
165
- it ( 'parses output from xcdevice list for iOS' , async ( ) => {
166
- ( execa . sync as jest . Mock ) . mockReturnValueOnce ( { stdout : xcrunOut } ) ;
216
+ it ( 'parses output list for iOS' , async ( ) => {
167
217
const devices = await listDevices ( [ 'iphoneos' , 'iphonesimulator' ] ) ;
168
218
169
219
// Find all available simulators
@@ -186,17 +236,6 @@ describe('listDevices', () => {
186
236
type : 'simulator' ,
187
237
} ) ;
188
238
189
- // Find all available iPhone's event when not available
190
- expect ( devices ) . toContainEqual ( {
191
- name : 'Adam’s iPhone' ,
192
- isAvailable : false ,
193
- udid : '1234567890-0987654321' ,
194
- version : '16.2 (20C65)' ,
195
- sdk : 'com.apple.platform.iphoneos' ,
196
- availabilityError :
197
- 'To use Adam’s iPhone for development, enable Developer Mode in Settings → Privacy & Security.' ,
198
- type : 'device' ,
199
- } ) ;
200
239
// Filter out AppleTV
201
240
expect ( devices ) . not . toContainEqual ( {
202
241
isAvailable : false ,
@@ -227,8 +266,7 @@ describe('listDevices', () => {
227
266
} ) ;
228
267
} ) ;
229
268
230
- it ( 'parses output from xcdevice list for tvOS' , async ( ) => {
231
- ( execa . sync as jest . Mock ) . mockReturnValueOnce ( { stdout : xcrunOut } ) ;
269
+ it ( 'parses output for tvOS' , async ( ) => {
232
270
const devices = await listDevices ( [ 'appletvos' , 'appletvsimulator' ] ) ;
233
271
234
272
// Filter out all available simulators
@@ -242,28 +280,7 @@ describe('listDevices', () => {
242
280
type : 'simulator' ,
243
281
} ) ;
244
282
245
- // Filter out all available iPhone's event when not available
246
- expect ( devices ) . not . toContainEqual ( {
247
- name : 'Adam’s iPhone' ,
248
- isAvailable : false ,
249
- udid : '1234567890-0987654321' ,
250
- version : '16.2 (20C65)' ,
251
- sdk : 'com.apple.platform.iphoneos' ,
252
- availabilityError :
253
- 'To use Adam’s iPhone for development, enable Developer Mode in Settings → Privacy & Security.' ,
254
- type : 'device' ,
255
- } ) ;
256
-
257
283
// Find AppleTV
258
- expect ( devices ) . toContainEqual ( {
259
- isAvailable : false ,
260
- name : 'Living Room' ,
261
- udid : '7656fbf922891c8a2c7682c9d845eaa6954c24d8' ,
262
- sdk : 'com.apple.platform.appletvos' ,
263
- version : '16.1 (20K71)' ,
264
- availabilityError : 'Living Room is not connected' ,
265
- type : 'device' ,
266
- } ) ;
267
284
expect ( devices ) . toContainEqual ( {
268
285
isAvailable : true ,
269
286
name : 'Apple TV 4K (2nd generation)' ,
@@ -284,4 +301,28 @@ describe('listDevices', () => {
284
301
type : 'device' ,
285
302
} ) ;
286
303
} ) ;
304
+
305
+ it ( 'parses and merges output from two commands' , async ( ) => {
306
+ const devices = await listDevices ( [ 'iphoneos' , 'iphonesimulator' ] ) ;
307
+
308
+ expect ( devices ) . toContainEqual ( {
309
+ availabilityError : undefined ,
310
+ dataPath :
311
+ '<REPLACED_ROOT>/Library/Developer/CoreSimulator/Devices/B3D623E3-9907-4E0A-B76B-13B13A47FE92/data' ,
312
+ dataPathSize : 4181225472 ,
313
+ deviceTypeIdentifier :
314
+ 'com.apple.CoreSimulator.SimDeviceType.iPhone-15-Pro-Max' ,
315
+ isAvailable : true ,
316
+ lastBootedAt : '2024-01-07T15:33:06Z' ,
317
+ logPath :
318
+ '<REPLACED_ROOT>/Library/Logs/CoreSimulator/B3D623E3-9907-4E0A-B76B-13B13A47FE92' ,
319
+ logPathSize : 745472 ,
320
+ name : 'iPhone 15 Pro Max' ,
321
+ sdk : 'com.apple.platform.iphonesimulator' ,
322
+ state : 'Shutdown' ,
323
+ type : 'simulator' ,
324
+ udid : 'B3D623E3-9907-4E0A-B76B-13B13A47FE92' ,
325
+ version : '17.0 (21A328)' ,
326
+ } ) ;
327
+ } ) ;
287
328
} ) ;
0 commit comments