detox 20.14.5 → 20.14.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (52) hide show
  1. package/Detox-android/com/wix/detox/{20.14.5/detox-20.14.5-javadoc.jar → 20.14.6/detox-20.14.6-javadoc.jar} +0 -0
  2. package/Detox-android/com/wix/detox/20.14.6/detox-20.14.6-javadoc.jar.md5 +1 -0
  3. package/Detox-android/com/wix/detox/20.14.6/detox-20.14.6-javadoc.jar.sha1 +1 -0
  4. package/Detox-android/com/wix/detox/20.14.6/detox-20.14.6-javadoc.jar.sha256 +1 -0
  5. package/Detox-android/com/wix/detox/20.14.6/detox-20.14.6-javadoc.jar.sha512 +1 -0
  6. package/Detox-android/com/wix/detox/{20.14.5/detox-20.14.5-sources.jar → 20.14.6/detox-20.14.6-sources.jar} +0 -0
  7. package/Detox-android/com/wix/detox/20.14.6/detox-20.14.6-sources.jar.md5 +1 -0
  8. package/Detox-android/com/wix/detox/20.14.6/detox-20.14.6-sources.jar.sha1 +1 -0
  9. package/Detox-android/com/wix/detox/20.14.6/detox-20.14.6-sources.jar.sha256 +1 -0
  10. package/Detox-android/com/wix/detox/20.14.6/detox-20.14.6-sources.jar.sha512 +1 -0
  11. package/Detox-android/com/wix/detox/{20.14.5/detox-20.14.5.pom → 20.14.6/detox-20.14.6.pom} +1 -1
  12. package/Detox-android/com/wix/detox/20.14.6/detox-20.14.6.pom.md5 +1 -0
  13. package/Detox-android/com/wix/detox/20.14.6/detox-20.14.6.pom.sha1 +1 -0
  14. package/Detox-android/com/wix/detox/20.14.6/detox-20.14.6.pom.sha256 +1 -0
  15. package/Detox-android/com/wix/detox/20.14.6/detox-20.14.6.pom.sha512 +1 -0
  16. package/Detox-android/com/wix/detox/maven-metadata.xml +4 -4
  17. package/Detox-android/com/wix/detox/maven-metadata.xml.md5 +1 -1
  18. package/Detox-android/com/wix/detox/maven-metadata.xml.sha1 +1 -1
  19. package/Detox-android/com/wix/detox/maven-metadata.xml.sha256 +1 -1
  20. package/Detox-android/com/wix/detox/maven-metadata.xml.sha512 +1 -1
  21. package/Detox-ios-src.tbz +0 -0
  22. package/Detox-ios.tbz +0 -0
  23. package/detox.d.ts +1 -1
  24. package/jest.config.js +1 -1
  25. package/local-cli/init.js +1 -1
  26. package/package.json +6 -5
  27. package/runners/jest/testEnvironment/index.js +23 -9
  28. package/src/DetoxWorker.js +1 -1
  29. package/src/devices/common/drivers/android/tools/ApkValidator.js +1 -1
  30. package/src/devices/runtime/drivers/android/AndroidDriver.js +1 -1
  31. package/src/ipc/IPCClient.js +2 -2
  32. package/src/ipc/IPCServer.js +3 -3
  33. package/src/realms/DetoxContext.js +2 -2
  34. package/src/realms/DetoxPrimaryContext.js +74 -26
  35. package/src/realms/DetoxSecondaryContext.js +2 -2
  36. package/Detox-android/com/wix/detox/20.14.5/detox-20.14.5-javadoc.jar.md5 +0 -1
  37. package/Detox-android/com/wix/detox/20.14.5/detox-20.14.5-javadoc.jar.sha1 +0 -1
  38. package/Detox-android/com/wix/detox/20.14.5/detox-20.14.5-javadoc.jar.sha256 +0 -1
  39. package/Detox-android/com/wix/detox/20.14.5/detox-20.14.5-javadoc.jar.sha512 +0 -1
  40. package/Detox-android/com/wix/detox/20.14.5/detox-20.14.5-sources.jar.md5 +0 -1
  41. package/Detox-android/com/wix/detox/20.14.5/detox-20.14.5-sources.jar.sha1 +0 -1
  42. package/Detox-android/com/wix/detox/20.14.5/detox-20.14.5-sources.jar.sha256 +0 -1
  43. package/Detox-android/com/wix/detox/20.14.5/detox-20.14.5-sources.jar.sha512 +0 -1
  44. package/Detox-android/com/wix/detox/20.14.5/detox-20.14.5.pom.md5 +0 -1
  45. package/Detox-android/com/wix/detox/20.14.5/detox-20.14.5.pom.sha1 +0 -1
  46. package/Detox-android/com/wix/detox/20.14.5/detox-20.14.5.pom.sha256 +0 -1
  47. package/Detox-android/com/wix/detox/20.14.5/detox-20.14.5.pom.sha512 +0 -1
  48. /package/Detox-android/com/wix/detox/{20.14.5/detox-20.14.5.aar → 20.14.6/detox-20.14.6.aar} +0 -0
  49. /package/Detox-android/com/wix/detox/{20.14.5/detox-20.14.5.aar.md5 → 20.14.6/detox-20.14.6.aar.md5} +0 -0
  50. /package/Detox-android/com/wix/detox/{20.14.5/detox-20.14.5.aar.sha1 → 20.14.6/detox-20.14.6.aar.sha1} +0 -0
  51. /package/Detox-android/com/wix/detox/{20.14.5/detox-20.14.5.aar.sha256 → 20.14.6/detox-20.14.6.aar.sha256} +0 -0
  52. /package/Detox-android/com/wix/detox/{20.14.5/detox-20.14.5.aar.sha512 → 20.14.6/detox-20.14.6.aar.sha512} +0 -0
