|
| 1 | +import { execSync } from 'node:child_process'; |
| 2 | + |
| 3 | +function detectIosSimulatorType() { |
| 4 | + if (process.env.DETOX_IOS_DEVICE_TYPE) { |
| 5 | + return process.env.DETOX_IOS_DEVICE_TYPE; |
| 6 | + } |
| 7 | + |
| 8 | + if (process.platform !== 'darwin') { |
| 9 | + return 'iPhone 14'; |
| 10 | + } |
| 11 | + |
| 12 | + try { |
| 13 | + const output = execSync('xcrun simctl list devices available', { |
| 14 | + stdio: ['ignore', 'pipe', 'ignore'], |
| 15 | + }).toString(); |
| 16 | + |
| 17 | + const lines = output |
| 18 | + .split('\n') |
| 19 | + .map(line => line.trim()) |
| 20 | + .filter(Boolean); |
| 21 | + |
| 22 | + const preferredPrefixes = ['iPhone 17', 'iPhone 16', 'iPhone 15', 'iPhone 14']; |
| 23 | + |
| 24 | + for (const prefix of preferredPrefixes) { |
| 25 | + const line = lines.find(item => item.startsWith(prefix) && item.includes('(')); |
| 26 | + if (line) { |
| 27 | + return line.split(' (')[0]; |
| 28 | + } |
| 29 | + } |
| 30 | + |
| 31 | + const fallbackLine = lines.find( |
| 32 | + item => item.startsWith('iPhone ') && item.includes('('), |
| 33 | + ); |
| 34 | + if (fallbackLine) { |
| 35 | + return fallbackLine.split(' (')[0]; |
| 36 | + } |
| 37 | + } catch { |
| 38 | + // fall through to default |
| 39 | + } |
| 40 | + |
| 41 | + return 'iPhone 14'; |
| 42 | +} |
| 43 | + |
| 44 | +function detectAndroidAvdName() { |
| 45 | + if (process.env.DETOX_AVD_NAME) { |
| 46 | + return process.env.DETOX_AVD_NAME; |
| 47 | + } |
| 48 | + |
| 49 | + if (process.platform !== 'darwin' && process.platform !== 'linux') { |
| 50 | + return 'Pixel_3a_API_33_arm64-v8a'; |
| 51 | + } |
| 52 | + |
| 53 | + try { |
| 54 | + const output = execSync('emulator -list-avds', { |
| 55 | + stdio: ['ignore', 'pipe', 'ignore'], |
| 56 | + }).toString(); |
| 57 | + const avds = output |
| 58 | + .split('\n') |
| 59 | + .map(line => line.trim()) |
| 60 | + .filter(Boolean); |
| 61 | + if (avds.length > 0) { |
| 62 | + return avds[0]; |
| 63 | + } |
| 64 | + } catch { |
| 65 | + // fall through to default |
| 66 | + } |
| 67 | + |
| 68 | + return 'Pixel_3a_API_33_arm64-v8a'; |
| 69 | +} |
| 70 | + |
| 71 | +const iosSimulatorType = detectIosSimulatorType(); |
| 72 | +const androidAvdName = detectAndroidAvdName(); |
| 73 | +const iosSimulatorArch = process.arch === 'arm64' ? 'arm64' : 'x86_64'; |
| 74 | +const iosBuildBase = |
| 75 | + 'xcodebuild -workspace ios/AwesomeProject.xcworkspace -UseNewBuildSystem=NO -scheme AwesomeProject -sdk iphonesimulator -destination "generic/platform=iOS Simulator" -derivedDataPath ios/build'; |
| 76 | + |
| 77 | +const config = { |
| 78 | + logger: { |
| 79 | + level: process.env.CI ? 'debug' : undefined, |
| 80 | + }, |
| 81 | + testRunner: { |
| 82 | + args: { |
| 83 | + config: 'e2e/jest.config.js', |
| 84 | + maxWorkers: process.env.CI ? 2 : undefined, |
| 85 | + _: ['e2e'], |
| 86 | + }, |
| 87 | + }, |
| 88 | + artifacts: { |
| 89 | + plugins: { |
| 90 | + log: process.env.CI ? 'failing' : undefined, |
| 91 | + screenshot: process.env.CI ? 'failing' : undefined, |
| 92 | + }, |
| 93 | + }, |
| 94 | + apps: { |
| 95 | + 'ios.debug': { |
| 96 | + type: 'ios.app', |
| 97 | + binaryPath: 'ios/build/Build/Products/Debug-iphonesimulator/AwesomeProject.app', |
| 98 | + build: `${iosBuildBase} -configuration Debug ARCHS=${iosSimulatorArch} ONLY_ACTIVE_ARCH=YES`, |
| 99 | + start: 'scripts/start-rn.sh ios', |
| 100 | + }, |
| 101 | + 'ios.release': { |
| 102 | + type: 'ios.app', |
| 103 | + binaryPath: |
| 104 | + 'ios/build/Build/Products/Release-iphonesimulator/AwesomeProject.app', |
| 105 | + build: |
| 106 | + `export RCT_NO_LAUNCH_PACKAGER=true && ${iosBuildBase} -configuration Release ARCHS=${iosSimulatorArch} ONLY_ACTIVE_ARCH=YES -quiet`, |
| 107 | + }, |
| 108 | + 'android.debug': { |
| 109 | + type: 'android.apk', |
| 110 | + binaryPath: 'android/app/build/outputs/apk/debug/app-debug.apk', |
| 111 | + build: |
| 112 | + 'cd android && ./gradlew assembleDebug assembleAndroidTest -DtestBuildType=debug', |
| 113 | + start: 'scripts/start-rn.sh android', |
| 114 | + reversePorts: [8081], |
| 115 | + }, |
| 116 | + 'android.release': { |
| 117 | + type: 'android.apk', |
| 118 | + binaryPath: 'android/app/build/outputs/apk/release/app-release.apk', |
| 119 | + build: |
| 120 | + 'cd android && ./gradlew assembleRelease assembleAndroidTest -DtestBuildType=release', |
| 121 | + }, |
| 122 | + }, |
| 123 | + devices: { |
| 124 | + simulator: { |
| 125 | + type: 'ios.simulator', |
| 126 | + device: { |
| 127 | + type: iosSimulatorType, |
| 128 | + }, |
| 129 | + }, |
| 130 | + attached: { |
| 131 | + type: 'android.attached', |
| 132 | + device: { |
| 133 | + adbName: '.*', |
| 134 | + }, |
| 135 | + }, |
| 136 | + emulator: { |
| 137 | + type: 'android.emulator', |
| 138 | + device: { |
| 139 | + avdName: androidAvdName, |
| 140 | + }, |
| 141 | + }, |
| 142 | + }, |
| 143 | + configurations: { |
| 144 | + 'ios.sim.debug': { |
| 145 | + device: 'simulator', |
| 146 | + app: 'ios.debug', |
| 147 | + }, |
| 148 | + 'ios.sim.release': { |
| 149 | + device: 'simulator', |
| 150 | + app: 'ios.release', |
| 151 | + }, |
| 152 | + 'android.att.debug': { |
| 153 | + device: 'attached', |
| 154 | + app: 'android.debug', |
| 155 | + }, |
| 156 | + 'android.att.release': { |
| 157 | + device: 'attached', |
| 158 | + app: 'android.release', |
| 159 | + }, |
| 160 | + 'android.emu.debug': { |
| 161 | + device: 'emulator', |
| 162 | + app: 'android.debug', |
| 163 | + }, |
| 164 | + 'android.emu.release': { |
| 165 | + device: 'emulator', |
| 166 | + app: 'android.release', |
| 167 | + }, |
| 168 | + }, |
| 169 | +}; |
| 170 | + |
| 171 | +export default config; |
0 commit comments