detox 19.9.0 → 21.0.0-breaking.new-global-lifecycle.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (219) hide show
  1. package/Detox-android/com/wix/detox/{19.9.0/detox-19.9.0-javadoc.jar → 21.0.0-breaking.new-global-lifecycle.0/detox-21.0.0-breaking.new-global-lifecycle.0-javadoc.jar} +0 -0
  2. package/Detox-android/com/wix/detox/21.0.0-breaking.new-global-lifecycle.0/detox-21.0.0-breaking.new-global-lifecycle.0-javadoc.jar.md5 +1 -0
  3. package/Detox-android/com/wix/detox/21.0.0-breaking.new-global-lifecycle.0/detox-21.0.0-breaking.new-global-lifecycle.0-javadoc.jar.sha1 +1 -0
  4. package/Detox-android/com/wix/detox/21.0.0-breaking.new-global-lifecycle.0/detox-21.0.0-breaking.new-global-lifecycle.0-javadoc.jar.sha256 +1 -0
  5. package/Detox-android/com/wix/detox/21.0.0-breaking.new-global-lifecycle.0/detox-21.0.0-breaking.new-global-lifecycle.0-javadoc.jar.sha512 +1 -0
  6. package/Detox-android/com/wix/detox/{19.9.0/detox-19.9.0-sources.jar → 21.0.0-breaking.new-global-lifecycle.0/detox-21.0.0-breaking.new-global-lifecycle.0-sources.jar} +0 -0
  7. package/Detox-android/com/wix/detox/21.0.0-breaking.new-global-lifecycle.0/detox-21.0.0-breaking.new-global-lifecycle.0-sources.jar.md5 +1 -0
  8. package/Detox-android/com/wix/detox/21.0.0-breaking.new-global-lifecycle.0/detox-21.0.0-breaking.new-global-lifecycle.0-sources.jar.sha1 +1 -0
  9. package/Detox-android/com/wix/detox/21.0.0-breaking.new-global-lifecycle.0/detox-21.0.0-breaking.new-global-lifecycle.0-sources.jar.sha256 +1 -0
  10. package/Detox-android/com/wix/detox/21.0.0-breaking.new-global-lifecycle.0/detox-21.0.0-breaking.new-global-lifecycle.0-sources.jar.sha512 +1 -0
  11. package/Detox-android/com/wix/detox/21.0.0-breaking.new-global-lifecycle.0/detox-21.0.0-breaking.new-global-lifecycle.0.aar +0 -0
  12. package/Detox-android/com/wix/detox/21.0.0-breaking.new-global-lifecycle.0/detox-21.0.0-breaking.new-global-lifecycle.0.aar.md5 +1 -0
  13. package/Detox-android/com/wix/detox/21.0.0-breaking.new-global-lifecycle.0/detox-21.0.0-breaking.new-global-lifecycle.0.aar.sha1 +1 -0
  14. package/Detox-android/com/wix/detox/21.0.0-breaking.new-global-lifecycle.0/detox-21.0.0-breaking.new-global-lifecycle.0.aar.sha256 +1 -0
  15. package/Detox-android/com/wix/detox/21.0.0-breaking.new-global-lifecycle.0/detox-21.0.0-breaking.new-global-lifecycle.0.aar.sha512 +1 -0
  16. package/Detox-android/com/wix/detox/{19.9.0/detox-19.9.0.pom → 21.0.0-breaking.new-global-lifecycle.0/detox-21.0.0-breaking.new-global-lifecycle.0.pom} +2 -2
  17. package/Detox-android/com/wix/detox/21.0.0-breaking.new-global-lifecycle.0/detox-21.0.0-breaking.new-global-lifecycle.0.pom.md5 +1 -0
  18. package/Detox-android/com/wix/detox/21.0.0-breaking.new-global-lifecycle.0/detox-21.0.0-breaking.new-global-lifecycle.0.pom.sha1 +1 -0
  19. package/Detox-android/com/wix/detox/21.0.0-breaking.new-global-lifecycle.0/detox-21.0.0-breaking.new-global-lifecycle.0.pom.sha256 +1 -0
  20. package/Detox-android/com/wix/detox/21.0.0-breaking.new-global-lifecycle.0/detox-21.0.0-breaking.new-global-lifecycle.0.pom.sha512 +1 -0
  21. package/Detox-android/com/wix/detox/maven-metadata.xml +4 -4
  22. package/Detox-android/com/wix/detox/maven-metadata.xml.md5 +1 -1
  23. package/Detox-android/com/wix/detox/maven-metadata.xml.sha1 +1 -1
  24. package/Detox-android/com/wix/detox/maven-metadata.xml.sha256 +1 -1
  25. package/Detox-android/com/wix/detox/maven-metadata.xml.sha512 +1 -1
  26. package/Detox-ios-src.tbz +0 -0
  27. package/Detox-ios.tbz +0 -0
  28. package/android/build.gradle +2 -2
  29. package/android/detox/build.gradle +2 -2
  30. package/android/detox/publish-pom.gradle +1 -5
  31. package/android/detox/publishing.gradle +7 -9
  32. package/android/detox/src/full/java/com/wix/detox/Detox.java +2 -59
  33. package/android/detox/src/full/java/com/wix/detox/NotificationDataParser.kt +3 -3
  34. package/android/detox/src/full/java/com/wix/detox/adapters/server/WebSocketClient.java +1 -3
  35. package/android/detox/src/full/java/com/wix/detox/espresso/DetoxAction.java +3 -1
  36. package/android/detox/src/full/java/com/wix/detox/espresso/UiAutomatorHelper.java +1 -1
  37. package/android/detox/src/full/java/com/wix/detox/espresso/matcher/ViewMatchers.kt +23 -16
  38. package/android/detox/src/full/java/com/wix/detox/reactnative/ReactNativeLoadingMonitor.kt +8 -54
  39. package/android/detox/src/main/java/com/wix/detox/common/DetoxErrors.java +1 -4
  40. package/android/detox/src/main/java/com/wix/detox/espresso/UiControllerSpy.kt +1 -2
  41. package/android/detox/src/main/java/com/wix/detox/espresso/action/AdjustSliderToPositionAction.kt +36 -0
  42. package/android/detox/src/{full → main}/java/com/wix/detox/espresso/action/GetAttributesAction.kt +1 -13
  43. package/android/detox/src/main/java/com/wix/detox/espresso/action/common/utils/UiControllerUtils.kt +1 -1
  44. package/android/detox/src/testFull/java/com/wix/detox/espresso/action/AdjustSliderToPositionActionTest.kt +59 -0
  45. package/android/detox/src/testFull/java/com/wix/detox/espresso/action/GetAttributesActionTest.kt +3 -15
  46. package/android/gradle/wrapper/gradle-wrapper.properties +1 -2
  47. package/android/gradlew +107 -181
  48. package/index.d.ts +208 -186
  49. package/index.js +1 -0
  50. package/internals.d.ts +124 -0
  51. package/internals.js +4 -0
  52. package/local-cli/build-framework-cache.js +2 -2
  53. package/local-cli/build.js +7 -8
  54. package/local-cli/build.test.js +46 -40
  55. package/local-cli/clean-framework-cache.js +3 -3
  56. package/local-cli/cli.js +0 -1
  57. package/local-cli/init.js +20 -55
  58. package/local-cli/templates/jest.js +9 -34
  59. package/local-cli/test.js +18 -282
  60. package/local-cli/test.test.js +332 -673
  61. package/local-cli/testCommand/TestRunnerCommand.js +157 -0
  62. package/local-cli/{utils/testCommandArgs.js → testCommand/builder.js} +10 -35
  63. package/local-cli/testCommand/middlewares.js +75 -0
  64. package/local-cli/{utils → testCommand}/warnings.js +0 -10
  65. package/local-cli/utils/jestInternals.js +13 -2
  66. package/local-cli/utils/yargsUtils.js +67 -0
  67. package/package.json +28 -22
  68. package/runners/deprecation.js +47 -0
  69. package/runners/jest/JestCircusEnvironment.js +3 -38
  70. package/runners/jest/adapter.d.ts +4 -10
  71. package/runners/jest/adapter.js +3 -6
  72. package/runners/jest/assignReporter.d.ts +4 -1
  73. package/runners/jest/assignReporter.js +3 -6
  74. package/runners/jest/deprecation.js +25 -0
  75. package/runners/jest/globalSetup.js +1 -0
  76. package/runners/jest/globalTeardown.js +1 -0
  77. package/runners/jest/index.js +21 -0
  78. package/runners/jest/reporter.js +1 -0
  79. package/runners/jest/reporters/DetoxReporter.js +5 -0
  80. package/runners/jest/specReporter.d.ts +4 -9
  81. package/runners/jest/specReporter.js +3 -10
  82. package/runners/jest/streamlineReporter.js +3 -22
  83. package/runners/jest/testEnvironment/index.js +155 -0
  84. package/runners/{jest-circus → jest/testEnvironment}/listeners/DetoxCoreListener.js +35 -17
  85. package/runners/{jest-circus → jest/testEnvironment}/listeners/DetoxInitErrorListener.js +1 -1
  86. package/runners/jest/testEnvironment/listeners/DetoxPlatformFilterListener.js +27 -0
  87. package/runners/jest/{SpecReporterImpl.js → testEnvironment/listeners/SpecReporter.js} +61 -7
  88. package/runners/jest/testEnvironment/listeners/WorkerAssignReporter.js +34 -0
  89. package/runners/jest/testEnvironment/listeners/index.js +13 -0
  90. package/runners/{jest-circus → jest/testEnvironment}/utils/assertExistingContext.js +2 -2
  91. package/runners/jest/testEnvironment/utils/assertJestCircus27.js +56 -0
  92. package/runners/jest/testEnvironment/utils/assertJestCircus27.test.js +23 -0
  93. package/runners/jest/{utils → testEnvironment/utils}/getFullTestName.js +0 -0
  94. package/runners/jest/{utils → testEnvironment/utils}/hasTimedOut.js +0 -0
  95. package/runners/jest/{utils → testEnvironment/utils}/index.js +0 -0
  96. package/runners/jest/{utils → testEnvironment/utils}/stdout.js +0 -0
  97. package/runners/jest-circus/environment/index.js +6 -0
  98. package/runners/jest-circus/index.js +1 -10
  99. package/runners/jest-circus/reporter.js +1 -0
  100. package/runners/migration.js +37 -0
  101. package/runners/mocha/DetoxMochaAdapter.js +3 -35
  102. package/runners/mocha/adapter.d.ts +4 -7
  103. package/runners/mocha/adapter.js +3 -5
  104. package/src/{Detox.js → DetoxWorker.js} +131 -164
  105. package/src/artifacts/ArtifactsManager.js +51 -2
  106. package/src/artifacts/log/android/ADBLogcatRecording.js +28 -11
  107. package/src/artifacts/providers/index.js +0 -4
  108. package/src/artifacts/utils/buildDefaultArtifactsRootDirpath.js +2 -4
  109. package/src/artifacts/utils/temporaryPath.js +2 -0
  110. package/src/client/AsyncWebSocket.js +1 -1
  111. package/src/client/actions/actions.js +2 -2
  112. package/src/configuration/collectCliConfig.js +2 -4
  113. package/src/configuration/composeAppsConfig.js +9 -67
  114. package/src/configuration/composeArtifactsConfig.js +6 -32
  115. package/src/configuration/composeBehaviorConfig.js +3 -13
  116. package/src/configuration/composeDeviceConfig.js +37 -62
  117. package/src/configuration/composeLoggerConfig.js +50 -0
  118. package/src/configuration/composeRunnerConfig.js +74 -14
  119. package/src/configuration/composeSessionConfig.js +1 -3
  120. package/src/configuration/index.js +24 -23
  121. package/src/configuration/utils/deviceAppTypes.js +0 -1
  122. package/src/devices/allocation/DeviceAllocator.js +3 -3
  123. package/src/devices/allocation/drivers/android/emulator/EmulatorAllocDriver.js +4 -3
  124. package/src/devices/allocation/drivers/android/emulator/EmulatorLauncher.js +2 -6
  125. package/src/devices/allocation/drivers/android/genycloud/GenyAllocDriver.js +0 -1
  126. package/src/devices/allocation/drivers/ios/SimulatorAllocDriver.js +1 -1
  127. package/src/devices/allocation/drivers/ios/SimulatorLauncher.js +3 -3
  128. package/src/devices/allocation/factories/index.js +0 -1
  129. package/src/devices/common/drivers/DeviceLauncher.js +2 -2
  130. package/src/devices/common/drivers/android/emulator/exec/EmulatorExec.js +1 -1
  131. package/src/devices/common/drivers/android/exec/ADB.js +0 -5
  132. package/src/devices/common/drivers/android/genycloud/services/GenyInstanceNaming.js +4 -9
  133. package/src/devices/common/drivers/ios/tools/AppleSimUtils.js +34 -9
  134. package/src/devices/lifecycle/GenyGlobalLifecycleHandler.js +1 -1
  135. package/src/devices/runtime/RuntimeDevice.js +69 -81
  136. package/src/devices/runtime/drivers/index.js +0 -1
  137. package/src/devices/runtime/drivers/ios/SimulatorDriver.js +3 -2
  138. package/src/devices/runtime/factories/ios.js +1 -8
  139. package/src/devices/runtime/utils/LaunchArgsEditor.js +4 -59
  140. package/src/devices/runtime/utils/Storage.js +4 -0
  141. package/src/environmentFactory.js +0 -8
  142. package/src/errors/DetoxConfigErrorComposer.js +76 -29
  143. package/src/errors/DetoxError.js +4 -0
  144. package/src/errors/DetoxRuntimeError.js +5 -5
  145. package/src/errors/index.js +2 -0
  146. package/src/ipc/IPCClient.js +117 -0
  147. package/src/ipc/IPCServer.js +87 -0
  148. package/src/ipc/state.js +76 -0
  149. package/src/logger/DetoxLogger.js +244 -0
  150. package/src/logger/DetoxTraceEventBuilder.js +21 -0
  151. package/src/logger/DetoxTracer.js +133 -0
  152. package/src/logger/TraceThreadDispatcher.js +52 -0
  153. package/src/{utils → logger}/customConsoleLogger.js +1 -1
  154. package/src/realms/DetoxConstants.js +13 -0
  155. package/src/realms/DetoxContext.js +170 -0
  156. package/src/realms/DetoxInternalsFacade.js +35 -0
  157. package/src/realms/DetoxPrimaryContext.js +229 -0
  158. package/src/realms/DetoxSecondaryContext.js +94 -0
  159. package/src/realms/index.js +10 -0
  160. package/src/realms/primary.js +3 -0
  161. package/src/realms/secondary.js +3 -0
  162. package/src/server/DetoxConnection.js +1 -1
  163. package/src/symbols.js +56 -0
  164. package/src/utils/ChromeTracingExporter.js +5 -6
  165. package/src/utils/Timer.js +14 -6
  166. package/{local-cli/utils/misc.js → src/utils/envUtils.js} +0 -9
  167. package/src/utils/logger.js +2 -162
  168. package/src/utils/shellUtils.js +18 -0
  169. package/src/utils/streamUtils.js +214 -0
  170. package/src/utils/trace.js +9 -44
  171. package/Detox-android/com/wix/detox/19.9.0/detox-19.9.0-javadoc.jar.md5 +0 -1
  172. package/Detox-android/com/wix/detox/19.9.0/detox-19.9.0-javadoc.jar.sha1 +0 -1
  173. package/Detox-android/com/wix/detox/19.9.0/detox-19.9.0-javadoc.jar.sha256 +0 -1
  174. package/Detox-android/com/wix/detox/19.9.0/detox-19.9.0-javadoc.jar.sha512 +0 -1
  175. package/Detox-android/com/wix/detox/19.9.0/detox-19.9.0-sources.jar.md5 +0 -1
  176. package/Detox-android/com/wix/detox/19.9.0/detox-19.9.0-sources.jar.sha1 +0 -1
  177. package/Detox-android/com/wix/detox/19.9.0/detox-19.9.0-sources.jar.sha256 +0 -1
  178. package/Detox-android/com/wix/detox/19.9.0/detox-19.9.0-sources.jar.sha512 +0 -1
  179. package/Detox-android/com/wix/detox/19.9.0/detox-19.9.0.aar +0 -0
  180. package/Detox-android/com/wix/detox/19.9.0/detox-19.9.0.aar.md5 +0 -1
  181. package/Detox-android/com/wix/detox/19.9.0/detox-19.9.0.aar.sha1 +0 -1
  182. package/Detox-android/com/wix/detox/19.9.0/detox-19.9.0.aar.sha256 +0 -1
  183. package/Detox-android/com/wix/detox/19.9.0/detox-19.9.0.aar.sha512 +0 -1
  184. package/Detox-android/com/wix/detox/19.9.0/detox-19.9.0.pom.md5 +0 -1
  185. package/Detox-android/com/wix/detox/19.9.0/detox-19.9.0.pom.sha1 +0 -1
  186. package/Detox-android/com/wix/detox/19.9.0/detox-19.9.0.pom.sha256 +0 -1
  187. package/Detox-android/com/wix/detox/19.9.0/detox-19.9.0.pom.sha512 +0 -1
  188. package/android/detox/src/full/java/com/wix/detox/espresso/action/AdjustSliderToPositionAction.kt +0 -22
  189. package/android/detox/src/full/java/com/wix/detox/espresso/common/SliderHelper.kt +0 -75
  190. package/android/detox/src/main/java/com/wix/detox/espresso/action/common/ReflectUtils.kt +0 -10
  191. package/android/detox/src/testFull/java/com/wix/detox/espresso/common/SliderHelperTest.kt +0 -39
  192. package/local-cli/templates/mocha.js +0 -32
  193. package/local-cli/utils/splitArgv.js +0 -107
  194. package/runners/integration.js +0 -16
  195. package/runners/jest/DetoxAdapterCircus.js +0 -60
  196. package/runners/jest/DetoxAdapterImpl.js +0 -81
  197. package/runners/jest/DetoxAdapterJasmine.js +0 -67
  198. package/runners/jest/DetoxStreamlineJestReporter.js +0 -98
  199. package/runners/jest/FailingTestsReporter.js +0 -16
  200. package/runners/jest/SpecReporterCircus.js +0 -51
  201. package/runners/jest/SpecReporterJasmine.js +0 -39
  202. package/runners/jest/WorkerAssignReporterCircus.js +0 -17
  203. package/runners/jest/WorkerAssignReporterImpl.js +0 -21
  204. package/runners/jest/WorkerAssignReporterJasmine.js +0 -15
  205. package/runners/jest/runnerInfo.js +0 -9
  206. package/runners/jest-circus/environment.js +0 -206
  207. package/runners/jest-circus/utils/assertJestCircus26.js +0 -39
  208. package/runners/jest-circus/utils/wrapErrorWithNoopLifecycle.js +0 -14
  209. package/src/DetoxConstants.js +0 -13
  210. package/src/DetoxExportWrapper.js +0 -140
  211. package/src/artifacts/timeline/TimelineArtifactPlugin.js +0 -95
  212. package/src/devices/allocation/drivers/NoneAllocDriver.js +0 -10
  213. package/src/devices/allocation/factories/none.js +0 -11
  214. package/src/index.js +0 -6
  215. package/src/utils/MissingDetox.js +0 -78
  216. package/src/utils/fakeTimestampsProvider.js +0 -9
  217. package/src/utils/getWorkerId.js +0 -5
  218. package/src/utils/lastFailedTests.js +0 -38
  219. package/src/utils/sh.js +0 -18
