Skip to content

Commit 1031872

Browse files
antonychanfacebook-github-bot
authored andcommittedOct 9, 2018
check isAvailable key on simulator object (#21557)
Summary: With the new xcode command line tools (10.1 beta2), running `xcrun simctl list --json devices` seems to gives us a slightly different format than what we were expecting. More specifically, the `availability` key is changed to `isAvailable` and returns `'YES'` if the simulator is available: Before: ```js devices: { 'iOS 9.2': [ { state: 'Shutdown', availability: '(unavailable, runtime profile not found)', name: 'iPhone 4s', udid: 'B9B5E161-416B-43C4-A78F-729CB96CC8C6', }, { state: 'Shutdown', availability: '(unavailable, runtime profile not found)', name: 'iPhone 5', udid: '1CCBBF8B-5773-4EA6-BD6F-C308C87A1ADB', }, ... ] } ``` After: ```js devices: { 'iOS 12.1': [ { state: 'Shutdown', isAvailable: 'YES', name: 'iPhone 6s', udid: 'D0F29BE7-CC3C-4976-888D-C739B4F50508', }, { state: 'Shutdown', isAvailable: 'YES', name: 'iPhone 6', udid: 'BA0D93BD-07E6-4182-9B0A-F60A2474139C', }, ... ] } ``` Without this fix, `npm run ios` is not able to launch the simulator correctly and returns the following error: ``` Could not find iPhone 6 simulator Error: Could not find iPhone 6 simulator at resolve (/Users/antonyc/Projects/AwesomeProject/node_modules/react-native/local-cli/runIOS/runIOS.js:148:13) at new Promise (<anonymous>) at runOnSimulator (/Users/antonyc/Projects/AwesomeProject/node_modules/react-native/local-cli/runIOS/runIOS.js:134:10) at Object.runIOS [as func] (/Users/antonyc/Projects/AwesomeProject/node_modules/react-native/local-cli/runIOS/runIOS.js:106:12) at Promise.resolve.then (/Users/antonyc/Projects/AwesomeProject/node_modules/react-native/local-cli/cliEntry.js:117:22) ``` Pull Request resolved: #21557 Differential Revision: D10248115 Pulled By: TheSavior fbshipit-source-id: 37197bbf828e4a6e254270d46411a6716a91afe3
1 parent a48fce8 commit 1031872

File tree

2 files changed

+56
-1
lines changed

2 files changed

+56
-1
lines changed
 

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

+52
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,58 @@ describe('findMatchingSimulator', () => {
6565
});
6666
});
6767

68+
it('should find simulator with new xcrun format', () => {
69+
expect(
70+
findMatchingSimulator(
71+
{
72+
devices: {
73+
'iOS 12.1': [
74+
{
75+
state: 'Shutdown',
76+
isAvailable: 'YES',
77+
name: 'iPhone 6s',
78+
udid: 'D0F29BE7-CC3C-4976-888D-C739B4F50508',
79+
},
80+
{
81+
state: 'Shutdown',
82+
isAvailable: 'YES',
83+
name: 'iPhone 6',
84+
udid: 'BA0D93BD-07E6-4182-9B0A-F60A2474139C',
85+
},
86+
{
87+
state: 'Shutdown',
88+
isAvailable: 'YES',
89+
name: 'iPhone XS Max',
90+
udid: 'B9B5E161-416B-43C4-A78F-729CB96CC8C6',
91+
availabilityError: '',
92+
},
93+
{
94+
state: 'Shutdown',
95+
isAvailable: 'YES',
96+
name: 'iPad Air',
97+
udid: '1CCBBF8B-5773-4EA6-BD6F-C308C87A1ADB',
98+
availabilityError: '',
99+
},
100+
{
101+
state: 'Shutdown',
102+
isAvailable: 'YES',
103+
name: 'iPad (5th generation)',
104+
udid: '9564ABEE-9EC2-4B4A-B443-D3710929A45A',
105+
availabilityError: '',
106+
},
107+
],
108+
},
109+
},
110+
'iPhone 6',
111+
),
112+
).toEqual({
113+
udid: 'BA0D93BD-07E6-4182-9B0A-F60A2474139C',
114+
name: 'iPhone 6',
115+
booted: false,
116+
version: 'iOS 12.1',
117+
});
118+
});
119+
68120
it('should return null if no simulators available', () => {
69121
expect(
70122
findMatchingSimulator(

‎local-cli/runIOS/findMatchingSimulator.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,10 @@ function findMatchingSimulator(simulators, simulatorName) {
3434
for (let i in devices[version]) {
3535
let simulator = devices[version][i];
3636
// Skipping non-available simulator
37-
if (simulator.availability !== '(available)') {
37+
if (
38+
simulator.availability !== '(available)' &&
39+
simulator.isAvailable !== 'YES'
40+
) {
3841
continue;
3942
}
4043
let booted = simulator.state === 'Booted';

0 commit comments

Comments
 (0)
Please sign in to comment.