detox 21.0.0-rc.5 → 21.0.0-rc.7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (186) hide show
  1. package/.eslintignore +1 -0
  2. package/Detox-android/com/wix/detox/{21.0.0-rc.5/detox-21.0.0-rc.5-javadoc.jar → 21.0.0-rc.7/detox-21.0.0-rc.7-javadoc.jar} +0 -0
  3. package/Detox-android/com/wix/detox/21.0.0-rc.7/detox-21.0.0-rc.7-javadoc.jar.md5 +1 -0
  4. package/Detox-android/com/wix/detox/21.0.0-rc.7/detox-21.0.0-rc.7-javadoc.jar.sha1 +1 -0
  5. package/Detox-android/com/wix/detox/21.0.0-rc.7/detox-21.0.0-rc.7-javadoc.jar.sha256 +1 -0
  6. package/Detox-android/com/wix/detox/21.0.0-rc.7/detox-21.0.0-rc.7-javadoc.jar.sha512 +1 -0
  7. package/Detox-android/com/wix/detox/{21.0.0-rc.5/detox-21.0.0-rc.5-sources.jar → 21.0.0-rc.7/detox-21.0.0-rc.7-sources.jar} +0 -0
  8. package/Detox-android/com/wix/detox/21.0.0-rc.7/detox-21.0.0-rc.7-sources.jar.md5 +1 -0
  9. package/Detox-android/com/wix/detox/21.0.0-rc.7/detox-21.0.0-rc.7-sources.jar.sha1 +1 -0
  10. package/Detox-android/com/wix/detox/21.0.0-rc.7/detox-21.0.0-rc.7-sources.jar.sha256 +1 -0
  11. package/Detox-android/com/wix/detox/21.0.0-rc.7/detox-21.0.0-rc.7-sources.jar.sha512 +1 -0
  12. package/Detox-android/com/wix/detox/21.0.0-rc.7/detox-21.0.0-rc.7.aar +0 -0
  13. package/Detox-android/com/wix/detox/21.0.0-rc.7/detox-21.0.0-rc.7.aar.md5 +1 -0
  14. package/Detox-android/com/wix/detox/21.0.0-rc.7/detox-21.0.0-rc.7.aar.sha1 +1 -0
  15. package/Detox-android/com/wix/detox/21.0.0-rc.7/detox-21.0.0-rc.7.aar.sha256 +1 -0
  16. package/Detox-android/com/wix/detox/21.0.0-rc.7/detox-21.0.0-rc.7.aar.sha512 +1 -0
  17. package/Detox-android/com/wix/detox/{21.0.0-rc.5/detox-21.0.0-rc.5.pom → 21.0.0-rc.7/detox-21.0.0-rc.7.pom} +1 -7
  18. package/Detox-android/com/wix/detox/21.0.0-rc.7/detox-21.0.0-rc.7.pom.md5 +1 -0
  19. package/Detox-android/com/wix/detox/21.0.0-rc.7/detox-21.0.0-rc.7.pom.sha1 +1 -0
  20. package/Detox-android/com/wix/detox/21.0.0-rc.7/detox-21.0.0-rc.7.pom.sha256 +1 -0
  21. package/Detox-android/com/wix/detox/21.0.0-rc.7/detox-21.0.0-rc.7.pom.sha512 +1 -0
  22. package/Detox-android/com/wix/detox/maven-metadata.xml +4 -4
  23. package/Detox-android/com/wix/detox/maven-metadata.xml.md5 +1 -1
  24. package/Detox-android/com/wix/detox/maven-metadata.xml.sha1 +1 -1
  25. package/Detox-android/com/wix/detox/maven-metadata.xml.sha256 +1 -1
  26. package/Detox-android/com/wix/detox/maven-metadata.xml.sha512 +1 -1
  27. package/Detox-ios-framework.tbz +0 -0
  28. package/Detox-ios-src.tbz +0 -0
  29. package/Detox-ios-xcuitest.tbz +0 -0
  30. package/android/build.gradle +1 -1
  31. package/android/detox/build.gradle +13 -8
  32. package/android/detox/src/full/java/com/wix/detox/espresso/DetoxAssertion.java +44 -25
  33. package/android/detox/src/full/java/com/wix/detox/espresso/EspressoDetox.java +6 -7
  34. package/android/detox/src/full/java/com/wix/detox/espresso/action/AdjustSliderToPositionAction.kt +2 -2
  35. package/android/detox/src/full/java/com/wix/detox/espresso/action/GetAttributesAction.kt +34 -35
  36. package/android/detox/src/full/java/com/wix/detox/espresso/common/MaterialSliderHelper.kt +21 -0
  37. package/android/detox/src/full/java/com/wix/detox/espresso/common/{SliderHelper.kt → ReactSliderHelper.kt} +6 -5
  38. package/android/detox/src/full/java/com/wix/detox/espresso/matcher/ViewMatchers.kt +2 -2
  39. package/android/detox/src/full/java/com/wix/detox/espresso/performer/MultipleViewsActionPerformer.kt +43 -0
  40. package/android/detox/src/full/java/com/wix/detox/espresso/performer/SingleViewActionPerformer.kt +19 -0
  41. package/android/detox/src/full/java/com/wix/detox/espresso/performer/ViewActionPerformer.kt +24 -0
  42. package/android/detox/src/full/java/com/wix/detox/espresso/web/WebElement.java +4 -4
  43. package/android/detox/src/full/java/com/wix/invoke/types/Invocation.java +7 -6
  44. package/android/detox/src/main/java/com/wix/detox/espresso/MultipleViewsAction.kt +4 -0
  45. package/android/detox/src/main/java/com/wix/detox/espresso/UiControllerSpy.kt +0 -1
  46. package/android/detox/src/main/java/com/wix/detox/espresso/ViewActionWithResult.kt +2 -1
  47. package/android/detox/src/main/java/com/wix/detox/espresso/action/common/MotionEvents.kt +60 -4
  48. package/android/detox/src/testFull/java/com/wix/detox/espresso/action/GetAttributesActionTest.kt +6 -5
  49. package/android/detox/src/testFull/java/com/wix/detox/espresso/common/MaterialSliderHelperTest.kt +33 -0
  50. package/android/detox/src/testFull/java/com/wix/detox/espresso/common/{SliderHelperTest.kt → ReactSliderHelperTest.kt} +3 -3
  51. package/android/detox/src/testFull/java/com/wix/detox/espresso/performer/ViewActionPerformerSpec.kt +37 -0
  52. package/android/detox/src/testFull/java/com/wix/invoke/JsonParserTest.java +23 -7
  53. package/android/detox/src/testFull/resources/targetInvocationEspressoWebDetoxScript.json +47 -0
  54. package/android/rninfo.gradle +3 -3
  55. package/detox.d.ts +1830 -0
  56. package/globals.d.ts +23 -0
  57. package/index.d.ts +2 -1823
  58. package/internals.d.ts +11 -1
  59. package/jest.config.js +108 -0
  60. package/local-cli/reset-lock-file.js +5 -9
  61. package/local-cli/testCommand/TestRunnerCommand.js +26 -3
  62. package/local-cli/utils/interruptListeners.js +15 -0
  63. package/package.json +2 -100
  64. package/runners/jest/reporter.js +21 -1
  65. package/runners/jest/reporters/DetoxIPCReporter.js +34 -0
  66. package/runners/jest/reporters/DetoxReporterDispatcher.js +144 -0
  67. package/runners/jest/reporters/DetoxSummaryReporter.js +16 -0
  68. package/runners/jest/reporters/DetoxVerboseReporter.js +16 -0
  69. package/runners/jest/reporters/index.js +6 -0
  70. package/runners/jest/testEnvironment/index.js +11 -0
  71. package/src/DetoxWorker.js +5 -11
  72. package/src/android/core/NativeElement.js +26 -29
  73. package/src/android/core/WebElement.js +24 -6
  74. package/src/android/espressoapi/DetoxAssertion.js +16 -14
  75. package/src/android/espressoapi/EspressoDetox.js +9 -2
  76. package/src/android/espressoapi/web/WebElement.js +1 -4
  77. package/src/android/interactions/native.js +2 -3
  78. package/src/artifacts/providers/index.js +3 -3
  79. package/src/artifacts/screenshot/SimulatorScreenshotPlugin.js +0 -17
  80. package/src/configuration/composeLoggerConfig.js +1 -0
  81. package/src/configuration/composeRunnerConfig.js +3 -1
  82. package/src/devices/allocation/DeviceAllocator.js +66 -20
  83. package/src/devices/allocation/DeviceList.js +44 -0
  84. package/src/devices/allocation/DeviceRegistry.js +189 -0
  85. package/src/devices/allocation/drivers/AllocationDriverBase.d.ts +15 -0
  86. package/src/devices/{common/drivers/android/tools → allocation/drivers/android}/FreeDeviceFinder.js +11 -10
  87. package/src/devices/allocation/drivers/android/attached/AttachedAndroidAllocDriver.js +22 -17
  88. package/src/devices/allocation/drivers/android/emulator/EmulatorAllocDriver.js +97 -38
  89. package/src/devices/allocation/drivers/android/emulator/EmulatorLauncher.js +32 -45
  90. package/src/devices/allocation/drivers/android/emulator/FreeEmulatorFinder.js +1 -1
  91. package/src/devices/allocation/drivers/android/emulator/FreePortFinder.js +37 -0
  92. package/src/devices/allocation/drivers/android/emulator/launchEmulatorProcess.js +3 -3
  93. package/src/devices/allocation/drivers/android/genycloud/GenyAllocDriver.js +104 -32
  94. package/src/devices/allocation/drivers/android/genycloud/GenyInstanceLauncher.js +40 -31
  95. package/src/devices/allocation/drivers/android/genycloud/GenyRegistry.js +121 -0
  96. package/src/devices/allocation/drivers/android/genycloud/services/GenyInstanceLifecycleService.js +24 -0
  97. package/src/devices/{common → allocation}/drivers/android/genycloud/services/GenyRecipesService.js +1 -1
  98. package/src/devices/allocation/drivers/android/genycloud/services/dto/GenyInstance.js +83 -0
  99. package/src/devices/allocation/drivers/android/genycloud/services/dto/GenyRecipe.js +25 -0
  100. package/src/devices/allocation/drivers/ios/SimulatorAllocDriver.js +95 -54
  101. package/src/devices/allocation/drivers/ios/SimulatorQuery.js +24 -0
  102. package/src/devices/allocation/factories/android.js +29 -35
  103. package/src/devices/allocation/factories/ios.js +6 -7
  104. package/src/devices/common/drivers/DeviceCookie.d.ts +12 -0
  105. package/src/devices/common/drivers/android/cookies.d.ts +11 -0
  106. package/src/devices/common/drivers/android/emulator/exec/EmulatorExec.js +17 -5
  107. package/src/devices/common/drivers/android/exec/ADB.js +1 -0
  108. package/src/devices/common/drivers/android/tools/instrumentationArgs.js +7 -1
  109. package/src/devices/common/drivers/ios/cookies.d.ts +9 -0
  110. package/src/devices/common/drivers/ios/tools/AppleSimUtils.js +3 -1
  111. package/src/devices/cookies/index.js +0 -6
  112. package/src/devices/runtime/drivers/android/genycloud/GenyCloudDriver.js +7 -6
  113. package/src/devices/runtime/drivers/ios/SimulatorDriver.js +5 -4
  114. package/src/devices/runtime/drivers/ios/XCUITestUtils.js +18 -7
  115. package/src/devices/runtime/factories/android.js +3 -11
  116. package/src/devices/runtime/factories/ios.js +3 -4
  117. package/src/{servicelocator → devices/servicelocator}/android/emulatorServiceLocator.js +1 -1
  118. package/src/devices/servicelocator/android/genycloudServiceLocator.js +17 -0
  119. package/src/devices/servicelocator/android/index.js +23 -0
  120. package/src/{validation → devices/validation}/EnvironmentValidatorBase.js +1 -0
  121. package/src/{validation → devices/validation}/android/GenycloudEnvValidator.js +2 -2
  122. package/src/{validation → devices/validation}/factories/index.js +1 -1
  123. package/src/{validation → devices/validation}/ios/IosSimulatorEnvValidator.js +2 -2
  124. package/src/environmentFactory.js +1 -11
  125. package/src/ios/web.js +21 -5
  126. package/src/ipc/IPCClient.js +22 -1
  127. package/src/ipc/IPCServer.js +42 -1
  128. package/src/ipc/SessionState.js +1 -0
  129. package/src/logger/DetoxLogger.js +2 -2
  130. package/src/realms/DetoxContext.js +8 -0
  131. package/src/realms/DetoxInternalsFacade.js +1 -0
  132. package/src/realms/DetoxPrimaryContext.js +48 -42
  133. package/src/realms/DetoxSecondaryContext.js +27 -0
  134. package/src/realms/symbols.js +6 -0
  135. package/src/utils/PIDService.js +27 -0
  136. package/src/utils/assertIsFunction.js +35 -0
  137. package/src/utils/environment.js +8 -15
  138. package/src/utils/errorUtils.js +3 -3
  139. package/src/utils/isArrowFunction.js +24 -0
  140. package/tsconfig.json +8 -3
  141. package/Detox-android/com/wix/detox/21.0.0-rc.5/detox-21.0.0-rc.5-javadoc.jar.md5 +0 -1
  142. package/Detox-android/com/wix/detox/21.0.0-rc.5/detox-21.0.0-rc.5-javadoc.jar.sha1 +0 -1
  143. package/Detox-android/com/wix/detox/21.0.0-rc.5/detox-21.0.0-rc.5-javadoc.jar.sha256 +0 -1
  144. package/Detox-android/com/wix/detox/21.0.0-rc.5/detox-21.0.0-rc.5-javadoc.jar.sha512 +0 -1
  145. package/Detox-android/com/wix/detox/21.0.0-rc.5/detox-21.0.0-rc.5-sources.jar.md5 +0 -1
  146. package/Detox-android/com/wix/detox/21.0.0-rc.5/detox-21.0.0-rc.5-sources.jar.sha1 +0 -1
  147. package/Detox-android/com/wix/detox/21.0.0-rc.5/detox-21.0.0-rc.5-sources.jar.sha256 +0 -1
  148. package/Detox-android/com/wix/detox/21.0.0-rc.5/detox-21.0.0-rc.5-sources.jar.sha512 +0 -1
  149. package/Detox-android/com/wix/detox/21.0.0-rc.5/detox-21.0.0-rc.5.aar +0 -0
  150. package/Detox-android/com/wix/detox/21.0.0-rc.5/detox-21.0.0-rc.5.aar.md5 +0 -1
  151. package/Detox-android/com/wix/detox/21.0.0-rc.5/detox-21.0.0-rc.5.aar.sha1 +0 -1
  152. package/Detox-android/com/wix/detox/21.0.0-rc.5/detox-21.0.0-rc.5.aar.sha256 +0 -1
  153. package/Detox-android/com/wix/detox/21.0.0-rc.5/detox-21.0.0-rc.5.aar.sha512 +0 -1
  154. package/Detox-android/com/wix/detox/21.0.0-rc.5/detox-21.0.0-rc.5.pom.md5 +0 -1
  155. package/Detox-android/com/wix/detox/21.0.0-rc.5/detox-21.0.0-rc.5.pom.sha1 +0 -1
  156. package/Detox-android/com/wix/detox/21.0.0-rc.5/detox-21.0.0-rc.5.pom.sha256 +0 -1
  157. package/Detox-android/com/wix/detox/21.0.0-rc.5/detox-21.0.0-rc.5.pom.sha512 +0 -1
  158. package/runners/jest/reporters/DetoxReporter.js +0 -36
  159. package/src/devices/DeviceRegistry.js +0 -176
  160. package/src/devices/allocation/drivers/AllocationDriverBase.js +0 -30
  161. package/src/devices/allocation/drivers/android/attached/AttachedAndroidLauncher.js +0 -13
  162. package/src/devices/allocation/drivers/android/emulator/EmulatorAllocationHelper.js +0 -72
  163. package/src/devices/allocation/drivers/android/genycloud/GenyDeviceRegistryFactory.js +0 -16
  164. package/src/devices/allocation/drivers/android/genycloud/GenyInstanceAllocationHelper.js +0 -65
  165. package/src/devices/allocation/drivers/ios/SimulatorLauncher.js +0 -21
  166. package/src/devices/common/drivers/DeviceAllocationHelper.js +0 -20
  167. package/src/devices/common/drivers/DeviceLauncher.js +0 -19
  168. package/src/devices/common/drivers/android/genycloud/services/GenyInstanceLifecycleService.js +0 -25
  169. package/src/devices/common/drivers/android/genycloud/services/GenyInstanceLookupService.js +0 -38
  170. package/src/devices/common/drivers/android/genycloud/services/GenyInstanceNaming.js +0 -14
  171. package/src/devices/common/drivers/android/genycloud/services/dto/GenyInstance.js +0 -66
  172. package/src/devices/common/drivers/android/genycloud/services/dto/GenyRecipe.js +0 -13
  173. package/src/devices/cookies/AndroidDeviceCookie.js +0 -13
  174. package/src/devices/cookies/AndroidEmulatorCookie.js +0 -6
  175. package/src/devices/cookies/AttachedAndroidDeviceCookie.js +0 -12
  176. package/src/devices/cookies/DeviceCookie.js +0 -4
  177. package/src/devices/cookies/GenycloudEmulatorCookie.js +0 -20
  178. package/src/devices/cookies/IosCookie.js +0 -6
  179. package/src/devices/cookies/IosSimulatorCookie.js +0 -10
  180. package/src/devices/lifecycle/GenyGlobalLifecycleHandler.js +0 -71
  181. package/src/devices/lifecycle/factories/GenyGlobalLifecycleHandlerFactory.js +0 -18
  182. package/src/servicelocator/android/genycloudServiceLocator.js +0 -21
  183. package/src/servicelocator/android/index.js +0 -25
  184. package/src/servicelocator/ios.js +0 -7
  185. /package/src/devices/{common → allocation}/drivers/android/genycloud/exec/GenyCloudExec.js +0 -0
  186. /package/src/devices/{common → allocation}/drivers/android/genycloud/services/GenyAuthService.js +0 -0
