From 0b5ff0d2b1b2a032bdb2afaed93baf7621af5037 Mon Sep 17 00:00:00 2001 From: Richard Evans Date: Thu, 1 Dec 2016 09:50:07 -0800 Subject: [PATCH] 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 https://github.com/facebook/react-native/pull/10558 Differential Revision: D4163616 Pulled By: hramos fbshipit-source-id: 26b44fb73ef402ce252e7a754036279e15359170 --- .../__tests__/findMatchingSimulator-test.js | 260 +++++++++++++++++- local-cli/runIOS/findMatchingSimulator.js | 4 +- 2 files changed, 261 insertions(+), 3 deletions(-) diff --git a/local-cli/runIOS/__tests__/findMatchingSimulator-test.js b/local-cli/runIOS/__tests__/findMatchingSimulator-test.js index d3d31f0a4..957f80cf6 100644 --- a/local-cli/runIOS/__tests__/findMatchingSimulator-test.js +++ b/local-cli/runIOS/__tests__/findMatchingSimulator-test.js @@ -149,7 +149,78 @@ describe('findMatchingSimulator', () => { }); }); - it('should return the botted simulator in list if none is defined', () => { + it('should return the first simulator in list if none is defined', () => { + expect(findMatchingSimulator({ + "devices": { + "iOS 9.2": [ + { + "state": "Shutdown", + "availability": "(unavailable, runtime profile not found)", + "name": "iPhone 4s", + "udid": "B9B5E161-416B-43C4-A78F-729CB96CC8C6" + }, + { + "state": "Shutdown", + "availability": "(available)", + "name": "iPhone 5", + "udid": "1CCBBF8B-5773-4EA6-BD6F-C308C87A1ADB" + }, + { + "state": "Shutdown", + "availability": "(available)", + "name": "iPhone 6", + "udid": "BA0D93BD-07E6-4182-9B0A-F60A2474139C" + }, + { + "state": "Shutdown", + "availability": "(available)", + "name": "iPhone 6 (Plus)", + "udid": "9564ABEE-9EC2-4B4A-B443-D3710929A45A" + }, + { + "state": "Shutdown", + "availability": "(unavailable, runtime profile not found)", + "name": "iPhone 6s", + "udid": "D0F29BE7-CC3C-4976-888D-C739B4F50508" + } + ], + "iOS 10.0": [ + { + "state": "Shutdown", + "availability": "(available)", + "name": "iPhone 6", + "udid": "2FF48AE5-CC3B-4C80-8D25-48966A6BE2C0" + }, + { + "state": "Shutdown", + "availability": "(available)", + "name": "iPhone 6 (Plus)", + "udid": "841E33FE-E8A1-4B65-9FF8-6EAA6442A3FC" + }, + { + "state": "Shutdown", + "availability": "(available)", + "name": "iPhone 6s", + "udid": "CBBB8FB8-77AB-49A9-8297-4CCFE3189C22" + }, + { + "state": "Shutdown", + "availability": "(available)", + "name": "iPhone 7", + "udid": "3A409DC5-5188-42A6-8598-3AA6F34607A5" + } + ] + } + }, + null + )).toEqual({ + udid: '1CCBBF8B-5773-4EA6-BD6F-C308C87A1ADB', + name: 'iPhone 5', + version: 'iOS 9.2' + }); + }); + + it('should return the booted simulator in list if none is defined', () => { expect(findMatchingSimulator({ "devices": { "iOS 9.2": [ @@ -193,4 +264,191 @@ describe('findMatchingSimulator', () => { version: 'iOS 9.2' }); }); + + it('should return the booted simulator in list even if another device is defined', () => { + expect(findMatchingSimulator({ + "devices": { + "iOS 9.2": [ + { + "state": "Shutdown", + "availability": "(unavailable, runtime profile not found)", + "name": "iPhone 4s", + "udid": "B9B5E161-416B-43C4-A78F-729CB96CC8C6" + }, + { + "state": "Shutdown", + "availability": "(available)", + "name": "iPhone 5", + "udid": "1CCBBF8B-5773-4EA6-BD6F-C308C87A1ADB" + }, + { + "state": "Shutdown", + "availability": "(available)", + "name": "iPhone 6", + "udid": "BA0D93BD-07E6-4182-9B0A-F60A2474139C" + }, + { + "state": "Shutdown", + "availability": "(available)", + "name": "iPhone 6 (Plus)", + "udid": "9564ABEE-9EC2-4B4A-B443-D3710929A45A" + }, + { + "state": "Booted", + "availability": "(available)", + "name": "iPhone 6s", + "udid": "D0F29BE7-CC3C-4976-888D-C739B4F50508" + } + ] + } + }, + "iPhone 6" + )).toEqual({ + udid: 'D0F29BE7-CC3C-4976-888D-C739B4F50508', + name: 'iPhone 6s', + version: 'iOS 9.2' + }); + }); + + it('should return the booted simulator in list if none is defined (multi ios versions)', () => { + expect(findMatchingSimulator({ + "devices": { + "iOS 9.2": [ + { + "state": "Shutdown", + "availability": "(unavailable, runtime profile not found)", + "name": "iPhone 4s", + "udid": "B9B5E161-416B-43C4-A78F-729CB96CC8C6" + }, + { + "state": "Shutdown", + "availability": "(available)", + "name": "iPhone 5", + "udid": "1CCBBF8B-5773-4EA6-BD6F-C308C87A1ADB" + }, + { + "state": "Shutdown", + "availability": "(available)", + "name": "iPhone 6", + "udid": "BA0D93BD-07E6-4182-9B0A-F60A2474139C" + }, + { + "state": "Shutdown", + "availability": "(available)", + "name": "iPhone 6 (Plus)", + "udid": "9564ABEE-9EC2-4B4A-B443-D3710929A45A" + }, + { + "state": "Shutdown", + "availability": "(available)", + "name": "iPhone 6s", + "udid": "D0F29BE7-CC3C-4976-888D-C739B4F50508" + } + ], + "iOS 10.0": [ + { + "state": "Shutdown", + "availability": "(available)", + "name": "iPhone 6", + "udid": "2FF48AE5-CC3B-4C80-8D25-48966A6BE2C0" + }, + { + "state": "Shutdown", + "availability": "(available)", + "name": "iPhone 6 (Plus)", + "udid": "841E33FE-E8A1-4B65-9FF8-6EAA6442A3FC" + }, + { + "state": "Shutdown", + "availability": "(available)", + "name": "iPhone 6s", + "udid": "CBBB8FB8-77AB-49A9-8297-4CCFE3189C22" + }, + { + "state": "Booted", + "availability": "(available)", + "name": "iPhone 7", + "udid": "3A409DC5-5188-42A6-8598-3AA6F34607A5" + } + ] + } + }, + null + )).toEqual({ + udid: '3A409DC5-5188-42A6-8598-3AA6F34607A5', + name: 'iPhone 7', + version: 'iOS 10.0' + }); + }); + + it('should return the booted simulator in list even if another device is defined (multi ios versions)', () => { + expect(findMatchingSimulator({ + "devices": { + "iOS 9.2": [ + { + "state": "Shutdown", + "availability": "(unavailable, runtime profile not found)", + "name": "iPhone 4s", + "udid": "B9B5E161-416B-43C4-A78F-729CB96CC8C6" + }, + { + "state": "Shutdown", + "availability": "(available)", + "name": "iPhone 5", + "udid": "1CCBBF8B-5773-4EA6-BD6F-C308C87A1ADB" + }, + { + "state": "Shutdown", + "availability": "(available)", + "name": "iPhone 6", + "udid": "BA0D93BD-07E6-4182-9B0A-F60A2474139C" + }, + { + "state": "Shutdown", + "availability": "(available)", + "name": "iPhone 6 (Plus)", + "udid": "9564ABEE-9EC2-4B4A-B443-D3710929A45A" + }, + { + "state": "Shutdown", + "availability": "(available)", + "name": "iPhone 6s", + "udid": "D0F29BE7-CC3C-4976-888D-C739B4F50508" + } + ], + "iOS 10.0": [ + { + "state": "Shutdown", + "availability": "(available)", + "name": "iPhone 6", + "udid": "2FF48AE5-CC3B-4C80-8D25-48966A6BE2C0" + }, + { + "state": "Shutdown", + "availability": "(available)", + "name": "iPhone 6 (Plus)", + "udid": "841E33FE-E8A1-4B65-9FF8-6EAA6442A3FC" + }, + { + "state": "Shutdown", + "availability": "(available)", + "name": "iPhone 6s", + "udid": "CBBB8FB8-77AB-49A9-8297-4CCFE3189C22" + }, + { + "state": "Booted", + "availability": "(available)", + "name": "iPhone 7", + "udid": "3A409DC5-5188-42A6-8598-3AA6F34607A5" + } + ] + } + }, + "iPhone 6s" + )).toEqual({ + udid: '3A409DC5-5188-42A6-8598-3AA6F34607A5', + name: 'iPhone 7', + version: 'iOS 10.0' + }); + }); }); diff --git a/local-cli/runIOS/findMatchingSimulator.js b/local-cli/runIOS/findMatchingSimulator.js index 975ce4089..494ab0810 100644 --- a/local-cli/runIOS/findMatchingSimulator.js +++ b/local-cli/runIOS/findMatchingSimulator.js @@ -47,8 +47,8 @@ function findMatchingSimulator(simulators, simulatorName) { version }; } - if (simulator.name === simulatorName) { - return { + if (simulator.name === simulatorName && !match) { + match = { udid: simulator.udid, name: simulator.name, version