detox 20.12.1 → 20.13.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (141) hide show
  1. package/Detox-android/com/wix/detox/{20.12.1/detox-20.12.1-javadoc.jar → 20.13.0/detox-20.13.0-javadoc.jar} +0 -0
  2. package/Detox-android/com/wix/detox/20.13.0/detox-20.13.0-javadoc.jar.md5 +1 -0
  3. package/Detox-android/com/wix/detox/20.13.0/detox-20.13.0-javadoc.jar.sha1 +1 -0
  4. package/Detox-android/com/wix/detox/20.13.0/detox-20.13.0-javadoc.jar.sha256 +1 -0
  5. package/Detox-android/com/wix/detox/20.13.0/detox-20.13.0-javadoc.jar.sha512 +1 -0
  6. package/Detox-android/com/wix/detox/{20.12.1/detox-20.12.1-sources.jar → 20.13.0/detox-20.13.0-sources.jar} +0 -0
  7. package/Detox-android/com/wix/detox/20.13.0/detox-20.13.0-sources.jar.md5 +1 -0
  8. package/Detox-android/com/wix/detox/20.13.0/detox-20.13.0-sources.jar.sha1 +1 -0
  9. package/Detox-android/com/wix/detox/20.13.0/detox-20.13.0-sources.jar.sha256 +1 -0
  10. package/Detox-android/com/wix/detox/20.13.0/detox-20.13.0-sources.jar.sha512 +1 -0
  11. package/Detox-android/com/wix/detox/20.13.0/detox-20.13.0.aar +0 -0
  12. package/Detox-android/com/wix/detox/20.13.0/detox-20.13.0.aar.md5 +1 -0
  13. package/Detox-android/com/wix/detox/20.13.0/detox-20.13.0.aar.sha1 +1 -0
  14. package/Detox-android/com/wix/detox/20.13.0/detox-20.13.0.aar.sha256 +1 -0
  15. package/Detox-android/com/wix/detox/20.13.0/detox-20.13.0.aar.sha512 +1 -0
  16. package/Detox-android/com/wix/detox/{20.12.1/detox-20.12.1.pom → 20.13.0/detox-20.13.0.pom} +1 -7
  17. package/Detox-android/com/wix/detox/20.13.0/detox-20.13.0.pom.md5 +1 -0
  18. package/Detox-android/com/wix/detox/20.13.0/detox-20.13.0.pom.sha1 +1 -0
  19. package/Detox-android/com/wix/detox/20.13.0/detox-20.13.0.pom.sha256 +1 -0
  20. package/Detox-android/com/wix/detox/20.13.0/detox-20.13.0.pom.sha512 +1 -0
  21. package/Detox-android/com/wix/detox/maven-metadata.xml +4 -4
  22. package/Detox-android/com/wix/detox/maven-metadata.xml.md5 +1 -1
  23. package/Detox-android/com/wix/detox/maven-metadata.xml.sha1 +1 -1
  24. package/Detox-android/com/wix/detox/maven-metadata.xml.sha256 +1 -1
  25. package/Detox-android/com/wix/detox/maven-metadata.xml.sha512 +1 -1
  26. package/Detox-ios-src.tbz +0 -0
  27. package/Detox-ios.tbz +0 -0
  28. package/android/detox/build.gradle +4 -3
  29. package/android/detox/src/full/java/com/wix/detox/espresso/action/AdjustSliderToPositionAction.kt +2 -2
  30. package/android/detox/src/full/java/com/wix/detox/espresso/action/GetAttributesAction.kt +30 -31
  31. package/android/detox/src/full/java/com/wix/detox/espresso/common/MaterialSliderHelper.kt +21 -0
  32. package/android/detox/src/full/java/com/wix/detox/espresso/common/{SliderHelper.kt → ReactSliderHelper.kt} +6 -5
  33. package/android/detox/src/full/java/com/wix/detox/espresso/matcher/ViewMatchers.kt +2 -2
  34. package/android/detox/src/testFull/java/com/wix/detox/espresso/common/MaterialSliderHelperTest.kt +33 -0
  35. package/android/detox/src/testFull/java/com/wix/detox/espresso/common/{SliderHelperTest.kt → ReactSliderHelperTest.kt} +3 -3
  36. package/internals.d.ts +10 -1
  37. package/local-cli/reset-lock-file.js +5 -9
  38. package/package.json +5 -6
  39. package/runners/jest/reporters/DetoxReporter.js +127 -9
  40. package/runners/jest/testEnvironment/index.js +5 -0
  41. package/src/DetoxWorker.js +5 -11
  42. package/src/artifacts/providers/index.js +3 -3
  43. package/src/artifacts/screenshot/SimulatorScreenshotPlugin.js +0 -17
  44. package/src/configuration/composeLoggerConfig.js +1 -0
  45. package/src/devices/allocation/DeviceAllocator.js +66 -20
  46. package/src/devices/allocation/DeviceList.js +44 -0
  47. package/src/devices/allocation/DeviceRegistry.js +189 -0
  48. package/src/devices/allocation/drivers/AllocationDriverBase.d.ts +15 -0
  49. package/src/devices/{common/drivers/android/tools → allocation/drivers/android}/FreeDeviceFinder.js +11 -10
  50. package/src/devices/allocation/drivers/android/attached/AttachedAndroidAllocDriver.js +22 -17
  51. package/src/devices/allocation/drivers/android/emulator/EmulatorAllocDriver.js +97 -38
  52. package/src/devices/allocation/drivers/android/emulator/EmulatorLauncher.js +32 -45
  53. package/src/devices/allocation/drivers/android/emulator/FreeEmulatorFinder.js +1 -1
  54. package/src/devices/allocation/drivers/android/emulator/FreePortFinder.js +37 -0
  55. package/src/devices/allocation/drivers/android/emulator/launchEmulatorProcess.js +3 -3
  56. package/src/devices/allocation/drivers/android/genycloud/GenyAllocDriver.js +104 -32
  57. package/src/devices/allocation/drivers/android/genycloud/GenyInstanceLauncher.js +40 -31
  58. package/src/devices/allocation/drivers/android/genycloud/GenyRegistry.js +121 -0
  59. package/src/devices/allocation/drivers/android/genycloud/services/GenyInstanceLifecycleService.js +24 -0
  60. package/src/devices/{common → allocation}/drivers/android/genycloud/services/GenyRecipesService.js +1 -1
  61. package/src/devices/allocation/drivers/android/genycloud/services/dto/GenyInstance.js +83 -0
  62. package/src/devices/allocation/drivers/android/genycloud/services/dto/GenyRecipe.js +25 -0
  63. package/src/devices/allocation/drivers/ios/SimulatorAllocDriver.js +94 -51
  64. package/src/devices/allocation/drivers/ios/SimulatorLauncher.js +11 -7
  65. package/src/devices/allocation/drivers/ios/SimulatorQuery.js +24 -0
  66. package/src/devices/allocation/factories/android.js +29 -35
  67. package/src/devices/allocation/factories/ios.js +7 -5
  68. package/src/devices/common/drivers/DeviceCookie.d.ts +12 -0
  69. package/src/devices/common/drivers/android/cookies.d.ts +11 -0
  70. package/src/devices/common/drivers/android/emulator/exec/EmulatorExec.js +17 -5
  71. package/src/devices/common/drivers/android/exec/ADB.js +1 -0
  72. package/src/devices/common/drivers/ios/cookies.d.ts +9 -0
  73. package/src/devices/cookies/index.js +0 -6
  74. package/src/devices/runtime/drivers/android/genycloud/GenyCloudDriver.js +7 -6
  75. package/src/devices/runtime/factories/android.js +3 -11
  76. package/src/devices/runtime/factories/ios.js +3 -2
  77. package/src/{servicelocator → devices/servicelocator}/android/emulatorServiceLocator.js +1 -1
  78. package/src/devices/servicelocator/android/genycloudServiceLocator.js +17 -0
  79. package/src/devices/servicelocator/android/index.js +23 -0
  80. package/src/{validation → devices/validation}/EnvironmentValidatorBase.js +1 -0
  81. package/src/{validation → devices/validation}/android/GenycloudEnvValidator.js +2 -2
  82. package/src/{validation → devices/validation}/factories/index.js +1 -1
  83. package/src/{validation → devices/validation}/ios/IosSimulatorEnvValidator.js +2 -2
  84. package/src/environmentFactory.js +1 -11
  85. package/src/ipc/IPCClient.js +22 -1
  86. package/src/ipc/IPCServer.js +40 -1
  87. package/src/ipc/SessionState.js +1 -0
  88. package/src/logger/DetoxLogger.js +2 -2
  89. package/src/realms/DetoxContext.js +8 -0
  90. package/src/realms/DetoxInternalsFacade.js +1 -0
  91. package/src/realms/DetoxPrimaryContext.js +48 -42
  92. package/src/realms/DetoxSecondaryContext.js +27 -0
  93. package/src/realms/symbols.js +6 -0
  94. package/src/utils/PIDService.js +27 -0
  95. package/src/utils/environment.js +8 -15
  96. package/src/utils/errorUtils.js +3 -3
  97. package/tsconfig.json +5 -3
  98. package/Detox-android/com/wix/detox/20.12.1/detox-20.12.1-javadoc.jar.md5 +0 -1
  99. package/Detox-android/com/wix/detox/20.12.1/detox-20.12.1-javadoc.jar.sha1 +0 -1
  100. package/Detox-android/com/wix/detox/20.12.1/detox-20.12.1-javadoc.jar.sha256 +0 -1
  101. package/Detox-android/com/wix/detox/20.12.1/detox-20.12.1-javadoc.jar.sha512 +0 -1
  102. package/Detox-android/com/wix/detox/20.12.1/detox-20.12.1-sources.jar.md5 +0 -1
  103. package/Detox-android/com/wix/detox/20.12.1/detox-20.12.1-sources.jar.sha1 +0 -1
  104. package/Detox-android/com/wix/detox/20.12.1/detox-20.12.1-sources.jar.sha256 +0 -1
  105. package/Detox-android/com/wix/detox/20.12.1/detox-20.12.1-sources.jar.sha512 +0 -1
  106. package/Detox-android/com/wix/detox/20.12.1/detox-20.12.1.aar +0 -0
  107. package/Detox-android/com/wix/detox/20.12.1/detox-20.12.1.aar.md5 +0 -1
  108. package/Detox-android/com/wix/detox/20.12.1/detox-20.12.1.aar.sha1 +0 -1
  109. package/Detox-android/com/wix/detox/20.12.1/detox-20.12.1.aar.sha256 +0 -1
  110. package/Detox-android/com/wix/detox/20.12.1/detox-20.12.1.aar.sha512 +0 -1
  111. package/Detox-android/com/wix/detox/20.12.1/detox-20.12.1.pom.md5 +0 -1
  112. package/Detox-android/com/wix/detox/20.12.1/detox-20.12.1.pom.sha1 +0 -1
  113. package/Detox-android/com/wix/detox/20.12.1/detox-20.12.1.pom.sha256 +0 -1
  114. package/Detox-android/com/wix/detox/20.12.1/detox-20.12.1.pom.sha512 +0 -1
  115. package/src/devices/DeviceRegistry.js +0 -176
  116. package/src/devices/allocation/drivers/AllocationDriverBase.js +0 -30
  117. package/src/devices/allocation/drivers/android/attached/AttachedAndroidLauncher.js +0 -13
  118. package/src/devices/allocation/drivers/android/emulator/EmulatorAllocationHelper.js +0 -72
  119. package/src/devices/allocation/drivers/android/genycloud/GenyDeviceRegistryFactory.js +0 -16
  120. package/src/devices/allocation/drivers/android/genycloud/GenyInstanceAllocationHelper.js +0 -65
  121. package/src/devices/common/drivers/DeviceAllocationHelper.js +0 -20
  122. package/src/devices/common/drivers/DeviceLauncher.js +0 -19
  123. package/src/devices/common/drivers/android/genycloud/services/GenyInstanceLifecycleService.js +0 -25
  124. package/src/devices/common/drivers/android/genycloud/services/GenyInstanceLookupService.js +0 -38
  125. package/src/devices/common/drivers/android/genycloud/services/GenyInstanceNaming.js +0 -14
  126. package/src/devices/common/drivers/android/genycloud/services/dto/GenyInstance.js +0 -66
  127. package/src/devices/common/drivers/android/genycloud/services/dto/GenyRecipe.js +0 -13
  128. package/src/devices/cookies/AndroidDeviceCookie.js +0 -13
  129. package/src/devices/cookies/AndroidEmulatorCookie.js +0 -6
  130. package/src/devices/cookies/AttachedAndroidDeviceCookie.js +0 -12
  131. package/src/devices/cookies/DeviceCookie.js +0 -4
  132. package/src/devices/cookies/GenycloudEmulatorCookie.js +0 -20
  133. package/src/devices/cookies/IosCookie.js +0 -6
  134. package/src/devices/cookies/IosSimulatorCookie.js +0 -10
  135. package/src/devices/lifecycle/GenyGlobalLifecycleHandler.js +0 -71
  136. package/src/devices/lifecycle/factories/GenyGlobalLifecycleHandlerFactory.js +0 -18
  137. package/src/servicelocator/android/genycloudServiceLocator.js +0 -21
  138. package/src/servicelocator/android/index.js +0 -25
  139. package/src/servicelocator/ios.js +0 -7
  140. /package/src/devices/{common → allocation}/drivers/android/genycloud/exec/GenyCloudExec.js +0 -0
  141. /package/src/devices/{common → allocation}/drivers/android/genycloud/services/GenyAuthService.js +0 -0
