detox 19.13.0 → 20.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (236) hide show
  1. package/Detox-android/com/wix/detox/{19.13.0/detox-19.13.0-javadoc.jar → 20.0.0/detox-20.0.0-javadoc.jar} +0 -0
  2. package/Detox-android/com/wix/detox/20.0.0/detox-20.0.0-javadoc.jar.md5 +1 -0
  3. package/Detox-android/com/wix/detox/20.0.0/detox-20.0.0-javadoc.jar.sha1 +1 -0
  4. package/Detox-android/com/wix/detox/20.0.0/detox-20.0.0-javadoc.jar.sha256 +1 -0
  5. package/Detox-android/com/wix/detox/20.0.0/detox-20.0.0-javadoc.jar.sha512 +1 -0
  6. package/Detox-android/com/wix/detox/{19.13.0/detox-19.13.0-sources.jar → 20.0.0/detox-20.0.0-sources.jar} +0 -0
  7. package/Detox-android/com/wix/detox/20.0.0/detox-20.0.0-sources.jar.md5 +1 -0
  8. package/Detox-android/com/wix/detox/20.0.0/detox-20.0.0-sources.jar.sha1 +1 -0
  9. package/Detox-android/com/wix/detox/20.0.0/detox-20.0.0-sources.jar.sha256 +1 -0
  10. package/Detox-android/com/wix/detox/20.0.0/detox-20.0.0-sources.jar.sha512 +1 -0
  11. package/Detox-android/com/wix/detox/20.0.0/detox-20.0.0.aar +0 -0
  12. package/Detox-android/com/wix/detox/20.0.0/detox-20.0.0.aar.md5 +1 -0
  13. package/Detox-android/com/wix/detox/20.0.0/detox-20.0.0.aar.sha1 +1 -0
  14. package/Detox-android/com/wix/detox/20.0.0/detox-20.0.0.aar.sha256 +1 -0
  15. package/Detox-android/com/wix/detox/20.0.0/detox-20.0.0.aar.sha512 +1 -0
  16. package/Detox-android/com/wix/detox/{19.13.0/detox-19.13.0.pom → 20.0.0/detox-20.0.0.pom} +1 -1
  17. package/Detox-android/com/wix/detox/20.0.0/detox-20.0.0.pom.md5 +1 -0
  18. package/Detox-android/com/wix/detox/20.0.0/detox-20.0.0.pom.sha1 +1 -0
  19. package/Detox-android/com/wix/detox/20.0.0/detox-20.0.0.pom.sha256 +1 -0
  20. package/Detox-android/com/wix/detox/20.0.0/detox-20.0.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/README.md +1 -1
  29. package/android/detox/src/full/java/com/wix/detox/Detox.java +2 -59
  30. package/android/detox/src/full/java/com/wix/detox/NotificationDataParser.kt +3 -3
  31. package/index.d.ts +354 -191
  32. package/index.js +1 -0
  33. package/internals.d.ts +298 -0
  34. package/internals.js +4 -0
  35. package/local-cli/build-framework-cache.js +2 -2
  36. package/local-cli/build.js +7 -8
  37. package/local-cli/build.test.js +46 -40
  38. package/local-cli/clean-framework-cache.js +3 -3
  39. package/local-cli/cli.js +8 -7
  40. package/local-cli/init.js +73 -68
  41. package/local-cli/rebuild-framework-cache.js +1 -1
  42. package/local-cli/reset-lock-file.js +16 -0
  43. package/local-cli/templates/jest.js +14 -36
  44. package/local-cli/test.js +24 -282
  45. package/local-cli/test.test.js +394 -648
  46. package/local-cli/testCommand/TestRunnerCommand.js +163 -0
  47. package/local-cli/{utils/testCommandArgs.js → testCommand/builder.js} +10 -36
  48. package/local-cli/testCommand/middlewares.js +66 -0
  49. package/local-cli/{utils → testCommand}/warnings.js +0 -13
  50. package/local-cli/utils/jestInternals.js +13 -2
  51. package/local-cli/utils/yargsUtils.js +67 -0
  52. package/package.json +32 -19
  53. package/runners/deprecation.js +45 -0
  54. package/runners/jest/JestCircusEnvironment.js +3 -38
  55. package/runners/jest/adapter.d.ts +4 -10
  56. package/runners/jest/adapter.js +3 -6
  57. package/runners/jest/assignReporter.d.ts +4 -1
  58. package/runners/jest/assignReporter.js +3 -6
  59. package/runners/jest/globalSetup.js +1 -0
  60. package/runners/jest/globalTeardown.js +1 -0
  61. package/runners/jest/index.d.ts +60 -0
  62. package/runners/jest/index.js +16 -0
  63. package/runners/jest/index.test.js +13 -0
  64. package/runners/jest/reporter.js +1 -0
  65. package/runners/jest/reporters/DetoxReporter.js +36 -0
  66. package/runners/jest/specReporter.d.ts +4 -9
  67. package/runners/jest/specReporter.js +3 -10
  68. package/runners/jest/streamlineReporter.js +3 -22
  69. package/runners/jest/testEnvironment/index.js +205 -0
  70. package/runners/jest/testEnvironment/listeners/DetoxCoreListener.js +166 -0
  71. package/runners/{jest-circus → jest/testEnvironment}/listeners/DetoxInitErrorListener.js +1 -1
  72. package/runners/jest/testEnvironment/listeners/DetoxPlatformFilterListener.js +27 -0
  73. package/runners/jest/{SpecReporterImpl.js → testEnvironment/listeners/SpecReporter.js} +61 -9
  74. package/runners/jest/testEnvironment/listeners/WorkerAssignReporter.js +30 -0
  75. package/runners/jest/testEnvironment/listeners/index.js +13 -0
  76. package/runners/{jest-circus → jest/testEnvironment}/utils/assertExistingContext.js +2 -2
  77. package/runners/jest/testEnvironment/utils/assertJestCircus27.js +70 -0
  78. package/runners/jest/testEnvironment/utils/assertJestCircus27.test.js +22 -0
  79. package/runners/jest/{utils → testEnvironment/utils}/getFullTestName.js +0 -0
  80. package/runners/jest/{utils → testEnvironment/utils}/hasTimedOut.js +0 -0
  81. package/runners/jest/{utils → testEnvironment/utils}/index.js +0 -0
  82. package/runners/jest/{utils → testEnvironment/utils}/stdout.js +0 -0
  83. package/runners/jest-circus/environment/index.js +6 -0
  84. package/runners/jest-circus/index.js +1 -10
  85. package/runners/jest-circus/reporter.js +1 -0
  86. package/runners/migration.js +37 -0
  87. package/runners/mocha/DetoxMochaAdapter.js +3 -35
  88. package/runners/mocha/adapter.d.ts +4 -7
  89. package/runners/mocha/adapter.js +3 -5
  90. package/src/DetoxWorker.js +327 -0
  91. package/src/android/interactions/native.js +2 -1
  92. package/src/artifacts/ArtifactsManager.js +51 -35
  93. package/src/artifacts/instruments/ios/SimulatorInstrumentsRecording.js +3 -3
  94. package/src/artifacts/log/ios/SimulatorLogRecording.js +1 -1
  95. package/src/artifacts/providers/index.js +0 -4
  96. package/src/artifacts/screenshot/SimulatorScreenshotPlugin.js +1 -1
  97. package/src/artifacts/templates/artifact/Artifact.js +1 -1
  98. package/src/artifacts/templates/plugin/ArtifactPlugin.js +1 -1
  99. package/src/artifacts/utils/buildDefaultArtifactsRootDirpath.js +2 -4
  100. package/src/artifacts/utils/temporaryPath.js +18 -5
  101. package/src/artifacts/video/SimulatorRecordVideoPlugin.js +1 -1
  102. package/src/client/AsyncWebSocket.js +8 -17
  103. package/src/client/Client.js +1 -1
  104. package/src/client/actions/actions.js +2 -2
  105. package/src/configuration/collectCliConfig.js +3 -16
  106. package/src/configuration/composeAppsConfig.js +12 -66
  107. package/src/configuration/composeArtifactsConfig.js +6 -32
  108. package/src/configuration/composeBehaviorConfig.js +3 -13
  109. package/src/configuration/composeDeviceConfig.js +38 -63
  110. package/src/configuration/composeLoggerConfig.js +59 -0
  111. package/src/configuration/composeRunnerConfig.js +127 -14
  112. package/src/configuration/composeSessionConfig.js +1 -3
  113. package/src/configuration/index.js +36 -30
  114. package/src/configuration/loadExternalConfig.js +1 -1
  115. package/src/configuration/utils/deviceAppTypes.js +0 -1
  116. package/src/devices/allocation/DeviceAllocator.js +4 -2
  117. package/src/devices/allocation/drivers/android/emulator/AVDValidator.js +1 -1
  118. package/src/devices/allocation/drivers/android/emulator/EmulatorAllocDriver.js +5 -3
  119. package/src/devices/allocation/drivers/android/emulator/EmulatorAllocationHelper.js +1 -1
  120. package/src/devices/allocation/drivers/android/emulator/EmulatorLauncher.js +3 -5
  121. package/src/devices/allocation/drivers/android/emulator/EmulatorVersionResolver.js +4 -6
  122. package/src/devices/allocation/drivers/android/emulator/launchEmulatorProcess.js +1 -1
  123. package/src/devices/allocation/drivers/android/genycloud/GenyInstanceAllocationHelper.js +1 -1
  124. package/src/devices/allocation/drivers/ios/SimulatorAllocDriver.js +1 -1
  125. package/src/devices/allocation/drivers/ios/SimulatorLauncher.js +3 -3
  126. package/src/devices/allocation/factories/index.js +0 -1
  127. package/src/devices/common/drivers/DeviceLauncher.js +2 -2
  128. package/src/devices/common/drivers/android/emulator/exec/EmulatorExec.js +1 -1
  129. package/src/devices/common/drivers/android/genycloud/services/GenyInstanceNaming.js +4 -9
  130. package/src/devices/common/drivers/android/genycloud/services/GenyRecipesService.js +1 -1
  131. package/src/devices/common/drivers/android/tools/EmulatorTelnet.js +1 -1
  132. package/src/devices/common/drivers/android/tools/FreeDeviceFinder.js +1 -1
  133. package/src/devices/common/drivers/ios/tools/AppleSimUtils.js +35 -10
  134. package/src/devices/lifecycle/GenyGlobalLifecycleHandler.js +13 -15
  135. package/src/devices/runtime/RuntimeDevice.js +85 -86
  136. package/src/devices/runtime/drivers/DeviceDriverBase.js +1 -1
  137. package/src/devices/runtime/drivers/android/AndroidDriver.js +3 -3
  138. package/src/devices/runtime/drivers/index.js +0 -1
  139. package/src/devices/runtime/drivers/ios/SimulatorDriver.js +4 -3
  140. package/src/devices/runtime/factories/ios.js +1 -8
  141. package/src/devices/runtime/utils/LaunchArgsEditor.js +4 -59
  142. package/src/devices/runtime/utils/Storage.js +4 -0
  143. package/src/environmentFactory.js +0 -8
  144. package/src/errors/DetoxConfigErrorComposer.js +92 -30
  145. package/src/errors/DetoxError.js +4 -0
  146. package/src/errors/DetoxRuntimeError.js +5 -5
  147. package/src/errors/index.js +2 -0
  148. package/src/ios/expectTwo.js +2 -1
  149. package/src/ipc/IPCClient.js +117 -0
  150. package/src/ipc/IPCServer.js +98 -0
  151. package/src/ipc/SessionState.js +62 -0
  152. package/src/logger/DetoxLogger.js +348 -0
  153. package/src/logger/index.js +5 -0
  154. package/src/logger/utils/BunyanLogger.js +76 -0
  155. package/src/logger/utils/CategoryThreadDispatcher.js +36 -0
  156. package/src/logger/utils/DetoxLogFinalizer.js +140 -0
  157. package/src/logger/utils/MessageStack.js +24 -0
  158. package/src/logger/utils/ThreadDispatcher.js +61 -0
  159. package/src/{utils → logger/utils}/customConsoleLogger.js +5 -4
  160. package/src/logger/utils/sanitizeBunyanContext.js +30 -0
  161. package/src/logger/utils/streamUtils.js +248 -0
  162. package/src/logger/utils/tracerLegacy.js +37 -0
  163. package/src/realms/DetoxConstants.js +13 -0
  164. package/src/realms/DetoxContext.js +183 -0
  165. package/src/realms/DetoxInternalsFacade.js +31 -0
  166. package/src/realms/DetoxPrimaryContext.js +261 -0
  167. package/src/realms/DetoxSecondaryContext.js +91 -0
  168. package/src/realms/index.js +10 -0
  169. package/src/realms/primary.js +3 -0
  170. package/src/realms/secondary.js +3 -0
  171. package/src/server/DetoxConnection.js +18 -23
  172. package/src/server/DetoxServer.js +7 -10
  173. package/src/server/DetoxSession.js +6 -6
  174. package/src/server/DetoxSessionManager.js +1 -1
  175. package/src/server/handlers/RegisteredConnectionHandler.js +1 -2
  176. package/src/symbols.js +50 -0
  177. package/src/utils/Timer.js +58 -33
  178. package/src/utils/argparse.js +11 -0
  179. package/src/utils/childProcess/exec.js +1 -1
  180. package/src/utils/childProcess/spawn.js +1 -1
  181. package/{local-cli/utils/misc.js → src/utils/envUtils.js} +0 -9
  182. package/src/utils/errorUtils.js +20 -0
  183. package/src/utils/logger.js +2 -162
  184. package/src/utils/shellUtils.js +18 -0
  185. package/src/utils/traceInvocationCall.js +21 -0
  186. package/src/utils/traceMethods.js +15 -0
  187. package/Detox-android/com/wix/detox/19.13.0/detox-19.13.0-javadoc.jar.md5 +0 -1
  188. package/Detox-android/com/wix/detox/19.13.0/detox-19.13.0-javadoc.jar.sha1 +0 -1
  189. package/Detox-android/com/wix/detox/19.13.0/detox-19.13.0-javadoc.jar.sha256 +0 -1
  190. package/Detox-android/com/wix/detox/19.13.0/detox-19.13.0-javadoc.jar.sha512 +0 -1
  191. package/Detox-android/com/wix/detox/19.13.0/detox-19.13.0-sources.jar.md5 +0 -1
  192. package/Detox-android/com/wix/detox/19.13.0/detox-19.13.0-sources.jar.sha1 +0 -1
  193. package/Detox-android/com/wix/detox/19.13.0/detox-19.13.0-sources.jar.sha256 +0 -1
  194. package/Detox-android/com/wix/detox/19.13.0/detox-19.13.0-sources.jar.sha512 +0 -1
  195. package/Detox-android/com/wix/detox/19.13.0/detox-19.13.0.aar +0 -0
  196. package/Detox-android/com/wix/detox/19.13.0/detox-19.13.0.aar.md5 +0 -1
  197. package/Detox-android/com/wix/detox/19.13.0/detox-19.13.0.aar.sha1 +0 -1
  198. package/Detox-android/com/wix/detox/19.13.0/detox-19.13.0.aar.sha256 +0 -1
  199. package/Detox-android/com/wix/detox/19.13.0/detox-19.13.0.aar.sha512 +0 -1
  200. package/Detox-android/com/wix/detox/19.13.0/detox-19.13.0.pom.md5 +0 -1
  201. package/Detox-android/com/wix/detox/19.13.0/detox-19.13.0.pom.sha1 +0 -1
  202. package/Detox-android/com/wix/detox/19.13.0/detox-19.13.0.pom.sha256 +0 -1
  203. package/Detox-android/com/wix/detox/19.13.0/detox-19.13.0.pom.sha512 +0 -1
  204. package/local-cli/templates/mocha.js +0 -32
  205. package/local-cli/utils/splitArgv.js +0 -107
  206. package/runners/integration.js +0 -16
  207. package/runners/jest/DetoxAdapterCircus.js +0 -60
  208. package/runners/jest/DetoxAdapterImpl.js +0 -81
  209. package/runners/jest/DetoxAdapterJasmine.js +0 -67
  210. package/runners/jest/DetoxStreamlineJestReporter.js +0 -98
  211. package/runners/jest/FailingTestsReporter.js +0 -16
  212. package/runners/jest/SpecReporterCircus.js +0 -51
  213. package/runners/jest/SpecReporterJasmine.js +0 -39
  214. package/runners/jest/WorkerAssignReporterCircus.js +0 -17
  215. package/runners/jest/WorkerAssignReporterImpl.js +0 -21
  216. package/runners/jest/WorkerAssignReporterJasmine.js +0 -15
  217. package/runners/jest/runnerInfo.js +0 -9
  218. package/runners/jest-circus/environment.js +0 -206
  219. package/runners/jest-circus/listeners/DetoxCoreListener.js +0 -113
  220. package/runners/jest-circus/utils/assertJestCircus26.js +0 -39
  221. package/runners/jest-circus/utils/wrapErrorWithNoopLifecycle.js +0 -14
  222. package/src/Detox.js +0 -317
  223. package/src/DetoxConstants.js +0 -13
  224. package/src/DetoxExportWrapper.js +0 -140
  225. package/src/artifacts/timeline/TimelineArtifactPlugin.js +0 -92
  226. package/src/configuration/utils/warnings.js +0 -12
  227. package/src/devices/allocation/drivers/NoneAllocDriver.js +0 -10
  228. package/src/devices/allocation/factories/none.js +0 -11
  229. package/src/index.js +0 -6
  230. package/src/utils/ChromeTracingExporter.js +0 -54
  231. package/src/utils/MissingDetox.js +0 -78
  232. package/src/utils/fakeTimestampsProvider.js +0 -9
  233. package/src/utils/getWorkerId.js +0 -5
  234. package/src/utils/lastFailedTests.js +0 -38
  235. package/src/utils/sh.js +0 -18
  236. package/src/utils/trace.js +0 -96
