|
1 | 1 | /** @type {Detox.DetoxConfig} */ |
| 2 | + |
| 3 | +const { execSync } = require('child_process'); |
| 4 | + |
| 5 | +// Currently we only test on `Pixel_4_API_31` |
| 6 | +const specificAvdName = null; |
| 7 | + |
| 8 | +// Returns the AVD name from available installed AVDs |
| 9 | +function getAVDName() { |
| 10 | + try { |
| 11 | + // Execute 'emulator -list-avds' command to get the list of AVDs |
| 12 | + const avdListOutput = execSync('emulator -list-avds').toString(); |
| 13 | + |
| 14 | + // Split the output to get individual AVD names |
| 15 | + const avdList = avdListOutput.trim().split('\n'); |
| 16 | + |
| 17 | + // Assuming you want to use the first AVD from the list, you can modify this logic as needed |
| 18 | + return specificAvdName !== null ? specificAvdName : avdList.length > 0 ? avdList[0] : null; |
| 19 | + } catch (error) { |
| 20 | + console.error('Error while fetching AVD list:', error); |
| 21 | + return null; |
| 22 | + } |
| 23 | +} |
| 24 | + |
| 25 | +// Function to get the latest iOS simulator device type |
| 26 | +function getLatestIphoneSimulatorDeviceType() { |
| 27 | + try { |
| 28 | + // Execute 'xcrun simctl list devices' command to get the list of iOS simulator devices |
| 29 | + const allSimulatorDevices = execSync('xcrun simctl list devices').toString(); |
| 30 | + |
| 31 | + // Filter the output to get the list of iPhone devices |
| 32 | + const filteredDevices = allSimulatorDevices.match(/iPhone[^)]*/g); |
| 33 | + |
| 34 | + // Clean the device names to get the final device type (excluding the device ID) |
| 35 | + const cleanedDevices = filteredDevices.map((device) => device.replace(/\(.*$/, '').trim()); |
| 36 | + |
| 37 | + // Order of iPhone models to prioritize |
| 38 | + const priorityOrder = [/Pro Max/i, /Pro/i, /\d/]; |
| 39 | + |
| 40 | + let selectedDeviceType = null; |
| 41 | + |
| 42 | + // Loop through the priority order and select the first matching device type |
| 43 | + for (const regex of priorityOrder) { |
| 44 | + const matchingDevice = cleanedDevices.find((device) => regex.test(device)); |
| 45 | + if (matchingDevice) { |
| 46 | + selectedDeviceType = matchingDevice; |
| 47 | + break; |
| 48 | + } |
| 49 | + } |
| 50 | + |
| 51 | + // If no matching device is found, default to the last device in the list |
| 52 | + if (!selectedDeviceType) { |
| 53 | + selectedDeviceType = cleanedDevices[cleanedDevices.length - 1]; |
| 54 | + } |
| 55 | + |
| 56 | + // Remove the trailing newline character from the device type |
| 57 | + const trimmedDeviceType = selectedDeviceType.replace('\n', ''); |
| 58 | + |
| 59 | + // Return the final device type |
| 60 | + return trimmedDeviceType; |
| 61 | + } catch (error) { |
| 62 | + console.error('Error while fetching iOS simulator device list:', error); |
| 63 | + return null; |
| 64 | + } |
| 65 | +} |
| 66 | + |
2 | 67 | module.exports = { |
3 | 68 | testRunner: { |
4 | 69 | $0: 'jest', |
@@ -37,13 +102,13 @@ module.exports = { |
37 | 102 | simulator: { |
38 | 103 | type: 'ios.simulator', |
39 | 104 | device: { |
40 | | - type: 'iPhone 13 Pro Max', |
| 105 | + type: getLatestIphoneSimulatorDeviceType(), |
41 | 106 | }, |
42 | 107 | }, |
43 | 108 | emulator: { |
44 | 109 | type: 'android.emulator', |
45 | 110 | device: { |
46 | | - avdName: 'Nexus_6P_API_27', |
| 111 | + avdName: getAVDName(), |
47 | 112 | }, |
48 | 113 | }, |
49 | 114 | }, |
|
0 commit comments