@@ -1,7 +1,6 @@
1
1
  const { exec } = require('child-process-promise');
2
2
  const osascript = require('node-osascript');
3
3
 
4
- const { execWithRetriesAndLogs } = require('../../../../utils/childProcess');
5
4
  const log = require('../../../../utils/logger').child({ cat: 'device,xcuitest' });
6
5
 
7
6
  async function launchXCUITest(
@@ -56,7 +55,7 @@ async function _runLaunchCommand(
56
55
  ).then(r => {
57
56
  log.info(`[XCUITest] XCUITest runner execution finished`);
58
57
  }).catch(e => {
59
- log.error(`[XCUITest] xcodebuild error has occurred during XCUITest execution:\n${e}`);
58
+ log.debug(`[XCUITest] XCUITest runner execution finished with message:\n${e}`);
60
59
  });
61
60
 
62
61
  // Get firewall global state (Firewall socketfilterfw):
@@ -67,7 +66,12 @@ async function _runLaunchCommand(
67
66
  }
68
67
 
69
68
  const isServerUp = await _waitForTestTargetServerToStart(testTargetServerPort, spawnedProcess);
70
- log.debug(`[XCUITest] Finished waiting for test target server to start, server is up: ${isServerUp}`);
69
+ if (!isServerUp) {
70
+ throw new Error(`[XCUITest] Test runner is not up after 90 seconds, aborting`);
71
+ } else {
72
+ const childProcess = spawnedProcess.childProcess;
73
+ log.debug(`[XCUITest] Test runner is up and running, PID: ${childProcess.pid}`);
74
+ }
71
75
  }
