detox 20.0.0-breaking.new-global-lifecycle.0 → 20.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (204) hide show
  1. package/Detox-android/com/wix/detox/{20.0.0-breaking.new-global-lifecycle.0/detox-20.0.0-breaking.new-global-lifecycle.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/{20.0.0-breaking.new-global-lifecycle.0/detox-20.0.0-breaking.new-global-lifecycle.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/{20.0.0-breaking.new-global-lifecycle.0/detox-20.0.0-breaking.new-global-lifecycle.0.pom → 20.0.0/detox-20.0.0.pom} +2 -8
  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/build.gradle +13 -8
  30. package/android/detox/build.gradle +14 -10
  31. package/android/detox/proguard-rules-app.pro +6 -0
  32. package/android/detox/proguard-rules.pro +3 -0
  33. package/android/detox/publish-pom.gradle +5 -1
  34. package/android/detox/publishing.gradle +35 -33
  35. package/android/detox/src/full/java/com/wix/detox/DetoxCrashHandler.kt +1 -1
  36. package/android/detox/src/full/java/com/wix/detox/LaunchArgs.java +9 -0
  37. package/android/detox/src/full/java/com/wix/detox/TestEngineFacade.kt +1 -1
  38. package/android/detox/src/full/java/com/wix/detox/adapters/server/WebSocketClient.java +3 -1
  39. package/android/detox/src/full/java/com/wix/detox/espresso/DetoxAction.java +1 -3
  40. package/android/detox/src/full/java/com/wix/detox/espresso/UiAutomatorHelper.java +1 -1
  41. package/android/detox/src/full/java/com/wix/detox/espresso/action/AdjustSliderToPositionAction.kt +22 -0
  42. package/android/detox/src/{main → full}/java/com/wix/detox/espresso/action/GetAttributesAction.kt +13 -1
  43. package/android/detox/src/full/java/com/wix/detox/espresso/common/SliderHelper.kt +75 -0
  44. package/android/detox/src/full/java/com/wix/detox/espresso/matcher/ViewMatchers.kt +16 -23
  45. package/android/detox/src/full/java/com/wix/detox/reactnative/ReactNativeExtension.kt +15 -2
  46. package/android/detox/src/full/java/com/wix/detox/reactnative/ReactNativeIdlingResources.kt +43 -38
  47. package/android/detox/src/full/java/com/wix/detox/reactnative/ReactNativeLoadingMonitor.kt +54 -8
  48. package/android/detox/src/full/java/com/wix/detox/reactnative/idlingresources/IdlingResourceDescription.kt +19 -13
  49. package/android/detox/src/full/java/com/wix/detox/reactnative/idlingresources/NetworkIdlingResource.java +33 -30
  50. package/android/detox/src/full/java/com/wix/detox/reactnative/idlingresources/timers/DelegatedIdleInterrogationStrategy.kt +7 -27
  51. package/android/detox/src/full/java/com/wix/detox/reactnative/idlingresources/timers/IdleInterrogationStrategy.kt +1 -11
  52. package/android/detox/src/full/java/com/wix/detox/reactnative/idlingresources/uimodule/RN66Workaround.kt +13 -4
  53. package/android/detox/src/main/java/com/wix/detox/common/DetoxErrors.java +4 -1
  54. package/android/detox/src/main/java/com/wix/detox/common/TextFileReader.kt +1 -1
  55. package/android/detox/src/main/java/com/wix/detox/espresso/UiControllerSpy.kt +2 -1
  56. package/android/detox/src/main/java/com/wix/detox/espresso/action/common/ReflectUtils.kt +10 -0
  57. package/android/detox/src/main/java/com/wix/detox/espresso/action/common/utils/UiControllerUtils.kt +1 -1
  58. package/android/detox/src/testFull/java/com/wix/detox/espresso/action/DetoxMultiTapSpec.kt +4 -3
  59. package/android/detox/src/testFull/java/com/wix/detox/espresso/action/GetAttributesActionTest.kt +15 -3
  60. package/android/detox/src/testFull/java/com/wix/detox/espresso/common/SliderHelperTest.kt +39 -0
  61. package/android/detox/src/testFull/java/com/wix/detox/reactnative/idlingresources/NetworkIdlingResourcesTest.kt +61 -0
  62. package/android/detox/src/testFull/java/com/wix/detox/reactnative/idlingresources/timers/DelegatedIdleInterrogationStrategySpec.kt +3 -11
  63. package/android/gradle/wrapper/gradle-wrapper.properties +2 -1
  64. package/android/gradlew +181 -107
  65. package/index.d.ts +198 -57
  66. package/internals.d.ts +220 -51
  67. package/local-cli/build.js +2 -2
  68. package/local-cli/build.test.js +14 -14
  69. package/local-cli/cli.js +8 -6
  70. package/local-cli/init.js +61 -21
  71. package/local-cli/rebuild-framework-cache.js +1 -1
  72. package/local-cli/reset-lock-file.js +16 -0
  73. package/local-cli/templates/jest.js +13 -10
  74. package/local-cli/test.js +14 -8
  75. package/local-cli/test.test.js +148 -61
  76. package/local-cli/testCommand/TestRunnerCommand.js +78 -71
  77. package/local-cli/testCommand/builder.js +0 -1
  78. package/local-cli/testCommand/middlewares.js +4 -13
  79. package/local-cli/testCommand/warnings.js +0 -3
  80. package/local-cli/utils/jestInternals.js +4 -1
  81. package/package.json +22 -15
  82. package/runners/deprecation.js +42 -44
  83. package/runners/jest/globalSetup.js +1 -1
  84. package/runners/jest/globalTeardown.js +1 -1
  85. package/runners/jest/index.d.ts +60 -0
  86. package/runners/jest/index.js +3 -8
  87. package/runners/jest/index.test.js +13 -0
  88. package/runners/jest/reporters/DetoxReporter.js +33 -2
  89. package/runners/jest/testEnvironment/index.js +119 -69
  90. package/runners/jest/testEnvironment/listeners/DetoxCoreListener.js +94 -51
  91. package/runners/jest/testEnvironment/listeners/DetoxPlatformFilterListener.js +1 -1
  92. package/runners/jest/testEnvironment/listeners/SpecReporter.js +14 -16
  93. package/runners/jest/testEnvironment/listeners/WorkerAssignReporter.js +2 -6
  94. package/runners/jest/testEnvironment/utils/assertJestCircus27.js +17 -3
  95. package/runners/jest/testEnvironment/utils/assertJestCircus27.test.js +0 -1
  96. package/src/DetoxWorker.js +107 -59
  97. package/src/android/core/NativeElement.js +56 -20
  98. package/src/android/core/NativeExpect.js +28 -9
  99. package/src/android/interactions/native.js +25 -18
  100. package/src/artifacts/ArtifactsManager.js +14 -47
  101. package/src/artifacts/instruments/ios/SimulatorInstrumentsRecording.js +3 -3
  102. package/src/artifacts/log/android/ADBLogcatRecording.js +11 -28
  103. package/src/artifacts/log/ios/SimulatorLogRecording.js +1 -1
  104. package/src/artifacts/screenshot/SimulatorScreenshotPlugin.js +1 -1
  105. package/src/artifacts/templates/artifact/Artifact.js +1 -1
  106. package/src/artifacts/templates/plugin/ArtifactPlugin.js +1 -1
  107. package/src/artifacts/timeline/TimelineContextTypes.js +7 -0
  108. package/src/artifacts/utils/temporaryPath.js +18 -7
  109. package/src/artifacts/video/SimulatorRecordVideoPlugin.js +1 -1
  110. package/src/client/AsyncWebSocket.js +8 -17
  111. package/src/client/Client.js +19 -2
  112. package/src/client/actions/formatters/sync-resources/NetworkFormatter.js +1 -1
  113. package/src/configuration/collectCliConfig.js +1 -12
  114. package/src/configuration/composeAppsConfig.js +5 -1
  115. package/src/configuration/composeDeviceConfig.js +1 -1
  116. package/src/configuration/composeLoggerConfig.js +19 -10
  117. package/src/configuration/composeRunnerConfig.js +62 -9
  118. package/src/configuration/index.js +14 -9
  119. package/src/configuration/loadExternalConfig.js +1 -1
  120. package/src/devices/allocation/DeviceAllocator.js +3 -2
  121. package/src/devices/allocation/drivers/android/emulator/AVDValidator.js +5 -5
  122. package/src/devices/allocation/drivers/android/emulator/EmulatorAllocDriver.js +4 -3
  123. package/src/devices/allocation/drivers/android/emulator/EmulatorAllocationHelper.js +1 -1
  124. package/src/devices/allocation/drivers/android/emulator/EmulatorLauncher.js +3 -2
  125. package/src/devices/allocation/drivers/android/emulator/EmulatorVersionResolver.js +4 -6
  126. package/src/devices/allocation/drivers/android/emulator/launchEmulatorProcess.js +1 -1
  127. package/src/devices/allocation/drivers/android/genycloud/GenyAllocDriver.js +1 -0
  128. package/src/devices/allocation/drivers/android/genycloud/GenyInstanceAllocationHelper.js +1 -1
  129. package/src/devices/common/drivers/android/exec/ADB.js +5 -0
  130. package/src/devices/common/drivers/android/genycloud/services/GenyInstanceNaming.js +3 -3
  131. package/src/devices/common/drivers/android/genycloud/services/GenyRecipesService.js +1 -1
  132. package/src/devices/common/drivers/android/tools/EmulatorTelnet.js +1 -1
  133. package/src/devices/common/drivers/android/tools/FreeDeviceFinder.js +1 -1
  134. package/src/devices/common/drivers/android/tools/MonitoredInstrumentation.js +1 -1
  135. package/src/devices/common/drivers/ios/tools/AppleSimUtils.js +29 -3
  136. package/src/devices/lifecycle/GenyGlobalLifecycleHandler.js +13 -15
  137. package/src/devices/runtime/RuntimeDevice.js +19 -12
  138. package/src/devices/runtime/drivers/DeviceDriverBase.js +1 -1
  139. package/src/devices/runtime/drivers/android/AndroidDriver.js +10 -2
  140. package/src/devices/runtime/drivers/ios/SimulatorDriver.js +1 -1
  141. package/src/errors/DetoxConfigErrorComposer.js +18 -3
  142. package/src/ios/expectTwo.js +153 -67
  143. package/src/ipc/IPCClient.js +12 -12
  144. package/src/ipc/IPCServer.js +34 -17
  145. package/src/ipc/{state.js → SessionState.js} +26 -31
  146. package/src/logger/DetoxLogger.js +261 -157
  147. package/src/logger/index.js +5 -0
  148. package/src/logger/utils/BunyanLogger.js +76 -0
  149. package/src/logger/utils/CategoryThreadDispatcher.js +36 -0
  150. package/src/logger/utils/DetoxLogFinalizer.js +140 -0
  151. package/src/logger/utils/MessageStack.js +24 -0
  152. package/src/logger/utils/ThreadDispatcher.js +61 -0
  153. package/src/logger/{customConsoleLogger.js → utils/customConsoleLogger.js} +5 -4
  154. package/src/logger/utils/sanitizeBunyanContext.js +30 -0
  155. package/src/{utils → logger/utils}/streamUtils.js +51 -17
  156. package/src/logger/utils/tracerLegacy.js +37 -0
  157. package/src/realms/DetoxContext.js +78 -65
  158. package/src/realms/DetoxInternalsFacade.js +8 -12
  159. package/src/realms/DetoxPrimaryContext.js +106 -73
  160. package/src/realms/DetoxSecondaryContext.js +29 -31
  161. package/src/server/DetoxConnection.js +18 -23
  162. package/src/server/DetoxServer.js +7 -10
  163. package/src/server/DetoxSession.js +6 -6
  164. package/src/server/DetoxSessionManager.js +1 -1
  165. package/src/server/handlers/RegisteredConnectionHandler.js +1 -2
  166. package/src/symbols.js +16 -22
  167. package/src/utils/Timer.js +55 -38
  168. package/src/utils/argparse.js +11 -0
  169. package/src/utils/childProcess/exec.js +1 -1
  170. package/src/utils/childProcess/spawn.js +1 -1
  171. package/src/utils/environment.js +30 -15
  172. package/src/utils/errorUtils.js +24 -3
  173. package/src/utils/invocationTraceDescriptions.js +43 -0
  174. package/src/utils/logger.js +1 -1
  175. package/src/utils/traceInvocationCall.js +21 -0
  176. package/src/utils/traceMethods.js +15 -0
  177. package/Detox-android/com/wix/detox/20.0.0-breaking.new-global-lifecycle.0/detox-20.0.0-breaking.new-global-lifecycle.0-javadoc.jar.md5 +0 -1
  178. package/Detox-android/com/wix/detox/20.0.0-breaking.new-global-lifecycle.0/detox-20.0.0-breaking.new-global-lifecycle.0-javadoc.jar.sha1 +0 -1
  179. package/Detox-android/com/wix/detox/20.0.0-breaking.new-global-lifecycle.0/detox-20.0.0-breaking.new-global-lifecycle.0-javadoc.jar.sha256 +0 -1
  180. package/Detox-android/com/wix/detox/20.0.0-breaking.new-global-lifecycle.0/detox-20.0.0-breaking.new-global-lifecycle.0-javadoc.jar.sha512 +0 -1
  181. package/Detox-android/com/wix/detox/20.0.0-breaking.new-global-lifecycle.0/detox-20.0.0-breaking.new-global-lifecycle.0-sources.jar.md5 +0 -1
  182. package/Detox-android/com/wix/detox/20.0.0-breaking.new-global-lifecycle.0/detox-20.0.0-breaking.new-global-lifecycle.0-sources.jar.sha1 +0 -1
  183. package/Detox-android/com/wix/detox/20.0.0-breaking.new-global-lifecycle.0/detox-20.0.0-breaking.new-global-lifecycle.0-sources.jar.sha256 +0 -1
  184. package/Detox-android/com/wix/detox/20.0.0-breaking.new-global-lifecycle.0/detox-20.0.0-breaking.new-global-lifecycle.0-sources.jar.sha512 +0 -1
  185. package/Detox-android/com/wix/detox/20.0.0-breaking.new-global-lifecycle.0/detox-20.0.0-breaking.new-global-lifecycle.0.aar +0 -0
  186. package/Detox-android/com/wix/detox/20.0.0-breaking.new-global-lifecycle.0/detox-20.0.0-breaking.new-global-lifecycle.0.aar.md5 +0 -1
  187. package/Detox-android/com/wix/detox/20.0.0-breaking.new-global-lifecycle.0/detox-20.0.0-breaking.new-global-lifecycle.0.aar.sha1 +0 -1
  188. package/Detox-android/com/wix/detox/20.0.0-breaking.new-global-lifecycle.0/detox-20.0.0-breaking.new-global-lifecycle.0.aar.sha256 +0 -1
  189. package/Detox-android/com/wix/detox/20.0.0-breaking.new-global-lifecycle.0/detox-20.0.0-breaking.new-global-lifecycle.0.aar.sha512 +0 -1
  190. package/Detox-android/com/wix/detox/20.0.0-breaking.new-global-lifecycle.0/detox-20.0.0-breaking.new-global-lifecycle.0.pom.md5 +0 -1
  191. package/Detox-android/com/wix/detox/20.0.0-breaking.new-global-lifecycle.0/detox-20.0.0-breaking.new-global-lifecycle.0.pom.sha1 +0 -1
  192. package/Detox-android/com/wix/detox/20.0.0-breaking.new-global-lifecycle.0/detox-20.0.0-breaking.new-global-lifecycle.0.pom.sha256 +0 -1
  193. package/Detox-android/com/wix/detox/20.0.0-breaking.new-global-lifecycle.0/detox-20.0.0-breaking.new-global-lifecycle.0.pom.sha512 +0 -1
  194. package/android/detox/src/full/java/com/wix/detox/reactnative/idlingresources/timers/DefaultIdleInterrogationStrategy.kt +0 -84
  195. package/android/detox/src/main/java/com/wix/detox/espresso/action/AdjustSliderToPositionAction.kt +0 -36
  196. package/android/detox/src/testFull/java/com/wix/detox/espresso/action/AdjustSliderToPositionActionTest.kt +0 -59
  197. package/android/detox/src/testFull/java/com/wix/detox/reactnative/idlingresources/timers/DefaultIdleInterrogationStrategySpec.kt +0 -115
  198. package/runners/jest/deprecation.js +0 -25
  199. package/src/configuration/utils/warnings.js +0 -12
  200. package/src/logger/DetoxTraceEventBuilder.js +0 -21
  201. package/src/logger/DetoxTracer.js +0 -133
  202. package/src/logger/TraceThreadDispatcher.js +0 -52
  203. package/src/utils/ChromeTracingExporter.js +0 -53
  204. package/src/utils/trace.js +0 -19
@@ -1,3 +1,4 @@
1
+ const CAF = require('caf');
1
2
  const _ = require('lodash');
2
3
 
3
4
  const Client = require('./client/Client');
@@ -11,7 +12,7 @@ const uuid = require('./utils/uuid');
11
12
  class DetoxWorker {
12
13
  constructor(context) {
13
14
  this._context = context;
14
- this._isCleaningUp = false;
15
+ this._injectedGlobalProperties = [];
15
16
  this._config = context[symbols.config];
16
17
  this._runtimeErrorComposer = new DetoxRuntimeErrorComposer(this._config);
17
18
  this._client = null;
@@ -32,6 +33,20 @@ class DetoxWorker {
32
33
  onError: this._onEmitError.bind(this),
33
34
  });
34
35
 
36
+
37
+ /** @type {DetoxInternals.RuntimeConfig['apps']} */
38
+ this._appsConfig = null;
39
+ /** @type {DetoxInternals.RuntimeConfig['artifacts']} */
40
+ this._artifactsConfig = null;
41
+ /** @type {DetoxInternals.RuntimeConfig['behavior']} */
42
+ this._behaviorConfig = null;
43
+ /** @type {DetoxInternals.RuntimeConfig['device']} */
44
+ this._deviceConfig = null;
45
+ /** @type {DetoxInternals.RuntimeConfig['session']} */
46
+ this._sessionConfig = null;
47
+
48
+ /** @type {string} */
49
+ this.id = 'worker';
35
50
  /** @type {Detox.Device} */
36
51
  this.device = null;
37
52
  /** @type {Detox.ElementFacade} */
@@ -51,20 +66,40 @@ class DetoxWorker {
51
66
  this.trace = this._context.trace;
52
67
  /** @deprecated */
53
68
  this.traceCall = this._context.traceCall;
69
+
70
+ this._reinstallAppsOnDevice = CAF(this._reinstallAppsOnDevice.bind(this));
71
+ this._initToken = new CAF.cancelToken();
72
+
73
+ this._cafWrap([
74
+ 'init',
75
+ 'onRunDescribeStart',
76
+ 'onTestStart',
77
+ 'onHookFailure',
78
+ 'onTestFnFailure',
79
+ 'onTestDone',
80
+ 'onRunDescribeFinish',
81
+ ]);
54
82
  }
55
83
 
56
- async init() {
57
- if (this._isCleaningUp) return;
84
+ /** @this {DetoxWorker} */
85
+ init = function* (signal) {
86
+ const {
87
+ apps: appsConfig,
88
+ artifacts: artifactsConfig,
89
+ behavior: behaviorConfig,
90
+ device: deviceConfig,
91
+ session: sessionConfig
92
+ } = this._config;
58
93
 
59
- const { appsConfig, artifactsConfig, behaviorConfig, deviceConfig, sessionConfig } = this._config;
60
94
  this._appsConfig = appsConfig;
61
95
  this._artifactsConfig = artifactsConfig;
62
96
  this._behaviorConfig = behaviorConfig;
63
97
  this._deviceConfig = deviceConfig;
64
98
  this._sessionConfig = sessionConfig;
99
+ // @ts-ignore
100
+ this._sessionConfig.sessionId = sessionConfig.sessionId || uuid.UUID();
65
101
  this._runtimeErrorComposer.appsConfig = this._appsConfig;
66
102
 
67
- sessionConfig.sessionId = sessionConfig.sessionId || uuid.UUID();
68
103
  this._client = new Client(sessionConfig);
69
104
  this._client.terminateApp = async () => {
70
105
  // @ts-ignore
@@ -73,8 +108,7 @@ class DetoxWorker {
73
108
  }
74
109
  };
75
110
 
76
- await this._client.connect();
77
- if (this._isCleaningUp) return;
111
+ yield this._client.connect();
78
112
 
79
113
  const invocationManager = new InvocationManager(this._client);
80
114
 
@@ -91,8 +125,7 @@ class DetoxWorker {
91
125
  } = environmentFactory.createFactories(this._deviceConfig);
92
126
 
93
127
  const envValidator = envValidatorFactory.createValidator();
94
- await envValidator.validate();
95
- if (this._isCleaningUp) return;
128
+ yield envValidator.validate();
96
129
 
97
130
  const commonDeps = {
98
131
  invocationManager,
@@ -103,8 +136,7 @@ class DetoxWorker {
103
136
 
104
137
  this._artifactsManager = artifactsManagerFactory.createArtifactsManager(this._artifactsConfig, commonDeps);
105
138
  this._deviceAllocator = deviceAllocatorFactory.createDeviceAllocator(commonDeps);
106
- this._deviceCookie = await this._deviceAllocator.allocate(this._deviceConfig);
107
- if (this._isCleaningUp) return;
139
+ this._deviceCookie = yield this._deviceAllocator.allocate(this._deviceConfig);
108
140
 
109
141
  this.device = runtimeDeviceFactory.createRuntimeDevice(
110
142
  this._deviceCookie,
@@ -115,7 +147,6 @@ class DetoxWorker {
115
147
  deviceConfig: this._deviceConfig,
116
148
  sessionConfig,
117
149
  });
118
- if (this._isCleaningUp) return;
119
150
 
120
151
  const matchers = matchersFactory.createMatchers({
121
152
  invocationManager,
@@ -125,34 +156,37 @@ class DetoxWorker {
125
156
  Object.assign(this, matchers);
126
157
 
127
158
  if (behaviorConfig.init.exposeGlobals) {
128
- Object.assign(DetoxWorker.global, {
159
+ const injectedGlobals = {
129
160
  ...matchers,
130
161
  device: this.device,
131
162
  detox: this,
132
- });
163
+ };
164
+
165
+ this._injectedGlobalProperties = Object.keys(injectedGlobals);
166
+ Object.assign(DetoxWorker.global, injectedGlobals);
133
167
  }
134
168
 
135
169
  // @ts-ignore
136
- await this.device.installUtilBinaries();
137
- if (this._isCleaningUp) return;
170
+ yield this.device.installUtilBinaries();
138
171
 
139
172
  if (behaviorConfig.init.reinstallApp) {
140
- await this._reinstallAppsOnDevice();
141
- if (this._isCleaningUp) return;
173
+ yield this._reinstallAppsOnDevice(signal);
142
174
  }
143
175
 
144
176
  const appAliases = Object.keys(this._appsConfig);
145
177
  if (appAliases.length === 1) {
146
- await this.device.selectApp(appAliases[0]);
178
+ yield this.device.selectApp(appAliases[0]);
147
179
  } else {
148
- await this.device.selectApp(null);
180
+ yield this.device.selectApp(null);
149
181
  }
150
-
151
- return this;
152
- }
182
+ };
153
183
 
154
184
  async cleanup() {
155
- this._isCleaningUp = true;
185
+ this._initToken.abort('CLEANUP');
186
+
187
+ for (const key of this._injectedGlobalProperties) {
188
+ delete DetoxWorker.global[key];
189
+ }
156
190
 
157
191
  if (this._artifactsManager) {
158
192
  await this._artifactsManager.onBeforeCleanup();
@@ -181,46 +215,45 @@ class DetoxWorker {
181
215
  return this._context.log;
182
216
  }
183
217
 
184
- onRunStart = async (...args) => this._artifactsManager.onRunStart(...args);
185
- onRunDescribeStart = async (...args) => this._artifactsManager.onRunDescribeStart(...args);
186
- onTestStart = async (testSummary) => {
187
- if (this._isCleaningUp) return;
218
+ onRunDescribeStart = function* (_signal, ...args) {
219
+ yield this._artifactsManager.onRunDescribeStart(...args);
220
+ };
221
+
222
+ onTestStart = function* (_signal, testSummary) {
188
223
  this._validateTestSummary('beforeEach', testSummary);
189
- this._logTestRunCheckpoint('DETOX_BEFORE_EACH', testSummary);
190
224
 
191
- if (this._isCleaningUp) return;
192
- await this._dumpUnhandledErrorsIfAny({
225
+ yield this._dumpUnhandledErrorsIfAny({
193
226
  pendingRequests: false,
194
227
  testName: testSummary.fullName,
195
228
  });
196
229
 
197
- if (this._isCleaningUp) return;
198
- await this._artifactsManager.onTestStart(testSummary);
230
+ yield this._artifactsManager.onTestStart(testSummary);
199
231
  };
200
- onHookStart = async (...args) => this._artifactsManager.onHookStart(...args);
201
- onHookFailure = async (...args) => this._artifactsManager.onHookFailure(...args);
202
- onHookSuccess = async (...args) => this._artifactsManager.onHookSuccess(...args);
203
- onTestFnStart = async (...args) => this._artifactsManager.onTestFnStart(...args);
204
- onTestFnFailure = async (...args) => this._artifactsManager.onTestFnFailure(...args);
205
- onTestFnSuccess = async (...args) => this._artifactsManager.onTestFnSuccess(...args);
206
- onTestDone = async (testSummary) => {
207
- if (this._isCleaningUp) return;
232
+
233
+ onHookFailure = function* (_signal, ...args) {
234
+ yield this._artifactsManager.onHookFailure(...args);
235
+ };
236
+
237
+ onTestFnFailure = function* (_signal, ...args) {
238
+ yield this._artifactsManager.onTestFnFailure(...args);
239
+ };
240
+
241
+ onTestDone = function* (_signal, testSummary) {
208
242
  this._validateTestSummary('afterEach', testSummary);
209
- this._logTestRunCheckpoint('DETOX_AFTER_EACH', testSummary);
210
243
 
211
- if (this._isCleaningUp) return;
212
- await this._artifactsManager.onTestDone(testSummary);
244
+ yield this._artifactsManager.onTestDone(testSummary);
213
245
 
214
- if (this._isCleaningUp) return;
215
- await this._dumpUnhandledErrorsIfAny({
246
+ yield this._dumpUnhandledErrorsIfAny({
216
247
  pendingRequests: testSummary.timedOut,
217
248
  testName: testSummary.fullName,
218
249
  });
219
250
  };
220
- onRunDescribeFinish = async (...args) => this._artifactsManager.onRunDescribeFinish(...args);
221
- onRunFinish = async (...args) => this._artifactsManager.onRunFinish(...args);
222
251
 
223
- async _reinstallAppsOnDevice() {
252
+ onRunDescribeFinish = function* (_signal, ...args) {
253
+ yield this._artifactsManager.onRunDescribeFinish(...args);
254
+ };
255
+
256
+ *_reinstallAppsOnDevice(_signal) {
224
257
  const appNames = _(this._appsConfig)
225
258
  .map((config, key) => [key, `${config.binaryPath}:${config.testBinaryPath}`])
226
259
  .uniqBy(1)
@@ -228,17 +261,14 @@ class DetoxWorker {
228
261
  .value();
229
262
 
230
263
  for (const appName of appNames) {
231
- await this.device.selectApp(appName);
232
- if (this._isCleaningUp) return;
233
- await this.device.uninstallApp();
234
- if (this._isCleaningUp) return;
235
- await this.device.installApp();
236
- if (this._isCleaningUp) return;
264
+ yield this.device.selectApp(appName);
265
+ yield this.device.uninstallApp();
237
266
  }
238
- }
239
267
 
240
- _logTestRunCheckpoint(event, { status, fullName }) {
241
- this.log.trace({ event, status }, `${status} test: ${JSON.stringify(fullName)}`);
268
+ for (const appName of appNames) {
269
+ yield this.device.selectApp(appName);
270
+ yield this.device.installApp();
271
+ }
242
272
  }
243
273
 
244
274
  _validateTestSummary(methodName, testSummary) {
@@ -269,10 +299,28 @@ class DetoxWorker {
269
299
  error
270
300
  );
271
301
  }
302
+
303
+ _cafWrap(methodNames) {
304
+ for (const methodName of methodNames) {
305
+ const cafMethod = CAF(this[methodName].bind(this));
306
+ this[methodName] = async (...args) => {
307
+ try {
308
+ await cafMethod(this._initToken.signal, ...args);
309
+ } catch (e) {
310
+ if (e !== 'CLEANUP') {
311
+ throw e;
312
+ }
313
+ }
314
+
315
+ return this;
316
+ };
317
+ }
318
+ }
319
+
272
320
  }
273
321
 
274
322
  /**
275
- * @type {NodeJS.Global}
323
+ * @type {NodeJS.Global | {}}
276
324
  */
277
325
  DetoxWorker.global = global;
278
326
 
@@ -5,6 +5,7 @@ const tempfile = require('tempfile');
5
5
 
6
6
  const DetoxRuntimeError = require('../../errors/DetoxRuntimeError');
7
7
  const invoke = require('../../invoke');
8
+ const { actionDescription } = require('../../utils/invocationTraceDescriptions');
8
9
  const actions = require('../actions/native');
9
10
  const DetoxMatcherApi = require('../espressoapi/DetoxMatcher');
10
11
  const { ActionInteraction } = require('../interactions/native');
@@ -18,12 +19,11 @@ class NativeElement {
18
19
  }
19
20
 
20
21
  _selectElementWithMatcher(matcher) {
21
- // if (!(matcher instanceof NativeMatcher)) throw new DetoxRuntimeError(`Element _selectElementWithMatcher argument must be a valid NativeMatcher, got ${typeof matcher}`);
22
22
  this._call = invoke.call(invoke.Espresso, 'onView', matcher._call);
23
23
  }
24
24
 
25
25
  atIndex(index) {
26
- if (typeof index !== 'number') throw new DetoxRuntimeError(`Element atIndex argument must be a number, got ${typeof index}`);
26
+ if (typeof index !== 'number') throw new DetoxRuntimeError({ message: `Element atIndex argument must be a number, got ${typeof index}` });
27
27
  const matcher = this._originalMatcher;
28
28
  this._originalMatcher._call = invoke.callDirectly(DetoxMatcherApi.matcherForAtIndex(index, matcher._call.value));
29
29
 
@@ -32,56 +32,84 @@ class NativeElement {
32
32
  }
33
33
 
34
34
  async tap(value) {
35
- return await new ActionInteraction(this._invocationManager, this, new actions.TapAction(value)).execute();
35
+ const action = new actions.TapAction(value);
36
+ const traceDescription = actionDescription.tapAtPoint(value);
37
+ return await new ActionInteraction(this._invocationManager, this, action, traceDescription).execute();
36
38
  }
37
39
 
38
40
  async tapAtPoint(value) {
39
- return await new ActionInteraction(this._invocationManager, this, new actions.TapAtPointAction(value)).execute();
41
+ const action = new actions.TapAtPointAction(value);
42
+ const traceDescription = actionDescription.tapAtPoint(value);
43
+ return await new ActionInteraction(this._invocationManager, this, action, traceDescription).execute();
40
44
  }
41
45
 
42
46
  async longPress() {
43
- return await new ActionInteraction(this._invocationManager, this, new actions.LongPressAction()).execute();
47
+ const action = new actions.LongPressAction();
48
+ const traceDescription = actionDescription.longPress();
49
+ return await new ActionInteraction(this._invocationManager, this, action, traceDescription).execute();
44
50
  }
45
51
 
46
52
  async multiTap(times) {
47
- return await new ActionInteraction(this._invocationManager, this, new actions.MultiClickAction(times)).execute();
53
+ if (typeof times !== 'number') throw new Error('times should be a number, but got ' + (times + (' (' + (typeof times + ')'))));
54
+ if (times < 1) throw new Error('times should be greater than 0, but got ' + times);
55
+
56
+ const action = new actions.MultiClickAction(times);
57
+ const traceDescription = actionDescription.multiTap(times);
58
+ return await new ActionInteraction(this._invocationManager, this, action, traceDescription).execute();
48
59
  }
49
60
 
50
61
  async tapBackspaceKey() {
51
- return await new ActionInteraction(this._invocationManager, this, new actions.PressKeyAction(67)).execute();
62
+ const action = new actions.PressKeyAction(67);
63
+ const traceDescription = actionDescription.tapBackspaceKey();
64
+ return await new ActionInteraction(this._invocationManager, this, action, traceDescription).execute();
52
65
  }
53
66
 
54
67
  async tapReturnKey() {
55
- return await new ActionInteraction(this._invocationManager, this, new actions.TypeTextAction('\n')).execute();
68
+ const action = new actions.TypeTextAction('\n');
69
+ const traceDescription = actionDescription.tapReturnKey();
70
+ return await new ActionInteraction(this._invocationManager, this, action, traceDescription).execute();
56
71
  }
57
72
 
58
73
  async typeText(value) {
59
- return await new ActionInteraction(this._invocationManager, this, new actions.TypeTextAction(value)).execute();
74
+ const action = new actions.TypeTextAction(value);
75
+ const traceDescription = actionDescription.typeText(value);
76
+ return await new ActionInteraction(this._invocationManager, this, action, traceDescription).execute();
60
77
  }
61
78
 
62
79
  async replaceText(value) {
63
- return await new ActionInteraction(this._invocationManager, this, new actions.ReplaceTextAction(value)).execute();
80
+ const action = new actions.ReplaceTextAction(value);
81
+ const traceDescription = actionDescription.replaceText(value);
82
+ return await new ActionInteraction(this._invocationManager, this, action, traceDescription).execute();
64
83
  }
65
84
 
66
85
  async clearText() {
67
- return await new ActionInteraction(this._invocationManager, this, new actions.ClearTextAction()).execute();
86
+ const action = new actions.ClearTextAction();
87
+ const traceDescription = actionDescription.clearText();
88
+ return await new ActionInteraction(this._invocationManager, this, action, traceDescription).execute();
68
89
  }
69
90
 
70
91
  async scroll(amount, direction = 'down', startPositionX, startPositionY) {
71
- // override the user's element selection with an extended matcher that looks for UIScrollView children
72
- // this._selectElementWithMatcher(this._originalMatcher._extendToDescendantScrollViews());
73
- return await new ActionInteraction(this._invocationManager, this, new actions.ScrollAmountAction(direction, amount, startPositionX, startPositionY)).execute();
92
+ const action = new actions.ScrollAmountAction(direction, amount, startPositionX, startPositionY);
93
+ const traceDescription = actionDescription.scroll(amount, direction, startPositionX, startPositionY);
94
+ return await new ActionInteraction(this._invocationManager, this, action, traceDescription).execute();
74
95
  }
75
96
 
76
97
  async scrollTo(edge) {
77
98
  // override the user's element selection with an extended matcher that looks for UIScrollView children
78
99
  this._selectElementWithMatcher(this._originalMatcher._extendToDescendantScrollViews());
79
- return await new ActionInteraction(this._invocationManager, this, new actions.ScrollEdgeAction(edge)).execute();
100
+
101
+ const action = new actions.ScrollEdgeAction(edge);
102
+ const traceDescription = actionDescription.scrollTo(edge);
103
+ return await new ActionInteraction(this._invocationManager, this, action, traceDescription).execute();
80
104
  }
81
105
 
82
106
  async scrollToIndex(index) {
107
+ // override the user's element selection with an extended matcher that looks for UIScrollView children
83
108
  this._selectElementWithMatcher(this._originalMatcher._extendToDescendantScrollViews());
84
- return await new ActionInteraction(this._invocationManager, this, new actions.ScrollToIndex(index)).execute();
109
+
110
+ const action = new actions.ScrollToIndex(index);
111
+ const traceDescription = actionDescription.scrollToIndex(index);
112
+ return await new ActionInteraction(this._invocationManager, this, action, traceDescription).execute();
85
113
  }
86
114
 
87
115
  /**
@@ -96,13 +124,17 @@ class NativeElement {
96
124
 
97
125
  // override the user's element selection with an extended matcher that avoids RN issues with RCTScrollView
98
126
  this._selectElementWithMatcher(this._originalMatcher._avoidProblematicReactNativeElements());
127
+
99
128
  const action = new actions.SwipeAction(direction, speed, normalizedSwipeOffset, normalizedStartingPointX, normalizedStartingPointY);
100
- return await new ActionInteraction(this._invocationManager, this, action).execute();
129
+ const traceDescription = actionDescription.swipe(direction, speed, normalizedSwipeOffset, normalizedStartingPointX, normalizedStartingPointY);
130
+ return await new ActionInteraction(this._invocationManager, this, action, traceDescription).execute();
101
131
  }
102
132
 
103
133
  async takeScreenshot(screenshotName) {
104
134
  // TODO this should be moved to a lower-layer handler of this use-case
105
- const resultBase64 = await new ActionInteraction(this._invocationManager, this, new actions.TakeElementScreenshot()).execute();
135
+ const action = new actions.TakeElementScreenshot();
136
+ const traceDescription = actionDescription.takeScreenshot(screenshotName);
137
+ const resultBase64 = await new ActionInteraction(this._invocationManager, this, action, traceDescription).execute();
106
138
  const filePath = tempfile('detox.element-screenshot.png');
107
139
  await fs.writeFile(filePath, resultBase64, 'base64');
108
140
 
@@ -115,12 +147,16 @@ class NativeElement {
115
147
  }
116
148
 
117
149
  async getAttributes() {
118
- const result = await new ActionInteraction(this._invocationManager, this, new actions.GetAttributes()).execute();
150
+ const action = new actions.GetAttributes();
151
+ const traceDescription = actionDescription.getAttributes();
152
+ const result = await new ActionInteraction(this._invocationManager, this, action, traceDescription).execute();
119
153
  return JSON.parse(result);
120
154
  }
121
155
 
122
156
  async adjustSliderToPosition(newPosition) {
123
- return await new ActionInteraction(this._invocationManager, this, new actions.AdjustSliderToPosition(newPosition)).execute();
157
+ const action = new actions.AdjustSliderToPosition(newPosition);
158
+ const traceDescription = actionDescription.adjustSliderToPosition(newPosition);
159
+ return await new ActionInteraction(this._invocationManager, this, action, traceDescription).execute();
124
160
  }
125
161
  }
126
162
 
@@ -1,3 +1,4 @@
1
+ const { expectDescription } = require('../../utils/invocationTraceDescriptions');
1
2
  const { MatcherAssertionInteraction } = require('../interactions/native');
2
3
  const matchers = require('../matchers/native');
3
4
 
@@ -19,7 +20,9 @@ class NativeExpectElement extends NativeExpect {
19
20
  }
20
21
 
21
22
  async toBeVisible(pct) {
22
- return await new MatcherAssertionInteraction(this._invocationManager, this._element, this._notCondition ? new matchers.VisibleMatcher(pct).not : new matchers.VisibleMatcher(pct)).execute();
23
+ const matcher = new matchers.VisibleMatcher(pct);
24
+ const traceDescription = expectDescription.toBeVisible(pct);
25
+ return await new MatcherAssertionInteraction(this._invocationManager, this._element, matcher, this._notCondition, traceDescription).execute();
23
26
  }
24
27
 
25
28
  async toBeNotVisible() {
@@ -27,7 +30,9 @@ class NativeExpectElement extends NativeExpect {
27
30
  }
28
31
 
29
32
  async toExist() {
30
- return await new MatcherAssertionInteraction(this._invocationManager, this._element, this._notCondition ? new matchers.ExistsMatcher().not : new matchers.ExistsMatcher()).execute();
33
+ const matcher = new matchers.ExistsMatcher();
34
+ const traceDescription = expectDescription.toExist();
35
+ return await new MatcherAssertionInteraction(this._invocationManager, this._element, matcher, this._notCondition, traceDescription).execute();
31
36
  }
32
37
 
33
38
  async toNotExist() {
@@ -35,7 +40,9 @@ class NativeExpectElement extends NativeExpect {
35
40
  }
36
41
 
37
42
  async toHaveText(text) {
38
- return await new MatcherAssertionInteraction(this._invocationManager, this._element, this._notCondition ? new matchers.TextMatcher(text).not : new matchers.TextMatcher(text)).execute();
43
+ const matcher = new matchers.TextMatcher(text);
44
+ const traceDescription = expectDescription.toHaveText(text);
45
+ return await new MatcherAssertionInteraction(this._invocationManager, this._element, matcher, this._notCondition, traceDescription).execute();
39
46
  }
40
47
 
41
48
  async toNotHaveText(text) {
@@ -43,7 +50,9 @@ class NativeExpectElement extends NativeExpect {
43
50
  }
44
51
 
45
52
  async toHaveLabel(value) {
46
- return await new MatcherAssertionInteraction(this._invocationManager, this._element, this._notCondition ? new matchers.LabelMatcher(value).not : new matchers.LabelMatcher(value)).execute();
53
+ const matcher = new matchers.LabelMatcher(value);
54
+ const traceDescription = expectDescription.toHaveLabel(value);
55
+ return await new MatcherAssertionInteraction(this._invocationManager, this._element, matcher, this._notCondition, traceDescription).execute();
47
56
  }
48
57
 
49
58
  async toNotHaveLabel(value) {
@@ -51,7 +60,9 @@ class NativeExpectElement extends NativeExpect {
51
60
  }
52
61
 
53
62
  async toHaveId(value) {
54
- return await new MatcherAssertionInteraction(this._invocationManager, this._element, this._notCondition ? new matchers.IdMatcher(value).not : new matchers.IdMatcher(value)).execute();
63
+ const matcher = new matchers.IdMatcher(value);
64
+ const traceDescription = expectDescription.toHaveId(value);
65
+ return await new MatcherAssertionInteraction(this._invocationManager, this._element, matcher, this._notCondition, traceDescription).execute();
55
66
  }
56
67
 
57
68
  async toNotHaveId(value) {
@@ -59,7 +70,9 @@ class NativeExpectElement extends NativeExpect {
59
70
  }
60
71
 
61
72
  async toHaveValue(value) {
62
- return await new MatcherAssertionInteraction(this._invocationManager, this._element, this._notCondition ? new matchers.ValueMatcher(value).not : new matchers.ValueMatcher(value)).execute();
73
+ const matcher = new matchers.ValueMatcher(value);
74
+ const traceDescription = expectDescription.toHaveValue(value);
75
+ return await new MatcherAssertionInteraction(this._invocationManager, this._element, matcher, this._notCondition, traceDescription).execute();
63
76
  }
64
77
 
65
78
  async toNotHaveValue(value) {
@@ -67,15 +80,21 @@ class NativeExpectElement extends NativeExpect {
67
80
  }
68
81
 
69
82
  async toHaveToggleValue(value) {
70
- return await new MatcherAssertionInteraction(this._invocationManager, this._element, this._notCondition ? new matchers.ToggleMatcher(value).not : new matchers.ToggleMatcher(value)).execute();
83
+ const matcher = new matchers.ToggleMatcher(value);
84
+ const traceDescription = expectDescription.toHaveToggleValue(value);
85
+ return await new MatcherAssertionInteraction(this._invocationManager, this._element, matcher, this._notCondition, traceDescription).execute();
71
86
  }
72
87
 
73
88
  async toHaveSliderPosition(value, tolerance = 0) {
74
- return await new MatcherAssertionInteraction(this._invocationManager, this._element, this._notCondition ? new matchers.SliderPositionMatcher(value, tolerance).not : new matchers.SliderPositionMatcher(value, tolerance)).execute();
89
+ const matcher = new matchers.SliderPositionMatcher(value, tolerance);
90
+ const traceDescription = expectDescription.toHaveSliderPosition(value, tolerance);
91
+ return await new MatcherAssertionInteraction(this._invocationManager, this._element, matcher, this._notCondition, traceDescription).execute();
75
92
  }
76
93
 
77
94
  async toBeFocused() {
78
- return await new MatcherAssertionInteraction(this._invocationManager, this._element, this._notCondition ? new matchers.FocusMatcher().not : new matchers.FocusMatcher()).execute();
95
+ const matcher = new matchers.FocusMatcher();
96
+ const traceDescription = expectDescription.toBeFocused();
97
+ return await new MatcherAssertionInteraction(this._invocationManager, this._element, matcher, this._notCondition, traceDescription).execute();
79
98
  }
80
99
 
81
100
  async toBeNotFocused() {
@@ -1,4 +1,7 @@
1
1
  const DetoxRuntimeError = require('../../errors/DetoxRuntimeError');
2
+ const { expectDescription, actionDescription } = require('../../utils/invocationTraceDescriptions');
3
+ const log = require('../../utils/logger').child({ cat: 'ws-client, ws' });
4
+ const traceInvocationCall = require('../../utils/traceInvocationCall').bind(null, log);
2
5
  const { ScrollAmountStopAtEdgeAction } = require('../actions/native');
3
6
  const { NativeMatcher } = require('../core/NativeMatcher');
4
7
  const DetoxAssertionApi = require('../espressoapi/DetoxAssertion');
@@ -9,45 +12,50 @@ function call(maybeAFunction) {
9
12
  }
10
13
 
11
14
  class Interaction {
12
- constructor(invocationManager) {
15
+ constructor(invocationManager, traceDescription) {
13
16
  this._call = undefined;
17
+ this._traceDescription = traceDescription;
14
18
  this._invocationManager = invocationManager;
15
19
  }
16
20
 
17
21
  async execute() {
18
- const resultObj = await this._invocationManager.execute(this._call);
19
- return resultObj ? resultObj.result : undefined;
22
+ return traceInvocationCall(this._traceDescription, this._call,
23
+ this._invocationManager.execute(this._call).then((resultObj) => resultObj ? resultObj.result : undefined));
20
24
  }
21
25
  }
22
26
 
23
27
  class ActionInteraction extends Interaction {
24
- constructor(invocationManager, element, action) {
25
- super(invocationManager);
28
+ constructor(invocationManager, element, action, traceDescription) {
29
+ super(invocationManager, traceDescription);
26
30
  this._call = EspressoDetoxApi.perform(call(element._call), action._call);
27
31
  // TODO: move this.execute() here from the caller
28
32
  }
29
33
  }
30
34
 
31
35
  class MatcherAssertionInteraction extends Interaction {
32
- constructor(invocationManager, element, matcher) {
33
- super(invocationManager);
36
+ constructor(invocationManager, element, matcher, notCondition, traceDescription) {
37
+ traceDescription = expectDescription.full(traceDescription, notCondition);
38
+ super(invocationManager, traceDescription);
39
+
40
+ matcher = notCondition ? matcher.not : matcher;
34
41
  this._call = DetoxAssertionApi.assertMatcher(call(element._call), matcher._call.value);
35
42
  // TODO: move this.execute() here from the caller
36
43
  }
37
44
  }
38
45
 
39
46
  class WaitForInteraction extends Interaction {
40
- constructor(invocationManager, element, assertionMatcher) {
41
- super(invocationManager);
47
+ constructor(invocationManager, element, assertionMatcher, expectTraceDescription) {
48
+ super(invocationManager, expectTraceDescription);
42
49
  this._element = element;
43
50
  this._assertionMatcher = assertionMatcher;
44
51
  this._element._selectElementWithMatcher(this._element._originalMatcher);
45
52
  }
46
53
 
47
54
  async withTimeout(timeout) {
48
- if (typeof timeout !== 'number') throw new DetoxRuntimeError(`WaitForInteraction withTimeout argument must be a number, got ${typeof timeout}`);
49
- if (timeout < 0) throw new DetoxRuntimeError('timeout must be larger than 0');
55
+ if (typeof timeout !== 'number') throw new DetoxRuntimeError({ message: `WaitForInteraction withTimeout argument must be a number, got ${typeof timeout}` });
56
+ if (timeout < 0) throw new DetoxRuntimeError({ message: 'timeout must be larger than 0' });
50
57
 
58
+ this._traceDescription = expectDescription.waitForWithTimeout(this._traceDescription, timeout);
51
59
  this._call = DetoxAssertionApi.waitForAssertMatcher(call(this._element._call), this._assertionMatcher._call.value, timeout / 1000);
52
60
  await this.execute();
53
61
  }
@@ -58,20 +66,18 @@ class WaitForInteraction extends Interaction {
58
66
  }
59
67
 
60
68
  class WaitForActionInteractionBase extends Interaction {
61
- constructor(invocationManager, element, matcher, searchMatcher) {
62
- super(invocationManager);
63
- //if (!(element instanceof NativeElement)) throw new DetoxRuntimeError(`WaitForActionInteraction ctor 1st argument must be a valid NativeElement, got ${typeof element}`);
64
- //if (!(matcher instanceof NativeMatcher)) throw new DetoxRuntimeError(`WaitForActionInteraction ctor 2nd argument must be a valid NativeMatcher, got ${typeof matcher}`);
69
+ constructor(invocationManager, element, matcher, searchMatcher, traceDescription) {
70
+ super(invocationManager, traceDescription);
71
+
65
72
  if (!(searchMatcher instanceof NativeMatcher))
66
- throw new DetoxRuntimeError(`WaitForActionInteraction ctor 3rd argument must be a valid NativeMatcher, got ${typeof searchMatcher}`);
73
+ throw new DetoxRuntimeError({ message: `WaitForActionInteraction ctor 3rd argument must be a valid NativeMatcher, got ${typeof searchMatcher}` });
74
+
67
75
  this._element = element;
68
76
  this._originalMatcher = matcher;
69
77
  this._searchMatcher = searchMatcher;
70
78
  }
71
79
 
72
80
  _prepare(searchAction) {
73
- //if (!searchAction instanceof Action) throw new DetoxRuntimeError(`WaitForActionInteraction _execute argument must be a valid Action, got ${typeof searchAction}`);
74
-
75
81
  this._call = DetoxAssertionApi.waitForAssertMatcherWithSearchAction(
76
82
  call(this._element._call),
77
83
  call(this._originalMatcher._call).value,
@@ -83,6 +89,7 @@ class WaitForActionInteractionBase extends Interaction {
83
89
 
84
90
  class WaitForActionInteraction extends WaitForActionInteractionBase {
85
91
  async scroll(amount, direction = 'down', scrollPositionX, scrollPositionY) {
92
+ this._traceDescription = expectDescription.waitFor(actionDescription.scroll(amount, direction, scrollPositionX, scrollPositionY));
86
93
  this._prepare(new ScrollAmountStopAtEdgeAction(direction, amount, scrollPositionX, scrollPositionY));
87
94
  await this.execute();
88
95
  }