Skip to content

Commit

Permalink
fix: pick selected simulator when defined instead of last booted (rea…
Browse files Browse the repository at this point in the history
…ct-native-community#1709)

* docs: fix missing codeblock langs & typos

* feat: add iPhone 14 as fallback simulator

* feat: add last booted simulator pick, if no other matches the finder

* fix: pick selected simulator when defined instead of last booted
  • Loading branch information
slavikdenis authored Oct 4, 2022
1 parent 49a945d commit e89f296
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1020,4 +1020,48 @@ describe('findMatchingSimulator', () => {
version: 'iOS 16.0',
});
});

it('should return picked simulator instead of last booted simulator in list (multi ios versions)', () => {
expect(
findMatchingSimulator(
{
devices: {
'com.apple.CoreSimulator.SimRuntime.iOS-16-0': [
{
udid: 'E1C0E452-2671-4EB5-B875-58E3DDC6EE81',
isAvailable: false,
state: 'Shutdown',
name: 'iPhone SE (3rd generation)',
},
{
lastBootedAt: '2022-09-21T11:38:28Z',
udid: '3AA90A75-D9C3-41A6-8DE1-43BE74A0C32B',
isAvailable: true,
state: 'Shutdown',
name: 'iPhone 14',
},
{
udid: '6F2FA108-AC7D-4D3C-BD13-56C5E7FCEDFE',
isAvailable: true,
state: 'Shutdown',
name: 'iPhone 14 Plus',
},
{
udid: 'D87B6D9E-F5B0-486F-BBE3-6EEC5A6D0C22',
isAvailable: false,
state: 'Shutdown',
name: 'iPhone 14 Pro',
},
],
},
},
{simulator: 'iPhone 14 Plus'},
),
).toEqual({
udid: '6F2FA108-AC7D-4D3C-BD13-56C5E7FCEDFE',
name: 'iPhone 14 Plus',
booted: false,
version: 'iOS 16.0',
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ function findMatchingSimulator(
}

let match;
let fallbackMatch;

for (const versionDescriptor in devices) {
const device = devices[versionDescriptor];
let version = versionDescriptor;
Expand Down Expand Up @@ -102,7 +104,7 @@ function findMatchingSimulator(
}
// If no match found, use first available simulator that was booted before
if (!!lastBootedAt && !match) {
match = simulatorDescriptor;
fallbackMatch = simulatorDescriptor;
}
// Keeps track of the first available simulator for use if we can't find one above.
if (simulatorName === null && !match) {
Expand All @@ -112,7 +114,7 @@ function findMatchingSimulator(
}
}

return match ?? null;
return match ?? fallbackMatch ?? null;
}

export default findMatchingSimulator;

0 comments on commit e89f296

Please sign in to comment.