@@ -0,0 +1,52 @@
1
+ const isUndefined = (x) => x === undefined;
2
+
3
+ class TraceThreadDispatcher {
4
+ /**
5
+ * @param {object} options
6
+ * @param {Detox.Logger} options.logger
7
+ * @param {string} options.name
8
+ * @param {number} options.min
9
+ * @param {number} [options.max]
10
+ */
11
+ constructor({ logger, name, min, max = Infinity }) {
12
+ this.logger = logger;
13
+ this.name = name;
14
+ this.min = min;
15
+ this.max = max;
16
+ this.stacks = [];
17
+ this.threads = [];
18
+ }
19
+
20
+ begin(id = 0) {
21
+ const tid = this._findTID(id);
22
+ this.threads[tid] = id;
23
+ this.stacks[tid] = (this.stacks[tid] || 0) + 1;
24
+ return this._transpose(tid);
25
+ }
26
+
27
+ end(id = 0) {
28
+ const tid = this._findTID(id);
29
+ if (this.stacks[tid] && --this.stacks[tid] === 0) {
30
+ delete this.threads[tid];
31
+ }
32
+ return this._transpose(tid);
33
+ }
34
+
35
+ _findTID(id) {
36
+ let tid = this.threads.indexOf(id);
37
+ if (tid === -1) {
38
+ tid = this.threads.findIndex(isUndefined);
39
+ }
40
+ return tid === -1 ? this.threads.length : tid;
41
+ }
42
+
43
+ _transpose(id) {
44
+ const result = this.min + id;
45
+ if (result > this.max) {
46
+ this.logger.warn({ event: 'THREAD_DISPATCHER' }, `${this.name} trace thread dispatcher has run out of available thread IDs: ${this.min}..${this.max}`);
47
+ }
48
+ return Math.min(result, this.max);
49
+ }
50
+ }
51
+
52
+ module.exports = TraceThreadDispatcher;
@@ -1,6 +1,6 @@
1
1
  const util = require('util');
