Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,63 @@ import findMatchingSimulator from '../findMatchingSimulator';
jest.dontMock('../findMatchingSimulator');

describe('findMatchingSimulator', () => {
it.each([
['com.apple.CoreSimulator.SimRuntime.iOS-10-3-1', 'iPhone 6', 'iOS 10.3.1'],
['iOS 10.3.1', 'iPhone 6', 'iOS 10.3.1'],
[
'com.apple.CoreSimulator.SimRuntime.iOS-10-3-1',
'iPad Pro (9.7-inch)',
'iOS 10.3.1',
],
[
'com.apple.CoreSimulator.SimRuntime.tvOS-10-2-1',
'Apple TV',
'tvOS 10.2.1',
],
])('should match a patch version in %s for %s', (runtime, name, version) => {
const simulator = {
state: 'Shutdown',
isAvailable: true,
name,
udid: 'B9B5E161-416B-43C4-A78F-729CB96CC8C6',
};

expect(
findMatchingSimulator(
{devices: {[runtime]: [simulator]}},
{simulator: `${name} (${version.split(' ')[1]})`},
),
).toEqual({
udid: simulator.udid,
name,
state: 'Shutdown',
version,
});
});

it.each(['3.1', '10.3.2'])(
'should not match iOS 10.3.1 when version %s is requested',
(version) => {
expect(
findMatchingSimulator(
{
devices: {
'iOS 10.3.1': [
{
state: 'Shutdown',
isAvailable: true,
name: 'iPhone 6',
udid: 'B9B5E161-416B-43C4-A78F-729CB96CC8C6',
},
],
},
},
{simulator: `iPhone 6 (${version})`},
),
).toBeNull();
},
);

it('should find simulator', () => {
expect(
findMatchingSimulator(
Expand Down
11 changes: 6 additions & 5 deletions packages/cli-platform-apple/src/tools/findMatchingSimulator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ function findMatchingSimulator(

if (findOptions && findOptions.simulator) {
const parsedSimulatorName = findOptions.simulator.match(
/(.*)? (?:\((\d+\.\d+)?\))$/,
/^(.*) \((\d+\.\d+(?:\.\d+)?)\)$/,
);
if (parsedSimulatorName && parsedSimulatorName[2] !== undefined) {
simulatorVersion = parsedSimulatorName[2];
Expand All @@ -64,18 +64,19 @@ function findMatchingSimulator(
let version = versionDescriptor;

if (/^com\.apple\.CoreSimulator\.SimRuntime\./g.test(version)) {
// Transform "com.apple.CoreSimulator.SimRuntime.iOS-12-2" into "iOS 12.2"
// Transform runtime identifiers into versions such as "iOS 12.2" or "iOS 10.3.1".
version = version.replace(
/^com\.apple\.CoreSimulator\.SimRuntime\.([^-]+)-([^-]+)-([^-]+)$/g,
'$1 $2.$3',
/^com\.apple\.CoreSimulator\.SimRuntime\.([^-]+)-(\d+(?:-\d+)+)$/,
(_, platform, runtimeVersion) =>
`${platform} ${runtimeVersion.replace(/-/g, '.')}`,
);
}

// Making sure the version of the simulator is an iOS or tvOS (Removes Apple Watch, etc)
if (!version.includes('iOS') && !version.includes('tvOS')) {
continue;
}
if (simulatorVersion && !version.endsWith(simulatorVersion)) {
if (simulatorVersion && !version.endsWith(` ${simulatorVersion}`)) {
continue;
}
for (const i in device) {
Expand Down
2 changes: 1 addition & 1 deletion packages/cli-platform-ios/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ Builds your app and starts it on iOS simulator.

> default: iPhone 14

Explicitly set the simulator to use. Optionally include iOS version between parenthesis at the end to match an exact version, e.g. `"iPhone 6 (10.0)"`.
Explicitly set the simulator to use. Optionally include iOS version between parenthesis at the end to match an exact version, e.g. `"iPhone 6 (10.0)"` or `"iPhone 6 (10.3.1)"`.

Notes: If selected simulator does not exist, cli will try to run fallback simulators in following order:

Expand Down
Loading