Skip to content

Commit 0b5ff0d

Browse files
Richard EvansFacebook Github Bot
Richard Evans
authored and
Facebook Github Bot
committed
Make run-ios find if a device is booted better
Summary: **Motivation** This morning I was trying to test on iPhone 7 with iOS 10 so I booted that device and ran "react-native run-ios" expecting it to notice I had a simulator running and install my app to it. Instead it switched my device to the iPhone 6s iOS 9.2. After digging it was found that run-ios did not handle multiple versions of iOS being installed very well when it came to checking for the booted device. This PR resolves that. **Test plan (required)** Tests were added for the situation of multiple iOS versions being installed and a slight change to the code was completed to make the new tests pass and continue to keep the old tests passing. Closes #10558 Differential Revision: D4163616 Pulled By: hramos fbshipit-source-id: 26b44fb73ef402ce252e7a754036279e15359170
1 parent 81b1a2c commit 0b5ff0d

File tree

2 files changed

+261
-3
lines changed

2 files changed

+261
-3
lines changed

local-cli/runIOS/__tests__/findMatchingSimulator-test.js

+259-1
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,78 @@ describe('findMatchingSimulator', () => {
149149
});
150150
});
151151

152-
it('should return the botted simulator in list if none is defined', () => {
152+
it('should return the first simulator in list if none is defined', () => {
153+
expect(findMatchingSimulator({
154+
"devices": {
155+
"iOS 9.2": [
156+
{
157+
"state": "Shutdown",
158+
"availability": "(unavailable, runtime profile not found)",
159+
"name": "iPhone 4s",
160+
"udid": "B9B5E161-416B-43C4-A78F-729CB96CC8C6"
161+
},
162+
{
163+
"state": "Shutdown",
164+
"availability": "(available)",
165+
"name": "iPhone 5",
166+
"udid": "1CCBBF8B-5773-4EA6-BD6F-C308C87A1ADB"
167+
},
168+
{
169+
"state": "Shutdown",
170+
"availability": "(available)",
171+
"name": "iPhone 6",
172+
"udid": "BA0D93BD-07E6-4182-9B0A-F60A2474139C"
173+
},
174+
{
175+
"state": "Shutdown",
176+
"availability": "(available)",
177+
"name": "iPhone 6 (Plus)",
178+
"udid": "9564ABEE-9EC2-4B4A-B443-D3710929A45A"
179+
},
180+
{
181+
"state": "Shutdown",
182+
"availability": "(unavailable, runtime profile not found)",
183+
"name": "iPhone 6s",
184+
"udid": "D0F29BE7-CC3C-4976-888D-C739B4F50508"
185+
}
186+
],
187+
"iOS 10.0": [
188+
{
189+
"state": "Shutdown",
190+
"availability": "(available)",
191+
"name": "iPhone 6",
192+
"udid": "2FF48AE5-CC3B-4C80-8D25-48966A6BE2C0"
193+
},
194+
{
195+
"state": "Shutdown",
196+
"availability": "(available)",
197+
"name": "iPhone 6 (Plus)",
198+
"udid": "841E33FE-E8A1-4B65-9FF8-6EAA6442A3FC"
199+
},
200+
{
201+
"state": "Shutdown",
202+
"availability": "(available)",
203+
"name": "iPhone 6s",
204+
"udid": "CBBB8FB8-77AB-49A9-8297-4CCFE3189C22"
205+
},
206+
{
207+
"state": "Shutdown",
208+
"availability": "(available)",
209+
"name": "iPhone 7",
210+
"udid": "3A409DC5-5188-42A6-8598-3AA6F34607A5"
211+
}
212+
]
213+
}
214+
},
215+
null
216+
)).toEqual({
217+
udid: '1CCBBF8B-5773-4EA6-BD6F-C308C87A1ADB',
218+
name: 'iPhone 5',
219+
version: 'iOS 9.2'
220+
});
221+
});
222+
223+
it('should return the booted simulator in list if none is defined', () => {
153224
expect(findMatchingSimulator({
154225
"devices": {
155226
"iOS 9.2": [
@@ -193,4 +264,191 @@ describe('findMatchingSimulator', () => {
193264
version: 'iOS 9.2'
194265
});
195266
});
267+
268+
it('should return the booted simulator in list even if another device is defined', () => {
269+
expect(findMatchingSimulator({
270+
"devices": {
271+
"iOS 9.2": [
272+
{
273+
"state": "Shutdown",
274+
"availability": "(unavailable, runtime profile not found)",
275+
"name": "iPhone 4s",
276+
"udid": "B9B5E161-416B-43C4-A78F-729CB96CC8C6"
277+
},
278+
{
279+
"state": "Shutdown",
280+
"availability": "(available)",
281+
"name": "iPhone 5",
282+
"udid": "1CCBBF8B-5773-4EA6-BD6F-C308C87A1ADB"
283+
},
284+
{
285+
"state": "Shutdown",
286+
"availability": "(available)",
287+
"name": "iPhone 6",
288+
"udid": "BA0D93BD-07E6-4182-9B0A-F60A2474139C"
289+
},
290+
{
291+
"state": "Shutdown",
292+
"availability": "(available)",
293+
"name": "iPhone 6 (Plus)",
294+
"udid": "9564ABEE-9EC2-4B4A-B443-D3710929A45A"
295+
},
296+
{
297+
"state": "Booted",
298+
"availability": "(available)",
299+
"name": "iPhone 6s",
300+
"udid": "D0F29BE7-CC3C-4976-888D-C739B4F50508"
301+
}
302+
]
303+
}
304+
},
305+
"iPhone 6"
306+
)).toEqual({
307+
udid: 'D0F29BE7-CC3C-4976-888D-C739B4F50508',
308+
name: 'iPhone 6s',
309+
version: 'iOS 9.2'
310+
});
311+
});
312+
313+
it('should return the booted simulator in list if none is defined (multi ios versions)', () => {
314+
expect(findMatchingSimulator({
315+
"devices": {
316+
"iOS 9.2": [
317+
{
318+
"state": "Shutdown",
319+
"availability": "(unavailable, runtime profile not found)",
320+
"name": "iPhone 4s",
321+
"udid": "B9B5E161-416B-43C4-A78F-729CB96CC8C6"
322+
},
323+
{
324+
"state": "Shutdown",
325+
"availability": "(available)",
326+
"name": "iPhone 5",
327+
"udid": "1CCBBF8B-5773-4EA6-BD6F-C308C87A1ADB"
328+
},
329+
{
330+
"state": "Shutdown",
331+
"availability": "(available)",
332+
"name": "iPhone 6",
333+
"udid": "BA0D93BD-07E6-4182-9B0A-F60A2474139C"
334+
},
335+
{
336+
"state": "Shutdown",
337+
"availability": "(available)",
338+
"name": "iPhone 6 (Plus)",
339+
"udid": "9564ABEE-9EC2-4B4A-B443-D3710929A45A"
340+
},
341+
{
342+
"state": "Shutdown",
343+
"availability": "(available)",
344+
"name": "iPhone 6s",
345+
"udid": "D0F29BE7-CC3C-4976-888D-C739B4F50508"
346+
}
347+
],
348+
"iOS 10.0": [
349+
{
350+
"state": "Shutdown",
351+
"availability": "(available)",
352+
"name": "iPhone 6",
353+
"udid": "2FF48AE5-CC3B-4C80-8D25-48966A6BE2C0"
354+
},
355+
{
356+
"state": "Shutdown",
357+
"availability": "(available)",
358+
"name": "iPhone 6 (Plus)",
359+
"udid": "841E33FE-E8A1-4B65-9FF8-6EAA6442A3FC"
360+
},
361+
{
362+
"state": "Shutdown",
363+
"availability": "(available)",
364+
"name": "iPhone 6s",
365+
"udid": "CBBB8FB8-77AB-49A9-8297-4CCFE3189C22"
366+
},
367+
{
368+
"state": "Booted",
369+
"availability": "(available)",
370+
"name": "iPhone 7",
371+
"udid": "3A409DC5-5188-42A6-8598-3AA6F34607A5"
372+
}
373+
]
374+
}
375+
},
376+
null
377+
)).toEqual({
378+
udid: '3A409DC5-5188-42A6-8598-3AA6F34607A5',
379+
name: 'iPhone 7',
380+
version: 'iOS 10.0'
381+
});
382+
});
383+
384+
it('should return the booted simulator in list even if another device is defined (multi ios versions)', () => {
385+
expect(findMatchingSimulator({
386+
"devices": {
387+
"iOS 9.2": [
388+
{
389+
"state": "Shutdown",
390+
"availability": "(unavailable, runtime profile not found)",
391+
"name": "iPhone 4s",
392+
"udid": "B9B5E161-416B-43C4-A78F-729CB96CC8C6"
393+
},
394+
{
395+
"state": "Shutdown",
396+
"availability": "(available)",
397+
"name": "iPhone 5",
398+
"udid": "1CCBBF8B-5773-4EA6-BD6F-C308C87A1ADB"
399+
},
400+
{
401+
"state": "Shutdown",
402+
"availability": "(available)",
403+
"name": "iPhone 6",
404+
"udid": "BA0D93BD-07E6-4182-9B0A-F60A2474139C"
405+
},
406+
{
407+
"state": "Shutdown",
408+
"availability": "(available)",
409+
"name": "iPhone 6 (Plus)",
410+
"udid": "9564ABEE-9EC2-4B4A-B443-D3710929A45A"
411+
},
412+
{
413+
"state": "Shutdown",
414+
"availability": "(available)",
415+
"name": "iPhone 6s",
416+
"udid": "D0F29BE7-CC3C-4976-888D-C739B4F50508"
417+
}
418+
],
419+
"iOS 10.0": [
420+
{
421+
"state": "Shutdown",
422+
"availability": "(available)",
423+
"name": "iPhone 6",
424+
"udid": "2FF48AE5-CC3B-4C80-8D25-48966A6BE2C0"
425+
},
426+
{
427+
"state": "Shutdown",
428+
"availability": "(available)",
429+
"name": "iPhone 6 (Plus)",
430+
"udid": "841E33FE-E8A1-4B65-9FF8-6EAA6442A3FC"
431+
},
432+
{
433+
"state": "Shutdown",
434+
"availability": "(available)",
435+
"name": "iPhone 6s",
436+
"udid": "CBBB8FB8-77AB-49A9-8297-4CCFE3189C22"
437+
},
438+
{
439+
"state": "Booted",
440+
"availability": "(available)",
441+
"name": "iPhone 7",
442+
"udid": "3A409DC5-5188-42A6-8598-3AA6F34607A5"
443+
}
444+
]
445+
}
446+
},
447+
"iPhone 6s"
448+
)).toEqual({
449+
udid: '3A409DC5-5188-42A6-8598-3AA6F34607A5',
450+
name: 'iPhone 7',
451+
version: 'iOS 10.0'
452+
});
453+
});
196454
});

local-cli/runIOS/findMatchingSimulator.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ function findMatchingSimulator(simulators, simulatorName) {
4747
version
4848
};
4949
}
50-
if (simulator.name === simulatorName) {
51-
return {
50+
if (simulator.name === simulatorName && !match) {
51+
match = {
5252
udid: simulator.udid,
5353
name: simulator.name,
5454
version

0 commit comments

Comments
 (0)