@@ -25,16 +25,6 @@ class DetoxConfigErrorComposer {
25
25
  _atPath() {
26
26
  return this.filepath ? ` at path:\n${this.filepath}` : '.';
27
27
  }
28
-
29
- _inTheAppConfig() {
30
- const { type } = this._getSelectedConfiguration();
31
- if (type) {
32
- return `in configuration ${J(this.configurationName)}`;
33
- }
34
-
35
- return `in the app config`;
36
- }
37
-
38
28
  _getSelectedConfiguration() {
39
29
  return _.get(this.contents, ['configurations', this.configurationName]);
40
30
  }
@@ -64,9 +54,10 @@ class DetoxConfigErrorComposer {
64
54
  }
65
55
 
66
56
  _focusOnDeviceConfig(deviceAlias, postProcess = _.identity) {
67
- const { type, device } = this._getSelectedConfiguration();
57
+ const { device } = this._getSelectedConfiguration();
68
58
  if (!deviceAlias) {
69
- if (type || !device) {
59
+ // istanbul ignore next
60
+ if (!device) {
70
61
  return this._focusOnConfiguration(postProcess);
71
62
  } else {
72
63
  return this._focusOnConfiguration(c => {
@@ -92,8 +83,7 @@ class DetoxConfigErrorComposer {
92
83
  if (alias) {
93
84
  return this.contents.devices[alias];
94
85
  } else {
95
- const config = this._getSelectedConfiguration();
96
- return config.type ? config : config.device;
86
+ return this._getSelectedConfiguration().device;
97
87
  }
98
88
  }
99
89
 
@@ -225,6 +215,61 @@ Examine your Detox config${this._atPath()}`,
225
215
  });
226
216
  }
227
217
 
218
+ configurationShouldNotUseLegacyFormat() {
219
+ const name = this.configurationName;
220
+ const localConfig = this._getSelectedConfiguration();
221
+ /* istanbul ignore next */
222
+ const deviceType = localConfig.type || '';
223
+ const isAndroid = deviceType.startsWith('android.');
224
+ const isIOS = deviceType.startsWith('ios.');
225
+ const appName = 'myApp' + (isIOS ? '.ios' : '') + (isAndroid ? '.android' : '');
226
+ const deviceName = isIOS ? 'simulator' : isAndroid ? 'emulator' : 'myDevice';
227
+ const appType = isIOS ? 'ios.app' : isAndroid ? 'android.apk' : '<optional property>';
228
+ const binaryPath = isIOS || isAndroid ? localConfig.binaryPath : (localConfig.binaryPath || '<optional property>');
229
+ const deviceQuery = isIOS || isAndroid ? localConfig.device : (localConfig.device || '<optional property>');
230
+
231
+ return new DetoxConfigError({
232
+ message: `The ${J(name)} configuration utilizes a deprecated all-in-one schema, that is not supported ` +
233
+ `by the current version of Detox.`,
234
+ hint: `Remove the "type" property. A valid configuration is expected to have both the "device" and "app" aliases ` +
235
+ `pointing to the corresponding keys in the 'devices' and 'apps' config sections. For example:\n
236
+ {
237
+ "apps": {
238
+ *-->${J(appName)}: {
239
+ | "type": ${J(appType)},
240
+ | "binaryPath": ${J(binaryPath)},
241
+ | },
242
+ | },
243
+ | "devices": {
244
+ |*->${J(deviceName)}: {
245
+ || "type": ${J(deviceType)},
246
+ || "device": ${J(deviceQuery)}
247
+ || },
248
+ ||},
249
+ ||"configurations": {
250
+ || ${J(name)}: {
251
+ || /* REMOVE (!) "type": ${J(deviceType)} */
252
+ |*--- "device": ${J(deviceName)},
253
+ *---- "app": ${J(appName)},
254
+ ...
255
+ }
256
+ }
257
+ }
258
+ Examine your Detox config${this._atPath()}`,
259
+ debugInfo: {
260
+ apps: this.contents.apps
261
+ ? _.mapValues(this.contents.apps, _.constant({}))
262
+ : undefined,
263
+ devices: this.contents.devices
264
+ ? _.mapValues(this.contents.devices, _.constant({}))
265
+ : undefined,
266
+
267
+ ...this._focusOnConfiguration(),
268
+ },
269
+ inspectOptions: { depth: 2 }
270
+ });
271
+ }
272
+
228
273
  // endregion
229
274
 
230
275
  // region composeDeviceConfig
@@ -345,7 +390,7 @@ Please check your Detox config${this._atPath()}`,
345
390
  case 'forceAdbInstall':
346
391
  return this._invalidPropertyType('forceAdbInstall', 'a boolean value', deviceAlias);
347
392
  case 'gpuMode':
348
- return this._invalidPropertyType('gpuMode', "'auto' | 'host' | 'swiftshader_indirect' | 'angle_indirect' | 'guest'", deviceAlias);
393
+ return this._invalidPropertyType('gpuMode', "'auto' | 'host' | 'swiftshader_indirect' | 'angle_indirect' | 'guest' | 'off'", deviceAlias);
349
394
  case 'headless':
350
395
  return this._invalidPropertyType('headless', 'a boolean value', deviceAlias);
351
396
  case 'readonly':
@@ -364,7 +409,7 @@ Please check your Detox config${this._atPath()}`,
364
409
  case 'gpuMode':
365
410
  return this._unsupportedPropertyByDeviceType('gpuMode', ['android.emulator'], deviceAlias);
366
411
  case 'headless':
367
- return this._unsupportedPropertyByDeviceType('headless', ['android.emulator'], deviceAlias);
412
+ return this._unsupportedPropertyByDeviceType('headless', ['ios.simulator', 'android.emulator'], deviceAlias);
368
413
  case 'readonly':
369
414
  return this._unsupportedPropertyByDeviceType('readonly', ['android.emulator'], deviceAlias);
370
415
  case 'utilBinaryPaths':
@@ -456,7 +501,15 @@ Examine your Detox config${this._atPath()}`,
456
501
 
457
502
  malformedAppLaunchArgs(appPath) {
458
503
  return new DetoxConfigError({
459
- message: `Invalid type of "launchArgs" property ${this._inTheAppConfig()}.\nExpected an object:`,
504
+ message: `Invalid type of "launchArgs" property in the app config.\nExpected an object:`,
505
+ debugInfo: this._focusOnAppConfig(appPath),
506
+ inspectOptions: { depth: 4 },
507
+ });
508
+ }
509
+
510
+ unsupportedReversePorts(appPath) {
511
+ return new DetoxConfigError({
512
+ message: `Non-Android app configs cannot have "reversePorts" property:`,
460
513
  debugInfo: this._focusOnAppConfig(appPath),
461
514
  inspectOptions: { depth: 4 },
462
515
  });
@@ -464,7 +517,7 @@ Examine your Detox config${this._atPath()}`,
464
517
 
465
518
  missingAppBinaryPath(appPath) {
466
519
  return new DetoxConfigError({
467
- message: `Missing "binaryPath" property ${this._inTheAppConfig()}.\nExpected a string:`,
520
+ message: `Missing "binaryPath" property in the app config.\nExpected a string:`,
468
521
  debugInfo: this._focusOnAppConfig(appPath, this._ensureProperty('binaryPath')),
469
522
  inspectOptions: { depth: 4 },
470
523
  });
@@ -538,18 +591,6 @@ Examine your Detox config${this._atPath()}`,
538
591
  });
539
592
  }
540
593
 
541
- oldSchemaHasAppAndApps() {
542
- return new DetoxConfigError({
543
- message: `Your configuration ${J(this.configurationName)} appears to be in a legacy format, which can’t contain "app" or "apps".`,
544
- hint: `Remove "type" property from configuration and use "device" property instead:\n` +
545
- `a) "device": { "type": ${J(this._getSelectedConfiguration().type)}, ... }\n` +
546
- `b) "device": "<alias-to-device>" // you should add that device configuration to "devices" with the same key` +
547
- `\n\nCheck your Detox config${this._atPath()}`,
548
- debugInfo: this._focusOnConfiguration(this._ensureProperty('type', 'device')),
549
- inspectOptions: { depth: 2 },
550
- });
551
- }
552
-
553
594
  ambiguousAppAndApps() {
554
595
  return new DetoxConfigError({
555
596
  message: `You can't have both "app" and "apps" defined in the ${J(this.configurationName)} configuration.`,
@@ -622,6 +663,27 @@ Examine your Detox config${this._atPath()}`,
622
663
  });
623
664
  }
624
665
 
666
+ invalidTestRunnerProperty(isGlobal) {
667
+ const testRunner = _.get(
668
+ isGlobal
669
+ ? this.contents
670
+ : this._getSelectedConfiguration(),
671
+ ['testRunner']
672
+ );
673
+
674
+ return new DetoxConfigError({
675
+ message: `testRunner should be an object, not a ${typeof testRunner}`,
676
+ hint: `Check that in your Detox config${this._atPath()}`,
677
+ inspectOptions: { depth: isGlobal ? 0 : 3 },
678
+ debugInfo: isGlobal ? {
679
+ testRunner,
680
+ ...this.contents,
681
+ } : {
682
+ ...this._focusOnConfiguration(c => _.pick(c, ['testRunner'])),
683
+ },
684
+ });
685
+ }
686
+
625
687
  cannotSkipAutostartWithMissingServer() {
626
688
  return new DetoxConfigError({
627
689
  message: `Cannot have both an undefined session.server URL and session.autoStart set to false`,
@@ -12,6 +12,10 @@ class DetoxError extends Error {
12
12
  return 'Please report this issue on our GitHub tracker:\nhttps://github.com/wix/Detox/issues';
13
13
  }
14
14
 
15
+ static get reportIssueIfJest() {
16
+ return `If you are using Detox with Jest according to the latest guide, ${_.lowerFirst(this.reportIssue)}`;
17
+ }
18
+
15
19
  static inspectObj(obj, options) {
16
20
  return util.inspect(obj, {
17
21
  colors: false,
@@ -4,23 +4,23 @@ const DetoxError = require('./DetoxError');
4
4
 
5
5
  /**
6
6
  * @typedef DetoxRuntimeErrorOptions
7
- * @property message { String }
7
+ * @property [message] { String }
8
8
  * @property [hint] { String }
9
- * @property [debugInfo] { String }
9
+ * @property [debugInfo] { * }
10
10
  * @property [noStack] { Boolean }
11
11
  * @property [inspectOptions] { Object }
12
12
  */
13
13
 
14
14
  class DetoxRuntimeError extends DetoxError {
15
15
  /**
16
- * @param options { DetoxRuntimeErrorOptions }
16
+ * @param [options] { String | DetoxRuntimeErrorOptions }
17
17
  */
18
18
  constructor(options) {
19
19
  super(formatOptions(options));
20
20
  this.name = 'DetoxRuntimeError';
21
21
 
22
- if (options && options.noStack) {
23
- delete this.stack;
22
+ if (options && typeof options !== 'string' && options.noStack) {
23
+ this.stack = '';
24
24
  }
25
25
  }
26
26
  }
@@ -1,4 +1,5 @@
1
1
  const DetoxConfigError = require('./DetoxConfigError');
2
+ const DetoxConfigErrorComposer = require('./DetoxConfigErrorComposer');
2
3
  const DetoxError = require('./DetoxError');
3
4
  const DetoxInternalError = require('./DetoxInternalError');
4
5
  const DetoxRuntimeError = require('./DetoxRuntimeError');
@@ -7,6 +8,7 @@ const DetoxRuntimeErrorComposer = require('./DetoxRuntimeErrorComposer');
7
8
  module.exports = {
8
9
  DetoxError,
9
10
  DetoxConfigError,
11
+ DetoxConfigErrorComposer,
10
12
  DetoxInternalError,
11
13
  DetoxRuntimeError,
12
14
  DetoxRuntimeErrorComposer,
@@ -8,7 +8,8 @@ const tempfile = require('tempfile');
8
8
 
9
9
  const { assertEnum, assertNormalized } = require('../utils/assertArgument');
10
10
  const { actionDescription, expectDescription } = require('../utils/invocationTraceDescriptions');
11
- const { traceInvocationCall } = require('../utils/trace');
11
+ const log = require('../utils/logger').child({ cat: 'ws-client, ws' });
12
+ const traceInvocationCall = require('../utils/traceInvocationCall').bind(null, log);
12
13
 
13
14
  const assertDirection = assertEnum(['left', 'right', 'up', 'down']);
14
15
  const assertSpeed = assertEnum(['fast', 'slow']);
@@ -0,0 +1,117 @@
1
+ const { IPC } = require('node-ipc');
2
+
3
+ const { DetoxInternalError } = require('../errors');
4
+ const { serializeObjectWithError } = require('../utils/errorUtils');
5
+
6
+ class IPCClient {
7
+ constructor({ id, logger, state }) {
8
+ this._id = id;
9
+ /** @type {import('../logger/DetoxLogger')} logger */
10
+ this._logger = logger.child({ cat: 'ipc' });
11
+ /** @type {import('./SessionState')} */
12
+ this._state = state;
13
+
14
+ this._client = null;
15
+ this._serverConnection = null;
16
+ }
17
+
18
+ async init() {
19
+ this._client = new IPC();
20
+
21
+ Object.assign(this._client.config, {
22
+ id: this._id,
23
+ appspace: 'detox.',
24
+ logger: (msg) => this._logger.trace(msg),
25
+ stopRetrying: 0,
26
+ maxRetries: 0,
27
+ });
28
+
29
+ await this._connectToServer();
30
+ await this._registerContext();
31
+ }
32
+
33
+ async dispose() {
34
+ this._serverConnection = null;
35
+
36
+ if (this._client) {
37
+ this._client.disconnect(this.serverId);
38
+ this._client = null;
39
+ }
40
+ }
41
+
42
+ get sessionState() {
43
+ return this._state;
44
+ }
45
+
46
+ get serverId() {
47
+ return this.sessionState.detoxIPCServer;
48
+ }
49
+
50
+ async registerWorker(workerId) {
51
+ const sessionState = await this._emit('registerWorker', { workerId });
52
+ this._state.patch(sessionState);
53
+ }
54
+
55
+ /**
56
+ * @param {DetoxInternals.DetoxTestFileReport[]} testResults
57
+ */
58
+ async reportTestResults(testResults) {
59
+ const sessionState = await this._emit('reportTestResults', {
60
+ testResults: testResults.map(r => serializeObjectWithError(r, 'testExecError')),
61
+ });
62
+ this._state.patch(sessionState);
63
+ }
64
+
65
+ async _connectToServer() {
66
+ const serverId = this.serverId;
67
+
68
+ this._serverConnection = await new Promise((resolve, reject) => {
69
+ this._client.connectTo(serverId, (client) => {
70
+ client.of[serverId]
71
+ .on('error', reject)
72
+ .on('disconnect', () => reject(new DetoxInternalError('IPC server has unexpectedly disconnected.')))
73
+ .on('connect', () => resolve(client.of[serverId]));
74
+ });
75
+ });
76
+
77
+ this._serverConnection.on('sessionStateUpdate', this._onSessionStateUpdate);
78
+ }
79
+
80
+ async _registerContext() {
81
+ const sessionState = await this._emit('registerContext', { id: this._id });
82
+ this._state.patch(sessionState);
83
+ }
84
+
85
+ async _emit(event, payload) {
86
+ if (!this._serverConnection) {
87
+ throw new DetoxInternalError(`IPC server ${this.serverId} has unexpectedly disconnected.`);
88
+ }
89
+
90
+ return new Promise((resolve, reject) => {
91
+ const server = this._serverConnection;
92
+
93
+ function onError(err) {
94
+ server.off('error', onError);
95
+ server.off(`${event}Done`, onDone);
96
+ reject(err);
97
+ }
98
+
99
+ function onDone(response) {
100
+ server.off(`${event}Done`, onDone);
101
+ server.off('error', onError);
102
+ resolve(response);
103
+ }
104
+
105
+ server
106
+ .on('error', onError)
107
+ .on(`${event}Done`, onDone)
108
+ .emit(event, payload);
109
+ });
110
+ }
111
+
112
+ _onSessionStateUpdate = (payload) => {
113
+ this._state.patch(payload);
114
+ };
115
+ }
116
+
117
+ module.exports = IPCClient;
@@ -0,0 +1,98 @@
1
+ const { uniqBy } = require('lodash');
2
+ const { IPC } = require('node-ipc');
3
+
4
+ const { serializeObjectWithError } = require('../utils/errorUtils');
5
+
6
+ class IPCServer {
7
+ /**
8
+ * @param {object} options
9
+ * @param {import('./SessionState')} options.sessionState
10
+ * @param {Detox.Logger} options.logger
11
+ */
12
+ constructor({ sessionState, logger }) {
13
+ this._sessionState = sessionState;
14
+ this._logger = logger.child({ cat: 'ipc,ipc-server' });
15
+ this._ipc = null;
16
+ this._workers = new Set();
17
+ }
18
+
19
+ get id() {
20
+ return this._sessionState.detoxIPCServer;
21
+ }
22
+
23
+ get sessionState() {
24
+ return this._sessionState;
25
+ }
26
+
27
+ async init() {
28
+ this._ipc = new IPC();
29
+ this._ipc.config.id = this.id;
30
+ this._ipc.config.appspace = 'detox.';
31
+ this._ipc.config.logger = (msg) => this._logger.trace(msg);
32
+
33
+ await new Promise((resolve) => {
34
+ // TODO: handle reject
35
+ this._ipc.serve(() => resolve());
36
+ this._ipc.server.on('registerContext', this.onRegisterContext.bind(this));
37
+ this._ipc.server.on('registerWorker', this.onRegisterWorker.bind(this));
38
+ this._ipc.server.on('reportTestResults', this.onReportTestResults.bind(this));
39
+ this._ipc.server.start();
40
+ });
41
+ }
42
+
43
+ async dispose() {
44
+ if (!this._ipc) {
45
+ return;
46
+ }
47
+
48
+ return new Promise((resolve, reject) =>{
49
+ // @ts-ignore
50
+ this._ipc.server.server.close(e => e ? reject(e) : resolve());
51
+ this._ipc.server.stop();
52
+ });
53
+ }
54
+
55
+ onRegisterContext({ id }, socket) {
56
+ this._sessionState.contexts.push(id);
57
+
58
+ this._ipc.server.emit(socket, 'registerContextDone', {
59
+ testResults: this._sessionState.testResults,
60
+ testSessionIndex: this._sessionState.testSessionIndex,
61
+ });
62
+ }
63
+
64
+ onRegisterWorker({ workerId }, socket = null) {
65
+ const workersCount = this._workers.add(workerId).size;
66
+ const shouldBroadcast = workersCount > this._sessionState.workersCount;
67
+ this._sessionState.workersCount = workersCount;
68
+
69
+ if (socket) {
70
+ this._ipc.server.emit(socket, 'registerWorkerDone', { workersCount });
71
+ }
72
+
73
+ if (shouldBroadcast) {
74
+ this._ipc.server.broadcast('sessionStateUpdate', { workersCount });
75
+ }
76
+ }
77
+
78
+ onReportTestResults({ testResults }, socket = null) {
79
+ const merged = uniqBy([
80
+ ...testResults.map(r => serializeObjectWithError(r, 'testExecError')),
81
+ ...this._sessionState.testResults
82
+ ], 'testFilePath');
83
+
84
+ this._sessionState.testResults.splice(0, Infinity, ...merged);
85
+
86
+ if (socket) {
87
+ this._ipc.server.emit(socket, 'reportTestResultsDone', {
88
+ testResults: this._sessionState.testResults,
89
+ });
90
+ }
91
+
92
+ this._ipc.server.broadcast('sessionStateUpdate', {
93
+ testResults: this._sessionState.testResults,
94
+ });
95
+ }
96
+ }
97
+
98
+ module.exports = IPCServer;
@@ -0,0 +1,62 @@
1
+ const vm = require('vm');
2
+
3
+ const cycle = require('json-cycle');
4
+
5
+ const context = vm.createContext({ require }, {
6
+ name: 'VM User Context',
7
+ });
8
+
9
+ class SessionState {
10
+ constructor({
11
+ id = '',
12
+ contexts = [],
13
+ detoxConfig = null,
14
+ detoxIPCServer = '',
15
+ testResults = [],
16
+ testSessionIndex = 0,
17
+ workersCount = 0
18
+ }) {
19
+ this.id = id;
20
+ this.contexts = contexts;
21
+ this.detoxConfig = detoxConfig;
22
+ this.detoxIPCServer = detoxIPCServer;
23
+ this.testResults = testResults;
24
+ this.testSessionIndex = testSessionIndex;
25
+ this.workersCount = workersCount;
26
+ }
27
+
28
+ patch(state) {
29
+ Object.assign(this, state);
30
+ }
31
+
32
+ stringify() {
33
+ return cycle.stringify(this, SessionState.stringifier);
34
+ }
35
+
36
+ /**
37
+ * @return {*}
38
+ */
39
+ static parse(stringified) {
40
+ const Class = this; // eslint-disable-line unicorn/no-this-assignment
41
+ // @ts-ignore
42
+ return new Class(cycle.parse(stringified, SessionState.reviver));
43
+ }
44
+
45
+ static reviver(key, val) {
46
+ if (typeof val === 'object' && val !== null && typeof val.$fn == 'string') {
47
+ return vm.runInContext(val.$fn, context);
48
+ } else {
49
+ return val;
50
+ }
51
+ }
52
+
53
+ static stringifier(key, val) {
54
+ if (typeof val === 'function') {
55
+ return { $fn: `(${val})` };
56
+ } else {
57
+ return val;
58
+ }
59
+ }
60
+ }
61
+
62
+ module.exports = SessionState;