detox 19.7.1 → 20.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 (205) hide show
  1. package/Detox-android/com/wix/detox/{19.7.1/detox-19.7.1-javadoc.jar → 20.0.0-breaking.new-global-lifecycle.0/detox-20.0.0-breaking.new-global-lifecycle.0-javadoc.jar} +0 -0
  2. 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 +1 -0
  3. 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 +1 -0
  4. 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 +1 -0
  5. 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 +1 -0
  6. package/Detox-android/com/wix/detox/{19.7.1/detox-19.7.1-sources.jar → 20.0.0-breaking.new-global-lifecycle.0/detox-20.0.0-breaking.new-global-lifecycle.0-sources.jar} +0 -0
  7. 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 +1 -0
  8. 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 +1 -0
  9. 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 +1 -0
  10. 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 +1 -0
  11. 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
  12. 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 +1 -0
  13. 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 +1 -0
  14. 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 +1 -0
  15. 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 +1 -0
  16. package/Detox-android/com/wix/detox/{19.7.1/detox-19.7.1.pom → 20.0.0-breaking.new-global-lifecycle.0/detox-20.0.0-breaking.new-global-lifecycle.0.pom} +1 -1
  17. 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 +1 -0
  18. 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 +1 -0
  19. 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 +1 -0
  20. 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 +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/detox/src/full/java/com/wix/detox/Detox.java +2 -59
  29. package/android/detox/src/full/java/com/wix/detox/NotificationDataParser.kt +3 -3
  30. package/android/detox/src/full/java/com/wix/detox/espresso/DetoxAction.java +3 -1
  31. package/android/detox/src/full/java/com/wix/detox/espresso/matcher/ViewMatchers.kt +23 -16
  32. package/android/detox/src/main/java/com/wix/detox/common/DetoxErrors.java +1 -0
  33. package/android/detox/src/main/java/com/wix/detox/espresso/action/AdjustSliderToPositionAction.kt +36 -0
  34. package/android/detox/src/{full → main}/java/com/wix/detox/espresso/action/GetAttributesAction.kt +1 -13
  35. package/android/detox/src/testFull/java/com/wix/detox/espresso/action/AdjustSliderToPositionActionTest.kt +59 -0
  36. package/android/detox/src/testFull/java/com/wix/detox/espresso/action/GetAttributesActionTest.kt +3 -15
  37. package/index.d.ts +208 -186
  38. package/index.js +1 -0
  39. package/internals.d.ts +129 -0
  40. package/internals.js +4 -0
  41. package/local-cli/build-framework-cache.js +2 -2
  42. package/local-cli/build.js +7 -8
  43. package/local-cli/build.test.js +46 -40
  44. package/local-cli/clean-framework-cache.js +3 -3
  45. package/local-cli/cli.js +0 -1
  46. package/local-cli/init.js +20 -55
  47. package/local-cli/templates/jest.js +9 -34
  48. package/local-cli/test.js +18 -282
  49. package/local-cli/test.test.js +332 -673
  50. package/local-cli/testCommand/TestRunnerCommand.js +156 -0
  51. package/local-cli/{utils/testCommandArgs.js → testCommand/builder.js} +10 -35
  52. package/local-cli/testCommand/middlewares.js +75 -0
  53. package/local-cli/{utils → testCommand}/warnings.js +0 -10
  54. package/local-cli/utils/jestInternals.js +13 -2
  55. package/local-cli/utils/yargsUtils.js +67 -0
  56. package/package.json +27 -21
  57. package/runners/deprecation.js +47 -0
  58. package/runners/jest/JestCircusEnvironment.js +3 -38
  59. package/runners/jest/adapter.d.ts +4 -10
  60. package/runners/jest/adapter.js +3 -6
  61. package/runners/jest/assignReporter.d.ts +4 -1
  62. package/runners/jest/assignReporter.js +3 -6
  63. package/runners/jest/deprecation.js +25 -0
  64. package/runners/jest/globalSetup.js +1 -0
  65. package/runners/jest/globalTeardown.js +1 -0
  66. package/runners/jest/index.js +21 -0
  67. package/runners/jest/reporter.js +1 -0
  68. package/runners/jest/reporters/DetoxReporter.js +5 -0
  69. package/runners/jest/specReporter.d.ts +4 -9
  70. package/runners/jest/specReporter.js +3 -10
  71. package/runners/jest/streamlineReporter.js +3 -22
  72. package/runners/jest/testEnvironment/index.js +155 -0
  73. package/runners/{jest-circus → jest/testEnvironment}/listeners/DetoxCoreListener.js +35 -17
  74. package/runners/{jest-circus → jest/testEnvironment}/listeners/DetoxInitErrorListener.js +1 -1
  75. package/runners/jest/testEnvironment/listeners/DetoxPlatformFilterListener.js +27 -0
  76. package/runners/jest/{SpecReporterImpl.js → testEnvironment/listeners/SpecReporter.js} +61 -7
  77. package/runners/jest/testEnvironment/listeners/WorkerAssignReporter.js +34 -0
  78. package/runners/jest/testEnvironment/listeners/index.js +13 -0
  79. package/runners/{jest-circus → jest/testEnvironment}/utils/assertExistingContext.js +2 -2
  80. package/runners/jest/testEnvironment/utils/assertJestCircus27.js +56 -0
  81. package/runners/jest/testEnvironment/utils/assertJestCircus27.test.js +23 -0
  82. package/runners/jest/{utils → testEnvironment/utils}/getFullTestName.js +0 -0
  83. package/runners/jest/{utils → testEnvironment/utils}/hasTimedOut.js +0 -0
  84. package/runners/jest/{utils → testEnvironment/utils}/index.js +0 -0
  85. package/runners/jest/{utils → testEnvironment/utils}/stdout.js +0 -0
  86. package/runners/jest-circus/environment/index.js +6 -0
  87. package/runners/jest-circus/index.js +1 -10
  88. package/runners/jest-circus/reporter.js +1 -0
  89. package/runners/migration.js +37 -0
  90. package/runners/mocha/DetoxMochaAdapter.js +3 -35
  91. package/runners/mocha/adapter.d.ts +4 -7
  92. package/runners/mocha/adapter.js +3 -5
  93. package/src/{Detox.js → DetoxWorker.js} +130 -168
  94. package/src/artifacts/ArtifactsManager.js +51 -2
  95. package/src/artifacts/log/android/ADBLogcatRecording.js +28 -11
  96. package/src/artifacts/providers/index.js +0 -4
  97. package/src/artifacts/utils/buildDefaultArtifactsRootDirpath.js +2 -4
  98. package/src/artifacts/utils/temporaryPath.js +2 -0
  99. package/src/client/AsyncWebSocket.js +1 -1
  100. package/src/client/actions/actions.js +2 -2
  101. package/src/configuration/collectCliConfig.js +2 -4
  102. package/src/configuration/composeAppsConfig.js +9 -67
  103. package/src/configuration/composeArtifactsConfig.js +6 -32
  104. package/src/configuration/composeBehaviorConfig.js +3 -13
  105. package/src/configuration/composeDeviceConfig.js +37 -62
  106. package/src/configuration/composeLoggerConfig.js +50 -0
  107. package/src/configuration/composeRunnerConfig.js +74 -14
  108. package/src/configuration/composeSessionConfig.js +1 -3
  109. package/src/configuration/index.js +24 -23
  110. package/src/configuration/utils/deviceAppTypes.js +0 -1
  111. package/src/devices/allocation/DeviceAllocator.js +3 -3
  112. package/src/devices/allocation/drivers/android/emulator/EmulatorAllocDriver.js +4 -3
  113. package/src/devices/allocation/drivers/android/emulator/EmulatorLauncher.js +2 -6
  114. package/src/devices/allocation/drivers/ios/SimulatorAllocDriver.js +1 -1
  115. package/src/devices/allocation/drivers/ios/SimulatorLauncher.js +3 -3
  116. package/src/devices/allocation/factories/index.js +0 -1
  117. package/src/devices/common/drivers/DeviceLauncher.js +2 -2
  118. package/src/devices/common/drivers/android/emulator/exec/EmulatorExec.js +1 -1
  119. package/src/devices/common/drivers/android/genycloud/services/GenyInstanceNaming.js +4 -9
  120. package/src/devices/common/drivers/ios/tools/AppleSimUtils.js +34 -9
  121. package/src/devices/lifecycle/GenyGlobalLifecycleHandler.js +1 -1
  122. package/src/devices/runtime/RuntimeDevice.js +69 -81
  123. package/src/devices/runtime/drivers/index.js +0 -1
  124. package/src/devices/runtime/drivers/ios/SimulatorDriver.js +3 -2
  125. package/src/devices/runtime/factories/ios.js +1 -8
  126. package/src/devices/runtime/utils/LaunchArgsEditor.js +4 -59
  127. package/src/devices/runtime/utils/Storage.js +4 -0
  128. package/src/environmentFactory.js +0 -8
  129. package/src/errors/DetoxConfigErrorComposer.js +76 -29
  130. package/src/errors/DetoxError.js +4 -0
  131. package/src/errors/DetoxRuntimeError.js +5 -5
  132. package/src/errors/index.js +2 -0
  133. package/src/ipc/IPCClient.js +117 -0
  134. package/src/ipc/IPCServer.js +81 -0
  135. package/src/ipc/state.js +67 -0
  136. package/src/logger/DetoxLogger.js +244 -0
  137. package/src/logger/DetoxTraceEventBuilder.js +21 -0
  138. package/src/logger/DetoxTracer.js +133 -0
  139. package/src/logger/TraceThreadDispatcher.js +52 -0
  140. package/src/{utils → logger}/customConsoleLogger.js +1 -1
  141. package/src/realms/DetoxConstants.js +13 -0
  142. package/src/realms/DetoxContext.js +170 -0
  143. package/src/realms/DetoxInternalsFacade.js +35 -0
  144. package/src/realms/DetoxPrimaryContext.js +228 -0
  145. package/src/realms/DetoxSecondaryContext.js +93 -0
  146. package/src/realms/index.js +10 -0
  147. package/src/realms/primary.js +3 -0
  148. package/src/realms/secondary.js +3 -0
  149. package/src/server/DetoxConnection.js +1 -1
  150. package/src/symbols.js +56 -0
  151. package/src/utils/Timer.js +14 -6
  152. package/{local-cli/utils/misc.js → src/utils/envUtils.js} +0 -9
  153. package/src/utils/logger.js +2 -162
  154. package/src/utils/shellUtils.js +18 -0
  155. package/src/utils/streamUtils.js +214 -0
  156. package/src/utils/trace.js +9 -44
  157. package/Detox-android/com/wix/detox/19.7.1/detox-19.7.1-javadoc.jar.md5 +0 -1
  158. package/Detox-android/com/wix/detox/19.7.1/detox-19.7.1-javadoc.jar.sha1 +0 -1
  159. package/Detox-android/com/wix/detox/19.7.1/detox-19.7.1-javadoc.jar.sha256 +0 -1
  160. package/Detox-android/com/wix/detox/19.7.1/detox-19.7.1-javadoc.jar.sha512 +0 -1
  161. package/Detox-android/com/wix/detox/19.7.1/detox-19.7.1-sources.jar.md5 +0 -1
  162. package/Detox-android/com/wix/detox/19.7.1/detox-19.7.1-sources.jar.sha1 +0 -1
  163. package/Detox-android/com/wix/detox/19.7.1/detox-19.7.1-sources.jar.sha256 +0 -1
  164. package/Detox-android/com/wix/detox/19.7.1/detox-19.7.1-sources.jar.sha512 +0 -1
  165. package/Detox-android/com/wix/detox/19.7.1/detox-19.7.1.aar +0 -0
  166. package/Detox-android/com/wix/detox/19.7.1/detox-19.7.1.aar.md5 +0 -1
  167. package/Detox-android/com/wix/detox/19.7.1/detox-19.7.1.aar.sha1 +0 -1
  168. package/Detox-android/com/wix/detox/19.7.1/detox-19.7.1.aar.sha256 +0 -1
  169. package/Detox-android/com/wix/detox/19.7.1/detox-19.7.1.aar.sha512 +0 -1
  170. package/Detox-android/com/wix/detox/19.7.1/detox-19.7.1.pom.md5 +0 -1
  171. package/Detox-android/com/wix/detox/19.7.1/detox-19.7.1.pom.sha1 +0 -1
  172. package/Detox-android/com/wix/detox/19.7.1/detox-19.7.1.pom.sha256 +0 -1
  173. package/Detox-android/com/wix/detox/19.7.1/detox-19.7.1.pom.sha512 +0 -1
  174. package/android/detox/src/full/java/com/wix/detox/espresso/action/AdjustSliderToPositionAction.kt +0 -22
  175. package/android/detox/src/full/java/com/wix/detox/espresso/common/SliderHelper.kt +0 -75
  176. package/android/detox/src/main/java/com/wix/detox/espresso/action/common/ReflectUtils.kt +0 -10
  177. package/android/detox/src/testFull/java/com/wix/detox/espresso/common/SliderHelperTest.kt +0 -39
  178. package/local-cli/templates/mocha.js +0 -32
  179. package/local-cli/utils/splitArgv.js +0 -107
  180. package/runners/integration.js +0 -16
  181. package/runners/jest/DetoxAdapterCircus.js +0 -60
  182. package/runners/jest/DetoxAdapterImpl.js +0 -81
  183. package/runners/jest/DetoxAdapterJasmine.js +0 -67
  184. package/runners/jest/DetoxStreamlineJestReporter.js +0 -98
  185. package/runners/jest/FailingTestsReporter.js +0 -16
  186. package/runners/jest/SpecReporterCircus.js +0 -51
  187. package/runners/jest/SpecReporterJasmine.js +0 -39
  188. package/runners/jest/WorkerAssignReporterCircus.js +0 -17
  189. package/runners/jest/WorkerAssignReporterImpl.js +0 -21
  190. package/runners/jest/WorkerAssignReporterJasmine.js +0 -15
  191. package/runners/jest/runnerInfo.js +0 -9
  192. package/runners/jest-circus/environment.js +0 -206
  193. package/runners/jest-circus/utils/assertJestCircus26.js +0 -39
  194. package/runners/jest-circus/utils/wrapErrorWithNoopLifecycle.js +0 -14
  195. package/src/DetoxConstants.js +0 -13
  196. package/src/DetoxExportWrapper.js +0 -140
  197. package/src/artifacts/timeline/TimelineArtifactPlugin.js +0 -90
  198. package/src/devices/allocation/drivers/NoneAllocDriver.js +0 -10
  199. package/src/devices/allocation/factories/none.js +0 -11
  200. package/src/index.js +0 -6
  201. package/src/utils/MissingDetox.js +0 -78
  202. package/src/utils/fakeTimestampsProvider.js +0 -9
  203. package/src/utils/getWorkerId.js +0 -5
  204. package/src/utils/lastFailedTests.js +0 -38
  205. package/src/utils/sh.js +0 -18