2
2
 
3
- const callsites = require('./callsites');
3
+ const callsites = require('../utils/callsites');
4
4
 
5
5
  const USER_STACK_FRAME_INDEX = 2;
6
6
 
@@ -0,0 +1,13 @@
1
+ module.exports = Object.freeze({
2
+ userNotificationTriggers: {
3
+ push: 'push',
4
+ calendar: 'calendar',
5
+ timeInterval: 'timeInterval',
6
+ location: 'location'
7
+ },
8
+ userActivityTypes: {
9
+ searchableItem: 'com.apple.corespotlightitem',
10
+ browsingWeb: 'NSUserActivityTypeBrowsingWeb',
11
+ },
12
+ searchableItemActivityIdentifier: 'kCSSearchableItemActivityIdentifier'
13
+ });
@@ -0,0 +1,170 @@
1
+ const funpermaproxy = require('funpermaproxy');
2
+
3
+ const { DetoxRuntimeError } = require('../errors');
4
+ const DetoxLogger = require('../logger/DetoxLogger');
5
+ const DetoxTracer = require('../logger/DetoxTracer');
6
+ const symbols = require('../symbols');
7
+
8
+ const DetoxConstants = require('./DetoxConstants');
9
+
10
+ const $cleanup = Symbol('cleanup');
11
+ const $logger = Symbol('logger');
12
+ const $restoreSessionState = Symbol('restoreSessionState');
13
+ const $sessionState = Symbol('restoreSessionState');
14
+ const $tracer = Symbol('tracer');
15
+
16
+ const _worker = Symbol('worker');
17
+
18
+ class DetoxContext {
19
+ constructor() {
20
+ this[symbols.globalSetup] = this[symbols.globalSetup].bind(this);
21
+ this[symbols.globalTeardown] = this[symbols.globalTeardown].bind(this);
22
+ this[symbols.reportFailedTests] = this[symbols.reportFailedTests].bind(this);
23
+ this[symbols.resolveConfig] = this[symbols.resolveConfig].bind(this);
24
+ this[symbols.setup] = this[symbols.setup].bind(this);
25
+ this[symbols.teardown] = this[symbols.teardown].bind(this);
26
+
27
+ this[$sessionState] = this[$restoreSessionState]();
28
+
29
+ const loggerConfig = this[$sessionState].detoxConfig
30
+ ? this[$sessionState].detoxConfig.loggerConfig
31
+ : undefined;
32
+
33
+ /**
34
+ * @protected
35
+ * @type {DetoxLogger & Detox.Logger}
36
+ */
37
+ this[$logger] = new DetoxLogger(loggerConfig);
38
+ /** @protected */
39
+ this[$tracer] = DetoxTracer.default({
40
+ logger: this[$logger],
41
+ });
42
+ /** @deprecated */
43
+ this.traceCall = this[$tracer].bind(this[$tracer]);
44
+ /** @type {import('../DetoxWorker') | null} */
45
+ this[_worker] = null;
46
+ }
47
+
48
+ //#region Public members
49
+ device = funpermaproxy(() => this[symbols.worker].device);
50
+
51
+ element = funpermaproxy.callable(() => this[symbols.worker].element);
52
+
53
+ waitFor = funpermaproxy.callable(() => this[symbols.worker].waitFor);
54
+
55
+ expect = funpermaproxy.callable(() => this[symbols.worker].expect);
56
+
57
+ by = funpermaproxy(() => this[symbols.worker].by);
58
+
59
+ web = funpermaproxy.callable(() => this[symbols.worker].web);
60
+
61
+ get DetoxConstants() {
62
+ return DetoxConstants;
63
+ }
64
+
65
+ /**
66
+ * @returns {Detox.Logger}
67
+ */
68
+ get log() {
69
+ return this[$logger];
70
+ }
71
+
72
+ /**
73
+ * @returns {Detox.Tracer}
74
+ */
75
+ get trace() {
76
+ return this[$tracer];
77
+ }
78
+ //#endregion
79
+
80
+ //#region Internal members
81
+ [symbols.onRunStart] = (...args) => this[symbols.worker].onRunStart(...args);
82
+ [symbols.onRunDescribeStart] = (...args) => this[symbols.worker].onRunDescribeStart(...args);
83
+ [symbols.onTestStart] = (...args) => this[symbols.worker].onTestStart(...args);
84
+ [symbols.onHookStart] = (...args) => this[symbols.worker].onHookStart(...args);
85
+ [symbols.onHookFailure] = (...args) => this[symbols.worker].onHookFailure(...args);
86
+ [symbols.onHookSuccess] = (...args) => this[symbols.worker].onHookSuccess(...args);
87
+ [symbols.onTestFnStart] = (...args) => this[symbols.worker].onTestFnStart(...args);
88
+ [symbols.onTestFnFailure] = (...args) => this[symbols.worker].onTestFnFailure(...args);
89
+ [symbols.onTestFnSuccess] = (...args) => this[symbols.worker].onTestFnSuccess(...args);
90
+ [symbols.onTestDone] = (...args) => this[symbols.worker].onTestDone(...args);
91
+ [symbols.onRunDescribeFinish] = (...args) => this[symbols.worker].onRunDescribeFinish(...args);
92
+ [symbols.onRunFinish] = (...args) => this[symbols.worker].onRunFinish(...args);
93
+ [symbols.config] = funpermaproxy(() => this[symbols.session].detoxConfig);
94
+ [symbols.session] = funpermaproxy(() => this[$sessionState]);
95
+ /** @abstract */
96
+ [symbols.reportFailedTests](_testFilePaths) {}
97
+ /**
98
+ * @abstract
99
+ * @param {Partial<DetoxInternals.DetoxGlobalSetupOptions>} _opts
100
+ * @returns {Promise<DetoxInternals.RuntimeConfig>}
101
+ */
102
+ async [symbols.resolveConfig](_opts) { return null; }
103
+
104
+ get [symbols.worker]() {
105
+ if (!this[_worker]) {
106
+ throw new DetoxRuntimeError({
107
+ message: `Detox worker instance has not been initialized in this context (${this.constructor.name}).`,
108
+ hint: DetoxRuntimeError.reportIssueIfJest + '\n' + 'Otherwise, make sure you call detox.setup() beforehand.',
109
+ });
110
+ }
111
+
112
+ return this[_worker];
113
+ }
114
+
115
+ /**
116
+ * @abstract
117
+ * @param {Partial<DetoxInternals.DetoxGlobalSetupOptions>} [_opts]
118
+ * @returns {Promise<void>}
119
+ */
120
+ async [symbols.globalSetup](_opts = {}) {}
121
+
122
+ /**
123
+ * @param {Partial<DetoxInternals.DetoxConfigurationSetupOptions>} [opts]
124
+ */
125
+ async [symbols.setup](opts) {
126
+ const theGlobal = opts.global || global;
127
+ theGlobal['__detox__'] = this;
128
+ this[$logger].overrideConsole(theGlobal);
129
+
130
+ const DetoxWorker = require('../DetoxWorker');
131
+ DetoxWorker.global = theGlobal;
132
+ this[_worker] = new DetoxWorker(this);
133
+ await this[_worker].init();
134
+ }
135
+
136
+ async [symbols.teardown]() {
137
+ try {
138
+ if (this[_worker]) {
139
+ await this[_worker].cleanup();
140
+ }
141
+ } finally {
142
+ this[_worker] = null;
143
+ }
144
+ }
145
+
146
+ /**
147
+ * @abstract
148
+ */
149
+ async [symbols.globalTeardown]() {}
150
+ //#endregion
151
+
152
+ //#region Protected members
153
+ /**
154
+ * @abstract
155
+ * @protected
156
+ */
157
+ [$restoreSessionState]() {
158
+ return null;
159
+ }
160
+ //#endregion
161
+ }
162
+
163
+ module.exports = DetoxContext;
164
+ module.exports.protected = {
165
+ $cleanup,
166
+ $logger,
167
+ $restoreSessionState,
168
+ $sessionState,
169
+ $tracer,
170
+ };
@@ -0,0 +1,35 @@
1
+ const funpermaproxy = require('funpermaproxy');
2
+
3
+ const symbols = require('../symbols');
4
+
5
+ class DetoxInternalsFacade {
6
+ /**
7
+ * @param context
8
+ */
9
+ constructor(context) {
10
+ this.config = context[symbols.config];
11
+ this.globalSetup = context[symbols.globalSetup];
12
+ this.globalTeardown = context[symbols.globalTeardown];
13
+ this.log = context.log;
14
+ this.setup = context[symbols.setup];
15
+ this.teardown = context[symbols.teardown];
16
+ this.onHookFailure = context[symbols.onHookFailure];
17
+ this.onHookStart = context[symbols.onHookStart];
18
+ this.onHookSuccess = context[symbols.onHookSuccess];
19
+ this.onRunDescribeFinish = context[symbols.onRunDescribeFinish];
20
+ this.onRunDescribeStart = context[symbols.onRunDescribeStart];
21
+ this.onRunFinish = context[symbols.onRunFinish];
22
+ this.onRunStart = context[symbols.onRunStart];
23
+ this.onTestDone = context[symbols.onTestDone];
24
+ this.onTestFnFailure = context[symbols.onTestFnFailure];
25
+ this.onTestFnStart = context[symbols.onTestFnStart];
26
+ this.onTestFnSuccess = context[symbols.onTestFnSuccess];
27
+ this.onTestStart = context[symbols.onTestStart];
28
+ this.reportFailedTests = context[symbols.reportFailedTests];
29
+ this.resolveConfig = context[symbols.resolveConfig];
30
+ this.session = context[symbols.session];
31
+ this.worker = funpermaproxy(() => context[symbols.worker]);
32
+ }
33
+ }
34
+
35
+ module.exports = DetoxInternalsFacade;
@@ -0,0 +1,229 @@
1
+ const path = require('path');
2
+ const { URL } = require('url');
3
+
4
+ const fs = require('fs-extra');
5
+ const pipe = require('multipipe');
6
+
7
+ const temporary = require('../artifacts/utils/temporaryPath');
8
+ const { DetoxRuntimeError } = require('../errors');
9
+ const { PrimarySessionState } = require('../ipc/state');
10
+ const symbols = require('../symbols');
11
+
12
+ const DetoxContext = require('./DetoxContext');
13
+
14
+ const { $logger, $restoreSessionState, $sessionState } = DetoxContext.protected;
15
+
16
+ const _finalizeLogs = Symbol('finalizeLogs');
17
+ const _globalLifecycleHandler = Symbol('globalLifecycleHandler');
18
+ const _ipcServer = Symbol('ipcServer');
19
+ const _resetLockFile = Symbol('resetLockFile');
20
+ const _wss = Symbol('wss');
21
+ const _dirty = Symbol('dirty');
22
+
23
+ class DetoxPrimaryContext extends DetoxContext {
24
+ constructor() {
25
+ super();
26
+
27
+ this[_dirty] = false;
28
+ this[_wss] = null;
29
+ this[_globalLifecycleHandler] = null;
30
+ /**
31
+ * @type {import('../ipc/IPCServer') | null}
32
+ */
33
+ this[_ipcServer] = null;
34
+ }
35
+
36
+ //#region Internal members
37
+ async [symbols.reportFailedTests](testFilePaths) {
38
+ if (this[_ipcServer]) {
39
+ this[_ipcServer].onFailedTests({ testFilePaths });
40
+ }
41
+ }
42
+
43
+ async [symbols.resolveConfig](opts = {}) {
44
+ const session = this[symbols.session];
45
+ if (!session.detoxConfig) {
46
+ const configuration = require('../configuration');
47
+ session.detoxConfig = await configuration.composeDetoxConfig(opts);
48
+ }
49
+
50
+ return session.detoxConfig;
51
+ }
52
+
53
+ /**
54
+ * @override
55
+ * @param {Partial<DetoxInternals.DetoxGlobalSetupOptions>} [opts]
56
+ */
57
+ async [symbols.globalSetup](opts) {
58
+ if (this[_dirty]) {
59
+ throw new DetoxRuntimeError({
60
+ message: 'Cannot initialize primary Detox context more than once.',
61
+ hint: DetoxRuntimeError.reportIssueIfJest,
62
+ });
63
+ }
64
+
65
+ this[_dirty] = true;
66
+ const detoxConfig = await this[symbols.resolveConfig](opts);
67
+
68
+ const { behaviorConfig, deviceConfig, loggerConfig, sessionConfig } = detoxConfig;
69
+ await this[$logger].setConfig(loggerConfig);
70
+
71
+ this.trace.begin({
72
+ cat: 'lifecycle',
73
+ args: this[$sessionState],
74
+ name: process.argv.slice(1).join(' '),
75
+ });
76
+
77
+ const IPCServer = require('../ipc/IPCServer');
78
+ this[_ipcServer] = new IPCServer({
79
+ sessionState: this[$sessionState],
80
+ logger: this[$logger],
81
+ });
82
+
83
+ await this[_ipcServer].init();
84
+
85
+ const environmentFactory = require('../environmentFactory');
86
+ this[_globalLifecycleHandler] = await environmentFactory.createGlobalLifecycleHandler(deviceConfig);
87
+
88
+ if (this[_globalLifecycleHandler]) {
89
+ await this[_globalLifecycleHandler].globalInit();
90
+ }
91
+
92
+ if (!behaviorConfig.init.keepLockFile) {
93
+ await this[_resetLockFile]();
94
+ }
95
+
96
+ const DetoxServer = require('../server/DetoxServer');
97
+ if (sessionConfig.autoStart) {
98
+ this[_wss] = new DetoxServer({
99
+ port: sessionConfig.server
100
+ ? new URL(sessionConfig.server).port
101
+ : 0,
102
+ standalone: false,
103
+ });
104
+
105
+ await this[_wss].open();
106
+ }
107
+
108
+ if (!sessionConfig.server && this[_wss]) {
109
+ sessionConfig.server = `ws://localhost:${this[_wss].port}`;
110
+ }
111
+
112
+ await fs.writeFile(this[$sessionState].detoxConfigSnapshotPath, this[$sessionState].stringify());
113
+ process.env.DETOX_CONFIG_SNAPSHOT_PATH = this[$sessionState].detoxConfigSnapshotPath;
114
+
115
+ // TODO: think about signal-exit and cleaning up the logs
116
+ }
117
+
118
+ /**
119
+ * @override
120
+ * @param {Partial<DetoxInternals.DetoxConfigurationSetupOptions>} [opts]
121
+ */
122
+ async [symbols.setup](opts) {
123
+ const workerId = opts.workerId || 1;
124
+ this[$sessionState].workerId = workerId;
125
+ this[_ipcServer].onRegisterWorker({ workerId });
126
+ await super[symbols.setup](opts);
127
+ }
128
+
129
+ /** @override */
130
+ async [symbols.globalTeardown]() {
131
+ if (this[_globalLifecycleHandler]) {
132
+ await this[_globalLifecycleHandler].globalCleanup();
133
+ this[_globalLifecycleHandler] = null;
134
+ }
135
+
136
+ if (this[_wss]) {
137
+ await this[_wss].close();
138
+ this[_wss] = null;
139
+ }
140
+
141
+ if (this[_ipcServer]) {
142
+ await this[_ipcServer].dispose();
143
+ this[_ipcServer] = null;
144
+ }
145
+
146
+ await fs.remove(this[$sessionState].detoxConfigSnapshotPath);
147
+ delete process.env.DETOX_CONFIG_SNAPSHOT_PATH;
148
+
149
+ try {
150
+ this.trace.end({ cat: 'lifecycle' });
151
+ await this[_finalizeLogs]();
152
+ } catch (err) {
153
+ this[$logger].error({ err }, 'Encountered an error while merging the process logs:');
154
+ }
155
+ }
156
+ //#endregion
157
+
158
+ //#region Protected members
159
+ /**
160
+ * @protected
161
+ * @override
162
+ * @return {PrimarySessionState}
163
+ */
164
+ [$restoreSessionState]() {
165
+ return new PrimarySessionState({
166
+ detoxConfigSnapshotPath: temporary.for.json(),
167
+ detoxIPCServer: `primary-${process.pid}`,
168
+ });
169
+ }
170
+ //#endregion
171
+
172
+ //#region Private members
173
+ async[_finalizeLogs]() {
174
+ const logs = [this[$logger].file, ...this[$sessionState].logFiles].filter(f => f && fs.existsSync(f));
175
+ if (logs.length === 0) {
176
+ return;
177
+ }
178
+
179
+ const streamUtils = require('../utils/streamUtils');
180
+ const { rootDir, plugins } = this[symbols.config].artifactsConfig || {};
181
+ const logConfig = plugins && plugins.log || 'none';
182
+ const enabled = rootDir && (typeof logConfig === 'string' ? logConfig !== 'none' : logConfig.enabled);
183
+
184
+ if (enabled) {
185
+ await fs.mkdirp(rootDir);
186
+ const [out1Stream, out2Stream, out3Stream] = ['detox.log.jsonl', 'detox.log', 'detox.trace.json']
187
+ .map((filename) => fs.createWriteStream(path.join(rootDir, filename)));
188
+
189
+ const mergedStream = streamUtils
190
+ .mergeSortedJSONL(
191
+ logs.map(filePath => fs.createReadStream(filePath).pipe(streamUtils.readJSONL()))
192
+ );
193
+
194
+ await Promise.all([
195
+ pipe(mergedStream, streamUtils.writeJSONL(), out1Stream),
196
+ pipe(mergedStream, streamUtils.debugStream(this[$logger].config.options), out2Stream),
197
+ pipe(mergedStream, streamUtils.chromeTraceStream(), streamUtils.writeJSON(), out3Stream),
198
+ ]);
199
+ }
200
+
201
+ await Promise.all(logs.map(filepath => fs.remove(filepath)));
202
+ }
203
+
204
+ async[_resetLockFile]() {
205
+ const DeviceRegistry = require('../devices/DeviceRegistry');
206
+
207
+ const deviceType = this[symbols.config].deviceConfig.type;
208
+
209
+ switch (deviceType) {
210
+ case 'ios.none':
211
+ case 'ios.simulator':
212
+ await DeviceRegistry.forIOS().reset();
213
+ break;
214
+ case 'android.attached':
215
+ case 'android.emulator':
216
+ case 'android.genycloud':
217
+ await DeviceRegistry.forAndroid().reset();
218
+ break;
219
+ }
220
+
221
+ if (deviceType === 'android.genycloud') {
222
+ const GenyDeviceRegistryFactory = require('../devices/allocation/drivers/android/genycloud/GenyDeviceRegistryFactory');
223
+ await GenyDeviceRegistryFactory.forGlobalShutdown().reset();
224
+ }
225
+ }
226
+ //#endregion
227
+ }
228
+
229
+ module.exports = DetoxPrimaryContext;
@@ -0,0 +1,94 @@
1
+ const fs = require('fs');
2
+
3
+ const { DetoxInternalError } = require('../errors');
4
+ const { SecondarySessionState } = require('../ipc/state');
5
+ const symbols = require('../symbols');
6
+
7
+ const DetoxContext = require('./DetoxContext');
8
+
9
+ const { $logger, $restoreSessionState, $sessionState } = DetoxContext.protected;
10
+ const _ipcClient = Symbol('ipcClient');
11
+
12
+ class DetoxSecondaryContext extends DetoxContext {
13
+ constructor() {
14
+ super();
15
+
16
+ /**
17
+ * @protected
18
+ * @type {*}
19
+ */
20
+ this[_ipcClient] = null;
21
+ }
22
+
23
+ //#region Internal members
24
+ async [symbols.reportFailedTests](testFilePaths) {
25
+ if (this[_ipcClient]) {
26
+ await this[_ipcClient].reportFailedTests(testFilePaths);
27
+ } else {
28
+ throw new DetoxInternalError('Detected an attempt to report failed tests using a non-initialized context.');
29
+ }
30
+ }
31
+
32
+ async [symbols.resolveConfig]() {
33
+ return this[symbols.config];
34
+ }
35
+
36
+ /** @override */
37
+ async [symbols.globalSetup](_opts = {}) {
38
+ // This is a no-op function.
39
+ // It is forbidden to add any logic to `globalSetup` of the secondary context.
40
+ // Violating this principle will almost definitely break some flows, where it is
41
+ // not guaranteed that `globalSetup` will ever get called. See UML diagrams.
42
+ }
43
+
44
+ /** @override */
45
+ async [symbols.globalTeardown]() {
46
+ // This is a no-op function.
47
+ // It is forbidden to add any logic to `globalTeardown` of the secondary context.
48
+ // Violating this principle will almost definitely break some flows, where it is
49
+ // not guaranteed that `globalTeardown` will ever get called. See UML diagrams.
50
+ }
51
+
52
+ /** @override */
53
+ async [symbols.setup](opts) {
54
+ const IPCClient = require('../ipc/IPCClient');
55
+
56
+ this[_ipcClient] = new IPCClient({
57
+ id: `secondary-${process.pid}`,
58
+ state: this[$sessionState],
59
+ logger: this[$logger],
60
+ });
61
+
62
+ const workerId = opts.workerId || 1;
63
+ await this[_ipcClient].init();
64
+ await this[_ipcClient].registerWorker(workerId);
65
+ await super[symbols.setup](opts);
66
+ }
67
+
68
+ /** @override */
69
+ async [symbols.teardown]() {
70
+ try {
71
+ await super[symbols.teardown]();
72
+ } finally {
73
+ if (this[_ipcClient]) {
74
+ await this[_ipcClient].dispose();
75
+ this[_ipcClient] = null;
76
+ }
77
+ }
78
+ }
79
+ //#endregion
80
+
81
+ //#region Protected members
82
+
83
+ /**
84
+ * @protected
85
+ * @override
86
+ * @return {SecondarySessionState}
87
+ */
88
+ [$restoreSessionState]() {
89
+ return SecondarySessionState.parse(fs.readFileSync(process.env.DETOX_CONFIG_SNAPSHOT_PATH));
90
+ }
91
+ //#endregion
92
+ }
93
+
94
+ module.exports = DetoxSecondaryContext;
@@ -0,0 +1,10 @@
1
+ function current() {
2
+ if (process.env.DETOX_CONFIG_SNAPSHOT_PATH) {
3
+ return require('./secondary');
4
+ } else {
5
+ return require('./primary');
6
+ }
7
+ }
8
+
9
+ /** @type {DetoxInternals.Facade} */
10
+ module.exports = global['__detox__'] || current();
@@ -0,0 +1,3 @@
1
+ const DetoxPrimaryContext = require('./DetoxPrimaryContext');
2
+
3
+ module.exports = new DetoxPrimaryContext();
@@ -0,0 +1,3 @@
1
+ const DetoxSecondaryContext = require('./DetoxSecondaryContext');
2
+
3
+ module.exports = new DetoxSecondaryContext();
@@ -3,7 +3,7 @@ const _ = require('lodash');
3
3
  const { WebSocket } = require('ws'); // eslint-disable-line @typescript-eslint/no-unused-vars, no-unused-vars
