1- const ChildProcess = require ( 'node:child_process' ) ;
2- const { iosDevice } = require ( './ios-devices' ) ;
3-
4- // Should be kept in sync with the constant defined in e2e workflow file
5- const DEFAULT_CI_AVD_NAME = 'e2e_emulator' ;
1+ const AppleDeviceUtil = require ( './ios-devices' ) ;
2+ const AndroidDeviceUtil = require ( './android-devices' ) ;
63
74const isRunningCI = process . env . CI != null ;
85
@@ -12,105 +9,24 @@ const apkBulidArchitecture = isRunningCI ? 'x86_64' : 'arm64-v8a';
129// it is assumed here that arm64-v8a AOSP emulator is not available in local setup.
1310const testButlerApkPath = isRunningCI ? [ '../Example/e2e/apps/test-butler-app-2.2.1.apk' ] : undefined ;
1411
15- function detectLocalAndroidEmulator ( ) {
16- // "RNS_E2E_AVD_NAME" can be set for local developement
17- const avdName = process . env . RNS_AVD_NAME ?? null ;
18- if ( avdName !== null ) {
19- return avdName
20- }
21-
22- // Fallback: try to use Android SDK
23- try {
24- let stdout = ChildProcess . execSync ( "emulator -list-avds" ) ;
25-
26- // Possibly convert Buffer to string
27- if ( typeof stdout !== 'string' ) {
28- stdout = stdout . toString ( ) ;
29- }
30-
31- const avdList = stdout . trim ( ) . split ( '\n' ) . map ( name => name . trim ( ) ) ;
32-
33- if ( avdList . length === 0 ) {
34- throw new Error ( 'No installed AVDs detected on the device' ) ;
35- }
36-
37- // Just select first one in the list.
38- // TODO: consider giving user a choice here.
39- return avdList [ 0 ] ;
40- } catch ( error ) {
41- const errorMessage = `Failed to find Android emulator. Set "RNS_E2E_AVD_NAME" env variable pointing to one. Cause: ${ error } ` ;
42- console . error ( errorMessage ) ;
43- throw new Error ( errorMessage ) ;
44- }
45- }
46-
47- function detectAndroidEmulatorName ( ) {
48- // "RNS_E2E_AVD_NAME" can be set for local developement
49- return isRunningCI ? DEFAULT_CI_AVD_NAME : detectLocalAndroidEmulator ( ) ;
50- }
51-
52- /**
53- * @returns {string | null } Device serial as requested by user, first serial from adb list or null
54- */
55- function resolveAndroidDeviceSerial ( ) {
56- const deviceSerial = process . env . RNS_DEVICE_SERIAL ?? null ;
57-
58- if ( deviceSerial !== null ) {
59- return deviceSerial ;
60- }
61-
62- // Fallback: try to use adb
63- try {
64- let stdout = ChildProcess . execSync ( "adb devices" ) ;
65-
66- // Possibly convert Buffer to string
67- if ( typeof stdout !== 'string' ) {
68- stdout = stdout . toString ( ) ;
69- }
70-
71- /** @type {string } */
72- const stringStdout = stdout ;
73-
74- // Example `adb devices` output:
75- //
76- // List of devices attached
77- // 6lh6huzhr48lu8t8 device
78- // emulator-5554 device
79-
80- const deviceList = stringStdout
81- . trim ( )
82- . split ( '\n' )
83- . map ( line => line . trim ( ) )
84- . filter ( ( line , index ) => line !== '' && index !== 0 ) // empty lines & header
85- . map ( line => line . split ( ' ' , 1 ) [ 0 ] ) ;
86-
87-
88- if ( deviceList . length === 0 ) {
89- throw new Error ( "Seems that the attached device list is empty" ) ;
90- }
91-
92- // Just select first one in the list.
93- // TODO: consider giving user a choice here.
94- return deviceList [ 0 ] ;
95- } catch ( error ) {
96- console . error ( `Failed to find attached device. Try setting "RNS_DEVICE_SERIAL" env variable pointing to one. Cause: ${ error } ` ) ;
97- }
98-
99- return null ;
100- }
101-
10212/**
10313 * The output of this function can be controlled through couple of env vars.
10414 *
10515 * * `RNS_DEVICE_SERIAL` env var can be specified in case of running
106- * tests with an attached device. It can also be an emulator.
16+ * tests with an attached Android device. It can also be an emulator.
10717 * The expected value here is the same as you would pass to `adb -s`.
10818 * You can find device serial by running `adb devices` command.
10919 *
110- * * `RNS_AVD_NAME` env var can be specified in case of running tests on emulator.
20+ * * `RNS_AVD_NAME` env var can be specified in case of running tests on Android emulator.
11121 * The exepected value here is the same as displayed in Android Studio or listed by
11222 * `emulator -list-avds`.
11323 *
24+ * * `RNS_APPLE_SIM_NAME` env var can be set in case of running tests on iOS simulator.
25+ * The expected value here is exactly as one listed in XCode.
26+ *
27+ * * `RNS_IOS_VERSION` env var can be specified to request particular iOS version
28+ * for the given simulator. Note that required SDK & simulators must be installed.
29+ *
11430 * @param {string } applicationName name (FabricExample / ScreensExample)
11531 * @returns {Detox.DetoxConfig }
11632 */
@@ -157,19 +73,22 @@ function commonDetoxConfigFactory(applicationName) {
15773 devices : {
15874 simulator : {
15975 type : 'ios.simulator' ,
160- device : iosDevice ,
76+ device : {
77+ type : AppleDeviceUtil . resolveAppleSimulatorName ( ) ,
78+ os : AppleDeviceUtil . getIOSVersion ( ) ,
79+ } ,
16180 } ,
16281 attached : {
16382 type : 'android.attached' ,
16483 device : {
165- adbName : resolveAndroidDeviceSerial ( ) ,
84+ adbName : AndroidDeviceUtil . resolveAndroidDeviceSerial ( ) ,
16685 } ,
16786 utilBinaryPaths : testButlerApkPath ,
16887 } ,
16988 emulator : {
17089 type : 'android.emulator' ,
17190 device : {
172- avdName : detectAndroidEmulatorName ( ) ,
91+ avdName : AndroidDeviceUtil . detectAndroidEmulatorName ( ) ,
17392 } ,
17493 utilBinaryPaths : testButlerApkPath ,
17594 } ,
0 commit comments