Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
async function killAllSimulators () {
if (process.env.CLOUD) {
return;
}
const allDevices = _.flatMap(_.values(await getDevices()));
const bootedDevices = allDevices.filter((device) => device.state === 'Booted');
for (const {udid} of bootedDevices) {
// It is necessary to stop the corresponding xcodebuild process before killing
// the simulator, otherwise it will be automatically restarted
await resetTestProcesses(udid, true);
await shutdown(udid);
}
await simKill();
}
} catch (err) {
log.error(`Error launching instruments: ${err.message}`);
let errIsCatchable = err.message === ERR_NEVER_CHECKED_IN ||
err.message === ERR_CRASHED_ON_STARTUP;
if (!errIsCatchable) {
throw err;
}
if (launchTries <= this.flakeyRetries) {
if (this.gotFBSOpenApplicationError) {
log.debug('Got the FBSOpenApplicationError, not killing the ' +
'sim but leaving it open so the app will launch');
this.gotFBSOpenApplicationError = false; // clear out for next launch
await B.delay(1000);
} else {
if (!this.realDevice) {
await killAllSimulators();
}
await B.delay(5000);
}
} else {
log.errorAndThrow('We exceeded the number of retries allowed for ' +
'instruments to successfully start; failing launch');
}
}
} while (true);
}
} catch (err) {
log.error(`Error launching instruments: ${err.message}`);
let errIsCatchable = err.message === ERR_NEVER_CHECKED_IN ||
err.message === ERR_CRASHED_ON_STARTUP;
if (!errIsCatchable) {
throw err;
}
if (launchTries <= this.flakeyRetries) {
if (this.gotFBSOpenApplicationError) {
log.debug('Got the FBSOpenApplicationError, not killing the ' +
'sim but leaving it open so the app will launch');
this.gotFBSOpenApplicationError = false; // clear out for next launch
await B.delay(1000);
} else {
if (!this.realDevice) {
await killAllSimulators();
}
await B.delay(5000);
}
} else {
log.errorAndThrow('We exceeded the number of retries allowed for ' +
'instruments to successfully start; failing launch');
}
}
} while (true); // eslint-disable-line no-constant-condition
}