@@ -0,0 +1 @@
1
+ 41fe7597fc91cef56a970ce36e1947dd
@@ -0,0 +1 @@
1
+ f0c6385bd03f1ca7cde9eb0ee10aa87bc583ba0c
@@ -0,0 +1 @@
1
+ de6832e43ad96840f5231e028982dd44742765d2a385706beb95bd7dfbedce37
@@ -0,0 +1 @@
1
+ 5511678c6182985267910a2f1318eda59f4d6483235c7b6a80be362e31719016d3e4b2f4669d6ceb1cdc85f232e7deb4b4bccb7bb3cf4887b2db19cd9e610633
@@ -0,0 +1 @@
1
+ 131a67c2ff6d50fb5c70facc1f37c1dd
@@ -0,0 +1 @@
1
+ 5c854f3314e2012f849ff2dbd3bf31cbedebedf1
@@ -0,0 +1 @@
1
+ 795cc8048628577eccc74dbe3f8782bdf1f1ad7c9d5296b31ee0db505b323fd3
@@ -0,0 +1 @@
1
+ 2d9b697f65d0ab4efb934f12ff1cac70ca8a1fe3d9471f11ca4d6073558ff94365c02d83d099bac31167542633c382fd54d8accee11e5e31cb496128e4547481
@@ -3,7 +3,7 @@
3
3
  <modelVersion>4.0.0</modelVersion>
4
4
  <groupId>com.wix</groupId>
5
5
  <artifactId>detox</artifactId>
6
- <version>20.14.5</version>
6
+ <version>20.14.6</version>
7
7
  <packaging>aar</packaging>
8
8
  <name>Detox</name>
9
9
  <description>Gray box end-to-end testing and automation library for mobile apps</description>
@@ -0,0 +1 @@
1
+ ca7f0ba78d30abe2f89e34115ef7e386
@@ -0,0 +1 @@
1
+ 39dbf9358b9ce31252f861c23b7dcb6fde1b4122
@@ -0,0 +1 @@
1
+ 8769d69e473f95377f2c7a8f491488994c6b40a290751f0b17c0930616afc6bf
@@ -0,0 +1 @@
1
+ f5367ebd7e55eeff0f4d3eec4e522a5959e6fcfa85c90f66d3d7ff129a2d18c455581520014677aec397fcf58efc91c6441ee5543cf20d3ec60beec45d4aa785
@@ -3,11 +3,11 @@
3
3
  <groupId>com.wix</groupId>
