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
package/index.js ADDED
@@ -0,0 +1 @@
1
+ module.exports = require('./src/realms');
package/internals.d.ts ADDED
@@ -0,0 +1,298 @@
1
+ /// <reference types="node" />
2
+ /// <reference path="index.d.ts"/>
3
+
4
+ declare global {
5
+ namespace DetoxInternals {
6
+ type DetoxStatus = 'inactive' | 'init' | 'active' | 'cleanup';
7
+
8
+ type Facade = {
9
+ //#region Initialization
10
+ /**
11
+ * Use with a caution, when you still have no config, yet need to avoid {@link Facade#init}
12
+ */
13
+ resolveConfig(options?: Partial<DetoxInitOptions>): Promise<RuntimeConfig>;
14
+
15
+ /**
16
+ * Returns one of statuses depending on what’s going with the current Detox context:
17
+ *
18
+ * `inactive` – before `init()` and after `cleanup()` is called.
19
+ * `init` – while `init()` is executing.
20
+ * `active` – after `init()` and before `cleanup()` is called.
21
+ * `cleanup` – while `cleanup()` is executing.
22
+ */
23
+ getStatus(): DetoxStatus;
24
+
25
+ /**
26
+ * Starts a new Detox test session with the provided configuration.
27
+ * See {@link https://wix.github.io/Detox/docs/api/internals} for more details.
28
+ */
29
+ init(options?: Partial<DetoxInitOptions>): Promise<void>;
30
+
31
+ /**
32
+ * This is the phase where Detox loads its expectation library and boots a device.
33
+ * You don't need to call it separately unless you use `init({ workerId: null })` override.
34
+ */
35
+ installWorker(options?: Partial<DetoxInstallWorkerOptions>): Promise<void>;
36
+
37
+ /**
38
+ * Deallocates the device.
39
+ * Most Client API (device, by, element, expect) will stop working, except for the logger.
40
+ */
41
+ uninstallWorker(): Promise<void>;
42
+
43
+ /**
44
+ * This method should be called when the main or child process is about to exit.
45
+ * See {@link https://wix.github.io/Detox/docs/api/internals} for more details.
46
+ */
47
+ cleanup(): Promise<void>;
48
+ //#endregion
49
+
50
+ //#region Lifecycle
51
+ /**
52
+ * Reports that the test runner started executing a test suite, e.g. a `beforeAll` hook or a first test.
53
+ */
54
+ onRunDescribeStart(event: {
55
+ /** Test suite name */
56
+ name: string;
57
+ }): Promise<void>;
58
+ /**
59
+ * Reports that the test runner started executing a specific test.
60
+ */
61
+ onTestStart(event: {
62
+ /** Test name */
63
+ title: string;
64
+ /** Test name including the ancestor suite titles */
65
+ fullName: string;
66
+ /**
67
+ * N-th time this test is running, if there is a retry mechanism.
68
+ *
69
+ * @default 1
70
+ */
71
+ invocations?: number;
72
+ status: 'running';
73
+ }): Promise<void>;
74
+ /**
75
+ * Reports about an error in the midst of `beforeAll`, `beforeEach`, `afterEach`, `afterAll` or any other hook.
76
+ */
77
+ onHookFailure(event: {
78
+ error: Error | string;
79
+ /**
80
+ * @example 'beforeAll'
81
+ * @example 'afterEach'
82
+ */
83
+ hook: string;
84
+ }): Promise<void>;
85
+ /**
86
+ * Reports about an error in the midst of a test function, `test` or `it`.
87
+ */
88
+ onTestFnFailure(event: {
89
+ error: Error | string;
90
+ }): Promise<void>;
91
+ /**
92
+ * Reports the final status of the test, `passed` or `failed`.
93
+ */
94
+ onTestDone(event: {
95
+ /** Test name */
96
+ title: string;
97
+ /** Test name including the ancestor suite titles */
98
+ fullName: string;
99
+ /**
100
+ * N-th time this test is running, if there is a retry mechanism.
101
+ *
102
+ * @default 1
103
+ */
104
+ invocations?: number;
105
+ status: 'passed' | 'failed';
106
+ /** Whether a timeout was the reason for why the test failed. */
107
+ timedOut?: boolean;
108
+ }): Promise<void>;
109
+ /**
110
+ * Reports that the test runner has finished executing a test suite, e.g. all the `afterAll` hooks have been executed or the last test has finished running.
111
+ */
112
+ onRunDescribeFinish(event: {
113
+ /** Test suite name */
114
+ name: string;
115
+ }): Promise<void>;
116
+
117
+ /**
118
+ * Reports to Detox CLI about passed and failed test files.
119
+ * The failed test files might be re-run again if
120
+ * {@link Detox.DetoxTestRunnerConfig#retries} is set to a non-zero.
121
+ *
122
+ * @param testResults - reports about test files
123
+ */
124
+ reportTestResults(testResults: DetoxTestFileReport[]): Promise<void>;
125
+ //#endregion
126
+
127
+ readonly config: RuntimeConfig;
128
+ readonly log: Detox.Logger;
129
+ readonly session: SessionState;
130
+ readonly tracing: {
131
+ /**
132
+ * Creates a readable stream of the currently recorded events in Chrome Trace Event format.
133
+ *
134
+ * @see {@link https://docs.google.com/document/d/1CvAClvFfyA5R-PhYUmn5OOQtYMH4h6I0nSsKchNAySU}
135
+ * @see {import('trace-event-lib').DurationBeginEvent}
136
+ * @see {import('trace-event-lib').DurationEndEvent}
137
+ * @see {import('trace-event-lib').InstantEvent}
138
+ */
139
+ createEventStream(): NodeJS.ReadableStream;
140
+ };
141
+
142
+ /**
143
+ * Not documented on purpose.
144
+ * Provides direct access to the object which holds the device driver, websocket client, matchers, expectations, etc.
145
+ */
146
+ readonly worker: Worker;
147
+ }
148
+
149
+ interface Worker extends Detox.DetoxExportWrapper {
150
+ readonly id: string;
151
+ }
152
+
153
+ type DetoxInitOptions = {
154
+ cwd: string;
155
+ /**
156
+ * @internal
157
+ */
158
+ argv: Record<string, unknown>;
159
+ testRunnerArgv: Record<string, unknown>;
160
+ override: Partial<Detox.DetoxConfig>;
161
+ /** @inheritDoc */
162
+ global: NodeJS.Global | {};
163
+ /**
164
+ * Worker ID. Used to distinguish allocated workers in parallel test execution environment.
165
+ *
166
+ * If explicitly set to null, tells {@link Facade#init} to skip {@link Facade#installWorker} call.
167
+ * Useful for complex test runner integrations, where you have to install the worker via a separate call,
168
+ * when the environment is ready for that.
169
+ *
170
+ * @default 'worker'
171
+ */
172
+ workerId: string | null;
173
+ };
174
+
175
+ type DetoxInstallWorkerOptions = {
176
+ /**
177
+ * Used for integration with sandboxed test environments.
178
+ * {@link DetoxInternals.Facade#setup} might override {@link Console} methods
179
+ * to integrate it with Detox loggeing subsystem.
180
+ */
181
+ global: NodeJS.Global | {};
182
+ /**
183
+ * Worker ID. Used to distinguish allocated workers in parallel test execution environment.
184
+ *
185
+ * @default 'worker'
186
+ */
187
+ workerId: string;
188
+ };
189
+
190
+ type DetoxTestFileReport = {
191
+ /**
192
+ * Global or relative path to the failed test file.
193
+ */
194
+ testFilePath: string;
195
+ /**
196
+ * Whether the test passed or not.
197
+ */
198
+ success: boolean;
199
+ /**
200
+ * Top-level error if the entire test file failed.
201
+ */
202
+ testExecError?: { name?: string; message: string; stack?: string; };
203
+ /**
204
+ * If the test failed, it should tell whether the failure is permanent.
205
+ * Permanent failure means that the test file should not be re-run.
206
+ *
207
+ * @default false
208
+ * @see {Detox.DetoxTestRunnerConfig#retries}
209
+ */
210
+ isPermanentFailure?: boolean;
211
+ };
212
+
213
+ type SessionState = Readonly<{
214
+ /**
215
+ * Randomly generated ID for the entire Detox test session, including retries.
216
+ */
217
+ id: string;
218
+ /**
219
+ * Results of test file executions. Primarily used for Detox CLI retry mechanism.
220
+ */
221
+ testResults: DetoxTestFileReport[];
222
+ /**
223
+ * Retry index of the test session: 0..retriesCount.
224
+ */
225
+ testSessionIndex: number;
226
+ /**
227
+ * Count of Detox contexts with a worker installed.
228
+ * Oversimplified, it reflects the count of allocated devices in the current test session.
229
+ *
230
+ * @see {Facade#init}
231
+ * @see {Facade#installWorker}
232
+ */
233
+ workersCount: number;
234
+ }>;
235
+
236
+ type RuntimeConfig = Readonly<{
237
+ configurationName: string;
238
+
239
+ /**
240
+ * Dictionary of app configurations,
241
+ * where the keys are defined by {@link Detox.DetoxAppConfig#name}
242
+ * or equal to "default" if the name is not configured.
243
+ */
244
+ apps: Record<string, Readonly<Detox.DetoxAppConfig>>;
245
+ artifacts: Readonly<RuntimeArtifactsConfig>;
246
+ behavior: Readonly<Detox.DetoxBehaviorConfig>;
247
+ cli: Readonly<CLIConfig>;
248
+ device: Readonly<Detox.DetoxDeviceConfig>;
249
+ logger: Readonly<Detox.DetoxLoggerConfig>;
250
+ testRunner: Readonly<Detox.DetoxTestRunnerConfig>;
251
+ session: Readonly<Detox.DetoxSessionConfig>;
252
+ }>;
253
+
254
+ type RuntimeArtifactsConfig = {
255
+ rootDir: string;
256
+ pathBuilder: string;
257
+ plugins: Readonly<{
258
+ log: Readonly<Detox.DetoxLogArtifactsPluginConfig>;
259
+ screenshot: Readonly<Detox.DetoxScreenshotArtifactsPluginConfig>;
260
+ video: Readonly<Detox.DetoxVideoArtifactsPluginConfig>;
261
+ instruments: Readonly<Detox.DetoxInstrumentsArtifactsPluginConfig>;
262
+ uiHierarchy: Readonly<Detox.DetoxUIHierarchyArtifactsPluginConfig>;
263
+ [pluginId: string]: unknown;
264
+ }>;
265
+ };
266
+
267
+ type CLIConfig = Readonly<Partial<{
268
+ appLaunchArgs: string;
269
+ artifactsLocation: string;
270
+ captureViewHierarchy: string;
271
+ cleanup: boolean;
272
+ configPath: string;
273
+ configuration: string;
274
+ debugSynchronization: number;
275
+ deviceBootArgs: string;
276
+ deviceName: string;
277
+ forceAdbInstall: boolean;
278
+ gpu: string;
279
+ inspectBrk: boolean;
280
+ headless: boolean;
281
+ jestReportSpecs: boolean;
282
+ keepLockFile: boolean;
283
+ loglevel: string;
284
+ readonlyEmu: boolean;
285
+ recordLogs: string;
286
+ recordPerformance: string;
287
+ recordVideos: string;
288
+ retries: number;
289
+ reuse: string;
290
+ takeScreenshots: string;
291
+ useCustomLogger: string;
292
+ }>>;
293
+ }
294
+ }
295
+
296
+ declare const detox: DetoxInternals.Facade;
297
+ export = detox;
298
+
package/internals.js ADDED
@@ -0,0 +1,4 @@
1
+ const realm = require('./src/realms');
2
+ const DetoxInternalsFacade = require('./src/realms/DetoxInternalsFacade');
3
+
4
+ module.exports = new DetoxInternalsFacade(realm);
@@ -2,7 +2,7 @@ const cp = require('child_process');
2
2
  const os = require('os');