@@ -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.globalTeardown].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,228 @@
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
+ this[$sessionState].workerId = opts.workerId;
124
+ this[_ipcServer].onRegisterWorker({ workerId: opts.workerId });
125
+ await super[symbols.setup](opts);
126
+ }
127
+
128
+ /** @override */
129
+ async [symbols.globalTeardown]() {
130
+ if (this[_globalLifecycleHandler]) {
131
+ await this[_globalLifecycleHandler].globalCleanup();
132
+ this[_globalLifecycleHandler] = null;
133
+ }
134
+
135
+ if (this[_wss]) {
136
+ await this[_wss].close();
137
+ this[_wss] = null;
138
+ }
139
+
140
+ if (this[_ipcServer]) {
141
+ await this[_ipcServer].dispose();
142
+ this[_ipcServer] = null;
143
+ }
144
+
145
+ await fs.remove(this[$sessionState].detoxConfigSnapshotPath);
146
+ delete process.env.DETOX_CONFIG_SNAPSHOT_PATH;
147
+
148
+ try {
149
+ this.trace.end({ cat: 'lifecycle' });
150
+ await this[_finalizeLogs]();
151
+ } catch (err) {
152
+ this[$logger].error({ err }, 'Encountered an error while merging the process logs:');
153
+ }
154
+ }
155
+ //#endregion
156
+
157
+ //#region Protected members
158
+ /**
159
+ * @protected
160
+ * @override
161
+ * @return {PrimarySessionState}
162
+ */
163
+ [$restoreSessionState]() {
164
+ return new PrimarySessionState({
165
+ detoxConfigSnapshotPath: temporary.for.json(),
166
+ detoxIPCServer: `primary-${process.pid}`,
167
+ });
168
+ }
169
+ //#endregion
170
+
171
+ //#region Private members
172
+ async[_finalizeLogs]() {
173
+ const logs = [this[$logger].file, ...this[$sessionState].logFiles].filter(f => f && fs.existsSync(f));
174
+ if (logs.length === 0) {
175
+ return;
176
+ }
177
+
178
+ const streamUtils = require('../utils/streamUtils');
179
+ const { rootDir, plugins } = this[symbols.config].artifactsConfig || {};
180
+ const logConfig = plugins && plugins.log || 'none';
181
+ const enabled = rootDir && (typeof logConfig === 'string' ? logConfig !== 'none' : logConfig.enabled);
182
+
183
+ if (enabled) {
184
+ await fs.mkdirp(rootDir);
185
+ const [out1Stream, out2Stream, out3Stream] = ['detox.log.jsonl', 'detox.log', 'detox.trace.json']
186
+ .map((filename) => fs.createWriteStream(path.join(rootDir, filename)));
187
+
188
+ const mergedStream = streamUtils
189
+ .mergeSortedJSONL(
190
+ logs.map(filePath => fs.createReadStream(filePath).pipe(streamUtils.readJSONL()))
191
+ );
192
+
193
+ await Promise.all([
194
+ pipe(mergedStream, streamUtils.writeJSONL(), out1Stream),
195
+ pipe(mergedStream, streamUtils.debugStream(this[$logger].config.options), out2Stream),
196
+ pipe(mergedStream, streamUtils.chromeTraceStream(), streamUtils.writeJSON(), out3Stream),
197
+ ]);
198
+ }
199
+
200
+ await Promise.all(logs.map(filepath => fs.remove(filepath)));
201
+ }
202
+
203
+ async[_resetLockFile]() {
204
+ const DeviceRegistry = require('../devices/DeviceRegistry');
205
+
206
+ const deviceType = this[symbols.config].deviceConfig.type;
207
+
208
+ switch (deviceType) {
209
+ case 'ios.none':
210
+ case 'ios.simulator':
211
+ await DeviceRegistry.forIOS().reset();
212
+ break;
213
+ case 'android.attached':
214
+ case 'android.emulator':
215
+ case 'android.genycloud':
216
+ await DeviceRegistry.forAndroid().reset();
217
+ break;
218
+ }
219
+
220
+ if (deviceType === 'android.genycloud') {
221
+ const GenyDeviceRegistryFactory = require('../devices/allocation/drivers/android/genycloud/GenyDeviceRegistryFactory');
222
+ await GenyDeviceRegistryFactory.forGlobalShutdown().reset();
223
+ }
224
+ }
225
+ //#endregion
226
+ }
227
+
228
+ module.exports = DetoxPrimaryContext;
@@ -0,0 +1,93 @@
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
+ await this[_ipcClient].init();
63
+ await this[_ipcClient].registerWorker(opts.workerId);
64
+ await super[symbols.setup](opts);
65
+ }
66
+
67
+ /** @override */
68
+ async [symbols.teardown]() {
69
+ try {
70
+ await super[symbols.teardown]();
71
+ } finally {
72
+ if (this[_ipcClient]) {
73
+ await this[_ipcClient].dispose();
74
+ this[_ipcClient] = null;
75
+ }
76
+ }
77
+ }
78
+ //#endregion
79
+
80
+ //#region Protected members
81
+
82
+ /**
83
+ * @protected
84
+ * @override
85
+ * @return {SecondarySessionState}
86
+ */
87
+ [$restoreSessionState]() {
88
+ return SecondarySessionState.parse(fs.readFileSync(process.env.DETOX_CONFIG_SNAPSHOT_PATH));
89
+ }
90
+ //#endregion
91
+ }
92
+
93
+ 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
+ };
@@ -26,14 +26,13 @@ class Timer {
26
26
  }
