detox 19.13.0 → 20.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (236) hide show
  1. package/Detox-android/com/wix/detox/{19.13.0/detox-19.13.0-javadoc.jar → 20.0.0/detox-20.0.0-javadoc.jar} +0 -0
  2. package/Detox-android/com/wix/detox/20.0.0/detox-20.0.0-javadoc.jar.md5 +1 -0
  3. package/Detox-android/com/wix/detox/20.0.0/detox-20.0.0-javadoc.jar.sha1 +1 -0
  4. package/Detox-android/com/wix/detox/20.0.0/detox-20.0.0-javadoc.jar.sha256 +1 -0
  5. package/Detox-android/com/wix/detox/20.0.0/detox-20.0.0-javadoc.jar.sha512 +1 -0
  6. package/Detox-android/com/wix/detox/{19.13.0/detox-19.13.0-sources.jar → 20.0.0/detox-20.0.0-sources.jar} +0 -0
  7. package/Detox-android/com/wix/detox/20.0.0/detox-20.0.0-sources.jar.md5 +1 -0
  8. package/Detox-android/com/wix/detox/20.0.0/detox-20.0.0-sources.jar.sha1 +1 -0
  9. package/Detox-android/com/wix/detox/20.0.0/detox-20.0.0-sources.jar.sha256 +1 -0
  10. package/Detox-android/com/wix/detox/20.0.0/detox-20.0.0-sources.jar.sha512 +1 -0
  11. package/Detox-android/com/wix/detox/20.0.0/detox-20.0.0.aar +0 -0
  12. package/Detox-android/com/wix/detox/20.0.0/detox-20.0.0.aar.md5 +1 -0
  13. package/Detox-android/com/wix/detox/20.0.0/detox-20.0.0.aar.sha1 +1 -0
  14. package/Detox-android/com/wix/detox/20.0.0/detox-20.0.0.aar.sha256 +1 -0
  15. package/Detox-android/com/wix/detox/20.0.0/detox-20.0.0.aar.sha512 +1 -0
  16. package/Detox-android/com/wix/detox/{19.13.0/detox-19.13.0.pom → 20.0.0/detox-20.0.0.pom} +1 -1
  17. package/Detox-android/com/wix/detox/20.0.0/detox-20.0.0.pom.md5 +1 -0
  18. package/Detox-android/com/wix/detox/20.0.0/detox-20.0.0.pom.sha1 +1 -0
  19. package/Detox-android/com/wix/detox/20.0.0/detox-20.0.0.pom.sha256 +1 -0
  20. package/Detox-android/com/wix/detox/20.0.0/detox-20.0.0.pom.sha512 +1 -0
  21. package/Detox-android/com/wix/detox/maven-metadata.xml +4 -4
  22. package/Detox-android/com/wix/detox/maven-metadata.xml.md5 +1 -1
  23. package/Detox-android/com/wix/detox/maven-metadata.xml.sha1 +1 -1
  24. package/Detox-android/com/wix/detox/maven-metadata.xml.sha256 +1 -1
  25. package/Detox-android/com/wix/detox/maven-metadata.xml.sha512 +1 -1
  26. package/Detox-ios-src.tbz +0 -0
  27. package/Detox-ios.tbz +0 -0
  28. package/README.md +1 -1
  29. package/android/detox/src/full/java/com/wix/detox/Detox.java +2 -59
  30. package/android/detox/src/full/java/com/wix/detox/NotificationDataParser.kt +3 -3
  31. package/index.d.ts +354 -191
  32. package/index.js +1 -0
  33. package/internals.d.ts +298 -0
  34. package/internals.js +4 -0
  35. package/local-cli/build-framework-cache.js +2 -2
  36. package/local-cli/build.js +7 -8
  37. package/local-cli/build.test.js +46 -40
  38. package/local-cli/clean-framework-cache.js +3 -3
  39. package/local-cli/cli.js +8 -7
  40. package/local-cli/init.js +73 -68
  41. package/local-cli/rebuild-framework-cache.js +1 -1
  42. package/local-cli/reset-lock-file.js +16 -0
  43. package/local-cli/templates/jest.js +14 -36
  44. package/local-cli/test.js +24 -282
  45. package/local-cli/test.test.js +394 -648
  46. package/local-cli/testCommand/TestRunnerCommand.js +163 -0
  47. package/local-cli/{utils/testCommandArgs.js → testCommand/builder.js} +10 -36
  48. package/local-cli/testCommand/middlewares.js +66 -0
  49. package/local-cli/{utils → testCommand}/warnings.js +0 -13
  50. package/local-cli/utils/jestInternals.js +13 -2
  51. package/local-cli/utils/yargsUtils.js +67 -0
  52. package/package.json +32 -19
  53. package/runners/deprecation.js +45 -0
  54. package/runners/jest/JestCircusEnvironment.js +3 -38
  55. package/runners/jest/adapter.d.ts +4 -10
  56. package/runners/jest/adapter.js +3 -6
  57. package/runners/jest/assignReporter.d.ts +4 -1
  58. package/runners/jest/assignReporter.js +3 -6
  59. package/runners/jest/globalSetup.js +1 -0
  60. package/runners/jest/globalTeardown.js +1 -0
  61. package/runners/jest/index.d.ts +60 -0
  62. package/runners/jest/index.js +16 -0
  63. package/runners/jest/index.test.js +13 -0
  64. package/runners/jest/reporter.js +1 -0
  65. package/runners/jest/reporters/DetoxReporter.js +36 -0
  66. package/runners/jest/specReporter.d.ts +4 -9
  67. package/runners/jest/specReporter.js +3 -10
  68. package/runners/jest/streamlineReporter.js +3 -22
  69. package/runners/jest/testEnvironment/index.js +205 -0
  70. package/runners/jest/testEnvironment/listeners/DetoxCoreListener.js +166 -0
  71. package/runners/{jest-circus → jest/testEnvironment}/listeners/DetoxInitErrorListener.js +1 -1
  72. package/runners/jest/testEnvironment/listeners/DetoxPlatformFilterListener.js +27 -0
  73. package/runners/jest/{SpecReporterImpl.js → testEnvironment/listeners/SpecReporter.js} +61 -9
  74. package/runners/jest/testEnvironment/listeners/WorkerAssignReporter.js +30 -0
  75. package/runners/jest/testEnvironment/listeners/index.js +13 -0
  76. package/runners/{jest-circus → jest/testEnvironment}/utils/assertExistingContext.js +2 -2
  77. package/runners/jest/testEnvironment/utils/assertJestCircus27.js +70 -0
  78. package/runners/jest/testEnvironment/utils/assertJestCircus27.test.js +22 -0
  79. package/runners/jest/{utils → testEnvironment/utils}/getFullTestName.js +0 -0
  80. package/runners/jest/{utils → testEnvironment/utils}/hasTimedOut.js +0 -0
  81. package/runners/jest/{utils → testEnvironment/utils}/index.js +0 -0
  82. package/runners/jest/{utils → testEnvironment/utils}/stdout.js +0 -0
  83. package/runners/jest-circus/environment/index.js +6 -0
  84. package/runners/jest-circus/index.js +1 -10
  85. package/runners/jest-circus/reporter.js +1 -0
  86. package/runners/migration.js +37 -0
  87. package/runners/mocha/DetoxMochaAdapter.js +3 -35
  88. package/runners/mocha/adapter.d.ts +4 -7
  89. package/runners/mocha/adapter.js +3 -5
  90. package/src/DetoxWorker.js +327 -0
  91. package/src/android/interactions/native.js +2 -1
  92. package/src/artifacts/ArtifactsManager.js +51 -35
  93. package/src/artifacts/instruments/ios/SimulatorInstrumentsRecording.js +3 -3
  94. package/src/artifacts/log/ios/SimulatorLogRecording.js +1 -1
  95. package/src/artifacts/providers/index.js +0 -4
  96. package/src/artifacts/screenshot/SimulatorScreenshotPlugin.js +1 -1
  97. package/src/artifacts/templates/artifact/Artifact.js +1 -1
  98. package/src/artifacts/templates/plugin/ArtifactPlugin.js +1 -1
  99. package/src/artifacts/utils/buildDefaultArtifactsRootDirpath.js +2 -4
  100. package/src/artifacts/utils/temporaryPath.js +18 -5
  101. package/src/artifacts/video/SimulatorRecordVideoPlugin.js +1 -1
  102. package/src/client/AsyncWebSocket.js +8 -17
  103. package/src/client/Client.js +1 -1
  104. package/src/client/actions/actions.js +2 -2
  105. package/src/configuration/collectCliConfig.js +3 -16
  106. package/src/configuration/composeAppsConfig.js +12 -66
  107. package/src/configuration/composeArtifactsConfig.js +6 -32
  108. package/src/configuration/composeBehaviorConfig.js +3 -13
  109. package/src/configuration/composeDeviceConfig.js +38 -63
  110. package/src/configuration/composeLoggerConfig.js +59 -0
  111. package/src/configuration/composeRunnerConfig.js +127 -14
  112. package/src/configuration/composeSessionConfig.js +1 -3
  113. package/src/configuration/index.js +36 -30
  114. package/src/configuration/loadExternalConfig.js +1 -1
  115. package/src/configuration/utils/deviceAppTypes.js +0 -1
  116. package/src/devices/allocation/DeviceAllocator.js +4 -2
  117. package/src/devices/allocation/drivers/android/emulator/AVDValidator.js +1 -1
  118. package/src/devices/allocation/drivers/android/emulator/EmulatorAllocDriver.js +5 -3
  119. package/src/devices/allocation/drivers/android/emulator/EmulatorAllocationHelper.js +1 -1
  120. package/src/devices/allocation/drivers/android/emulator/EmulatorLauncher.js +3 -5
  121. package/src/devices/allocation/drivers/android/emulator/EmulatorVersionResolver.js +4 -6
  122. package/src/devices/allocation/drivers/android/emulator/launchEmulatorProcess.js +1 -1
  123. package/src/devices/allocation/drivers/android/genycloud/GenyInstanceAllocationHelper.js +1 -1
  124. package/src/devices/allocation/drivers/ios/SimulatorAllocDriver.js +1 -1
  125. package/src/devices/allocation/drivers/ios/SimulatorLauncher.js +3 -3
  126. package/src/devices/allocation/factories/index.js +0 -1
  127. package/src/devices/common/drivers/DeviceLauncher.js +2 -2
  128. package/src/devices/common/drivers/android/emulator/exec/EmulatorExec.js +1 -1
  129. package/src/devices/common/drivers/android/genycloud/services/GenyInstanceNaming.js +4 -9
  130. package/src/devices/common/drivers/android/genycloud/services/GenyRecipesService.js +1 -1
  131. package/src/devices/common/drivers/android/tools/EmulatorTelnet.js +1 -1
  132. package/src/devices/common/drivers/android/tools/FreeDeviceFinder.js +1 -1
  133. package/src/devices/common/drivers/ios/tools/AppleSimUtils.js +35 -10
  134. package/src/devices/lifecycle/GenyGlobalLifecycleHandler.js +13 -15
  135. package/src/devices/runtime/RuntimeDevice.js +85 -86
  136. package/src/devices/runtime/drivers/DeviceDriverBase.js +1 -1
  137. package/src/devices/runtime/drivers/android/AndroidDriver.js +3 -3
  138. package/src/devices/runtime/drivers/index.js +0 -1
  139. package/src/devices/runtime/drivers/ios/SimulatorDriver.js +4 -3
  140. package/src/devices/runtime/factories/ios.js +1 -8
  141. package/src/devices/runtime/utils/LaunchArgsEditor.js +4 -59
  142. package/src/devices/runtime/utils/Storage.js +4 -0
  143. package/src/environmentFactory.js +0 -8
  144. package/src/errors/DetoxConfigErrorComposer.js +92 -30
  145. package/src/errors/DetoxError.js +4 -0
  146. package/src/errors/DetoxRuntimeError.js +5 -5
  147. package/src/errors/index.js +2 -0
  148. package/src/ios/expectTwo.js +2 -1
  149. package/src/ipc/IPCClient.js +117 -0
  150. package/src/ipc/IPCServer.js +98 -0
  151. package/src/ipc/SessionState.js +62 -0
  152. package/src/logger/DetoxLogger.js +348 -0
  153. package/src/logger/index.js +5 -0
  154. package/src/logger/utils/BunyanLogger.js +76 -0
  155. package/src/logger/utils/CategoryThreadDispatcher.js +36 -0
  156. package/src/logger/utils/DetoxLogFinalizer.js +140 -0
  157. package/src/logger/utils/MessageStack.js +24 -0
  158. package/src/logger/utils/ThreadDispatcher.js +61 -0
  159. package/src/{utils → logger/utils}/customConsoleLogger.js +5 -4
  160. package/src/logger/utils/sanitizeBunyanContext.js +30 -0
  161. package/src/logger/utils/streamUtils.js +248 -0
  162. package/src/logger/utils/tracerLegacy.js +37 -0
  163. package/src/realms/DetoxConstants.js +13 -0
  164. package/src/realms/DetoxContext.js +183 -0
  165. package/src/realms/DetoxInternalsFacade.js +31 -0
  166. package/src/realms/DetoxPrimaryContext.js +261 -0
  167. package/src/realms/DetoxSecondaryContext.js +91 -0
  168. package/src/realms/index.js +10 -0
  169. package/src/realms/primary.js +3 -0
  170. package/src/realms/secondary.js +3 -0
  171. package/src/server/DetoxConnection.js +18 -23
  172. package/src/server/DetoxServer.js +7 -10
  173. package/src/server/DetoxSession.js +6 -6
  174. package/src/server/DetoxSessionManager.js +1 -1
  175. package/src/server/handlers/RegisteredConnectionHandler.js +1 -2
  176. package/src/symbols.js +50 -0
  177. package/src/utils/Timer.js +58 -33
  178. package/src/utils/argparse.js +11 -0
  179. package/src/utils/childProcess/exec.js +1 -1
  180. package/src/utils/childProcess/spawn.js +1 -1
  181. package/{local-cli/utils/misc.js → src/utils/envUtils.js} +0 -9
  182. package/src/utils/errorUtils.js +20 -0
  183. package/src/utils/logger.js +2 -162
  184. package/src/utils/shellUtils.js +18 -0
  185. package/src/utils/traceInvocationCall.js +21 -0
  186. package/src/utils/traceMethods.js +15 -0
  187. package/Detox-android/com/wix/detox/19.13.0/detox-19.13.0-javadoc.jar.md5 +0 -1
  188. package/Detox-android/com/wix/detox/19.13.0/detox-19.13.0-javadoc.jar.sha1 +0 -1
  189. package/Detox-android/com/wix/detox/19.13.0/detox-19.13.0-javadoc.jar.sha256 +0 -1
  190. package/Detox-android/com/wix/detox/19.13.0/detox-19.13.0-javadoc.jar.sha512 +0 -1
  191. package/Detox-android/com/wix/detox/19.13.0/detox-19.13.0-sources.jar.md5 +0 -1
  192. package/Detox-android/com/wix/detox/19.13.0/detox-19.13.0-sources.jar.sha1 +0 -1
  193. package/Detox-android/com/wix/detox/19.13.0/detox-19.13.0-sources.jar.sha256 +0 -1
  194. package/Detox-android/com/wix/detox/19.13.0/detox-19.13.0-sources.jar.sha512 +0 -1
  195. package/Detox-android/com/wix/detox/19.13.0/detox-19.13.0.aar +0 -0
  196. package/Detox-android/com/wix/detox/19.13.0/detox-19.13.0.aar.md5 +0 -1
  197. package/Detox-android/com/wix/detox/19.13.0/detox-19.13.0.aar.sha1 +0 -1
  198. package/Detox-android/com/wix/detox/19.13.0/detox-19.13.0.aar.sha256 +0 -1
  199. package/Detox-android/com/wix/detox/19.13.0/detox-19.13.0.aar.sha512 +0 -1
  200. package/Detox-android/com/wix/detox/19.13.0/detox-19.13.0.pom.md5 +0 -1
  201. package/Detox-android/com/wix/detox/19.13.0/detox-19.13.0.pom.sha1 +0 -1
  202. package/Detox-android/com/wix/detox/19.13.0/detox-19.13.0.pom.sha256 +0 -1
  203. package/Detox-android/com/wix/detox/19.13.0/detox-19.13.0.pom.sha512 +0 -1
  204. package/local-cli/templates/mocha.js +0 -32
  205. package/local-cli/utils/splitArgv.js +0 -107
  206. package/runners/integration.js +0 -16
  207. package/runners/jest/DetoxAdapterCircus.js +0 -60
  208. package/runners/jest/DetoxAdapterImpl.js +0 -81
  209. package/runners/jest/DetoxAdapterJasmine.js +0 -67
  210. package/runners/jest/DetoxStreamlineJestReporter.js +0 -98
  211. package/runners/jest/FailingTestsReporter.js +0 -16
  212. package/runners/jest/SpecReporterCircus.js +0 -51
  213. package/runners/jest/SpecReporterJasmine.js +0 -39
  214. package/runners/jest/WorkerAssignReporterCircus.js +0 -17
  215. package/runners/jest/WorkerAssignReporterImpl.js +0 -21
  216. package/runners/jest/WorkerAssignReporterJasmine.js +0 -15
  217. package/runners/jest/runnerInfo.js +0 -9
  218. package/runners/jest-circus/environment.js +0 -206
  219. package/runners/jest-circus/listeners/DetoxCoreListener.js +0 -113
  220. package/runners/jest-circus/utils/assertJestCircus26.js +0 -39
  221. package/runners/jest-circus/utils/wrapErrorWithNoopLifecycle.js +0 -14
  222. package/src/Detox.js +0 -317
  223. package/src/DetoxConstants.js +0 -13
  224. package/src/DetoxExportWrapper.js +0 -140
  225. package/src/artifacts/timeline/TimelineArtifactPlugin.js +0 -92
  226. package/src/configuration/utils/warnings.js +0 -12
  227. package/src/devices/allocation/drivers/NoneAllocDriver.js +0 -10
  228. package/src/devices/allocation/factories/none.js +0 -11
  229. package/src/index.js +0 -6
  230. package/src/utils/ChromeTracingExporter.js +0 -54
  231. package/src/utils/MissingDetox.js +0 -78
  232. package/src/utils/fakeTimestampsProvider.js +0 -9
  233. package/src/utils/getWorkerId.js +0 -5
  234. package/src/utils/lastFailedTests.js +0 -38
  235. package/src/utils/sh.js +0 -18
  236. package/src/utils/trace.js +0 -96
