|
| 1 | +import { execSync, spawnSync } from 'child_process'; |
| 2 | +import { getSimulatorUDID, isSimulatorBooted } from './ios_shared'; |
| 3 | +import { sleep } from './shared'; |
| 4 | + |
| 5 | +const START_CHUNK = 6; |
| 6 | +const MAX_SIMULATORS = 12; |
| 7 | + |
| 8 | +function bootSimulator(udid: string, label: number) { |
| 9 | + try { |
| 10 | + console.log(`Booting simulator ${label}: ${udid}`); |
| 11 | + const result = execSync(`xcrun simctl boot ${udid}`, { stdio: 'pipe' }).toString(); |
| 12 | + console.log(`Boot command output: ${result}`); |
| 13 | + } catch (error: any) { |
| 14 | + console.error(`Error: Boot command failed for ${udid}`); |
| 15 | + console.error(error.stderr?.toString() || error.message); |
| 16 | + return false; |
| 17 | + } |
| 18 | + |
| 19 | + return true; |
| 20 | +} |
| 21 | + |
| 22 | +async function startSimulatorsFromEnvIOS() { |
| 23 | + console.log("Starting iOS simulators from environment variables..."); |
| 24 | + |
| 25 | + const simulators = []; |
| 26 | + for (let i = 1; i <= MAX_SIMULATORS; i++) { |
| 27 | + const udid = getSimulatorUDID(i); |
| 28 | + if (!udid) { |
| 29 | + throw new Error(`Error: Simulator ${i} (IOS_${i}_SIMULATOR) is not set`); |
| 30 | + } |
| 31 | + simulators.push({ label: i, udid }); |
| 32 | + } |
| 33 | + |
| 34 | + for (let i = 0; i < simulators.length; i += START_CHUNK) { |
| 35 | + const chunk = simulators.slice(i, i + START_CHUNK); |
| 36 | + |
| 37 | + for (const sim of chunk) { |
| 38 | + const success = bootSimulator(sim.udid, sim.label); |
| 39 | + if (!success) throw new Error(`Failed to boot simulator with parameters: ${sim.udid}:${sim.label}`); |
| 40 | + } |
| 41 | + |
| 42 | + // Wait for simulators to boot |
| 43 | + await sleep(5000); |
| 44 | + |
| 45 | + for (const sim of chunk) { |
| 46 | + const booted = isSimulatorBooted(sim.udid); |
| 47 | + console.log(`Post-boot status for ${sim.udid}: ${booted ? 'Booted' : 'Not booted'}`); |
| 48 | + if (!booted) { |
| 49 | + console.error(`Error: Simulator ${sim.udid} did not boot successfully.`); |
| 50 | + return; |
| 51 | + } |
| 52 | + } |
| 53 | + } |
| 54 | + |
| 55 | + console.log("Opening iOS Simulator app..."); |
| 56 | + spawnSync('open', ['-a', 'Simulator']); |
| 57 | +} |
| 58 | + |
| 59 | +startSimulatorsFromEnvIOS(); |
0 commit comments