4
4
 
5
5
  const DetoxRuntimeError = require('../errors/DetoxRuntimeError');
6
- const logger = require('../utils/logger').child({ __filename });
6
+ const logger = require('../utils/logger').child({ __filename, cat: 'ws-server,ws' });
7
7
 
8
8
  const AnonymousConnectionHandler = require('./handlers/AnonymousConnectionHandler');
9
9
 
package/src/symbols.js ADDED
@@ -0,0 +1,56 @@
1
+ /**
2
+ * @type {{
3
+ * readonly config: unique symbol;
4
+ * readonly globalSetup: unique symbol;
5
+ * readonly globalTeardown: unique symbol;
6
+ * readonly onHookFailure: unique symbol;
7
+ * readonly onHookStart: unique symbol;
8
+ * readonly onHookSuccess: unique symbol;
9
+ * readonly onRunDescribeFinish: unique symbol;
10
+ * readonly onRunDescribeStart: unique symbol;
11
+ * readonly onRunFinish: unique symbol;
12
+ * readonly onRunStart: unique symbol;
13
+ * readonly onTestDone: unique symbol;
14
+ * readonly onTestFnFailure: unique symbol;
15
+ * readonly onTestFnStart: unique symbol;
16
+ * readonly onTestFnSuccess: unique symbol;
17
+ * readonly onTestStart: unique symbol;
18
+ * readonly reportFailedTests: unique symbol;
19
+ * readonly resolveConfig: unique symbol;
20
+ * readonly session: unique symbol;
21
+ * readonly setup: unique symbol;
22
+ * readonly teardown: unique symbol;
23
+ * readonly worker: unique symbol;
24
+ * }}
25
+ */
26
+ module.exports = {
27
+ //#region Lifecycle
28
+ onRunStart: Symbol('run_start'),
29
+ onRunDescribeStart: Symbol('run_describe_start'),
30
+ onTestStart: Symbol('test_start'),
31
+ onHookStart: Symbol('hook_start'),
32
+ onHookFailure: Symbol('hook_failure'),
33
+ onHookSuccess: Symbol('hook_success'),
34
+ onTestFnStart: Symbol('test_fn_start'),
35
+ onTestFnFailure: Symbol('test_fn_failure'),
36
+ onTestFnSuccess: Symbol('test_fn_success'),
37
+ onTestDone: Symbol('test_done'),
38
+ onRunDescribeFinish: Symbol('run_describe_finish'),
39
+ onRunFinish: Symbol('run_finish'),
40
+ //#endregion
41
+
42
+ //#region IPC
43
+ reportFailedTests: Symbol('reportFailedTests'),
44
+ //#endregion
45
+
46
+ //#region Main
47
+ config: Symbol('config'),
48
+ globalSetup: Symbol('globalSetup'),
49
+ globalTeardown: Symbol('globalTeardown'),
50
+ resolveConfig: Symbol('resolveConfig'),
51
+ session: Symbol('session'),
52
+ setup: Symbol('setup'),
53
+ teardown: Symbol('teardown'),
54
+ worker: Symbol('worker'),
55
+ //#endregion
56
+ };