@@ -1,113 +0,0 @@
1
- // @ts-nocheck
2
- const _ = require('lodash');
3
-
4
- const {
5
- onRunDescribeStart,
6
- onTestStart,
7
- onHookFailure,
8
- onTestFnFailure,
9
- onTestDone,
10
- onRunDescribeFinish,
11
- } = require('../../integration').lifecycle;
12
- const { getFullTestName, hasTimedOut } = require('../../jest/utils');
13
-
14
- const RETRY_TIMES = Symbol.for('RETRY_TIMES');
15
-
16
- class DetoxCoreListener {
17
- constructor({ detox, env }) {
18
- this._startedTests = new WeakSet();
19
- this._testsFailedBeforeStart = new WeakSet();
20
- this._env = env;
21
- this._testRunTimes = 1;
22
- this.detox = detox;
23
- }
24
-
25
- async run_describe_start({ describeBlock: { name, children } }) {
26
- if (children.length) {
27
- await this.detox[onRunDescribeStart]({ name });
28
- }
29
- }
30
-
31
- async run_describe_finish({ describeBlock: { name, children } }) {
32
- if (children.length) {
33
- await this.detox[onRunDescribeFinish]({ name });
34
- }
35
- }
36
-
37
- async test_start({ test }) {
38
- if (!_.isEmpty(test.errors)) {
39
- this._testsFailedBeforeStart.add(test);
40
- }
41
-
42
- const circusRetryTimes = +this._env.global[RETRY_TIMES];
43
- this._testRunTimes = isNaN(circusRetryTimes) ? 1 : 1 + circusRetryTimes;
44
- }
45
-
46
- async hook_start(_event, state) {
47
- await this._onBeforeActualTestStart(state.currentlyRunningTest);
48
- }
49
-
50
- async hook_failure({ error, hook }) {
51
- await this.detox[onHookFailure]({
52
- error,
53
- hook: hook.type,
54
- });
55
- }
56
-
57
- async test_fn_start({ test }) {
58
- await this._onBeforeActualTestStart(test);
59
- }
60
-
61
- async test_fn_failure({ error }) {
62
- await this.detox[onTestFnFailure]({ error });
63
- }
64
-
65
- async _onBeforeActualTestStart(test) {
66
- if (!test || test.status === 'skip' || this._startedTests.has(test) || this._testsFailedBeforeStart.has(test)) {
67
- return;
68
- }
69
-
70
- this._startedTests.add(test);
71
-
72
- await this.detox[onTestStart]({
73
- ...this._getTestMetadata(test),
74
- status: 'running',
75
- });
76
- }
77
-
78
- _getTestMetadata(test) {
79
- return {
80
- title: test.name,
81
- parent: test.parent.name,
82
- fullName: getFullTestName(test),
83
- functionCode: test.fn.toString(),
84
- invocations: this._getTestInvocations(test),
85
- };
86
- }
87
-
88
- _getTestInvocations(test) {
89
- const { DETOX_RERUN_INDEX } = process.env;
90
-
91
- if (!isNaN(DETOX_RERUN_INDEX)) {
92
- return Number(DETOX_RERUN_INDEX) * this._testRunTimes + test.invocations;
93
- } else {
94
- return test.invocations;
95
- }
96
- }
97
-
98
- async test_done({ test }) {
99
- if (this._startedTests.has(test)) {
100
- await this.detox[onTestDone]({
101
- ...this._getTestMetadata(test),
102
- status: _.isEmpty(test.errors) ? 'passed' : 'failed',
103
- errors: _.isEmpty(test.errors) ? undefined : test.errors,
104
- asyncError: _.isEmpty(test.asyncError) ? undefined : test.asyncError,
105
- timedOut: hasTimedOut(test)
106
- });
107
-
108
- this._startedTests.delete(test);
109
- }
110
- }
111
- }
112
-
113
- module.exports = DetoxCoreListener;
@@ -1,39 +0,0 @@
1
- const fs = require('fs');
2
- const path = require('path');
3
-
4
- const DetoxRuntimeError = require('../../../src/errors/DetoxRuntimeError');
5
-
6
- function assertJestCircus26(maybeProjectConfig) {
7
- const projectConfig = maybeProjectConfig.projectConfig || maybeProjectConfig;
8
-
9
- if (!/jest-circus/.test(projectConfig.testRunner)) {
10
- throw new DetoxRuntimeError('Cannot run tests without "jest-circus" npm package, exiting.');
11
- }
12
-
13
- const circusPackageJson = path.join(path.dirname(projectConfig.testRunner), 'package.json');
14
- if (!fs.existsSync(circusPackageJson)) {
15
- throw new DetoxRuntimeError('Check that you have an installed copy of "jest-circus" npm package, exiting.');
16
- }
17
-
18
- const circusVersion = require(circusPackageJson).version || '';
19
- const [major, minor, patch] = circusVersion.split('.');
20
- if (major < 26) {
21
- throw new DetoxRuntimeError(
22
- `Cannot use older versions of "jest-circus", exiting.\n` +
23
- `You have jest-circus@${circusVersion}. Update to ^26.0.0 or newer.`
24
- );
25
- }
26
-
27
- if (major == 26 && minor == 5 && patch < 2) {
28
- throw new DetoxRuntimeError(
29
- `You have jest-circus@${circusVersion} currently installed.\n` +
30
- `Unfortunately, it is incompatible with Detox due to this critical issue:\n\n` +
31
- `https://github.com/wix/Detox/issues/2390\n\n` +
32
- `Please update to jest-circus@^26.5.2 (or newer) to proceed.`
33
- );
34
- }
35
-
36
- return maybeProjectConfig;
37
- }
38
-
39
- module.exports = assertJestCircus26;
@@ -1,14 +0,0 @@
1
- const _ = require('lodash');
2
-
3
- const lifecycleSymbols = require('../../integration').lifecycle;
4
-
5
- function wrapErrorWithNoopLifecycle(error) {
6
- const wrapper = { error };
7
- for (const symbol of Object.values(lifecycleSymbols)) {
8
- wrapper[symbol] = _.noop;
9
- }
10
-
11
- return wrapper;
12
- }
13
-
14
- module.exports = wrapErrorWithNoopLifecycle;
package/src/Detox.js DELETED
@@ -1,317 +0,0 @@
1
- // @ts-nocheck
2
- const { URL } = require('url');
3
- const util = require('util');
4
-
5
- const _ = require('lodash');
6
-
7
- const lifecycleSymbols = require('../runners/integration').lifecycle;
8
-
9
- const Client = require('./client/Client');
10
- const environmentFactory = require('./environmentFactory');
11
- const { DetoxRuntimeErrorComposer } = require('./errors');
12
- const { InvocationManager } = require('./invoke');
13
- const DetoxServer = require('./server/DetoxServer');
14
- const AsyncEmitter = require('./utils/AsyncEmitter');
15
- const Deferred = require('./utils/Deferred');
16
- const MissingDetox = require('./utils/MissingDetox');
17
- const logger = require('./utils/logger');
18
- const log = logger.child({ __filename });
19
-
20
- const _initHandle = Symbol('_initHandle');
21
- const _assertNoPendingInit = Symbol('_assertNoPendingInit');
22
-
23
- class Detox {
24
- constructor(config) {
25
- log.trace(
26
- { event: 'DETOX_CREATE', config },
27
- 'created a Detox instance with config:\n%s',
28
- util.inspect(_.omit(config, ['errorComposer']), {
29
- getters: false,
30
- depth: Infinity,
31
- maxArrayLength: Infinity,
32
- maxStringLength: Infinity,
33
- breakLength: false,
34
- compact: false,
35
- })
36
- );
37
-
38
- this[_initHandle] = null;
39
-
40
- for (const [key, symbol] of Object.entries(lifecycleSymbols)) {
41
- this[symbol] = (...args) => this._artifactsManager[key](...args);
42
- }
43
-
44
- this[lifecycleSymbols.onTestStart] = this.beforeEach;
45
- this[lifecycleSymbols.onTestDone] = this.afterEach;
46
-
47
- const { appsConfig, artifactsConfig, behaviorConfig, deviceConfig, sessionConfig } = config;
48
-
49
- this._appsConfig = appsConfig;
50
- this._artifactsConfig = artifactsConfig;
51
- this._behaviorConfig = behaviorConfig;
52
- this._deviceConfig = deviceConfig;
53
- this._sessionConfig = sessionConfig;
54
- this._runtimeErrorComposer = new DetoxRuntimeErrorComposer({ appsConfig });
55
-
56
- this._client = null;
57
- this._server = null;
58
- this._artifactsManager = null;
59
- this._eventEmitter = new AsyncEmitter({
60
- events: [
61
- 'bootDevice',
62
- 'beforeShutdownDevice',
63
- 'shutdownDevice',
64
- 'beforeTerminateApp',
65
- 'terminateApp',
66
- 'beforeUninstallApp',
67
- 'beforeLaunchApp',
68
- 'launchApp',
69
- 'appReady',
70
- 'createExternalArtifact',
71
- ],
72
- onError: this._onEmitError.bind(this),
73
- });
74
-
75
- this.device = null;
76
- this._deviceAllocator = null;
77
- this._deviceCookie = null;
78
- }
79
-
80
- init() {
81
- if (!this[_initHandle]) {
82
- this[_initHandle] = new Deferred();
83
-
84
- const { resolve, reject } = this[_initHandle];
85
- this._doInit().then(resolve, reject);
86
- }
87
-
88
- return this[_initHandle].promise;
89
- }
90
-
91
- async cleanup() {
92
- await this[_assertNoPendingInit]().catch(_.noop);
93
-
94
- if (this._artifactsManager) {
95
- await this._artifactsManager.onBeforeCleanup();
96
- this._artifactsManager = null;
97
- }
98
-
99
- if (this._client) {
100
- this._client.dumpPendingRequests();
101
- await this._client.cleanup();
102
- this._client = null;
103
- }
104
-
105
- if (this.device) {
106
- const shutdown = this._behaviorConfig.cleanup.shutdownDevice;
107
- await this.device._cleanup();
108
- await this._deviceAllocator.free(this._deviceCookie, { shutdown });
109
- }
110
-
111
- if (this._server) {
112
- await this._server.close();
113
- this._server = null;
114
- }
115
-
116
- this._deviceAllocator = null;
117
- this._deviceCookie = null;
118
- this.device = null;
119
- }
120
-
121
- async beforeEach(testSummary) {
122
- await this[_assertNoPendingInit]();
123
-
124
- this._validateTestSummary('beforeEach', testSummary);
125
- this._logTestRunCheckpoint('DETOX_BEFORE_EACH', testSummary);
126
- await this._dumpUnhandledErrorsIfAny({
127
- pendingRequests: false,
128
- testName: testSummary.fullName,
129
- });
130
- await this._artifactsManager.onTestStart(testSummary);
131
- }
132
-
133
- async afterEach(testSummary) {
134
- await this[_assertNoPendingInit]();
135
-
136
- this._validateTestSummary('afterEach', testSummary);
137
- this._logTestRunCheckpoint('DETOX_AFTER_EACH', testSummary);
138
- await this._artifactsManager.onTestDone(testSummary);
139
- await this._dumpUnhandledErrorsIfAny({
140
- pendingRequests: testSummary.timedOut,
141
- testName: testSummary.fullName,
142
- });
143
- }
144
-
145
- async _doInit() {
146
- const behaviorConfig = this._behaviorConfig.init;
147
- const sessionConfig = this._sessionConfig;
148
-
149
- if (sessionConfig.autoStart) {
150
- this._server = new DetoxServer({
151
- port: sessionConfig.server
152
- ? new URL(sessionConfig.server).port
153
- : 0,
154
- standalone: false,
155
- });
156
-
157
- await this._server.open();
158
-
159
- if (!sessionConfig.server) {
160
- sessionConfig.server = `ws://localhost:${this._server.port}`;
161
- }
162
- }
163
-
164
- this._client = new Client(sessionConfig);
165
- this._client.terminateApp = async () => {
166
- if (this.device && this.device._isAppRunning()) {
167
- await this.device.terminateApp();
168
- }
169
- };
170
-
171
- await this._client.connect();
172
-
173
- const invocationManager = new InvocationManager(this._client);
174
-
175
- const {
176
- envValidatorFactory,
177
- deviceAllocatorFactory,
178
- artifactsManagerFactory,
179
- matchersFactory,
180
- runtimeDeviceFactory,
181
- } = environmentFactory.createFactories(this._deviceConfig);
182
-
183
- const envValidator = envValidatorFactory.createValidator();
184
- await envValidator.validate();
185
-
186
- const commonDeps = {
187
- invocationManager,
188
- client: this._client,
189
- eventEmitter: this._eventEmitter,
190
- runtimeErrorComposer: this._runtimeErrorComposer,
191
- };
192
-
193
- this._artifactsManager = artifactsManagerFactory.createArtifactsManager(this._artifactsConfig, commonDeps);
194
-
195
- this._deviceAllocator = deviceAllocatorFactory.createDeviceAllocator(commonDeps);
196
- this._deviceCookie = await this._deviceAllocator.allocate(this._deviceConfig);
197
-
198
- this.device = runtimeDeviceFactory.createRuntimeDevice(
199
- this._deviceCookie,
200
- commonDeps,
201
- {
202
- appsConfig: this._appsConfig,
203
- behaviorConfig: this._behaviorConfig,
204
- deviceConfig: this._deviceConfig,
205
- sessionConfig,
206
- });
207
- await this.device._prepare();
208
-
209
- const matchers = matchersFactory.createMatchers({
210
- invocationManager,
211
- runtimeDevice: this.device,
212
- eventEmitter: this._eventEmitter,
213
- });
214
- Object.assign(this, matchers);
215
-
216
- if (behaviorConfig.exposeGlobals) {
217
- Object.assign(Detox.global, {
218
- ...matchers,
219
- device: this.device,
220
- });
221
- }
222
-
223
- await this.device.installUtilBinaries();
224
- if (behaviorConfig.reinstallApp) {
225
- await this._reinstallAppsOnDevice();
226
- }
227
-
228
- return this;
229
- }
230
-
231
- [_assertNoPendingInit]() {
232
- const handle = this[_initHandle];
233
- if (!handle) {
234
- return Promise.resolve();
235
- }
236
-
237
- if (handle.status === Deferred.PENDING) {
238
- handle.reject(this._runtimeErrorComposer.abortedDetoxInit());
239
- }
240
-
241
- return handle.promise;
242
- }
243
-
244
- async _reinstallAppsOnDevice() {
245
- const appNames = _(this._appsConfig)
246
- .map((config, key) => [key, `${config.binaryPath}:${config.testBinaryPath}`])
247
- .uniqBy(1)
248
- .map(0)
249
- .value();
250
-
251
- for (const appName of appNames) {
252
- await this.device.selectApp(appName);
253
- await this.device.uninstallApp();
254
- }
255
-
256
- for (const appName of appNames) {
257
- await this.device.selectApp(appName);
258
- await this.device.installApp();
259
- }
260
-
261
- if (appNames.length !== 1) {
262
- await this.device.selectApp(null);
263
- }
264
- }
265
-
266
- _logTestRunCheckpoint(event, { status, fullName }) {
267
- log.trace({ event, status }, `${status} test: ${JSON.stringify(fullName)}`);
268
- }
269
-
270
- _validateTestSummary(methodName, testSummary) {
271
- if (!_.isPlainObject(testSummary)) {
272
- throw this._runtimeErrorComposer.invalidTestSummary(methodName, testSummary);
273
- }
274
-
275
- switch (testSummary.status) {
276
- case 'running':
277
- case 'passed':
278
- case 'failed':
279
- break;
280
- default:
281
- throw this._runtimeErrorComposer.invalidTestSummaryStatus(methodName, testSummary);
282
- }
283
- }
284
-
285
- async _dumpUnhandledErrorsIfAny({ testName, pendingRequests }) {
286
- if (pendingRequests) {
287
- this._client.dumpPendingRequests({ testName });
288
- }
289
- }
290
-
291
- _onEmitError({ error, eventName, eventObj }) {
292
- log.error(
293
- { event: 'EMIT_ERROR', fn: eventName },
294
- `Caught an exception in: emitter.emit("${eventName}", ${JSON.stringify(eventObj)})\n\n`,
295
- error
296
- );
297
- }
298
-
299
- static async globalInit(configs) {
300
- const handler = await environmentFactory.createGlobalLifecycleHandler(configs.deviceConfig);
301
- if (handler) {
302
- await handler.globalInit();
303
- }
304
- }
305
-
306
- static async globalCleanup(configs) {
307
- const handler = await environmentFactory.createGlobalLifecycleHandler(configs.deviceConfig);
308
- if (handler) {
309
- await handler.globalCleanup();
310
- }
311
- }
312
- }
313
-
314
- Detox.none = new MissingDetox();
315
- Detox.global = global;
316
-
317
- module.exports = Detox;
@@ -1,13 +0,0 @@
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
- });
@@ -1,140 +0,0 @@
1
- // @ts-nocheck
2
- const funpermaproxy = require('funpermaproxy');
3
-
4
- const Detox = require('./Detox');
5
- const DetoxConstants = require('./DetoxConstants');
6
- const configuration = require('./configuration');
7
- const logger = require('./utils/logger');
8
- const log = logger.child({ __filename });
9
- const { trace, traceCall } = require('./utils/trace');
10
-
11
- const _detox = Symbol('detox');
12
- const _shouldLogInitError = Symbol('shouldLogInitError');
13
-
14
- class DetoxExportWrapper {
15
- constructor() {
16
- this[_detox] = Detox.none;
17
- this[_shouldLogInitError] = true;
18
-
19
- this.init = this.init.bind(this);
20
- this.cleanup = this.cleanup.bind(this);
21
-
22
- this.DetoxConstants = DetoxConstants;
23
-
24
- this._definePassthroughMethod('beforeEach');
25
- this._definePassthroughMethod('afterEach');
26
- this._definePassthroughMethod('suiteStart');
27
- this._definePassthroughMethod('suiteEnd');
28
-
29
- this._definePassthroughMethod('element');
30
- this._definePassthroughMethod('expect');
31
- this._definePassthroughMethod('waitFor');
32
-
33
- this._defineProxy('by');
34
- this._defineProxy('device');
35
- this._defineProxy('web');
36
-
37
- this.trace = trace;
38
- this.traceCall = traceCall;
39
- }
40
-
41
- async init(configOverride, userParams) {
42
- let configError, exposeGlobals, resolvedConfig;
43
-
44
- trace.init();
45
- logger.reinitialize(Detox.global);
46
-
47
- try {
48
- resolvedConfig = await configuration.composeDetoxConfig({
49
- override: configOverride,
50
- userParams,
51
- });
52
-
53
- exposeGlobals = resolvedConfig.behaviorConfig.init.exposeGlobals;
54
- } catch (err) {
55
- configError = err;
56
- exposeGlobals = true;
57
- }
58
-
59
- try {
60
- if (exposeGlobals) {
61
- Detox.none.initContext(Detox.global);
62
- }
63
-
64
- if (configError) {
65
- throw configError;
66
- }
67
-
68
- this[_detox] = new Detox(resolvedConfig);
69
- await traceCall('detoxInit', this[_detox].init());
70
- Detox.none.setError(null);
71
-
72
- return this[_detox];
73
- } catch (err) {
74
- if (this[_shouldLogInitError]) {
75
- log.error({ event: 'DETOX_INIT_ERROR' }, '\n', err);
76
- }
77
-
78
- Detox.none.setError(err);
79
- throw err;
80
- }
81
- }
82
-
83
- async cleanup() {
84
- Detox.none.cleanupContext(Detox.global);
85
-
86
- if (this[_detox] !== Detox.none) {
87
- await this[_detox].cleanup();
88
- this[_detox] = Detox.none;
89
- }
90
- }
91
-
92
- _definePassthroughMethod(name) {
93
- this[name] = (...args) => {
94
- return this[_detox][name](...args);
95
- };
96
- }
97
-
98
- _defineProxy(name) {
99
- this[name] = funpermaproxy(() => this[_detox][name]);
100
- }
101
-
102
- /** Use for test runners with sandboxed global */
103
- _setGlobal(global) {
104
- Detox.global = global;
105
- return this;
106
- }
107
-
108
- /** @internal */
109
- _suppressLoggingInitErrors() {
110
- this[_shouldLogInitError] = false;
111
- return this;
112
- }
113
- }
114
-
115
- DetoxExportWrapper.prototype.hook = configuration.hook;
116
-
117
- DetoxExportWrapper.prototype.globalInit = async function() {
118
- try {
119
- // TODO This can only work in Jest, where config info etc. is available globally through env vars rather
120
- // than argv (e.g. in Mocha) -- which we don't have available here.
121
- // We will resolve this, ultimately, in https://github.com/wix/Detox/issues/2894 (DAS project), where
122
- // this whole hack would be removed altogether.
123
- const configs = await configuration.composeDetoxConfig({});
124
- await Detox.globalInit(configs);
125
- } catch (error) {
126
- log.warn({ event: 'GLOBAL_INIT' }, 'An error occurred!');
127
- throw error;
128
- }
129
- };
130
-
131
- DetoxExportWrapper.prototype.globalCleanup = async function() {
132
- try {
133
- const configs = await configuration.composeDetoxConfig({});
134
- await Detox.globalCleanup(configs);
135
- } catch (error) {
136
- log.warn({ event: 'GLOBAL_CLEANUP' }, 'An error occurred!', error);
137
- }
138
- };
139
-
140
- module.exports = DetoxExportWrapper;