Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: bump generic iPhone for iOS 13.0 #1068

Merged
merged 1 commit into from
Sep 16, 2019
Merged
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
10 changes: 10 additions & 0 deletions lib/ios-generic-simulators.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
export default {
'ipad simulator': [
['0.0', 'iPad Retina'],
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might be worth noting that these need to be strictly in order, or the parsing logic won't work.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right. Maybe I should just sort them

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I sort them now to be safe.

['10.3', 'iPad Air'],
],
'iphone simulator': [
['0.0', 'iPhone 6'],
['13.0', 'iPhone X'],
]
};
47 changes: 32 additions & 15 deletions lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { SubProcess, exec } from 'teen_process';
import xcode from 'appium-xcode';
import _ from 'lodash';
import log from './logger';
import iosGenericSimulators from './ios-generic-simulators';
import _fs from 'fs';
import url from 'url';
import v8 from 'v8';
Expand Down Expand Up @@ -57,21 +58,37 @@ async function getAndCheckIosSdkVersion () {
}
}

function translateDeviceName (platformVersion, devName = '') {
let deviceName = devName;
switch (devName.toLowerCase().trim()) {
case 'iphone simulator':
deviceName = 'iPhone 6';
break;
case 'ipad simulator':
// iPad Retina is no longer available for ios 10.3
// so we pick another iPad to use as default
deviceName = platformVersion && util.compareVersions(platformVersion, '<', '10.3') ? 'iPad Retina' : 'iPad Air';
break;
}

if (deviceName !== devName) {
log.debug(`Changing deviceName from '${devName}' to '${deviceName}'`);
/**
* Get the generic simulator for a given IOS version and device type (iPhone, iPad)
*
* @param {string|number} platformVersion IOS version. e.g.) 13.0
* @param {string} deviceName Type of IOS device. Can be iPhone, iPad (possibly more in the future)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missing return description

*
* @returns {string} Generic iPhone or iPad simulator (if applicable)
*/
function getGenericSimulatorForIosVersion (platformVersion, deviceName) {
let genericSimulators = iosGenericSimulators[deviceName];

if (genericSimulators) {
genericSimulators = genericSimulators.sort(([simOne], [simTwo]) => util.compareVersions(simOne, '<', simTwo) ? -1 : 1);

// Find the highest iOS version in the list that is below the provided version
let genericIosSimulator;
for (const [platformVersionFromList, iosSimulator] of genericSimulators) {
if (util.compareVersions(platformVersionFromList, '>', platformVersion)) {
break;
}
genericIosSimulator = iosSimulator;
}
return genericIosSimulator;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can the result be undefined?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No. The lowest iOS version in the list is 0.0 so every iOS version we test it against will be above that.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it makes sense to leave a comment about that

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I changed it so now it can be undefined and translateDeviceName handles that case.

}
}

function translateDeviceName (platformVersion, deviceName = '') {
const deviceNameTranslated = getGenericSimulatorForIosVersion(platformVersion, deviceName.toLowerCase().trim());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is it necessary to change the device name to lower case?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mykola-mokhnach yeah if somebody provides iPhone Simulator we want it to be case-insensitive.

if (deviceNameTranslated) {
log.debug(`Changing deviceName from '${deviceName}' to '${deviceNameTranslated}'`);
return deviceNameTranslated;
}
return deviceName;
}
Expand Down
26 changes: 22 additions & 4 deletions test/unit/utils-specs.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,20 +66,38 @@ describe('utils', function () {
}));

describe('determineDevice', function () {
const ipadDeviceName = 'iPad Simulator';
const iphoneDeviceName = 'iPhone Simulator';
const outrageouslyHighIosVersion = '999999.999999';

it('should set the correct iPad simulator generic device', function () {
const ipadDeviceName = 'iPad Simulator';
let deviceName = translateDeviceName('10.1.2', ipadDeviceName);
deviceName.should.equal('iPad Retina');
deviceName = translateDeviceName(10.103, ipadDeviceName);
});
it('should set the correct iPad simulator generic device for iOS >= 10.3', function () {
let deviceName = translateDeviceName(10.103, ipadDeviceName);
deviceName.should.equal('iPad Air');
deviceName = translateDeviceName('10.3', ipadDeviceName);
deviceName.should.equal('iPad Air');
deviceName = translateDeviceName(10.3, ipadDeviceName);
deviceName.should.equal('iPad Air');
});
it('should set the correct iPhone simulator generic device', function () {
let deviceName = translateDeviceName(10.3, 'iPhone Simulator');
deviceName.should.equal('iPhone 6');
translateDeviceName('0.0', iphoneDeviceName).should.equal('iPhone 6');
translateDeviceName('10.3', iphoneDeviceName).should.equal('iPhone 6');
});
it('should set the correct iPhone simulator generic device for simulators gte iOS 13.0', function () {
translateDeviceName('13.0', iphoneDeviceName).should.equal('iPhone X');
});
it('should set the default iPhone simulator to the highest generic device that is defined in ios-generic-simulators.js', function () {
// The highest iOS version we define for iPhone in ios-generic-simulators.js is currently iOS 13.0
// If this changes, update this test
translateDeviceName(outrageouslyHighIosVersion, iphoneDeviceName).should.equal('iPhone X');
});
it('should set the default iPad simulator to the highest generic device that is defined in ios-generic-simulators.js', function () {
// The highest iOS version for iPad we define in ios-generic-simulators.js is currently iOS 10.3
// If this changes, update this test
translateDeviceName(outrageouslyHighIosVersion, ipadDeviceName).should.equal('iPad Air');
});
});

Expand Down