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 shutdownOtherSimulators (currentDevice) {
const allDevices = _.flatMap(_.values(await getDevices()));
const otherBootedDevices = allDevices.filter((device) => device.udid !== currentDevice.udid && device.state === 'Booted');
if (_.isEmpty(otherBootedDevices)) {
log.info('No other running simulators have been detected');
return;
}
log.info(`Detected ${otherBootedDevices.length} other running Simulator${otherBootedDevices.length === 1 ? '' : 's'}.` +
`Shutting ${otherBootedDevices.length === 1 ? 'it' : 'them'} down...`);
for (const {udid} of otherBootedDevices) {
// 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);
}
}
async function shutdownSimulator (device) {
// stop XCTest processes if running to avoid unexpected side effects
await resetTestProcesses(device.udid, true);
await device.shutdown();
}
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();
}
async startWda (sessionId, realDevice) {
this.wda = new WebDriverAgent(this.xcodeVersion, this.opts);
// Don't cleanup the processes if webDriverAgentUrl is set
if (!util.hasValue(this.wda.webDriverAgentUrl)) {
await this.wda.cleanupObsoleteProcesses();
}
const usePortForwarding = this.isRealDevice()
&& !this.wda.webDriverAgentUrl
&& isLocalHost(this.wda.wdaBaseUrl);
await DEVICE_CONNECTIONS_FACTORY.requestConnection(this.opts.udid, this.wda.url.port, {
devicePort: this.wda.wdaRemotePort,
usePortForwarding,
});
// Let multiple WDA binaries with different derived data folders be built in parallel
// Concurrent WDA builds from the same source will cause xcodebuild synchronization errors
async function updateProjectFile (agentPath, newBundleId) {
let projectFilePath = `${agentPath}/${PROJECT_FILE}`;
try {
// Assuming projectFilePath is in the correct state, create .old from projectFilePath
await fs.copyFile(projectFilePath, `${projectFilePath}.old`);
await replaceInFile(projectFilePath, new RegExp(WDA_RUNNER_BUNDLE_ID.replace('.', '\.'), 'g'), newBundleId); // eslint-disable-line no-useless-escape
log.debug(`Successfully updated '${projectFilePath}' with bundle id '${newBundleId}'`);
} catch (err) {
log.debug(`Error updating project file: ${err.message}`);
log.warn(`Unable to update project file '${projectFilePath}' with ` +
`bundle id '${newBundleId}'. WebDriverAgent may not start`);
}
}
async fetchWDABundle () {
if (!this.derivedDataPath) {
return await bundleWDASim();
}
const wdaBundlePath = await fs.walkDir(this.derivedDataPath, true, (item) => item.endsWith('WebDriverAgentRunner-Runner.app'));
if (!wdaBundlePath) {
throw new Error(`Couldn't find the WDA bundle in the ${this.derivedDataPath}`);
}
return wdaBundlePath;
}