4
4
  <artifactId>detox</artifactId>
5
5
  <versioning>
6
- <latest>20.14.5</latest>
7
- <release>20.14.5</release>
6
+ <latest>20.14.6</latest>
7
+ <release>20.14.6</release>
8
8
  <versions>
9
- <version>20.14.5</version>
9
+ <version>20.14.6</version>
10
10
  </versions>
11
- <lastUpdated>20231224164415</lastUpdated>
11
+ <lastUpdated>20231228113250</lastUpdated>
12
12
  </versioning>
13
13
  </metadata>
@@ -1 +1 @@
1
- 74cdf7b5ef32bcc52364e12cbdac9ecb
1
+ e246abca05b05658f3638d3bcb578f87
@@ -1 +1 @@
1
- f27b95426e12342add47387c1bee2b2d18b8c861
1
+ c764f25216e2352efe7a3b70d6a0777d3f2f1932
@@ -1 +1 @@
1
- 126b5c81bef151395b59d09c0e656d55fa2a35202bcaae4805464f8bb61be58d
1
+ 5ddd6ab77f6cdaedc23e661ddd0dea0a833ff3c7f9a9adddd7b37187c0fa16e0
@@ -1 +1 @@
1
- 689b5dedc7e658990cd8985b88b6a85c9cfcb4b7caf1d2691acbf44fe309f44e4c79cc00558c10af83aa1a05186fd6e4ac88d7d3051a0705932a330b519b7e80
1
+ d3472cfee8606dd4d43b6745b376f38f2eb200cf9b4a000f607d366a4b5e03544d9616be14d68f7e7f3abe43805cf29f52c155729374da11090e62d53d603837
package/Detox-ios-src.tbz CHANGED
Binary file
package/Detox-ios.tbz CHANGED
Binary file
package/detox.d.ts CHANGED
@@ -214,7 +214,7 @@ declare global {
214
214
  * This flag tells Detox to print messages like these every time the device gets assigned to a specific suite:
215
215
  *
216
216
  * ```plain text
217
- * 18:03:29.869 detox[40125] i starter.test.js is assigned to 4EC84833-C7EA-4CA3-A6E9-5C30A29EA596 (iPhone 12 Pro Max)
217
+ * 18:03:29.869 detox[40125] i starter.test.js is assigned to 4EC84833-C7EA-4CA3-A6E9-5C30A29EA596 (iPhone 15)
218
218
  * ```
219
219
  *
220
220
  * @default true
package/jest.config.js CHANGED
@@ -74,7 +74,7 @@ module.exports = {
74
74
  'runners/jest/testEnvironment',
75
75
  'src/DetoxWorker.js',
76
76
  'src/logger/utils/streamUtils.js',
77
- 'src/realms'
77
+ 'src/realms',
78
78
  ],
79
79
  resetMocks: true,
80
80
  resetModules: true,
package/local-cli/init.js CHANGED
@@ -106,7 +106,7 @@ function createDefaultConfigurations() {
106
106
  simulator: {
107
107
  type: 'ios.simulator',
108
108
  device: {
109
- type: 'iPhone 12',
109
+ type: 'iPhone 15',
110
110
  },
111
111
  },
112
112
  attached: {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "detox",
3
3
  "description": "E2E tests and automation for mobile",
4
- "version": "20.14.5",
4
+ "version": "20.14.6",
5
5
  "bin": {
6
6
  "detox": "local-cli/cli.js"
7
7
  },
@@ -37,7 +37,7 @@
37
37
  "@types/bunyan": "^1.8.8",
38
38
  "@types/child-process-promise": "^2.2.1",
39
39
  "@types/fs-extra": "^9.0.13",
40
- "@types/jest": "^28.1.8",
40
+ "@types/jest": "^29.0.0",
41
41
  "@types/node": "^14.18.33",
42
42
  "@types/node-ipc": "^9.2.0",
43
43
  "@types/ws": "^7.4.0",
@@ -50,8 +50,8 @@
50
50
  "eslint-plugin-no-only-tests": "^3.1.0",
51
51
  "eslint-plugin-node": "^11.1.0",
52
52
  "eslint-plugin-unicorn": "^47.0.0",
53
- "jest": "^28.1.3",
54
- "jest-allure2-reporter": "2.0.0-alpha.11",
53
+ "jest": "^29.0.0",
54
+ "jest-allure2-reporter": "^2.0.0-beta.2",
55
55
  "mockdate": "^2.0.1",
56
56
  "prettier": "^2.4.1",
57
57
  "react-native": "0.71.10",
@@ -72,6 +72,7 @@
72
72
  "funpermaproxy": "^1.1.0",
73
73
  "glob": "^8.0.3",
74
74
  "ini": "^1.3.4",
75
+ "jest-environment-emit": "^1.0.3",
75
76
  "json-cycle": "^1.3.0",
76
77
  "lodash": "^4.17.11",
77
78
  "multi-sort-stream": "^1.0.3",
@@ -109,5 +110,5 @@
109
110
  "browserslist": [
110
111
  "node 14"
111
112
  ],
112
- "gitHead": "826ba256c4a629c12497396c612cdff98794efc8"
113
+ "gitHead": "80bff595538780c7b8019c7db796142414600cf9"
113
114
  }
@@ -1,5 +1,6 @@
1
1
  const path = require('path');
2
2
 
3
+ const WithEmitter = require('jest-environment-emit');
3
4
  const resolveFrom = require('resolve-from');
4
5
  const maybeNodeEnvironment = require(resolveFrom(process.cwd(), 'jest-environment-node'));
5
6
  /** @type {typeof import('@jest/environment').JestEnvironment} */
@@ -31,7 +32,7 @@ const log = detox.log.child({ cat: 'lifecycle,jest-environment' });
31
32
  /**
32
33
  * @see https://www.npmjs.com/package/jest-circus#overview
33
34
  */
34
- class DetoxCircusEnvironment extends NodeEnvironment {
35
+ class DetoxCircusEnvironment extends WithEmitter(NodeEnvironment) {
35
36
  constructor(config, context) {
36
37
  super(assertJestCircus27(config), assertExistingContext(context));
37
38
 
@@ -62,6 +63,8 @@ class DetoxCircusEnvironment extends NodeEnvironment {
62
63
  SpecReporter,
63
64
  WorkerAssignReporter,
64
65
  });
66
+
67
+ this.testEvents.on('*', this._onTestEvent.bind(this));
65
68
  }
66
69
 
67
70
  /** @override */
@@ -72,19 +75,13 @@ class DetoxCircusEnvironment extends NodeEnvironment {
72
75
 
73
76
  // @ts-expect-error TS2425
74
77
  async handleTestEvent(event, state) {
78
+ await super.handleTestEvent(event, state);
79
+
75
80
  if (detox.session.unsafe_earlyTeardown) {
76
81
  if (event.name === 'test_fn_start' || event.name === 'hook_start') {
77
82
  throw new Error('Detox halted test execution due to an early teardown request');
78
83
  }
79
84
  }
80
-
81
- this._timer.schedule(state.testTimeout != null ? state.testTimeout : this.setupTimeout);
82
-
83
- if (SYNC_CIRCUS_EVENTS.has(event.name)) {
84
- this._handleTestEventSync(event, state);
85
- } else {
86
- await this._handleTestEventAsync(event, state);
87
- }
88
85
  }
89
86
 
90
87
  /** @override */
@@ -147,6 +144,23 @@ class DetoxCircusEnvironment extends NodeEnvironment {
147
144
  }
148
145
  }
149
146
 
147
+ /** @private */
148
+ _onTestEvent({ type, event, state }) {
149
+ const timeout = state && state.testTimeout != null ? state.testTimeout : this.setupTimeout;
150
+
151
+ this._timer.schedule(timeout);
152
+
153
+ if (event) {
154
+ if (SYNC_CIRCUS_EVENTS.has(event.name)) {
155
+ this._handleTestEventSync(event, state);
156
+ } else {
157
+ return this._handleTestEventAsync(event, state);
158
+ }
159
+ } else {
160
+ return this._handleTestEventAsync({ name: type }, null);
161
+ }
162
+ }
163
+
150
164
  /** @private */
151
165
  async _handleTestEventAsync(event, state = null) {
152
166
  const description = `handling ${state ? 'jest-circus' : 'jest-environment'} "${event.name}" event`;
@@ -132,7 +132,7 @@ class DetoxWorker {
132
132
  };
133
133
 
134
134
  this._artifactsManager = artifactsManagerFactory.createArtifactsManager(this._artifactsConfig, commonDeps);
135
- this._deviceCookie = yield this._context[symbols.allocateDevice]();
135
+ this._deviceCookie = yield this._context[symbols.allocateDevice](this._deviceConfig);
136
136
 
137
137
  this.device = runtimeDeviceFactory.createRuntimeDevice(
138
138
  this._deviceCookie,
@@ -1,6 +1,6 @@
1
1
  const DetoxRuntimeError = require('../../../../../errors/DetoxRuntimeError');
2
2
 
3
- const setupGuideHint = 'For further assistance, visit the Android setup guide: https://github.com/wix/Detox/blob/master/docs/Introduction.Android.md';
3
+ const setupGuideHint = 'For further assistance, visit the project setup guide (select the Android tabs): https://wix.github.io/Detox/docs/introduction/project-setup';
4
4
 
5
5
  class ApkValidator {
6
6
  constructor(aapt) {
@@ -280,7 +280,7 @@ class AndroidDriver extends DeviceDriverBase {
280
280
  throw new DetoxRuntimeError({
281
281
  message: `The test APK could not be found at path: '${testApkPath}'`,
282
282
  hint: 'Try running the detox build command, and make sure it was configured to execute a build command (e.g. \'./gradlew assembleAndroidTest\')' +
283
- '\nFor further assistance, visit the Android setup guide: https://github.com/wix/Detox/blob/master/docs/Introduction.Android.md',
283
+ '\nFor further assistance, visit the project setup guide (select the Android tabs): https://wix.github.io/Detox/docs/introduction/project-setup',
284
284
  });
285
285
  }
286
286
  return testApkPath;
@@ -60,8 +60,8 @@ class IPCClient {
60
60
  this._sessionState.patch(sessionState);
61
61
  }
62
62
 
63
- async allocateDevice() {
64
- const { deviceCookie, error } = deserializeObjectWithError(await this._emit('allocateDevice', {}));
63
+ async allocateDevice(deviceConfig) {
64
+ const { deviceCookie, error } = deserializeObjectWithError(await this._emit('allocateDevice', { deviceConfig }));
65
65
  if (error) {
66
66
  throw error;
67
67
  }
@@ -9,7 +9,7 @@ class IPCServer {
9
9
  * @param {import('./SessionState')} options.sessionState
10
10
  * @param {Detox.Logger} options.logger
11
11
  * @param {object} options.callbacks
12
- * @param {() => Promise<any>} options.callbacks.onAllocateDevice
12
+ * @param {(deviceConfig: DetoxInternals.RuntimeConfig['device']) => Promise<any>} options.callbacks.onAllocateDevice
13
13
  * @param {(cookie: any) => Promise<void>} options.callbacks.onDeallocateDevice
14
14
  */
15
15
  constructor({ sessionState, logger, callbacks }) {
@@ -104,11 +104,11 @@ class IPCServer {
104
104
  this._ipc.server.broadcast('sessionStateUpdate', newState);
105
105
  }
106
106
 
107
- async onAllocateDevice(_payload, socket) {
107
+ async onAllocateDevice({ deviceConfig }, socket) {
108
108
  let deviceCookie;
109
109
 
110
110
  try {
111
- deviceCookie = await this._callbacks.onAllocateDevice();
111
+ deviceCookie = await this._callbacks.onAllocateDevice(deviceConfig);
112
112
  this._ipc.server.emit(socket, 'allocateDeviceDone', { deviceCookie });
113
113
  } catch (error) {
114
114
  this._ipc.server.emit(socket, 'allocateDeviceDone', serializeObjectWithError({ error }));
@@ -152,10 +152,10 @@ class DetoxContext {
152
152
  }
153
153
 
154
154
  /** @abstract */
155
- async [symbols.allocateDevice]() {}
155
+ async [symbols.allocateDevice](_deviceConfig) {}
156
156
 
157
157
  /** @abstract */
158
- async [symbols.deallocateDevice]() {}
158
+ async [symbols.deallocateDevice](_deviceCookie) {}
159
159
 
160
160
  async [symbols.uninstallWorker]() {
161
161
  try {
@@ -23,7 +23,9 @@ const _emergencyTeardown = Symbol('emergencyTeardown');
23
23
  const _lifecycleLogger = Symbol('lifecycleLogger');
24
24
  const _sessionFile = Symbol('sessionFile');
25
25
  const _logFinalError = Symbol('logFinalError');
26
- const _deviceAllocator = Symbol('deviceAllocator');
26
+ const _cookieAllocators = Symbol('cookieAllocators');
27
+ const _deviceAllocators = Symbol('deviceAllocators');
28
+ const _createDeviceAllocator = Symbol('createDeviceAllocator');
27
29
  //#endregion
28
30
 
29
31
  class DetoxPrimaryContext extends DetoxContext {
@@ -32,7 +34,8 @@ class DetoxPrimaryContext extends DetoxContext {
32
34
 
33
35
  this[_dirty] = false;
34
36
  this[_wss] = null;
35
- this[_deviceAllocator] = null;
37
+ this[_cookieAllocators] = {};
38
+ this[_deviceAllocators] = {};
36
39
 
37
40
  /** Path to file where the initial session object is serialized */
38
41
  this[_sessionFile] = '';
@@ -85,7 +88,6 @@ class DetoxPrimaryContext extends DetoxContext {
85
88
  const detoxConfig = await this[symbols.resolveConfig](opts);
86
89
 
87
90
  const {
88
- device: deviceConfig,
89
91
  logger: loggerConfig,
90
92
  session: sessionConfig
91
93
  } = detoxConfig;
@@ -109,16 +111,6 @@ class DetoxPrimaryContext extends DetoxContext {
109
111
 
110
112
  await this[_ipcServer].init();
111
113
 
112
- const environmentFactory = require('../environmentFactory');
113
-
114
- const { deviceAllocatorFactory } = environmentFactory.createFactories(deviceConfig);
115
- this[_deviceAllocator] = deviceAllocatorFactory.createDeviceAllocator({
116
- detoxConfig,
117
- detoxSession: this[$sessionState],
118
- });
119
-
120
- await this[_deviceAllocator].init();
121
-
122
114
  // TODO: Detox-server creation ought to be delegated to a generator/factory.
123
115
  const DetoxServer = require('../server/DetoxServer');
124
116
  if (sessionConfig.autoStart) {
@@ -162,17 +154,20 @@ class DetoxPrimaryContext extends DetoxContext {
162
154
  }
163
155
 
164
156
  /** @override */
165
- async [symbols.allocateDevice]() {
166
- const { device } = this[$sessionState].detoxConfig;
167
- const deviceCookie = await this[_deviceAllocator].allocate(device);
157
+ async [symbols.allocateDevice](deviceConfig) {
158
+ const deviceAllocator = await this[_createDeviceAllocator](deviceConfig);
159
+ const deviceCookie = await deviceAllocator.allocate(deviceConfig);
160
+ this[_cookieAllocators][deviceCookie.id] = deviceAllocator;
168
161
 
169
162
  try {
170
- return await this[_deviceAllocator].postAllocate(deviceCookie);
163
+ return await deviceAllocator.postAllocate(deviceCookie);
171
164
  } catch (e) {
172
165
  try {
173
- await this[_deviceAllocator].free(deviceCookie, { shutdown: true });
166
+ await deviceAllocator.free(deviceCookie, { shutdown: true });
174
167
  } catch (e2) {
175
- this[symbols.logger].error({ cat: 'device', err: e2 }, `Failed to free ${deviceCookie.name || deviceCookie.id} after a failed allocation`);
168
+ this[symbols.logger].error({ cat: 'device', err: e2 }, `Failed to free ${deviceCookie.name || deviceCookie.id} after a failed allocation attempt`);
169
+ } finally {
170
+ delete this[_cookieAllocators][deviceCookie.id];
176
171
  }
177
172
 
178
173
  throw e;
@@ -181,7 +176,17 @@ class DetoxPrimaryContext extends DetoxContext {
181
176
 
182
177
  /** @override */
183
178
  async [symbols.deallocateDevice](cookie) {
184
- await this[_deviceAllocator].free(cookie);
179
+ const deviceAllocator = this[_cookieAllocators][cookie.id];
180
+ if (!deviceAllocator) {
181
+ throw new DetoxRuntimeError({
182
+ message: `Cannot deallocate device ${cookie.id} because it was not allocated by this context.`,
183
+ hint: `See the actually known allocated devices below:`,
184
+ debugInfo: Object.keys(this[_cookieAllocators]).map(id => `- ${id}`).join('\n'),
185
+ });
186
+ }
187
+
188
+ await deviceAllocator.free(cookie);
189
+ delete this[_cookieAllocators][cookie.id];
185
190
  }
186
191
 
187
192
  /** @override */
@@ -191,11 +196,18 @@ class DetoxPrimaryContext extends DetoxContext {
191
196
  await this[symbols.uninstallWorker]();
192
197
  }
193
198
  } finally {
194
- if (this[_deviceAllocator]) {
195
- await this[_deviceAllocator].cleanup();
196
- this[_deviceAllocator] = null;
199
+ for (const key of Object.keys(this[_deviceAllocators])) {
200
+ const deviceAllocator = this[_deviceAllocators][key];
201
+ delete this[_deviceAllocators][key];
202
+ try {
203
+ await deviceAllocator.cleanup();
204
+ } catch (err) {
205
+ this[symbols.logger].error({ cat: 'device', err }, `Failed to cleanup the device allocation driver for ${key}`);
206
+ }
197
207
  }
198
208
 
209
+ this[_cookieAllocators] = {};
210
+
199
211
  if (this[_wss]) {
200
212
  await this[_wss].close();
201
213
  this[_wss] = null;
@@ -227,11 +239,18 @@ class DetoxPrimaryContext extends DetoxContext {
227
239
  return;
228
240
  }
229
241
 
230
- if (this[_deviceAllocator]) {
231
- this[_deviceAllocator].emergencyCleanup();
232
- this[_deviceAllocator] = null;
242
+ for (const key of Object.keys(this[_deviceAllocators])) {
243
+ const deviceAllocator = this[_deviceAllocators][key];
244
+ delete this[_deviceAllocators][key];
245
+ try {
246
+ deviceAllocator.emergencyCleanup();
247
+ } catch (err) {
248
+ this[symbols.logger].error({ cat: 'device', err }, `Failed to clean up the device allocation driver for ${key} in emergency mode`);
249
+ }
233
250
  }
234
251
 
252
+ this[_cookieAllocators] = {};
253
+
235
254
  if (this[_wss]) {
236
255
  this[_wss].close();
237
256
  }
@@ -253,6 +272,35 @@ class DetoxPrimaryContext extends DetoxContext {
253
272
  }
254
273
  };
255
274
 
275
+ /** @param {Detox.DetoxDeviceConfig} deviceConfig */
276
+ [_createDeviceAllocator] = async (deviceConfig) => {
277
+ const deviceType = deviceConfig.type;
278
+ if (!this[_deviceAllocators][deviceType]) {
279
+ const environmentFactory = require('../environmentFactory');
280
+ const { deviceAllocatorFactory } = environmentFactory.createFactories(deviceConfig);
281
+ const { detoxConfig } = this[$sessionState];
282
+ const deviceAllocator = deviceAllocatorFactory.createDeviceAllocator({
283
+ detoxConfig,
284
+ detoxSession: this[$sessionState],
285
+ });
286
+
287
+ try {
288
+ await deviceAllocator.init();
289
+ this[_deviceAllocators][deviceType] = deviceAllocator;
290
+ } catch (e) {
291
+ try {
292
+ await deviceAllocator.cleanup();
293
+ } catch (e2) {
294
+ this[symbols.logger].error({ cat: 'device', err: e2 }, `Failed to cleanup the device allocation driver for ${deviceType} after a failed initialization`);
295
+ }
296
+
297
+ throw e;
298
+ }
299
+ }
300
+
301
+ return this[_deviceAllocators][deviceType];
302
+ };
303
+
256
304
  [_logFinalError] = (err) => {
257
305
  this[_lifecycleLogger].error(err, 'Encountered an error while merging the process logs:');
258
306
  };
@@ -63,9 +63,9 @@ class DetoxSecondaryContext extends DetoxContext {
63
63
  }
64
64
 
65
65
  /** @override */
66
- async [symbols.allocateDevice]() {
66
+ async [symbols.allocateDevice](deviceConfig) {
67
67
  if (this[_ipcClient]) {
68
- const deviceCookie = await this[_ipcClient].allocateDevice();
68
+ const deviceCookie = await this[_ipcClient].allocateDevice(deviceConfig);
69
69
  return deviceCookie;
70
70
  } else {
71
71
  throw new DetoxInternalError('Detected an attempt to allocate a device using a non-initialized context.');
@@ -1 +0,0 @@
1
- 9452502e485f0c19f6431080657c1af6
@@ -1 +0,0 @@
1
- d324cf797101d537d40f9422ab2b0f163379fe75
@@ -1 +0,0 @@
1
- d8141a3643a29682690d3257f0f5e811e5fa0b22aead686f0fea8c2972156c18
@@ -1 +0,0 @@
1
- f26a08a896ef35d2069791f08befbfd865cc4610d5a3264b83bbb34a9c952f046f92767703b91eab575e45e3bb1728134f4bd6dbdd7367e7e0036173a0445b90
@@ -1 +0,0 @@
1
- b356bf18b2b37c77db5dd233ca785842
@@ -1 +0,0 @@
1
- a7a84377ebebbdeb54e6bbf30e8bae594621203f
@@ -1 +0,0 @@
1
- 7609141047f1b998e32fd6989e1e5b6afd75690a95960823deaf29e98b6505db
@@ -1 +0,0 @@
1
- f740dc4eefc2cfec141723687fa4d3acfa5207ce127b461125b7b4fd04ebfa45af4918a489070ea89d144b1df25355311ae1f92b8c17bb3b0edcae84d48762bd
@@ -1 +0,0 @@
1
- 05628b1955b9d2e1e5c173f0accda092
@@ -1 +0,0 @@
1
- a6b46ecde38a5029dae5de5391aed0f49f16691d
@@ -1 +0,0 @@
1
- 82757e7e370b217bed5afc7cec09b3b717ea3b308ba25cd60d035cbd82711a18
@@ -1 +0,0 @@
1
- 5a680241676911e186fb41e4ce30d779be5cfa00e91e5c618ae3c9f713906b6add4334b8ca311a46613fa6063ea394f6eac48665d4c7882da42021f3ebf72fdc