3
3
  const path = require('path');
4
4
 
5
- const log = require('../src/utils/logger').child({ __filename });
5
+ const detox = require('../internals');
6
6
 
7
7
  module.exports.command = 'build-framework-cache';
8
8
  module.exports.desc = 'Builds a cached Detox framework for the current environment in ~/Library/Detox. The cached framework is unique for each combination of Xcode and Detox version. (macOS only)';
@@ -11,6 +11,6 @@ module.exports.handler = async function buildFrameworkCache() {
11
11
  if (os.platform() === 'darwin') {
12
12
  cp.execSync(path.join(__dirname, '../scripts/build_framework.ios.sh'), { stdio: 'inherit' });
13
13
  } else {
14
- log.info(`The command is supported only on macOS, skipping the execution.`);
14
+ detox.log.info(`The command is supported only on macOS, skipping the execution.`);
15
15
  }
16
16
  };
@@ -4,8 +4,7 @@ const fs = require('fs');
4
4
 
5
5
  const _ = require('lodash');
6
6
 
7
- const { composeDetoxConfig } = require('../src/configuration');
8
- const log = require('../src/utils/logger').child({ __filename });
7
+ const detox = require('../internals');
9
8
 
10
9
  module.exports.command = 'build';
11
10
  module.exports.desc = "Runs the user-provided build command, as defined in the 'build' property of the specified configuration.";
