detox 20.12.2 → 20.13.0
Sign up to get free protection for your applications and to get access to all the features.
- package/Detox-android/com/wix/detox/{20.12.2/detox-20.12.2-javadoc.jar → 20.13.0/detox-20.13.0-javadoc.jar} +0 -0
- package/Detox-android/com/wix/detox/20.13.0/detox-20.13.0-javadoc.jar.md5 +1 -0
- package/Detox-android/com/wix/detox/20.13.0/detox-20.13.0-javadoc.jar.sha1 +1 -0
- package/Detox-android/com/wix/detox/20.13.0/detox-20.13.0-javadoc.jar.sha256 +1 -0
- package/Detox-android/com/wix/detox/20.13.0/detox-20.13.0-javadoc.jar.sha512 +1 -0
- package/Detox-android/com/wix/detox/{20.12.2/detox-20.12.2-sources.jar → 20.13.0/detox-20.13.0-sources.jar} +0 -0
- package/Detox-android/com/wix/detox/20.13.0/detox-20.13.0-sources.jar.md5 +1 -0
- package/Detox-android/com/wix/detox/20.13.0/detox-20.13.0-sources.jar.sha1 +1 -0
- package/Detox-android/com/wix/detox/20.13.0/detox-20.13.0-sources.jar.sha256 +1 -0
- package/Detox-android/com/wix/detox/20.13.0/detox-20.13.0-sources.jar.sha512 +1 -0
- package/Detox-android/com/wix/detox/{20.12.2/detox-20.12.2.pom → 20.13.0/detox-20.13.0.pom} +1 -1
- package/Detox-android/com/wix/detox/20.13.0/detox-20.13.0.pom.md5 +1 -0
- package/Detox-android/com/wix/detox/20.13.0/detox-20.13.0.pom.sha1 +1 -0
- package/Detox-android/com/wix/detox/20.13.0/detox-20.13.0.pom.sha256 +1 -0
- package/Detox-android/com/wix/detox/20.13.0/detox-20.13.0.pom.sha512 +1 -0
- package/Detox-android/com/wix/detox/maven-metadata.xml +4 -4
- package/Detox-android/com/wix/detox/maven-metadata.xml.md5 +1 -1
- package/Detox-android/com/wix/detox/maven-metadata.xml.sha1 +1 -1
- package/Detox-android/com/wix/detox/maven-metadata.xml.sha256 +1 -1
- package/Detox-android/com/wix/detox/maven-metadata.xml.sha512 +1 -1
- package/Detox-ios-src.tbz +0 -0
- package/Detox-ios.tbz +0 -0
- package/local-cli/reset-lock-file.js +5 -9
- package/package.json +5 -6
- package/runners/jest/testEnvironment/index.js +1 -1
- package/src/DetoxWorker.js +5 -11
- package/src/artifacts/providers/index.js +3 -3
- package/src/artifacts/screenshot/SimulatorScreenshotPlugin.js +0 -17
- package/src/configuration/composeLoggerConfig.js +1 -0
- package/src/devices/allocation/DeviceAllocator.js +66 -20
- package/src/devices/allocation/DeviceList.js +44 -0
- package/src/devices/allocation/DeviceRegistry.js +189 -0
- package/src/devices/allocation/drivers/AllocationDriverBase.d.ts +15 -0
- package/src/devices/{common/drivers/android/tools → allocation/drivers/android}/FreeDeviceFinder.js +11 -10
- package/src/devices/allocation/drivers/android/attached/AttachedAndroidAllocDriver.js +22 -17
- package/src/devices/allocation/drivers/android/emulator/EmulatorAllocDriver.js +97 -38
- package/src/devices/allocation/drivers/android/emulator/EmulatorLauncher.js +32 -45
- package/src/devices/allocation/drivers/android/emulator/FreeEmulatorFinder.js +1 -1
- package/src/devices/allocation/drivers/android/emulator/FreePortFinder.js +37 -0
- package/src/devices/allocation/drivers/android/emulator/launchEmulatorProcess.js +3 -3
- package/src/devices/allocation/drivers/android/genycloud/GenyAllocDriver.js +104 -32
- package/src/devices/allocation/drivers/android/genycloud/GenyInstanceLauncher.js +40 -31
- package/src/devices/allocation/drivers/android/genycloud/GenyRegistry.js +121 -0
- package/src/devices/allocation/drivers/android/genycloud/services/GenyInstanceLifecycleService.js +24 -0
- package/src/devices/{common → allocation}/drivers/android/genycloud/services/GenyRecipesService.js +1 -1
- package/src/devices/allocation/drivers/android/genycloud/services/dto/GenyInstance.js +83 -0
- package/src/devices/allocation/drivers/android/genycloud/services/dto/GenyRecipe.js +25 -0
- package/src/devices/allocation/drivers/ios/SimulatorAllocDriver.js +94 -51
- package/src/devices/allocation/drivers/ios/SimulatorLauncher.js +11 -7
- package/src/devices/allocation/drivers/ios/SimulatorQuery.js +24 -0
- package/src/devices/allocation/factories/android.js +29 -35
- package/src/devices/allocation/factories/ios.js +7 -5
- package/src/devices/common/drivers/DeviceCookie.d.ts +12 -0
- package/src/devices/common/drivers/android/cookies.d.ts +11 -0
- package/src/devices/common/drivers/android/emulator/exec/EmulatorExec.js +17 -5
- package/src/devices/common/drivers/android/exec/ADB.js +1 -0
- package/src/devices/common/drivers/ios/cookies.d.ts +9 -0
- package/src/devices/cookies/index.js +0 -6
- package/src/devices/runtime/drivers/android/genycloud/GenyCloudDriver.js +7 -6
- package/src/devices/runtime/factories/android.js +3 -11
- package/src/devices/runtime/factories/ios.js +3 -2
- package/src/{servicelocator → devices/servicelocator}/android/emulatorServiceLocator.js +1 -1
- package/src/devices/servicelocator/android/genycloudServiceLocator.js +17 -0
- package/src/devices/servicelocator/android/index.js +23 -0
- package/src/{validation → devices/validation}/EnvironmentValidatorBase.js +1 -0
- package/src/{validation → devices/validation}/android/GenycloudEnvValidator.js +2 -2
- package/src/{validation → devices/validation}/factories/index.js +1 -1
- package/src/{validation → devices/validation}/ios/IosSimulatorEnvValidator.js +2 -2
- package/src/environmentFactory.js +1 -11
- package/src/ipc/IPCClient.js +17 -1
- package/src/ipc/IPCServer.js +27 -1
- package/src/logger/DetoxLogger.js +2 -2
- package/src/realms/DetoxContext.js +6 -0
- package/src/realms/DetoxPrimaryContext.js +42 -42
- package/src/realms/DetoxSecondaryContext.js +19 -0
- package/src/realms/symbols.js +4 -0
- package/src/utils/PIDService.js +27 -0
- package/src/utils/environment.js +8 -15
- package/src/utils/errorUtils.js +2 -2
- package/tsconfig.json +5 -3
- package/Detox-android/com/wix/detox/20.12.2/detox-20.12.2-javadoc.jar.md5 +0 -1
- package/Detox-android/com/wix/detox/20.12.2/detox-20.12.2-javadoc.jar.sha1 +0 -1
- package/Detox-android/com/wix/detox/20.12.2/detox-20.12.2-javadoc.jar.sha256 +0 -1
- package/Detox-android/com/wix/detox/20.12.2/detox-20.12.2-javadoc.jar.sha512 +0 -1
- package/Detox-android/com/wix/detox/20.12.2/detox-20.12.2-sources.jar.md5 +0 -1
- package/Detox-android/com/wix/detox/20.12.2/detox-20.12.2-sources.jar.sha1 +0 -1
- package/Detox-android/com/wix/detox/20.12.2/detox-20.12.2-sources.jar.sha256 +0 -1
- package/Detox-android/com/wix/detox/20.12.2/detox-20.12.2-sources.jar.sha512 +0 -1
- package/Detox-android/com/wix/detox/20.12.2/detox-20.12.2.pom.md5 +0 -1
- package/Detox-android/com/wix/detox/20.12.2/detox-20.12.2.pom.sha1 +0 -1
- package/Detox-android/com/wix/detox/20.12.2/detox-20.12.2.pom.sha256 +0 -1
- package/Detox-android/com/wix/detox/20.12.2/detox-20.12.2.pom.sha512 +0 -1
- package/src/devices/DeviceRegistry.js +0 -176
- package/src/devices/allocation/drivers/AllocationDriverBase.js +0 -30
- package/src/devices/allocation/drivers/android/attached/AttachedAndroidLauncher.js +0 -13
- package/src/devices/allocation/drivers/android/emulator/EmulatorAllocationHelper.js +0 -72
- package/src/devices/allocation/drivers/android/genycloud/GenyDeviceRegistryFactory.js +0 -16
- package/src/devices/allocation/drivers/android/genycloud/GenyInstanceAllocationHelper.js +0 -65
- package/src/devices/common/drivers/DeviceAllocationHelper.js +0 -20
- package/src/devices/common/drivers/DeviceLauncher.js +0 -19
- package/src/devices/common/drivers/android/genycloud/services/GenyInstanceLifecycleService.js +0 -25
- package/src/devices/common/drivers/android/genycloud/services/GenyInstanceLookupService.js +0 -38
- package/src/devices/common/drivers/android/genycloud/services/GenyInstanceNaming.js +0 -14
- package/src/devices/common/drivers/android/genycloud/services/dto/GenyInstance.js +0 -66
- package/src/devices/common/drivers/android/genycloud/services/dto/GenyRecipe.js +0 -13
- package/src/devices/cookies/AndroidDeviceCookie.js +0 -13
- package/src/devices/cookies/AndroidEmulatorCookie.js +0 -6
- package/src/devices/cookies/AttachedAndroidDeviceCookie.js +0 -12
- package/src/devices/cookies/DeviceCookie.js +0 -4
- package/src/devices/cookies/GenycloudEmulatorCookie.js +0 -20
- package/src/devices/cookies/IosCookie.js +0 -6
- package/src/devices/cookies/IosSimulatorCookie.js +0 -10
- package/src/devices/lifecycle/GenyGlobalLifecycleHandler.js +0 -71
- package/src/devices/lifecycle/factories/GenyGlobalLifecycleHandlerFactory.js +0 -18
- package/src/servicelocator/android/genycloudServiceLocator.js +0 -21
- package/src/servicelocator/android/index.js +0 -25
- package/src/servicelocator/ios.js +0 -7
- /package/Detox-android/com/wix/detox/{20.12.2/detox-20.12.2.aar → 20.13.0/detox-20.13.0.aar} +0 -0
- /package/Detox-android/com/wix/detox/{20.12.2/detox-20.12.2.aar.md5 → 20.13.0/detox-20.13.0.aar.md5} +0 -0
- /package/Detox-android/com/wix/detox/{20.12.2/detox-20.12.2.aar.sha1 → 20.13.0/detox-20.13.0.aar.sha1} +0 -0
- /package/Detox-android/com/wix/detox/{20.12.2/detox-20.12.2.aar.sha256 → 20.13.0/detox-20.13.0.aar.sha256} +0 -0
- /package/Detox-android/com/wix/detox/{20.12.2/detox-20.12.2.aar.sha512 → 20.13.0/detox-20.13.0.aar.sha512} +0 -0
- /package/src/devices/{common → allocation}/drivers/android/genycloud/exec/GenyCloudExec.js +0 -0
- /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[
|
35
|
+
this[_deviceAllocator] = null;
|
36
|
+
|
37
37
|
/** Path to file where the initial session object is serialized */
|
38
38
|
this[_sessionFile] = '';
|
39
39
|
/**
|
@@ -85,7 +85,6 @@ class DetoxPrimaryContext extends DetoxContext {
|
|
85
85
|
const detoxConfig = await this[symbols.resolveConfig](opts);
|
86
86
|
|
87
87
|
const {
|
88
|
-
behavior: behaviorConfig,
|
89
88
|
device: deviceConfig,
|
90
89
|
logger: loggerConfig,
|
91
90
|
session: sessionConfig
|
@@ -102,20 +101,23 @@ class DetoxPrimaryContext extends DetoxContext {
|
|
102
101
|
this[_ipcServer] = new IPCServer({
|
103
102
|
sessionState: this[$sessionState],
|
104
103
|
logger: this[symbols.logger],
|
104
|
+
callbacks: {
|
105
|
+
onAllocateDevice: this[symbols.allocateDevice].bind(this),
|
106
|
+
onDeallocateDevice: this[symbols.deallocateDevice].bind(this),
|
107
|
+
},
|
105
108
|
});
|
106
109
|
|
107
110
|
await this[_ipcServer].init();
|
108
111
|
|
109
112
|
const environmentFactory = require('../environmentFactory');
|
110
|
-
this[_globalLifecycleHandler] = await environmentFactory.createGlobalLifecycleHandler(deviceConfig);
|
111
113
|
|
112
|
-
|
113
|
-
|
114
|
-
|
114
|
+
const { deviceAllocatorFactory } = environmentFactory.createFactories(deviceConfig);
|
115
|
+
this[_deviceAllocator] = deviceAllocatorFactory.createDeviceAllocator({
|
116
|
+
detoxConfig,
|
117
|
+
detoxSession: this[$sessionState],
|
118
|
+
});
|
115
119
|
|
116
|
-
|
117
|
-
await this[_resetLockFile]();
|
118
|
-
}
|
120
|
+
await this[_deviceAllocator].init();
|
119
121
|
|
120
122
|
// TODO: Detox-server creation ought to be delegated to a generator/factory.
|
121
123
|
const DetoxServer = require('../server/DetoxServer');
|
@@ -159,6 +161,29 @@ class DetoxPrimaryContext extends DetoxContext {
|
|
159
161
|
await super[symbols.installWorker]({ ...opts, workerId });
|
160
162
|
}
|
161
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
|
+
|
162
187
|
/** @override */
|
163
188
|
async [symbols.cleanup]() {
|
164
189
|
try {
|
@@ -166,9 +191,9 @@ class DetoxPrimaryContext extends DetoxContext {
|
|
166
191
|
await this[symbols.uninstallWorker]();
|
167
192
|
}
|
168
193
|
} finally {
|
169
|
-
if (this[
|
170
|
-
await this[
|
171
|
-
this[
|
194
|
+
if (this[_deviceAllocator]) {
|
195
|
+
await this[_deviceAllocator].cleanup();
|
196
|
+
this[_deviceAllocator] = null;
|
172
197
|
}
|
173
198
|
|
174
199
|
if (this[_wss]) {
|
@@ -202,9 +227,9 @@ class DetoxPrimaryContext extends DetoxContext {
|
|
202
227
|
return;
|
203
228
|
}
|
204
229
|
|
205
|
-
if (this[
|
206
|
-
this[
|
207
|
-
this[
|
230
|
+
if (this[_deviceAllocator]) {
|
231
|
+
this[_deviceAllocator].emergencyCleanup();
|
232
|
+
this[_deviceAllocator] = null;
|
208
233
|
}
|
209
234
|
|
210
235
|
if (this[_wss]) {
|
@@ -247,31 +272,6 @@ class DetoxPrimaryContext extends DetoxContext {
|
|
247
272
|
});
|
248
273
|
}
|
249
274
|
//#endregion
|
250
|
-
|
251
|
-
//#region Private members
|
252
|
-
async[_resetLockFile]() {
|
253
|
-
const DeviceRegistry = require('../devices/DeviceRegistry');
|
254
|
-
|
255
|
-
const deviceType = this[symbols.config].device.type;
|
256
|
-
|
257
|
-
switch (deviceType) {
|
258
|
-
case 'ios.none':
|
259
|
-
case 'ios.simulator':
|
260
|
-
await DeviceRegistry.forIOS().reset();
|
261
|
-
break;
|
262
|
-
case 'android.attached':
|
263
|
-
case 'android.emulator':
|
264
|
-
case 'android.genycloud':
|
265
|
-
await DeviceRegistry.forAndroid().reset();
|
266
|
-
break;
|
267
|
-
}
|
268
|
-
|
269
|
-
if (deviceType === 'android.genycloud') {
|
270
|
-
const GenyDeviceRegistryFactory = require('../devices/allocation/drivers/android/genycloud/GenyDeviceRegistryFactory');
|
271
|
-
await GenyDeviceRegistryFactory.forGlobalShutdown().reset();
|
272
|
-
}
|
273
|
-
}
|
274
|
-
//#endregion
|
275
275
|
}
|
276
276
|
|
277
277
|
module.exports = DetoxPrimaryContext;
|
@@ -62,6 +62,25 @@ class DetoxSecondaryContext extends DetoxContext {
|
|
62
62
|
}
|
63
63
|
}
|
64
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
|
+
|
65
84
|
/** @override */
|
66
85
|
async [symbols.cleanup]() {
|
67
86
|
try {
|
package/src/realms/symbols.js
CHANGED
@@ -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;
|
@@ -34,6 +36,8 @@ module.exports = {
|
|
34
36
|
//#region IPC
|
35
37
|
reportTestResults: Symbol('reportTestResults'),
|
36
38
|
conductEarlyTeardown: Symbol('conductEarlyTeardown'),
|
39
|
+
allocateDevice: Symbol('allocateDevice'),
|
40
|
+
deallocateDevice: Symbol('deallocateDevice'),
|
37
41
|
//#endregion
|
38
42
|
|
39
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;
|
package/src/utils/environment.js
CHANGED
@@ -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
|
23
|
-
const
|
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
|
199
|
-
return
|
197
|
+
function getDetoxLockFilePath() {
|
198
|
+
return DETOX_LOCK_FILE_PATH;
|
200
199
|
}
|
201
200
|
|
202
|
-
|
203
|
-
|
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
|
-
|
233
|
-
|
234
|
-
getGenyCloudGlobalCleanupFilePath,
|
226
|
+
getDetoxLockFilePath,
|
227
|
+
getDeviceRegistryPath,
|
235
228
|
getLastFailedTestsPath,
|
236
229
|
getHomeDir,
|
237
230
|
};
|
package/src/utils/errorUtils.js
CHANGED
@@ -40,7 +40,7 @@ function asError(error) {
|
|
40
40
|
return isError(error) ? error : new Error(error);
|
41
41
|
}
|
42
42
|
|
43
|
-
function serializeObjectWithError(obj, errorKey) {
|
43
|
+
function serializeObjectWithError(obj, errorKey = 'error') {
|
44
44
|
if (obj[errorKey] instanceof Error) {
|
45
45
|
return { ...obj, [errorKey]: serializeError(obj[errorKey]) };
|
46
46
|
}
|
@@ -48,7 +48,7 @@ function serializeObjectWithError(obj, errorKey) {
|
|
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": ["
|
5
|
-
"target": "
|
4
|
+
"lib": ["es2022"],
|
5
|
+
"target": "ES2022",
|
6
6
|
"allowJs": true,
|
7
7
|
"checkJs": true,
|
8
|
-
"moduleResolution": "
|
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
|
-
9f36d2885a93f2a409ee4e590f8678fe
|
@@ -1 +0,0 @@
|
|
1
|
-
7627d2bccbd1f922472cb85f9e8480210d672d39
|
@@ -1 +0,0 @@
|
|
1
|
-
43075c10900e4d81f273d56e642d1230ec01a4748996955a452ee0374aec0200
|
@@ -1 +0,0 @@
|
|
1
|
-
2ba3ccabd9c41ad2ffb785c5c2ca9b5baedfe51fadcdcdc7b2c7c215335b061e693f7985800d562dd2e7449503e7e5d44a4332daf00a85f4e5b05da848a1f37f
|
@@ -1 +0,0 @@
|
|
1
|
-
bc5126d7b11cf8ad581aab27d743b430
|
@@ -1 +0,0 @@
|
|
1
|
-
ad9dc488b327afa3154138a147f3873dd4f6b644
|
@@ -1 +0,0 @@
|
|
1
|
-
d80d2d1e03c7f3b8b75ed70946e31725694cb29d4900eacc115276295b773347
|
@@ -1 +0,0 @@
|
|
1
|
-
be1d9cc4b36042e3f0416159a7b9509ce9e35de4eaabad53c385690a893bc51a0f453e0fe46173e91436b9f1e3dcbe9ab209434e1173558d5a87e5a94c8b278b
|
@@ -1 +0,0 @@
|
|
1
|
-
06ea49e97933d82debed143a3e362af8
|
@@ -1 +0,0 @@
|
|
1
|
-
866a73f92aa581f2d23afd5df152cce65a882de6
|
@@ -1 +0,0 @@
|
|
1
|
-
b7e47d08915a497db5f42985f3435420bf7580178c6975d1f257123c7bc53b4f
|
@@ -1 +0,0 @@
|
|
1
|
-
f7fbbb355ce037d0519ad63caeebab6447f1e38f25ce44d495267510f7e4576978fff4b676f1a86966e7f638b4678b7bc769f50e4ffa1d106c786db72b9f7d6b
|
@@ -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;
|
@@ -1,72 +0,0 @@
|
|
1
|
-
const logger = require('../../../../../utils/logger').child({ cat: 'device' });
|
2
|
-
const DeviceAllocationHelper = require('../../../../common/drivers/DeviceAllocationHelper');
|
3
|
-
|
4
|
-
const DetoxEmulatorsPortRange = {
|
5
|
-
min: 10000,
|
6
|
-
max: 20000
|
7
|
-
};
|
8
|
-
|
9
|
-
class AllocationResult {
|
10
|
-
constructor(adbName, placeholderPort) {
|
11
|
-
this.adbName = adbName;
|
12
|
-
this.placeholderPort = placeholderPort;
|
13
|
-
}
|
14
|
-
|
15
|
-
get isRunning() {
|
16
|
-
return !this.placeholderPort;
|
17
|
-
}
|
18
|
-
}
|
19
|
-
|
20
|
-
class EmulatorAllocationHelper extends DeviceAllocationHelper {
|
21
|
-
constructor(deviceRegistry, freeDeviceFinder, rand = Math.random) {
|
22
|
-
super(deviceRegistry, logger);
|
23
|
-
this._freeDeviceFinder = freeDeviceFinder;
|
24
|
-
this._rand = rand;
|
25
|
-
}
|
26
|
-
|
27
|
-
/**
|
28
|
-
* @param avdName
|
29
|
-
* @returns {Promise<AllocationResult>}
|
30
|
-
*/
|
31
|
-
async allocateDevice(avdName) {
|
32
|
-
this._logAllocationAttempt(avdName);
|
33
|
-
|
34
|
-
const result = await this._doSynchronizedAllocation(avdName);
|
35
|
-
this._logAllocationResult(avdName, result.adbName);
|
36
|
-
|
37
|
-
return result;
|
38
|
-
}
|
39
|
-
|
40
|
-
async deallocateDevice(adbName) {
|
41
|
-
await this._deviceRegistry.disposeDevice(adbName);
|
42
|
-
}
|
43
|
-
|
44
|
-
/**
|
45
|
-
* @returns {Promise<AllocationResult>}
|
46
|
-
* @private
|
47
|
-
*/
|
48
|
-
async _doSynchronizedAllocation(avdName) {
|
49
|
-
let placeholderPort = null;
|
50
|
-
let adbName = null;
|
51
|
-
|
52
|
-
await this._deviceRegistry.allocateDevice(async () => {
|
53
|
-
adbName = await this._freeDeviceFinder.findFreeDevice(avdName);
|
54
|
-
if (!adbName) {
|
55
|
-
placeholderPort = this._allocateEmulatorPlaceholderPort();
|
56
|
-
adbName = `emulator-${placeholderPort}`;
|
57
|
-
}
|
58
|
-
return adbName;
|
59
|
-
});
|
60
|
-
|
61
|
-
return new AllocationResult(adbName, placeholderPort);
|
62
|
-
}
|
63
|
-
|
64
|
-
_allocateEmulatorPlaceholderPort() {
|
65
|
-
const { min, max } = DetoxEmulatorsPortRange;
|
66
|
-
let port = this._rand() * (max - min) + min;
|
67
|
-
port = port & 0xFFFFFFFE; // Should always be even
|
68
|
-
return port;
|
69
|
-
}
|
70
|
-
}
|
71
|
-
|
72
|
-
module.exports = EmulatorAllocationHelper;
|
@@ -1,16 +0,0 @@
|
|
1
|
-
const environment = require('../../../../../utils/environment');
|
2
|
-
const DeviceRegistry = require('../../../../DeviceRegistry');
|
3
|
-
|
4
|
-
class GenyDeviceRegistryFactory {
|
5
|
-
forRuntime() {
|
6
|
-
return DeviceRegistry.forAndroid();
|
7
|
-
}
|
8
|
-
|
9
|
-
forGlobalShutdown() {
|
10
|
-
return new DeviceRegistry({
|
11
|
-
lockfilePath: environment.getGenyCloudGlobalCleanupFilePath(),
|
12
|
-
});
|
13
|
-
}
|
14
|
-
}
|
15
|
-
|
16
|
-
module.exports = new GenyDeviceRegistryFactory();
|