@@ -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 () => {
55
+ if (this[_ipcServer]) {
56
+ await this[_ipcServer].onConductEarlyTeardown();
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 () => {
37
+ if (this[_ipcClient]) {
38
+ await this[_ipcClient].conductEarlyTeardown();
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 {
@@ -5,6 +5,8 @@
5
5
  * readonly getStatus: unique symbol;
6
6
  * readonly init: unique symbol;
7
7
  * readonly installWorker: unique symbol;
8
+ * readonly allocateDevice: unique symbol;
9
+ * readonly deallocateDevice: unique symbol;
8
10
  * readonly logger: unique symbol;
9
11
  * readonly onHookFailure: unique symbol;
10
12
  * readonly onRunDescribeFinish: unique symbol;
@@ -12,6 +14,7 @@
12
14
  * readonly onTestDone: unique symbol;
13
15
  * readonly onTestFnFailure: unique symbol;
14
16
  * readonly onTestStart: unique symbol;
17
+ * readonly conductEarlyTeardown: unique symbol;
15
18
  * readonly reportTestResults: unique symbol;
16
19
  * readonly resolveConfig: unique symbol;
17
20
  * readonly session: unique symbol;
@@ -32,6 +35,9 @@ module.exports = {
32
35
 
33
36
  //#region IPC
34
37
  reportTestResults: Symbol('reportTestResults'),
38
+ conductEarlyTeardown: Symbol('conductEarlyTeardown'),
39
+ allocateDevice: Symbol('allocateDevice'),
40
+ deallocateDevice: Symbol('deallocateDevice'),
35
41
  //#endregion
36
42
 
37
43
  //#region Main
@@ -0,0 +1,27 @@
1
+ const { pid } = require('process');
2
+
3
+ class PIDService {
4
+ getPid() {
5
+ return pid;
6
+ }
7
+
8
+ /**
9
+ * Checks if the other process id is running in the current operating system
10
+ * @param {number} otherPID
11
+ * @returns {boolean}
12
+ */
13
+ isAlive(otherPID) {
14
+ try {
15
+ process.kill(otherPID, 0);
16
+ return true;
17
+ } catch (ex) {
18
+ if (ex.code === 'ESRCH') {
19
+ return false;
20
+ }
21
+ throw ex;
22
+ }
23
+ }
24
+
25
+ }
26
+
27
+ module.exports = PIDService;
@@ -19,9 +19,8 @@ function which(executable, path) {
19
19
  const DETOX_LIBRARY_ROOT_PATH = path.join(appdatapath.appDataPath(), 'Detox');
20
20
  const MISSING_SDK_ERROR = `$ANDROID_SDK_ROOT is not defined, set the path to the SDK installation directory into $ANDROID_SDK_ROOT,
21
21
  Go to https://developer.android.com/studio/command-line/variables.html for more details`;
22
- const DEVICE_LOCK_FILE_PATH_IOS = path.join(DETOX_LIBRARY_ROOT_PATH, 'device.registry.state.lock');
23
- const DEVICE_LOCK_FILE_PATH_ANDROID = path.join(DETOX_LIBRARY_ROOT_PATH, 'android-device.registry.state.lock');
24
- const GENYCLOUD_GLOBAL_CLEANUP_FILE_PATH = path.join(DETOX_LIBRARY_ROOT_PATH, 'genycloud-cleanup.lock');
22
+ const DETOX_LOCK_FILE_PATH = path.join(DETOX_LIBRARY_ROOT_PATH, 'global-context.json');
23
+ const DEVICE_REGISTRY_PATH = path.join(DETOX_LIBRARY_ROOT_PATH, 'device.registry.json');
25
24
  const LAST_FAILED_TESTS_PATH = path.join(DETOX_LIBRARY_ROOT_PATH, 'last-failed.txt');
26
25
 
27
26
  function getAndroidSDKPath() {
@@ -195,17 +194,12 @@ function getDetoxLibraryRootPath() {
195
194
  return DETOX_LIBRARY_ROOT_PATH;
196
195
  }
197
196
 
198
- function getDeviceLockFilePathIOS() {
199
- return DEVICE_LOCK_FILE_PATH_IOS;
197
+ function getDetoxLockFilePath() {
198
+ return DETOX_LOCK_FILE_PATH;
200
199
  }
201
200
 
202
- // TODO This can probably be merged with IOS' by now
203
- function getDeviceLockFilePathAndroid() {
204
- return DEVICE_LOCK_FILE_PATH_ANDROID;
205
- }
206
-
207
- function getGenyCloudGlobalCleanupFilePath() {
208
- return GENYCLOUD_GLOBAL_CLEANUP_FILE_PATH;
201
+ function getDeviceRegistryPath() {
202
+ return DEVICE_REGISTRY_PATH;
209
203
  }
210
204
 
211
205
  function getLastFailedTestsPath() {
@@ -229,9 +223,8 @@ module.exports = {
229
223
  getAndroidSDKPath,
230
224
  getAndroidEmulatorPath,
231
225
  getDetoxLibraryRootPath,
232
- getDeviceLockFilePathIOS,
233
- getDeviceLockFilePathAndroid,
234
- getGenyCloudGlobalCleanupFilePath,
226
+ getDetoxLockFilePath,
227
+ getDeviceRegistryPath,
235
228
  getLastFailedTestsPath,
236
229
  getHomeDir,
237
230
  };
@@ -40,15 +40,15 @@ function asError(error) {
40
40
  return isError(error) ? error : new Error(error);
41
41
  }
42
42
 
43
- function serializeObjectWithError(obj, errorKey) {
44
- if (obj[errorKey]) {
43
+ function serializeObjectWithError(obj, errorKey = 'error') {
44
+ if (obj[errorKey] instanceof Error) {
45
45
  return { ...obj, [errorKey]: serializeError(obj[errorKey]) };
46
46
  }
47
47
 
48
48
  return obj;
49
49
  }
50
50
 
51
- function deserializeObjectWithError(obj, errorKey) {
51
+ function deserializeObjectWithError(obj, errorKey = 'error') {
52
52
  if (typeof obj[errorKey] === 'object' && !(obj[errorKey] instanceof Error)) {
53
53
  return { ...obj, [errorKey]: deserializeError(obj[errorKey]) };
54
54
  }
package/tsconfig.json CHANGED
@@ -1,11 +1,11 @@
1
1
  {
2
2
  "compilerOptions": {
3
3
  "module": "commonjs",
4
- "lib": ["es2018"],
5
- "target": "ES2018",
4
+ "lib": ["es2022"],
5
+ "target": "ES2022",
6
6
  "allowJs": true,
7
7
  "checkJs": true,
8
- "moduleResolution": "node",
8
+ "moduleResolution": "node16",
9
9
  "resolveJsonModule": true,
10
10
  "esModuleInterop": true,
11
11
  "noEmit": true,
@@ -20,6 +20,8 @@
20
20
  ],
21
21
  "exclude": [
22
22
  "android",
23
+ "allure-report",
24
+ "allure-results",
23
25
  "coverage",
24
26
  "ios",
25
27
  "test"
@@ -1 +0,0 @@
1
- 0780bd77755cae9d89bc326c195d8eb1
@@ -1 +0,0 @@
1
- 9168cee63c5b35da49de50f34c9c41ad5fc0c449
@@ -1 +0,0 @@
1
- d3b9a104400c779bb7a1e70546c33abd374cf8eeb55ac5b4098a6c54737d0411
@@ -1 +0,0 @@
1
- ba86f8d9c3163eefc5d13776f4288708d96e00c83bea5527bbbd1a1c2027c79e6d44d19a8c85959bc48f3b7311c2969c96ea4d26569adb18f8f90fb56f7b558e
@@ -1 +0,0 @@
1
- 70745a3a7e09a2682c6a8902a413bff1
@@ -1 +0,0 @@
1
- 1da2776757d2a28dc4c3e73a7b469b4d92dee9c8
@@ -1 +0,0 @@
1
- 931d28ebdf7b9bceb5ad5ec36cd7b3696f91e6955579f505c311c1b5334fb57a
@@ -1 +0,0 @@
1
- 4750dd9cab79b2cab696c552101c755c609e6a4bfa5ab75d742004cbf4fe5bfdbc87b36096e1145559c5a5f65b6216181b6690efaa73016df660a4865d774782
@@ -1 +0,0 @@
1
- c90cc85230997f3663da1741d1eabc0e
@@ -1 +0,0 @@
1
- 0e17ccf18dbb2e0295e72b77cae67275591d956a
@@ -1 +0,0 @@
1
- 00528b5d136df63bc93f55c2f890a1ad69179f341663310b520227f6b7aad63b
@@ -1 +0,0 @@
1
- 37984e2491685ede0325d74f460ad2a13dc55bd906124e0932fa09e29e2394a91cbbf691aa854848503113f04dfe148a483e616c736918f6e0077af6aa311a31
@@ -1 +0,0 @@
1
- 1ebd5db42295ac98e2151fc5c24b8903
@@ -1 +0,0 @@
1
- e5614e7546e21d6757c4b338efc93e6b6a0a4bf6
@@ -1 +0,0 @@
1
- b38cc093a239ee307a854533ad801c3ee7548c01519f7964da7d0285486a09a8
@@ -1 +0,0 @@
1
- 5f94777c0cbddf9a24e2f661fc598fec79e71d555107020bcbb366a728307e990ae7205b210346562faa08fc00774ff3a9336e8fd185c80bd1fa9ebb4d2fa8c5
@@ -1,176 +0,0 @@
1
- // @ts-nocheck
2
- const fs = require('fs-extra');
3
- const _ = require('lodash');
4
-
5
- const ExclusiveLockfile = require('../utils/ExclusiveLockfile');
6
- const environment = require('../utils/environment');
7
- const safeAsync = require('../utils/safeAsync');
8
-
9
- const readOptions = {
10
- encoding: 'utf8',
11
- };
12
-
13
- const FIELD_NAME_ID = 'id';
14
- const FIELD_NAME_DATA = 'data';
15
-
16
- class DevicesList {
17
- constructor(devices) {
18
- this._devices = Object.freeze(devices);
19
- }
20
-
21
- /**
22
- * @returns {{id: string, data: *?}[]}
23
- */
24
- get rawDevices() {
25
- return this._devices;
26
- }
27
-
28
- /**
29
- * @param {string} deviceId
30
- * @returns {boolean}
31
- */
32
- includes(deviceId) {
33
- return DevicesList._includes(deviceId, this._devices);
34
- }
35
-
36
- static _includes(deviceId, devices) {
37
- return _.some(devices, [FIELD_NAME_ID, deviceId]);
38
- }
39
- }
40
-
41
- class DeviceRegistry {
42
- constructor({ lockfilePath }) {
43
- /***
44
- * @private
45
- * @type {string}
46
- */
47
- this._lockfilePath = lockfilePath;
48
-
49
- /***
50
- * @protected
51
- * @type {ExclusiveLockfile}
52
- */
53
- this._lockfile = new ExclusiveLockfile(lockfilePath, {
54
- getInitialState: this._getInitialLockFileState.bind(this),
55
- readOptions,
56
- });
57
- }
58
-
59
- async reset() {
60
- await this._lockfile.exclusively(() => {
61
- const empty = this._getInitialLockFileState();
62
- this._lockfile.write(empty);
63
- });
64
- }
65
-
66
- /***
67
- * @param {string|Function} getDeviceId
68
- * @param {*?} data
69
- * @returns {Promise<string>}
70
- */
71
- async allocateDevice(getDeviceId, data) {
72
- return this._lockfile.exclusively(async () => {
73
- const deviceId = await safeAsync(getDeviceId);
74
- this._registerDevice(deviceId, data);
75
- return deviceId;
76
- });
77
- }
78
-
79
- /***
80
- * @param {string|Function} getDeviceId
81
- * @returns {Promise<void>}
82
- */
83
- async disposeDevice(getDeviceId) {
84
- await this._lockfile.exclusively(async () => {
85
- const deviceId = await safeAsync(getDeviceId);
86
- if (deviceId) {
87
- this._unregisterDevice(deviceId);
88
- }
89
- });
90
- }
91
-
92
- /***
93
- * @param {string} deviceId
94
- * @returns {boolean}
95
- */
96
- includes(deviceId) {
97
- const devices = this._lockfile.read();
98
- return DevicesList._includes(deviceId, devices);
99
- }
100
-
101
- /***
102
- * @returns {DevicesList}
103
- */
104
- getRegisteredDevices() {
105
- const devices = this._lockfile.read();
106
- return new DevicesList(devices);
107
- }
108
-
109
- /***
110
- * @returns {DevicesList}
111
- */
112
- async readRegisteredDevices() {
113
- let result = null;
114
- await this._lockfile.exclusively(() => {
115
- result = this.getRegisteredDevices();
116
- });
117
- return result;
118
- }
119
-
120
- /***
121
- * @returns {DevicesList}
122
- */
123
- readRegisteredDevicesUNSAFE() {
124
- const contents = fs.readFileSync(this._lockfilePath, readOptions);
125
- const devices = JSON.parse(contents);
126
- return new DevicesList(devices);
127
- }
128
-
129
- /***
130
- * @private
131
- */
132
- _getInitialLockFileState() {
133
- return [];
134
- }
135
-
136
- /**
137
- * @private
138
- */
139
- _registerDevice(deviceId, data) {
140
- const state = this._lockfile.read();
141
- let newState = _.reject(state, [FIELD_NAME_ID, deviceId]);
142
-
143
- const device = {};
144
- device[FIELD_NAME_ID] = deviceId;
145
-
146
- if (data) {
147
- device[FIELD_NAME_DATA] = data;
148
- }
149
-
150
- newState = _.concat(newState, device);
151
- this._lockfile.write(newState);
152
- }
153
-
154
- /**
155
- * @private
156
- */
157
- _unregisterDevice(deviceId) {
158
- const state = this._lockfile.read();
159
- const newState = _.reject(state, [FIELD_NAME_ID, deviceId]);
160
- this._lockfile.write(newState);
161
- }
162
-
163
- static forIOS() {
164
- return new DeviceRegistry({
165
- lockfilePath: environment.getDeviceLockFilePathIOS(),
166
- });
167
- }
168
-
169
- static forAndroid() {
170
- return new DeviceRegistry({
171
- lockfilePath: environment.getDeviceLockFilePathAndroid(),
172
- });
173
- }
174
- }
175
-
176
- module.exports = DeviceRegistry;
@@ -1,30 +0,0 @@
1
- /* eslint @typescript-eslint/no-unused-vars: ["error", { "args": "none" }] */
2
- // @ts-nocheck
3
-
4
- /**
5
- * @typedef DeallocOptions
6
- * @property shutdown { Boolean }
7
- */
8
-
9
- class AllocationDriverBase {
10
- /**
11
- * @param deviceConfig { Object }
12
- * @return {Promise<DeviceCookie>}
13
- */
14
- async allocate(deviceConfig) {}
15
-
16
- /**
17
- * @param {DeviceCookie} deviceCookie
18
- * @return {Promise<void>}
19
- */
20
- async postAllocate(deviceCookie) {}
21
-
22
- /**
23
- * @param cookie { DeviceCookie }
24
- * @param options { DeallocOptions }
25
- * @return {Promise<void>}
26
- */
27
- async free(cookie, options) {}
28
- }
29
-
30
- module.exports = AllocationDriverBase;
@@ -1,13 +0,0 @@
1
- const DeviceLauncher = require('../../../../common/drivers/DeviceLauncher');
2
-
3
- class AttachedAndroidLauncher extends DeviceLauncher {
4
- constructor(eventEmitter) {
5
- super(eventEmitter);
6
- }
7
-
8
- notifyLaunchCompleted(adbName) {
9
- return super._notifyBootEvent(adbName, 'device', false);
10
- }
11
- }
12
-
13
- module.exports = AttachedAndroidLauncher;