@@ -38,27 +37,27 @@ module.exports.builder = {
38
37
  };
39
38
 
40
39
  module.exports.handler = async function build(argv) {
41
- const { errorComposer, appsConfig } = await composeDetoxConfig({ argv });
40
+ const { apps: appsConfig, errorComposer } = await detox.resolveConfig({ argv });
42
41
  const apps = _.entries(appsConfig);
43
42
 
44
43
  for (const [appName, app] of apps) {
45
44
  const buildScript = app.build;
46
45
 
47
46
  if (argv['if-missing'] && app.binaryPath && fs.existsSync(app.binaryPath)) {
48
- log.info(`Skipping build for "${appName}" app...`);
47
+ detox.log.info(`Skipping build for "${appName}" app...`);
49
48
  continue;
50
49
  }
51
50
 
52
51
  if (buildScript) {
53
52
  try {
54
53
  if (apps.length > 1) {
55
- log.info(`Building "${appName}" app...`);
54
+ detox.log.info(`Building "${appName}" app...`);
56
55
  }
57
56
 
58
- log.info(buildScript);
57
+ detox.log.info(buildScript);
59
58
  cp.execSync(buildScript, { stdio: 'inherit' });
60
59
  } catch (e) {
61
- log.warn("\n\nImportant: 'detox build' is a convenience shortcut for calling your own build command, as provided in the config file.\nFailures in this build command are not the responsibility of Detox. You are responsible for maintaining this command.\n");
60
+ detox.log.warn("\n\nImportant: 'detox build' is a convenience shortcut for calling your own build command, as provided in the config file.\nFailures in this build command are not the responsibility of Detox. You are responsible for maintaining this command.\n");
62
61
  throw e;
63
62
  }
64
63
  } else if (!argv.silent) {
@@ -66,7 +65,7 @@ module.exports.handler = async function build(argv) {
66
65
  }
67
66
 
68
67
  if (app.binaryPath && !fs.existsSync(app.binaryPath)) {
69
- log.warn('\nImportant: after running the build command, Detox could not find your app at the given binary path:\n\t' + app.binaryPath + "\nMake sure it is correct, otherwise you'll get an error on an attempt to install your app.\n");
68
+ detox.log.warn('After running the build command, Detox could not find your app at the given binary path:\n\t' + app.binaryPath + "\nMake sure it is correct, otherwise you'll get an error on an attempt to install your app.\n");
70
69
  }
71
70
  }
72
71
  };
@@ -1,51 +1,57 @@
1
- // @ts-nocheck
2
- jest.mock('child_process');
3
- jest.mock('../src/utils/logger');
4
- jest.mock('../src/configuration');
5
-
6
1
  const tempfile = require('tempfile');
7
2
 
8
- const DetoxConfigErrorComposer = require('../src/errors/DetoxConfigErrorComposer');
9
-
10
3
  describe('build', () => {
11
- let log, execSync, composeDetoxConfig, detoxConfig;
4
+ let execSync, detox, callCli;
12
5
 
13
6
  beforeEach(() => {
14
- detoxConfig = {
15
- appsConfig: {},
16
- artifactsConfig: {},
17
- behaviorConfig: {},
18
- deviceConfig: {},
19
- sessionConfig: {},
20
- errorComposer: new DetoxConfigErrorComposer(),
21
- };
22
-
23
- log = require('../src/utils/logger');
7
+ // @ts-ignore
8
+ callCli = global.callCli;
9
+ jest.mock('child_process');
24
10
  execSync = require('child_process').execSync;
25
- composeDetoxConfig = require('../src/configuration').composeDetoxConfig;
26
- composeDetoxConfig.mockReturnValue(Promise.resolve(detoxConfig));
11
+
12
+ jest.mock('../src/utils/logger');
13
+ jest.mock('../internals', () => {
14
+ const DetoxConfigErrorComposer = require('../src/errors/DetoxConfigErrorComposer');
15
+
16
+ const config = {
17
+ apps: {},
18
+ artifacts: {},
19
+ behavior: {},
20
+ errorComposer: new DetoxConfigErrorComposer(),
21
+ device: {},
22
+ session: {}
23
+ };
24
+
25
+ return ({
26
+ config,
27
+ resolveConfig: jest.fn().mockResolvedValue(config),
28
+ log: require('../src/utils/logger')
29
+ });
30
+ });
31
+
32
+ detox = require('../internals');
27
33
  });
28
34
 
29
- it('passes argv to composeConfig', async () => {
35
+ it('passes argv to resolveConfig', async () => {
30
36
  await callCli('./build', 'build -C /etc/.detoxrc.js -c myconf').catch(() => {});
31
37
 
32
- expect(composeDetoxConfig).toHaveBeenCalledWith({
38
+ expect(detox.resolveConfig).toHaveBeenCalledWith({
33
39
  argv: expect.objectContaining({
34
- 'config-path': '/etc/.detoxrc.js',
35
- 'configuration': 'myconf',
40
+ 'C': '/etc/.detoxrc.js',
41
+ 'c': 'myconf',
36
42
  }),
37
43
  });
38
44
  });
39
45
 
40
46
  it('runs the build script from the composed device config', async () => {
41
- detoxConfig.appsConfig.default = { build: 'yet another command' };
47
+ detox.config.apps.default = { build: 'yet another command' };
42
48
 
43
49
  await callCli('./build', 'build');
44
50
  expect(execSync).toHaveBeenCalledWith('yet another command', expect.anything());
45
51
  });
46
52
 
47
53
  it('skips building the app if the binary exists and --if-missing flag is set', async () => {
48
- detoxConfig.appsConfig.default = { build: 'yet another command', binaryPath: __filename };
54
+ detox.config.apps.default = { build: 'yet another command', binaryPath: __filename };
49
55
 
50
56
  await callCli('./build', 'build -i');
51
57
  expect(execSync).not.toHaveBeenCalled();
@@ -53,46 +59,46 @@ describe('build', () => {
53
59
  await callCli('./build', 'build --if-missing');
54
60
  expect(execSync).not.toHaveBeenCalled();
55
61
 
56
- expect(log.info).toHaveBeenCalledWith('Skipping build for "default" app...');
62
+ expect(detox.log.info).toHaveBeenCalledWith('Skipping build for "default" app...');
57
63
  });
58
64
 
59
65
  it('fails with an error if a build script has not been found', async () => {
60
- detoxConfig.appsConfig.default = {};
66
+ detox.config.apps.default = {};
61
67
  await expect(callCli('./build', 'build')).rejects.toThrowError(/Failed to build/);
62
68
  });
63
69
 
64
70
  it('should ignore missing build command with -s, --silent flag', async () => {
65
- detoxConfig.appsConfig.default = {};
71
+ detox.config.apps.default = {};
66
72
  await expect(callCli('./build', 'build -s')).resolves.not.toThrowError();
67
- expect(log.warn).not.toHaveBeenCalled();
73
+ expect(detox.log.warn).not.toHaveBeenCalled();
68
74
  });
69
75
 
70
76
  it('should print a warning upon user build script failure', async () => {
71
- detoxConfig.appsConfig.default = { build: 'a command' };
77
+ detox.config.apps.default = { build: 'a command' };
72
78
  execSync.mockImplementation(() => { throw new Error('Build failure'); });
73
79
  await expect(callCli('./build', 'build')).rejects.toThrowError(/Build failure/);
74
- expect(log.warn).toHaveBeenCalledWith(expect.stringContaining('You are responsible'));
80
+ expect(detox.log.warn).toHaveBeenCalledWith(expect.stringContaining('You are responsible'));
75
81
  });
76
82
 
77
83
  it('should print a warning if app is not found at binary path', async () => {
78
- detoxConfig.appsConfig.default = { binaryPath: tempfile() };
84
+ detox.config.apps.default = { binaryPath: tempfile() };
79
85
  await expect(callCli('./build', 'build -s')).resolves.not.toThrowError();
80
- expect(log.warn).toHaveBeenCalledWith(expect.stringContaining('could not find your app at the given binary path'));
86
+ expect(detox.log.warn).toHaveBeenCalledWith(expect.stringContaining('could not find your app at the given binary path'));
81
87
  });
82
88
 
83
89
  it('should print extra message with the app name before building (in a multi-app configuration)', async () => {
84
- detoxConfig.appsConfig.app1 = { binaryPath: tempfile(), build: ':' };
85
- detoxConfig.appsConfig.app2 = { binaryPath: tempfile(), build: ':' };
90
+ detox.config.apps.app1 = { binaryPath: tempfile(), build: ':' };
91
+ detox.config.apps.app2 = { binaryPath: tempfile(), build: ':' };
86
92
 
87
93
  await expect(callCli('./build', 'build -s')).resolves.not.toThrowError();
88
- expect(log.info).toHaveBeenCalledWith(expect.stringContaining('app1'));
89
- expect(log.info).toHaveBeenCalledWith(expect.stringContaining('app2'));
94
+ expect(detox.log.info).toHaveBeenCalledWith(expect.stringContaining('app1'));
95
+ expect(detox.log.info).toHaveBeenCalledWith(expect.stringContaining('app2'));
90
96
  });
91
97
 
92
98
  it('should not print that extra message when the app is single', async () => {
93
- detoxConfig.appsConfig.default = { binaryPath: tempfile(), build: ':' };
99
+ detox.config.apps.default = { binaryPath: tempfile(), build: ':' };
94
100
 
95
101
  await expect(callCli('./build', 'build -s')).resolves.not.toThrowError();
96
- expect(log.info).not.toHaveBeenCalledWith(expect.stringContaining('default'));
102
+ expect(detox.log.info).not.toHaveBeenCalledWith(expect.stringContaining('default'));
97
103
  });
98
104
  });
@@ -3,7 +3,7 @@ const path = require('path');
3
3
 
4
4
  const fs = require('fs-extra');
5
5
 
6
- const log = require('../src/utils/logger').child({ __filename });
6
+ const detox = require('../internals');
7
7
 
8
8
  module.exports.command = 'clean-framework-cache';
9
9
  module.exports.desc = "Deletes all Detox cached frameworks from ~/Library/Detox. Cached framework can be rebuilt using the 'build-framework-cache' command. (macOS only)";
@@ -11,9 +11,9 @@ module.exports.desc = "Deletes all Detox cached frameworks from ~/Library/Detox.
11
11
  module.exports.handler = async function cleanFrameworkCache() {
12
12
  if (os.platform() === 'darwin') {
13
13
  const frameworkPath = path.join(os.homedir(), '/Library/Detox');
14
- log.info(`Removing framework binaries from ${frameworkPath}`);
14
+ detox.log.info(`Removing framework binaries from ${frameworkPath}`);
15
15
  await fs.remove(frameworkPath);
16
16
  } else {
17
- log.info(`The command is supported only on macOS, skipping the execution.`);
17
+ detox.log.info(`The command is supported only on macOS, skipping the execution.`);
18
18
  }
19
19
  };
package/local-cli/cli.js CHANGED
@@ -1,9 +1,11 @@
1
1
  #!/usr/bin/env node
2
- global.DETOX_CLI = true;
2
+ const fs = require('fs');
3
+
4
+ const _ = require('lodash');
3
5
  const yargs = require('yargs');
4
6
 
7
+ const logger = require('../internals').log.child({ cat: 'cli' });
5
8
  const DetoxError = require('../src/errors/DetoxError');
6
- const logger = require('../src/utils/logger').child({ __filename });
7
9
 
8
10
  yargs
9
11
  .scriptName('detox')
@@ -26,12 +28,11 @@ yargs
26
28
  .wrap(yargs.terminalWidth() * 0.9)
27
29
  .fail(function(msg, err, program) {
28
30
  if (err) {
29
- const lines = DetoxError.format(err).split('\n');
30
- for (const line of lines) {
31
- logger.error(line);
32
- }
31
+ logger.error(DetoxError.format(err));
33
32
  // eslint-disable-next-line no-console
34
- console.error('');
33
+ process.stderr.write('\n');
34
+ // @ts-ignore
35
+ _.attempt(() => fs.unlinkSync(logger.file));
35
36
  // eslint-disable-next-line no-process-exit
36
37
  process.exit(1);
37
38
  }