Skip to content

Commit

Permalink
Add iOS platform version automatically in e2e tests
Browse files Browse the repository at this point in the history
When running the iOS e2e tests locally, we no longer require to specify the platform version because we can fetch the available iOS simulator runtimes and pick the latest one.
  • Loading branch information
fluiddot committed Mar 10, 2021
1 parent 8cd45a3 commit d55a5bc
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ const ios = {

exports.iosLocal = {
...ios,
platformVersion: '14.2',
deviceName: 'iPhone 11',
};

Expand Down
37 changes: 37 additions & 0 deletions packages/react-native-editor/__device-tests__/helpers/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,18 @@ const isLocalEnvironment = () => {
return testEnvironment.toLowerCase() === 'local';
};

const getIOSPlatformVersions = () => {
const { runtimes = [] } = JSON.parse(
childProcess.execSync( 'xcrun simctl list runtimes --json' ).toString()
);

return runtimes
.reverse()
.filter(
( { name, isAvailable } ) => name.startsWith( 'iOS' ) && isAvailable
);
};

// Initialises the driver and desired capabilities for appium
const setupDriver = async () => {
const branch = process.env.CIRCLE_BRANCH || '';
Expand Down Expand Up @@ -105,6 +117,31 @@ const setupDriver = async () => {
desiredCaps.app = `sauce-storage:Gutenberg-${ safeBranchName }.app.zip`; // App should be preloaded to sauce storage, this can also be a URL
if ( isLocalEnvironment() ) {
desiredCaps = _.clone( iosLocal );

const iosPlatformVersions = getIOSPlatformVersions();
if ( iosPlatformVersions.length === 0 ) {
throw new Error(
'No iOS simulators available! Please verify that you have iOS simulators installed.'
);
}
// eslint-disable-next-line no-console
console.log(
'Available iOS platform versions:',
iosPlatformVersions.map( ( { name } ) => name )
);

if (
! desiredCaps.platformVersion &&
iosPlatformVersions.length > 0
) {
desiredCaps.platformVersion = iosPlatformVersions[ 0 ].version;

// eslint-disable-next-line no-console
console.log(
`Using iOS ${ desiredCaps.platformVersion } platform version`
);
}

desiredCaps.app = path.resolve( localIOSAppPath );
}
}
Expand Down

0 comments on commit d55a5bc

Please sign in to comment.