27
27
 
28
28
  async run(action) {
29
- const error = new DetoxRuntimeError();
30
- delete error.stack;
29
+ const error = new DetoxRuntimeError({
30
+ message: `Exceeded timeout of ${this._timeout}ms while ${this.description}`,
31
+ noStack: true,
32
+ });
31
33
 
32
34
  return Promise.race([
33
- this._timeoutDeferred.promise.then(() => {
34
- error.message = `Exceeded timeout of ${this._timeout}ms while ${this.description}`;
35
- throw error;
36
- }),
35
+ this._timeoutDeferred.promise.then(() => { throw error; }),
37
36
  Promise.resolve().then(action),
38
37
  ]);
39
38
  }
@@ -52,6 +51,15 @@ class Timer {
52
51
  this._timeoutHandle = setTimeout(() => this._timeoutDeferred.resolve(), extraDelayMs);
53
52
  }
54
53
  }
54
+
55
+ static async run({ description, timeout, fn }) {
56
+ const timer = new Timer({ description, timeout });
57
+ try {
58
+ await timer.run(fn);
59
+ } finally {
60
+ timer.dispose();
61
+ }
62
+ }
55
63
  }
56
64
 
57
65
  module.exports = Timer;
@@ -1,13 +1,5 @@
1
1
  const path = require('path');
2
2
 
3
- function getPlatformSpecificString(platform) {
4
- switch (platform) {
5
- case 'ios': return ':android:';
6
- case 'android': return ':ios:';
7
- default: return undefined;
8
- }
9
- }
10
-
11
3
  function printEnvironmentVariables(envObject) {
12
4
  return Object.entries(envObject).reduce((cli, [key, value]) => {
13
5
  if (value == null || value === '') {
@@ -33,7 +25,6 @@ function prependNodeModulesBinToPATH(env) {
33
25
  }
34
26
 
35
27
  module.exports = {
36
- getPlatformSpecificString,
37
28
  printEnvironmentVariables,
38
29
  prependNodeModulesBinToPATH,
39
30
  };