72
76
 
73
77
  function runXCUITest(
@@ -102,7 +106,6 @@ function runXCUITest(
102
106
 
103
107
  const options = {
104
108
  maxBuffer: 1024 * 1024 * 10, // 10MB
105
- retries: 1,
106
109
  };
107
110
 
108
111
  const command = `${env.TEST_RUNNER_IS_DETOX_ACTIVE ? Object.keys(env).map(key => `${key}=${env[key]}`).join(' ') : ''} ${xcodebuildBinary} ${flags.map(flag => flag.includes(' ') ? `"${flag}"` : flag).join(' ')}`;
@@ -119,7 +122,15 @@ function runXCUITest(
119
122
  }
120
123
  }
121
124
 
122
- return execWithRetriesAndLogs(command, options);
125
+ const result = exec(command, options);
126
+
127
+ result.childProcess.stderr.on('data', (data) => {
128
+ if (data.includes('Testing started completed')) {
129
+ result.childProcess.kill('SIGTERM');
130
+ }
131
+ });
132
+
133
+ return result;
123
134
  }
124
135
 
125
136
  function _runCommandInTerminal(command, options) {
@@ -145,7 +156,7 @@ function _runCommandInTerminal(command, options) {
145
156
  end tell
146
157
  `;
147
158
 
148
- return execWithRetriesAndLogs(`osascript -e '${appleScript}'`, options);
159
+ return exec(`osascript -e '${appleScript}'`, options);
149
160
  }
150
161
 
151
162
  function _allowNetworkPermissionsXCUITest() {
@@ -173,7 +184,7 @@ function _allowNetworkPermissionsXCUITest() {
173
184
  childProcess.stdin.pause();
174
185
  childProcess.kill('SIGTERM');
175
186
 
176
- }, 30000);
187
+ }, 30000).unref();
177
188
  }
178
189
 
179
190
  async function _waitForTestTargetServerToStart(testTargetServerPort, cpPromise) {
@@ -3,7 +3,7 @@ const RuntimeDeviceFactory = require('./base');
3
3
 
4
4
  class RuntimeDriverFactoryAndroid extends RuntimeDeviceFactory {
5
5
  _createDriverDependencies(commonDeps) {
6
- const serviceLocator = require('../../../servicelocator/android');
6
+ const serviceLocator = require('../../servicelocator/android');
7
7
  const adb = serviceLocator.adb;
8
8
  const aapt = serviceLocator.aapt;
9
9
  const apkValidator = serviceLocator.apkValidator;
@@ -43,23 +43,15 @@ class AndroidEmulator extends RuntimeDriverFactoryAndroid {
43
43
 
44
44
  class AndroidAttached extends RuntimeDriverFactoryAndroid {
45
45
  _createDriver(deviceCookie, deps, configs) {
46
- const props = {
47
- adbName: deviceCookie.adbName,
48
- };
49
-
50
46
  const { AttachedAndroidRuntimeDriver } = require('../drivers');
51
- return new AttachedAndroidRuntimeDriver(deps, props);
47
+ return new AttachedAndroidRuntimeDriver(deps, deviceCookie);
52
48
  }
53
49
  }
54
50
 
55
51
  class Genycloud extends RuntimeDriverFactoryAndroid {
56
52
  _createDriver(deviceCookie, deps, configs) {
57
- const props = {
58
- instance: deviceCookie.instance,
59
- };
60
-
61
53
  const { GenycloudRuntimeDriver } = require('../drivers');
62
- return new GenycloudRuntimeDriver(deps, props);
54
+ return new GenycloudRuntimeDriver(deps, deviceCookie);
63
55
  }
64
56
  }
65
57
 
@@ -2,15 +2,14 @@ const RuntimeDeviceFactory = require('./base');
2
2
 
3
3
  class RuntimeDriverFactoryIos extends RuntimeDeviceFactory {
4
4
  _createDriverDependencies(commonDeps) {
5
- const serviceLocator = require('../../../servicelocator/ios');
6
- const applesimutils = serviceLocator.appleSimUtils;
7
5
  const { eventEmitter } = commonDeps;
8
6
 
9
- const SimulatorLauncher = require('../../allocation/drivers/ios/SimulatorLauncher');
7
+ const AppleSimUtils = require('../../../devices/common/drivers/ios/tools/AppleSimUtils');
8
+ const applesimutils = new AppleSimUtils();
9
+
10
10
  return {
11
11
  ...commonDeps,
12
12
  applesimutils,
13
- simulatorLauncher: new SimulatorLauncher({ applesimutils, eventEmitter }),
14
13
  };
15
14
  }
16
15
  }
@@ -1,4 +1,4 @@
1
- const { EmulatorExec } = require('../../devices/common/drivers/android/emulator/exec/EmulatorExec');
1
+ const { EmulatorExec } = require('../../common/drivers/android/emulator/exec/EmulatorExec');
2
2
 
3
3
  class EmulatorServiceLocator {
4
4
  constructor() {
@@ -0,0 +1,17 @@
1
+ class GenycloudServiceLocator {
2
+ constructor() {
3
+ this._exec = null;
4
+ }
5
+
6
+ // Note: important to keep lazy because of implicit validations that are sensitive (inside environment, in particular).
7
+ get exec() {
8
+ if (!this._exec) {
9
+ const Exec = require('../../allocation/drivers/android/genycloud/exec/GenyCloudExec');
10
+ const environment = require('../../../utils/environment');
11
+ this._exec = new Exec(environment.getGmsaasPath());
12
+ }
13
+ return this._exec;
14
+ }
15
+ }
16
+
17
+ module.exports = new GenycloudServiceLocator();
@@ -0,0 +1,23 @@
1
+ const AndroidDevicePathBuilder = require('../../../artifacts/utils/AndroidDevicePathBuilder');
2
+ const AAPT = require('../../common/drivers/android/exec/AAPT');
3
+ const ADB = require('../../common/drivers/android/exec/ADB');
4
+ const ApkValidator = require('../../common/drivers/android/tools/ApkValidator');
5
+ const { TempFileTransfer } = require('../../common/drivers/android/tools/TempFileTransfer');
6
+
7
+ const AndroidServiceLocator = {
8
+ get emulator() {
9
+ return require('./emulatorServiceLocator');
10
+ },
11
+
12
+ get genycloud() {
13
+ return require('./genycloudServiceLocator');
14
+ },
15
+ };
16
+
17
+ AndroidServiceLocator.adb = new ADB();
18
+ AndroidServiceLocator.aapt = new AAPT();
19
+ AndroidServiceLocator.apkValidator = new ApkValidator(AndroidServiceLocator.aapt);
20
+ AndroidServiceLocator.fileTransfer = new TempFileTransfer(AndroidServiceLocator.adb);
21
+ AndroidServiceLocator.devicePathBuilder = new AndroidDevicePathBuilder();
22
+
23
+ module.exports = AndroidServiceLocator;
@@ -1,4 +1,5 @@
1
1
  class EnvironmentValidatorBase {
2
+ /* istanbul ignore next */
2
3
  validate() {}
3
4
  }
4
5
 
@@ -1,8 +1,8 @@
1
1
  // @ts-nocheck
2
2
  const semver = require('semver');
3
3
 
4
- const DetoxRuntimeError = require('../../errors/DetoxRuntimeError');
5
- const environment = require('../../utils/environment');
4
+ const { DetoxRuntimeError } = require('../../../errors');
5
+ const environment = require('../../../utils/environment');
6
6
  const EnvironmentValidatorBase = require('../EnvironmentValidatorBase');
7
7
 
8
8
  const MIN_GMSAAS_VERSION = '1.6.0';
@@ -7,7 +7,7 @@ class Genycloud extends EnvValidatorFactory {
7
7
  const serviceLocator = require('../../servicelocator/android');
8
8
  const exec = serviceLocator.genycloud.exec;
9
9
 
10
- const GenyAuthService = require('../../devices/common/drivers/android/genycloud/services/GenyAuthService');
10
+ const GenyAuthService = require('../../allocation/drivers/android/genycloud/services/GenyAuthService');
11
11
  const authService = new GenyAuthService(exec);
12
12
 
13
13
  const GenycloudEnvValidator = require('../android/GenycloudEnvValidator');
@@ -1,7 +1,7 @@
1
1
  const fs = require('fs');
2
2
 
3
- const DetoxRuntimeError = require('../../errors/DetoxRuntimeError');
4
- const environment = require('../../utils/environment');
3
+ const DetoxRuntimeError = require('../../../errors/DetoxRuntimeError');
4
+ const environment = require('../../../utils/environment');
5
5
  const EnvironmentValidatorBase = require('../EnvironmentValidatorBase');
6
6
 
7
7
  class IosSimulatorEnvValidator extends EnvironmentValidatorBase {
@@ -2,9 +2,9 @@
2
2
  const artifactsManagerFactories = require('./artifacts/factories');
3
3
  const deviceAllocationFactories = require('./devices/allocation/factories');
4
4
  const runtimeDeviceFactories = require('./devices/runtime/factories');
5
+ const envValidationFactories = require('./devices/validation/factories');
5
6
  const matchersFactories = require('./matchers/factories');
6
7
  const resolveModuleFromPath = require('./utils/resolveModuleFromPath');
7
- const envValidationFactories = require('./validation/factories');
8
8
 
9
9
  function validateConfig(deviceConfig) {
10
10
  const classes = _getFactoryClasses(deviceConfig);
@@ -36,15 +36,6 @@ function createFactories(deviceConfig) {
36
36
  return _getExternalModuleFactories(deviceConfig);
37
37
  }
38
38
 
39
- function createGlobalLifecycleHandler(deviceConfig) {
40
- if (deviceConfig.type === 'android.genycloud') {
41
- const FactoryClass = require('./devices/lifecycle/factories/GenyGlobalLifecycleHandlerFactory');
42
- const factory = new FactoryClass();
43
- return factory.createHandler();
44
- }
45
- return null;
46
- }
47
-
48
39
  function _getFactoryClasses(deviceConfig) {
49
40
  let envValidatorFactoryClass;
50
41
  let artifactsManagerFactoryClass;
@@ -115,5 +106,4 @@ function _getExternalModuleFactories(deviceConfig) {
115
106
  module.exports = {
116
107
  validateConfig,
117
108
  createFactories,
118
- createGlobalLifecycleHandler,
119
109
  };
package/src/ios/web.js CHANGED
@@ -121,14 +121,30 @@ class WebElement {
121
121
  return this.withAction('moveCursorToEnd', traceDescription);
122
122
  }
123
123
 
124
- runScript(script) {
124
+ async runScript(script, args) {
125
+ if (args !== undefined && args.length !== 0) {
126
+ return await this.runScriptWithArgs(script, args);
127
+ }
128
+
125
129
  const traceDescription = webViewActionDescription.runScript(script);
126
- return this.withAction('runScript', traceDescription, script);
130
+ const result = await this.withAction('runScript', traceDescription, script);
131
+
132
+ if (result['result'] !== undefined) {
133
+ return result['result'];
134
+ } else {
135
+ throw new DetoxRuntimeError(`Failed to extract result from result: ${JSON.stringify(result)}`);
136
+ }
127
137
  }
128
138
 
129
- runScriptWithArgs(script, ...args) {
130
- const traceDescription = webViewActionDescription.runScriptWithArgs(script, ...args);
131
- return this.withAction('runScriptWithArgs', traceDescription, script, ...args);
139
+ async runScriptWithArgs(script, args) {
140
+ const traceDescription = webViewActionDescription.runScriptWithArgs(script, args);
141
+ const result = await this.withAction('runScriptWithArgs', traceDescription, script, args);
142
+
143
+ if (result['result'] !== undefined) {
144
+ return result['result'];
145
+ } else {
146
+ throw new DetoxRuntimeError(`Failed to extract result from result: ${JSON.stringify(result)}`);
147
+ }
132
148
  }
133
149
 
134
150
  async getCurrentUrl() {
@@ -1,7 +1,7 @@
1
1
  const { IPC } = require('node-ipc');
2
2
 
3
3
  const { DetoxInternalError } = require('../errors');
4
- const { serializeObjectWithError } = require('../utils/errorUtils');
4
+ const { serializeObjectWithError, deserializeObjectWithError } = require('../utils/errorUtils');
5
5
 
6
6
  class IPCClient {
7
7
  constructor({ id, logger, sessionState }) {
@@ -60,6 +60,22 @@ class IPCClient {
60
60
  this._sessionState.patch(sessionState);
61
61
  }
62
62
 
63
+ async allocateDevice() {
64
+ const { deviceCookie, error } = deserializeObjectWithError(await this._emit('allocateDevice', {}));
65
+ if (error) {
66
+ throw error;
67
+ }
68
+
69
+ return deviceCookie;
70
+ }
71
+
72
+ async deallocateDevice(deviceCookie) {
73
+ const { error } = deserializeObjectWithError(await this._emit('deallocateDevice', { deviceCookie }));
74
+ if (error) {
75
+ throw error;
76
+ }
77
+ }
78
+
63
79
  /**
64
80
  * @param {DetoxInternals.DetoxTestFileReport[]} testResults
65
81
  */
@@ -70,6 +86,11 @@ class IPCClient {
70
86
  this._sessionState.patch(sessionState);
71
87
  }
72
88
 
89
+ async conductEarlyTeardown({ permanent }) {
90
+ const sessionState = await this._emit('conductEarlyTeardown', { permanent });
91
+ this._sessionState.patch(sessionState);
92
+ }
93
+
73
94
  async _connectToServer() {
74
95
  const serverId = this.serverId;
75
96
 
@@ -8,11 +8,15 @@ class IPCServer {
8
8
  * @param {object} options
9
9
  * @param {import('./SessionState')} options.sessionState
10
10
  * @param {Detox.Logger} options.logger
11
+ * @param {object} options.callbacks
12
+ * @param {() => Promise<any>} options.callbacks.onAllocateDevice
13
+ * @param {(cookie: any) => Promise<void>} options.callbacks.onDeallocateDevice
11
14
  */
12
- constructor({ sessionState, logger }) {
15
+ constructor({ sessionState, logger, callbacks }) {
13
16
  this._sessionState = sessionState;
14
17
  this._logger = logger.child({ cat: 'ipc,ipc-server' });
15
18
  this._ipc = null;
19
+ this._callbacks = callbacks;
16
20
  this._workers = new Set();
17
21
  this._contexts = new Set();
18
22
  }
@@ -38,9 +42,12 @@ class IPCServer {
38
42
  await new Promise((resolve) => {
39
43
  // TODO: handle reject
40
44
  this._ipc.serve(() => resolve());
45
+ this._ipc.server.on('conductEarlyTeardown', this.onConductEarlyTeardown.bind(this));
41
46
  this._ipc.server.on('registerContext', this.onRegisterContext.bind(this));
42
47
  this._ipc.server.on('registerWorker', this.onRegisterWorker.bind(this));
43
48
  this._ipc.server.on('reportTestResults', this.onReportTestResults.bind(this));
49
+ this._ipc.server.on('allocateDevice', this.onAllocateDevice.bind(this));
50
+ this._ipc.server.on('deallocateDevice', this.onDeallocateDevice.bind(this));
44
51
  this._ipc.server.start();
45
52
  });
46
53
  }
@@ -66,6 +73,7 @@ class IPCServer {
66
73
  this._ipc.server.emit(socket, 'registerContextDone', {
67
74
  testResults: this._sessionState.testResults,
68
75
  testSessionIndex: this._sessionState.testSessionIndex,
76
+ unsafe_earlyTeardown: this._sessionState.unsafe_earlyTeardown,
69
77
  });
70
78
  }
71
79
 
@@ -83,6 +91,39 @@ class IPCServer {
83
91
  }
84
92
  }
85
93
 
94
+ onConductEarlyTeardown({ permanent }, socket = null) {
95
+ const newState = { unsafe_earlyTeardown: true };
96
+ if (permanent) {
97
+ Object.assign(this._sessionState, newState);
98
+ }
99
+
100
+ if (socket) {
101
+ this._ipc.server.emit(socket, 'conductEarlyTeardownDone', newState);
102
+ }
103
+
104
+ this._ipc.server.broadcast('sessionStateUpdate', newState);
105
+ }
106
+
107
+ async onAllocateDevice(_payload, socket) {
108
+ let deviceCookie;
109
+
110
+ try {
111
+ deviceCookie = await this._callbacks.onAllocateDevice();
112
+ this._ipc.server.emit(socket, 'allocateDeviceDone', { deviceCookie });
113
+ } catch (error) {
114
+ this._ipc.server.emit(socket, 'allocateDeviceDone', serializeObjectWithError({ error }));
115
+ }
116
+ }
117
+
118
+ async onDeallocateDevice({ deviceCookie }, socket) {
119
+ try {
120
+ await this._callbacks.onDeallocateDevice(deviceCookie);
121
+ this._ipc.server.emit(socket, 'deallocateDeviceDone', {});
122
+ } catch (error) {
123
+ this._ipc.server.emit(socket, 'deallocateDeviceDone', serializeObjectWithError({ error }));
124
+ }
125
+ }
126
+
86
127
  onReportTestResults({ testResults }, socket = null) {
87
128
  const merged = uniqBy([
88
129
  ...testResults.map(r => serializeObjectWithError(r, 'testExecError')),
@@ -20,6 +20,7 @@ class SessionState {
20
20
  this.detoxIPCServer = detoxIPCServer;
21
21
  this.testResults = testResults;
22
22
  this.testSessionIndex = testSessionIndex;
23
+ this.unsafe_earlyTeardown = undefined;
23
24
  this.workersCount = workersCount;
24
25
  }
25
26
 
@@ -249,7 +249,7 @@ class DetoxLogger {
249
249
  _complete(level, maybeContext, maybeMessage, maybeAction) {
250
250
  const action = typeof maybeContext !== 'string' ? maybeAction : maybeMessage;
251
251
  const args = maybeAction === action ? [maybeContext, maybeMessage] : [maybeContext];
252
- const { context, msg } = this._parseArgs(null, args);
252
+ const { context, msg } = this._parseArgs({ ph: 'B' }, args);
253
253
  const end = (ctx) => this[level].end({
254
254
  id: context.id,
255
255
  cat: context.cat,
@@ -257,7 +257,7 @@ class DetoxLogger {
257
257
  });
258
258
 
259
259
  let result;
260
- this._beginInternal(level, { ...context, ph: 'B' }, msg);
260
+ this._beginInternal(level, context, msg);
261
261
  try {
262
262
  result = typeof action === 'function'
263
263
  ? action()
@@ -101,6 +101,8 @@ class DetoxContext {
101
101
  });
102
102
  /** @abstract */
103
103
  [symbols.reportTestResults](_testResults) {}
104
+ /** @abstract */
105
+ [symbols.conductEarlyTeardown](_permanent) {}
104
106
  /**
105
107
  * @abstract
106
108
  * @param {Partial<DetoxInternals.DetoxInitOptions>} _opts
@@ -149,6 +151,12 @@ class DetoxContext {
149
151
  await this[$worker].init();
150
152
  }
151
153
 
154
+ /** @abstract */
155
+ async [symbols.allocateDevice]() {}
156
+
157
+ /** @abstract */
158
+ async [symbols.deallocateDevice]() {}
159
+
152
160
  async [symbols.uninstallWorker]() {
153
161
  try {
154
162
  if (this[$worker]) {
@@ -24,6 +24,7 @@ class DetoxInternalsFacade {
24
24
  this.resolveConfig = context[symbols.resolveConfig];
25
25
  this.session = context[symbols.session];
26
26
  this.tracing = context[symbols.tracing];
27
+ this.unsafe_conductEarlyTeardown = context[symbols.conductEarlyTeardown];
27
28
  this.worker = funpermaproxy(() => context[symbols.worker]);
28
29
  }
29
30
  }
@@ -16,15 +16,14 @@ const symbols = require('./symbols');
16
16
  const { $logFinalizer, $restoreSessionState, $sessionState, $worker } = DetoxContext.protected;
17
17
 
18
18
  //#region Private symbols
19
- const _globalLifecycleHandler = Symbol('globalLifecycleHandler');
20
19
  const _ipcServer = Symbol('ipcServer');
21
- const _resetLockFile = Symbol('resetLockFile');
22
20
  const _wss = Symbol('wss');
23
21
  const _dirty = Symbol('dirty');
24
22
  const _emergencyTeardown = Symbol('emergencyTeardown');
25
23
  const _lifecycleLogger = Symbol('lifecycleLogger');
26
24
  const _sessionFile = Symbol('sessionFile');
27
25
  const _logFinalError = Symbol('logFinalError');
26
+ const _deviceAllocator = Symbol('deviceAllocator');
28
27
  //#endregion
29
28
 
30
29
  class DetoxPrimaryContext extends DetoxContext {
@@ -33,7 +32,8 @@ class DetoxPrimaryContext extends DetoxContext {
33
32
 
34
33
  this[_dirty] = false;
35
34
  this[_wss] = null;
36
- this[_globalLifecycleHandler] = null;
35
+ this[_deviceAllocator] = null;
36
+
37
37
  /** Path to file where the initial session object is serialized */
38
38
  this[_sessionFile] = '';
39
39
  /**
@@ -51,6 +51,12 @@ class DetoxPrimaryContext extends DetoxContext {
51
51
  }
52
52
  }
53
53
 
54
+ [symbols.conductEarlyTeardown] = async (permanent = false) => {
55
+ if (this[_ipcServer]) {
56
+ await this[_ipcServer].onConductEarlyTeardown({ permanent });
57
+ }
58
+ };
59
+
54
60
  async [symbols.resolveConfig](opts = {}) {
55
61
  const session = this[$sessionState];
56
62
  if (!session.detoxConfig) {
@@ -79,7 +85,6 @@ class DetoxPrimaryContext extends DetoxContext {
79
85
  const detoxConfig = await this[symbols.resolveConfig](opts);
80
86
 
81
87
  const {
82
- behavior: behaviorConfig,
83
88
  device: deviceConfig,
84
89
  logger: loggerConfig,
85
90
  session: sessionConfig
@@ -96,20 +101,23 @@ class DetoxPrimaryContext extends DetoxContext {
96
101
  this[_ipcServer] = new IPCServer({
97
102
  sessionState: this[$sessionState],
98
103
  logger: this[symbols.logger],
104
+ callbacks: {
105
+ onAllocateDevice: this[symbols.allocateDevice].bind(this),
106
+ onDeallocateDevice: this[symbols.deallocateDevice].bind(this),
107
+ },
99
108
  });
100
109
 
101
110
  await this[_ipcServer].init();
102
111
 
103
112
  const environmentFactory = require('../environmentFactory');
104
- this[_globalLifecycleHandler] = await environmentFactory.createGlobalLifecycleHandler(deviceConfig);
105
113
 
106
- if (this[_globalLifecycleHandler]) {
107
- await this[_globalLifecycleHandler].globalInit();
108
- }
114
+ const { deviceAllocatorFactory } = environmentFactory.createFactories(deviceConfig);
115
+ this[_deviceAllocator] = deviceAllocatorFactory.createDeviceAllocator({
116
+ detoxConfig,
117
+ detoxSession: this[$sessionState],
118
+ });
109
119
 
110
- if (!behaviorConfig.init.keepLockFile) {
111
- await this[_resetLockFile]();
112
- }
120
+ await this[_deviceAllocator].init();
113
121
 
114
122
  // TODO: Detox-server creation ought to be delegated to a generator/factory.
115
123
  const DetoxServer = require('../server/DetoxServer');
@@ -153,6 +161,29 @@ class DetoxPrimaryContext extends DetoxContext {
153
161
  await super[symbols.installWorker]({ ...opts, workerId });
154
162
  }
155
163
 
164
+ /** @override */
165
+ async [symbols.allocateDevice]() {
166
+ const { device } = this[$sessionState].detoxConfig;
167
+ const deviceCookie = await this[_deviceAllocator].allocate(device);
168
+
169
+ try {
170
+ return await this[_deviceAllocator].postAllocate(deviceCookie);
171
+ } catch (e) {
172
+ try {
173
+ await this[_deviceAllocator].free(deviceCookie, { shutdown: true });
174
+ } catch (e2) {
175
+ this[symbols.logger].error({ cat: 'device', err: e2 }, `Failed to free ${deviceCookie.name || deviceCookie.id} after a failed allocation`);
176
+ }
177
+
178
+ throw e;
179
+ }
180
+ }
181
+
182
+ /** @override */
183
+ async [symbols.deallocateDevice](cookie) {
184
+ await this[_deviceAllocator].free(cookie);
185
+ }
186
+
156
187
  /** @override */
157
188
  async [symbols.cleanup]() {
158
189
  try {
@@ -160,9 +191,9 @@ class DetoxPrimaryContext extends DetoxContext {
160
191
  await this[symbols.uninstallWorker]();
161
192
  }
162
193
  } finally {
163
- if (this[_globalLifecycleHandler]) {
164
- await this[_globalLifecycleHandler].globalCleanup();
165
- this[_globalLifecycleHandler] = null;
194
+ if (this[_deviceAllocator]) {
195
+ await this[_deviceAllocator].cleanup();
196
+ this[_deviceAllocator] = null;
166
197
  }
167
198
 
168
199
  if (this[_wss]) {
@@ -196,9 +227,9 @@ class DetoxPrimaryContext extends DetoxContext {
196
227
  return;
197
228
  }
198
229
 
199
- if (this[_globalLifecycleHandler]) {
200
- this[_globalLifecycleHandler].emergencyCleanup();
201
- this[_globalLifecycleHandler] = null;
230
+ if (this[_deviceAllocator]) {
231
+ this[_deviceAllocator].emergencyCleanup();
232
+ this[_deviceAllocator] = null;
202
233
  }
203
234
 
204
235
  if (this[_wss]) {
@@ -241,31 +272,6 @@ class DetoxPrimaryContext extends DetoxContext {
241
272
  });
242
273
  }
243
274
  //#endregion
244
-
245
- //#region Private members
246
- async[_resetLockFile]() {
247
- const DeviceRegistry = require('../devices/DeviceRegistry');
248
-
249
- const deviceType = this[symbols.config].device.type;
250
-
251
- switch (deviceType) {
252
- case 'ios.none':
253
- case 'ios.simulator':
254
- await DeviceRegistry.forIOS().reset();
255
- break;
256
- case 'android.attached':
257
- case 'android.emulator':
258
- case 'android.genycloud':
259
- await DeviceRegistry.forAndroid().reset();
260
- break;
261
- }
262
-
263
- if (deviceType === 'android.genycloud') {
264
- const GenyDeviceRegistryFactory = require('../devices/allocation/drivers/android/genycloud/GenyDeviceRegistryFactory');
265
- await GenyDeviceRegistryFactory.forGlobalShutdown().reset();
266
- }
267
- }
268
- //#endregion
269
275
  }
270
276
 
271
277
  module.exports = DetoxPrimaryContext;
@@ -33,6 +33,14 @@ class DetoxSecondaryContext extends DetoxContext {
33
33
  }
34
34
  }
35
35
 
36
+ [symbols.conductEarlyTeardown] = async (permanent = false) => {
37
+ if (this[_ipcClient]) {
38
+ await this[_ipcClient].conductEarlyTeardown({ permanent });
39
+ } else {
40
+ throw new DetoxInternalError('Detected an attempt to report early teardown using a non-initialized context.');
41
+ }
42
+ };
43
+
36
44
  async [symbols.resolveConfig]() {
37
45
  return this[symbols.config];
38
46
  }
@@ -54,6 +62,25 @@ class DetoxSecondaryContext extends DetoxContext {
54
62
  }
55
63
  }
56
64
 
65
+ /** @override */
66
+ async [symbols.allocateDevice]() {
67
+ if (this[_ipcClient]) {
68
+ const deviceCookie = await this[_ipcClient].allocateDevice();
69
+ return deviceCookie;
70
+ } else {
71
+ throw new DetoxInternalError('Detected an attempt to allocate a device using a non-initialized context.');
72
+ }
73
+ }
74
+
75
+ /** @override */
76
+ async [symbols.deallocateDevice](deviceCookie) {
77
+ if (this[_ipcClient]) {
78
+ await this[_ipcClient].deallocateDevice(deviceCookie);
79
+ } else {
80
+ throw new DetoxInternalError('Detected an attempt to allocate a device using a non-initialized context.');
81
+ }
82
+ }
83
+
57
84
  /** @override */
58
85
  async [symbols.cleanup]() {
59
86
  try {