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

Sign up to get free protection for your applications and to get access to all the features.
Files changed (192) hide show
  1. package/Detox-android/com/wix/detox/{20.0.3-breaking.new-global-lifecycle.0/detox-20.0.3-breaking.new-global-lifecycle.0-javadoc.jar → 20.0.3/detox-20.0.3-javadoc.jar} +0 -0
  2. package/Detox-android/com/wix/detox/20.0.3/detox-20.0.3-javadoc.jar.md5 +1 -0
  3. package/Detox-android/com/wix/detox/20.0.3/detox-20.0.3-javadoc.jar.sha1 +1 -0
  4. package/Detox-android/com/wix/detox/20.0.3/detox-20.0.3-javadoc.jar.sha256 +1 -0
  5. package/Detox-android/com/wix/detox/20.0.3/detox-20.0.3-javadoc.jar.sha512 +1 -0
  6. package/Detox-android/com/wix/detox/{20.0.3-breaking.new-global-lifecycle.0/detox-20.0.3-breaking.new-global-lifecycle.0-sources.jar → 20.0.3/detox-20.0.3-sources.jar} +0 -0
  7. package/Detox-android/com/wix/detox/20.0.3/detox-20.0.3-sources.jar.md5 +1 -0
  8. package/Detox-android/com/wix/detox/20.0.3/detox-20.0.3-sources.jar.sha1 +1 -0
  9. package/Detox-android/com/wix/detox/20.0.3/detox-20.0.3-sources.jar.sha256 +1 -0
  10. package/Detox-android/com/wix/detox/20.0.3/detox-20.0.3-sources.jar.sha512 +1 -0
  11. package/Detox-android/com/wix/detox/20.0.3/detox-20.0.3.aar +0 -0
  12. package/Detox-android/com/wix/detox/20.0.3/detox-20.0.3.aar.md5 +1 -0
  13. package/Detox-android/com/wix/detox/20.0.3/detox-20.0.3.aar.sha1 +1 -0
  14. package/Detox-android/com/wix/detox/20.0.3/detox-20.0.3.aar.sha256 +1 -0
  15. package/Detox-android/com/wix/detox/20.0.3/detox-20.0.3.aar.sha512 +1 -0
  16. package/Detox-android/com/wix/detox/{20.0.3-breaking.new-global-lifecycle.0/detox-20.0.3-breaking.new-global-lifecycle.0.pom → 20.0.3/detox-20.0.3.pom} +1 -7
  17. package/Detox-android/com/wix/detox/20.0.3/detox-20.0.3.pom.md5 +1 -0
  18. package/Detox-android/com/wix/detox/20.0.3/detox-20.0.3.pom.sha1 +1 -0
  19. package/Detox-android/com/wix/detox/20.0.3/detox-20.0.3.pom.sha256 +1 -0
  20. package/Detox-android/com/wix/detox/20.0.3/detox-20.0.3.pom.sha512 +1 -0
  21. package/Detox-android/com/wix/detox/maven-metadata.xml +4 -4
  22. package/Detox-android/com/wix/detox/maven-metadata.xml.md5 +1 -1
  23. package/Detox-android/com/wix/detox/maven-metadata.xml.sha1 +1 -1
  24. package/Detox-android/com/wix/detox/maven-metadata.xml.sha256 +1 -1
  25. package/Detox-android/com/wix/detox/maven-metadata.xml.sha512 +1 -1
  26. package/Detox-ios-src.tbz +0 -0
  27. package/Detox-ios.tbz +0 -0
  28. package/README.md +1 -1
  29. package/android/build.gradle +12 -7
  30. package/android/detox/build.gradle +13 -9
  31. package/android/detox/proguard-rules-app.pro +6 -0
  32. package/android/detox/proguard-rules.pro +3 -0
  33. package/android/detox/publishing.gradle +27 -27
  34. package/android/detox/src/full/java/com/wix/detox/DetoxCrashHandler.kt +1 -1
  35. package/android/detox/src/full/java/com/wix/detox/LaunchArgs.java +9 -0
  36. package/android/detox/src/full/java/com/wix/detox/TestEngineFacade.kt +1 -1
  37. package/android/detox/src/full/java/com/wix/detox/reactnative/ReactNativeExtension.kt +15 -2
  38. package/android/detox/src/full/java/com/wix/detox/reactnative/ReactNativeIdlingResources.kt +43 -38
  39. package/android/detox/src/full/java/com/wix/detox/reactnative/idlingresources/IdlingResourceDescription.kt +19 -13
  40. package/android/detox/src/full/java/com/wix/detox/reactnative/idlingresources/NetworkIdlingResource.java +33 -30
  41. package/android/detox/src/full/java/com/wix/detox/reactnative/idlingresources/timers/DelegatedIdleInterrogationStrategy.kt +7 -27
  42. package/android/detox/src/full/java/com/wix/detox/reactnative/idlingresources/timers/IdleInterrogationStrategy.kt +1 -11
  43. package/android/detox/src/main/java/com/wix/detox/common/TextFileReader.kt +1 -1
  44. package/android/detox/src/testFull/java/com/wix/detox/espresso/action/DetoxMultiTapSpec.kt +4 -3
  45. package/android/detox/src/testFull/java/com/wix/detox/reactnative/idlingresources/NetworkIdlingResourcesTest.kt +61 -0
  46. package/android/detox/src/testFull/java/com/wix/detox/reactnative/idlingresources/timers/DelegatedIdleInterrogationStrategySpec.kt +3 -11
  47. package/index.d.ts +195 -59
  48. package/internals.d.ts +205 -43
  49. package/local-cli/build.js +1 -1
  50. package/local-cli/cli.js +11 -6
  51. package/local-cli/init.js +61 -21
  52. package/local-cli/rebuild-framework-cache.js +1 -1
  53. package/local-cli/reset-lock-file.js +16 -0
  54. package/local-cli/templates/jest.js +13 -10
  55. package/local-cli/test.js +14 -8
  56. package/local-cli/test.test.js +142 -61
  57. package/local-cli/testCommand/TestRunnerCommand.js +97 -77
  58. package/local-cli/testCommand/TestRunnerError.js +17 -0
  59. package/local-cli/testCommand/TestRunnerError.test.js +25 -0
  60. package/local-cli/testCommand/builder.js +0 -1
  61. package/local-cli/testCommand/middlewares.js +4 -13
  62. package/local-cli/testCommand/warnings.js +0 -3
  63. package/local-cli/utils/jestInternals.js +4 -1
  64. package/package.json +23 -18
  65. package/runners/deprecation.js +42 -44
  66. package/runners/jest/globalSetup.js +1 -1
  67. package/runners/jest/globalTeardown.js +1 -1
  68. package/runners/jest/index.d.ts +60 -0
  69. package/runners/jest/index.js +3 -8
  70. package/runners/jest/index.test.js +13 -0
  71. package/runners/jest/reporters/DetoxReporter.js +33 -2
  72. package/runners/jest/testEnvironment/index.js +119 -69
  73. package/runners/jest/testEnvironment/listeners/DetoxCoreListener.js +93 -46
  74. package/runners/jest/testEnvironment/listeners/DetoxPlatformFilterListener.js +1 -1
  75. package/runners/jest/testEnvironment/listeners/SpecReporter.js +13 -15
  76. package/runners/jest/testEnvironment/listeners/WorkerAssignReporter.js +1 -5
  77. package/runners/jest/testEnvironment/utils/assertJestCircus27.js +17 -3
  78. package/runners/jest/testEnvironment/utils/assertJestCircus27.test.js +0 -1
  79. package/src/DetoxWorker.js +99 -62
  80. package/src/android/core/NativeElement.js +56 -20
  81. package/src/android/core/NativeExpect.js +28 -9
  82. package/src/android/interactions/native.js +25 -18
  83. package/src/artifacts/ArtifactsManager.js +14 -47
  84. package/src/artifacts/instruments/ios/SimulatorInstrumentsRecording.js +3 -3
  85. package/src/artifacts/log/ios/SimulatorLogRecording.js +1 -1
  86. package/src/artifacts/screenshot/SimulatorScreenshotPlugin.js +1 -1
  87. package/src/artifacts/templates/artifact/Artifact.js +1 -1
  88. package/src/artifacts/templates/plugin/ArtifactPlugin.js +1 -1
  89. package/src/artifacts/timeline/TimelineContextTypes.js +7 -0
  90. package/src/artifacts/utils/temporaryPath.js +49 -8
  91. package/src/artifacts/video/SimulatorRecordVideoPlugin.js +1 -1
  92. package/src/client/AsyncWebSocket.js +8 -17
  93. package/src/client/Client.js +19 -2
  94. package/src/client/actions/formatters/sync-resources/NetworkFormatter.js +1 -1
  95. package/src/configuration/collectCliConfig.js +1 -12
  96. package/src/configuration/composeAppsConfig.js +4 -0
  97. package/src/configuration/composeDeviceConfig.js +1 -1
  98. package/src/configuration/composeLoggerConfig.js +19 -10
  99. package/src/configuration/composeRunnerConfig.js +14 -9
  100. package/src/configuration/index.js +5 -1
  101. package/src/configuration/loadExternalConfig.js +1 -1
  102. package/src/devices/allocation/DeviceAllocator.js +3 -2
  103. package/src/devices/allocation/drivers/android/emulator/AVDValidator.js +5 -5
  104. package/src/devices/allocation/drivers/android/emulator/EmulatorAllocDriver.js +4 -3
  105. package/src/devices/allocation/drivers/android/emulator/EmulatorAllocationHelper.js +1 -1
  106. package/src/devices/allocation/drivers/android/emulator/EmulatorLauncher.js +6 -5
  107. package/src/devices/allocation/drivers/android/emulator/EmulatorVersionResolver.js +4 -6
  108. package/src/devices/allocation/drivers/android/emulator/launchEmulatorProcess.js +4 -17
  109. package/src/devices/allocation/drivers/android/genycloud/GenyInstanceAllocationHelper.js +1 -1
  110. package/src/devices/common/drivers/android/exec/ADB.js +4 -0
  111. package/src/devices/common/drivers/android/genycloud/services/GenyInstanceNaming.js +3 -3
  112. package/src/devices/common/drivers/android/genycloud/services/GenyRecipesService.js +1 -1
  113. package/src/devices/common/drivers/android/tools/EmulatorTelnet.js +1 -1
  114. package/src/devices/common/drivers/android/tools/FreeDeviceFinder.js +1 -1
  115. package/src/devices/common/drivers/android/tools/MonitoredInstrumentation.js +1 -1
  116. package/src/devices/common/drivers/ios/tools/AppleSimUtils.js +29 -3
  117. package/src/devices/lifecycle/GenyGlobalLifecycleHandler.js +13 -15
  118. package/src/devices/runtime/RuntimeDevice.js +19 -12
  119. package/src/devices/runtime/drivers/DeviceDriverBase.js +1 -1
  120. package/src/devices/runtime/drivers/android/AndroidDriver.js +10 -2
  121. package/src/devices/runtime/drivers/ios/SimulatorDriver.js +1 -1
  122. package/src/errors/DetoxConfigErrorComposer.js +14 -1
  123. package/src/errors/DetoxError.js +5 -1
  124. package/src/ios/expectTwo.js +153 -67
  125. package/src/ipc/IPCClient.js +12 -13
  126. package/src/ipc/IPCServer.js +28 -24
  127. package/src/ipc/{state.js → SessionState.js} +26 -53
  128. package/src/logger/DetoxLogger.js +287 -154
  129. package/src/logger/index.js +5 -0
  130. package/src/logger/utils/BunyanLogger.js +115 -0
  131. package/src/logger/utils/CategoryThreadDispatcher.js +37 -0
  132. package/src/logger/utils/DetoxLogFinalizer.js +162 -0
  133. package/src/logger/utils/MessageStack.js +35 -0
  134. package/src/logger/utils/ThreadDispatcher.js +61 -0
  135. package/src/logger/{customConsoleLogger.js → utils/customConsoleLogger.js} +23 -6
  136. package/src/logger/utils/getMainCategory.js +5 -0
  137. package/src/logger/utils/sanitizeBunyanContext.js +30 -0
  138. package/src/logger/utils/streams/BunyanTransformer.js +72 -0
  139. package/src/logger/utils/streams/ChromeTraceTransformer.js +127 -0
  140. package/src/logger/utils/streams/DetoxJSONLParser.js +31 -0
  141. package/src/logger/utils/streams/JSONLStringer.js +55 -0
  142. package/src/logger/utils/streams/index.js +7 -0
  143. package/src/logger/utils/streams/transformers.js +39 -0
  144. package/src/logger/utils/tracerLegacy.js +37 -0
  145. package/src/realms/DetoxContext.js +79 -65
  146. package/src/realms/DetoxInternalsFacade.js +8 -12
  147. package/src/realms/DetoxPrimaryContext.js +104 -70
  148. package/src/realms/DetoxSecondaryContext.js +29 -32
  149. package/src/server/DetoxConnection.js +18 -23
  150. package/src/server/DetoxServer.js +7 -10
  151. package/src/server/DetoxSession.js +6 -6
  152. package/src/server/DetoxSessionManager.js +1 -1
  153. package/src/server/handlers/RegisteredConnectionHandler.js +1 -2
  154. package/src/symbols.js +16 -22
  155. package/src/utils/Timer.js +55 -38
  156. package/src/utils/argparse.js +11 -0
  157. package/src/utils/childProcess/exec.js +1 -1
  158. package/src/utils/childProcess/spawn.js +1 -1
  159. package/src/utils/errorUtils.js +24 -3
  160. package/src/utils/invocationTraceDescriptions.js +43 -0
  161. package/src/utils/logger.js +1 -1
  162. package/src/utils/pathUtils.js +11 -0
  163. package/src/utils/shellUtils.js +17 -0
  164. package/src/utils/traceInvocationCall.js +21 -0
  165. package/src/utils/traceMethods.js +15 -0
  166. package/Detox-android/com/wix/detox/20.0.3-breaking.new-global-lifecycle.0/detox-20.0.3-breaking.new-global-lifecycle.0-javadoc.jar.md5 +0 -1
  167. package/Detox-android/com/wix/detox/20.0.3-breaking.new-global-lifecycle.0/detox-20.0.3-breaking.new-global-lifecycle.0-javadoc.jar.sha1 +0 -1
  168. package/Detox-android/com/wix/detox/20.0.3-breaking.new-global-lifecycle.0/detox-20.0.3-breaking.new-global-lifecycle.0-javadoc.jar.sha256 +0 -1
  169. package/Detox-android/com/wix/detox/20.0.3-breaking.new-global-lifecycle.0/detox-20.0.3-breaking.new-global-lifecycle.0-javadoc.jar.sha512 +0 -1
  170. package/Detox-android/com/wix/detox/20.0.3-breaking.new-global-lifecycle.0/detox-20.0.3-breaking.new-global-lifecycle.0-sources.jar.md5 +0 -1
  171. package/Detox-android/com/wix/detox/20.0.3-breaking.new-global-lifecycle.0/detox-20.0.3-breaking.new-global-lifecycle.0-sources.jar.sha1 +0 -1
  172. package/Detox-android/com/wix/detox/20.0.3-breaking.new-global-lifecycle.0/detox-20.0.3-breaking.new-global-lifecycle.0-sources.jar.sha256 +0 -1
  173. package/Detox-android/com/wix/detox/20.0.3-breaking.new-global-lifecycle.0/detox-20.0.3-breaking.new-global-lifecycle.0-sources.jar.sha512 +0 -1
  174. package/Detox-android/com/wix/detox/20.0.3-breaking.new-global-lifecycle.0/detox-20.0.3-breaking.new-global-lifecycle.0.aar +0 -0
  175. package/Detox-android/com/wix/detox/20.0.3-breaking.new-global-lifecycle.0/detox-20.0.3-breaking.new-global-lifecycle.0.aar.md5 +0 -1
  176. package/Detox-android/com/wix/detox/20.0.3-breaking.new-global-lifecycle.0/detox-20.0.3-breaking.new-global-lifecycle.0.aar.sha1 +0 -1
  177. package/Detox-android/com/wix/detox/20.0.3-breaking.new-global-lifecycle.0/detox-20.0.3-breaking.new-global-lifecycle.0.aar.sha256 +0 -1
  178. package/Detox-android/com/wix/detox/20.0.3-breaking.new-global-lifecycle.0/detox-20.0.3-breaking.new-global-lifecycle.0.aar.sha512 +0 -1
  179. package/Detox-android/com/wix/detox/20.0.3-breaking.new-global-lifecycle.0/detox-20.0.3-breaking.new-global-lifecycle.0.pom.md5 +0 -1
  180. package/Detox-android/com/wix/detox/20.0.3-breaking.new-global-lifecycle.0/detox-20.0.3-breaking.new-global-lifecycle.0.pom.sha1 +0 -1
  181. package/Detox-android/com/wix/detox/20.0.3-breaking.new-global-lifecycle.0/detox-20.0.3-breaking.new-global-lifecycle.0.pom.sha256 +0 -1
  182. package/Detox-android/com/wix/detox/20.0.3-breaking.new-global-lifecycle.0/detox-20.0.3-breaking.new-global-lifecycle.0.pom.sha512 +0 -1
  183. package/android/detox/src/full/java/com/wix/detox/reactnative/idlingresources/timers/DefaultIdleInterrogationStrategy.kt +0 -84
  184. package/android/detox/src/testFull/java/com/wix/detox/reactnative/idlingresources/timers/DefaultIdleInterrogationStrategySpec.kt +0 -115
  185. package/runners/jest/deprecation.js +0 -25
  186. package/src/configuration/utils/warnings.js +0 -12
  187. package/src/logger/DetoxTraceEventBuilder.js +0 -21
  188. package/src/logger/DetoxTracer.js +0 -133
  189. package/src/logger/TraceThreadDispatcher.js +0 -52
  190. package/src/utils/ChromeTracingExporter.js +0 -54
  191. package/src/utils/streamUtils.js +0 -214
  192. package/src/utils/trace.js +0 -19
package/internals.d.ts CHANGED
@@ -3,84 +3,233 @@
3
3
 
4
4
  declare global {
5
5
  namespace DetoxInternals {
6
+ type DetoxStatus = 'inactive' | 'init' | 'active' | 'cleanup';
7
+
6
8
  type Facade = {
7
- // region Initialization
9
+ //#region Initialization
8
10
  /**
9
- * Use with a caution, when you still have no config, yet need to avoid {@link Facade#globalSetup}
11
+ * Use with a caution, when you still have no config, yet need to avoid {@link Facade#init}
10
12
  */
11
- resolveConfig(options?: Partial<DetoxGlobalSetupOptions>): Promise<RuntimeConfig>;
13
+ resolveConfig(options?: Partial<DetoxInitOptions>): Promise<RuntimeConfig>;
12
14
 
13
15
  /**
14
- * This is the phase where Detox reads its configuration, starts a server.
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.
15
22
  */
16
- globalSetup(options?: Partial<DetoxGlobalSetupOptions>): Promise<void>;
23
+ getStatus(): DetoxStatus;
17
24
 
18
25
  /**
19
- * This is the phase where Detox loads its expection library and starts a device.
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.
20
28
  */
21
- setup(options?: Partial<DetoxConfigurationSetupOptions>): Promise<void>;
29
+ init(options?: Partial<DetoxInitOptions>): Promise<void>;
22
30
 
23
31
  /**
24
- * The teardown phase deallocates the device.
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.
25
34
  */
26
- teardown(): Promise<void>;
35
+ installWorker(options?: Partial<DetoxInstallWorkerOptions>): Promise<void>;
27
36
 
28
37
  /**
29
- * The global cleanup phase should happen after all the tests have finished.
30
- * This is the phase where the Detox server shuts down.
38
+ * Deallocates the device.
39
+ * Most Client API (device, by, element, expect) will stop working, except for the logger.
31
40
  */
32
- globalTeardown(): Promise<void>;
33
- // endregion
41
+ uninstallWorker(): Promise<void>;
34
42
 
35
- // region Lifecycle
36
- onRunStart(event: unknown): Promise<void>;
37
- onRunDescribeStart(event: unknown): Promise<void>;
38
- onTestStart(event: unknown): Promise<void>;
39
- onHookStart(event: unknown): Promise<void>;
40
- onHookFailure(event: unknown): Promise<void>;
41
- onHookSuccess(event: unknown): Promise<void>;
42
- onTestFnStart(event: unknown): Promise<void>;
43
- onTestFnFailure(event: unknown): Promise<void>;
44
- onTestFnSuccess(event: unknown): Promise<void>;
45
- onTestDone(event: unknown): Promise<void>;
46
- onRunDescribeFinish(event: unknown): Promise<void>;
47
- onRunFinish(event: unknown): Promise<void>;
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
48
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>;
49
109
  /**
50
- * Reports to Detox CLI about failed tests that could have been re-run if
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
51
120
  * {@link Detox.DetoxTestRunnerConfig#retries} is set to a non-zero.
52
121
  *
53
- * @param testFilePaths array of failed test files' paths
54
- * @param permanent whether the failure is permanent, and the tests
55
- * should not be re-run.
122
+ * @param testResults - reports about test files
56
123
  */
57
- reportFailedTests(testFilePaths: string[], permanent?: boolean): Promise<void>;
58
- // endregion
124
+ reportTestResults(testResults: DetoxTestFileReport[]): Promise<void>;
125
+ //#endregion
59
126
 
60
127
  readonly config: RuntimeConfig;
61
128
  readonly log: Detox.Logger;
62
- readonly trace: Detox.Tracer;
63
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
+ }
64
148
 
65
- readonly worker: unknown;
149
+ interface Worker extends Detox.DetoxExportWrapper {
150
+ readonly id: string;
66
151
  }
67
152
 
68
- type DetoxGlobalSetupOptions = {
153
+ type DetoxInitOptions = {
69
154
  cwd: string;
155
+ /**
156
+ * @internal
157
+ */
70
158
  argv: Record<string, unknown>;
71
159
  testRunnerArgv: Record<string, unknown>;
72
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;
73
173
  };
74
174
 
75
- type DetoxConfigurationSetupOptions = {
76
- global: NodeJS.Global;
77
- workerId: number;
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;
78
211
  };
79
212
 
80
213
  type SessionState = Readonly<{
81
- failedTestFiles: string[];
82
- testFilesToRetry: string[];
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
+ */
83
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
+ */
84
233
  workersCount: number;
85
234
  }>;
86
235
 
@@ -93,16 +242,29 @@ declare global {
93
242
  * or equal to "default" if the name is not configured.
94
243
  */
95
244
  apps: Record<string, Readonly<Detox.DetoxAppConfig>>;
96
- artifacts: Readonly<Detox.DetoxArtifactsConfig>;
245
+ artifacts: Readonly<RuntimeArtifactsConfig>;
97
246
  behavior: Readonly<Detox.DetoxBehaviorConfig>;
98
- cli: Readonly<DetoxCLIConfig>;
247
+ cli: Readonly<CLIConfig>;
99
248
  device: Readonly<Detox.DetoxDeviceConfig>;
100
249
  logger: Readonly<Detox.DetoxLoggerConfig>;
101
250
  testRunner: Readonly<Detox.DetoxTestRunnerConfig>;
102
251
  session: Readonly<Detox.DetoxSessionConfig>;
103
252
  }>;
104
253
 
105
- type DetoxCLIConfig = Readonly<Partial<{
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<{
106
268
  appLaunchArgs: string;
107
269
  artifactsLocation: string;
108
270
  captureViewHierarchy: string;
@@ -65,7 +65,7 @@ module.exports.handler = async function build(argv) {
65
65
  }
66
66
 
67
67
  if (app.binaryPath && !fs.existsSync(app.binaryPath)) {
68
- detox.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");
69
69
  }
70
70
  }
71
71
  };
package/local-cli/cli.js CHANGED
@@ -1,8 +1,11 @@
1
1
  #!/usr/bin/env node
2
+ const fs = require('fs');
3
+
4
+ const _ = require('lodash');
2
5
  const yargs = require('yargs');
3
6
 
7
+ const logger = require('../internals').log.child({ cat: 'cli' });
4
8
  const DetoxError = require('../src/errors/DetoxError');
5
- const logger = require('../src/utils/logger').child({ __filename });
6
9
 
7
10
  yargs
8
11
  .scriptName('detox')
@@ -25,12 +28,14 @@ yargs
25
28
  .wrap(yargs.terminalWidth() * 0.9)
26
29
  .fail(function(msg, err, program) {
27
30
  if (err) {
28
- const lines = DetoxError.format(err).split('\n');
29
- for (const line of lines) {
30
- logger.error(line);
31
+ const message = DetoxError.format(err);
32
+ if (message) {
33
+ logger.error(message);
34
+ process.stderr.write('\n');
31
35
  }
32
- // eslint-disable-next-line no-console
33
- console.error('');
36
+
37
+ // @ts-ignore
38
+ _.attempt(() => fs.unlinkSync(logger.file));
34
39
  // eslint-disable-next-line no-process-exit
35
40
  process.exit(1);
36
41
  }
package/local-cli/init.js CHANGED
@@ -1,5 +1,6 @@
1
1
  const fs = require('fs');
2
2
  const path = require('path');
3
+ const util = require('util');
3
4
 
4
5
  const detox = require('../internals');
5
6
 
@@ -8,10 +9,11 @@ const jestTemplates = require('./templates/jest');
8
9
  let exitCode = 0;
9
10
 
10
11
  module.exports.command = 'init';
11
- module.exports.desc = 'Scaffold initial E2E test folder structure for Detox';
12
+ module.exports.desc = 'Creates template files to get you started with Detox';
12
13
  module.exports.builder = {};
13
14
 
14
15
  module.exports.handler = async function init() {
16
+ createDetoxConfig();
15
17
  createJestFolderE2E();
16
18
  process.exit(exitCode); // eslint-disable-line
17
19
  };
@@ -51,44 +53,66 @@ function createFile(filename, content) {
51
53
 
52
54
  function createJestFolderE2E() {
53
55
  createFolder('e2e', {
54
- 'config.json': jestTemplates.runnerConfig,
56
+ 'jest.config.js': jestTemplates.runnerConfig,
55
57
  'starter.test.js': jestTemplates.starter,
56
58
  });
59
+ }
57
60
 
58
- createFile('.detoxrc.json', JSON.stringify({
59
- testRunner: {
60
- args: {
61
- config: 'e2e/config.json'
62
- },
63
- },
64
-
65
- ...createDefaultConfigurations(),
66
- }, null, 2));
61
+ function createDetoxConfig() {
62
+ createFile('.detoxrc.js',
63
+ '/** @type {Detox.DetoxConfig} */\n' +
64
+ 'module.exports = ' +
65
+ util.inspect(createDefaultConfigurations(), { compact: false, depth: Infinity }) +
66
+ ';\n'
67
+ );
67
68
  }
68
69
 
70
+ /** @returns {Detox.DetoxConfig} */
69
71
  function createDefaultConfigurations() {
70
72
  return {
71
73
  testRunner: {
72
74
  args: {
73
75
  $0: 'jest',
74
- config: 'e2e/config.json',
76
+ config: 'e2e/jest.config.js',
77
+ },
78
+ jest: {
79
+ setupTimeout: 120000,
75
80
  },
76
81
  },
77
82
  apps: {
78
- ios: {
83
+ 'ios.debug': {
79
84
  type: 'ios.app',
80
- binaryPath: 'SPECIFY_PATH_TO_YOUR_APP_BINARY',
85
+ binaryPath: 'ios/build/Build/Products/Debug-iphonesimulator/YOUR_APP.app',
86
+ build: 'xcodebuild -workspace ios/YOUR_APP.xcworkspace -scheme YOUR_APP -configuration Debug -sdk iphonesimulator -derivedDataPath ios/build',
87
+ },
88
+ 'ios.release': {
89
+ type: 'ios.app',
90
+ binaryPath: 'ios/build/Build/Products/Release-iphonesimulator/YOUR_APP.app',
91
+ build: 'xcodebuild -workspace ios/YOUR_APP.xcworkspace -scheme YOUR_APP -configuration Release -sdk iphonesimulator -derivedDataPath ios/build',
92
+ },
93
+ 'android.debug': {
94
+ type: 'android.apk',
95
+ binaryPath: 'android/app/build/outputs/apk/debug/app-debug.apk',
96
+ build: 'cd android ; ./gradlew assembleDebug assembleAndroidTest -DtestBuildType=debug ; cd -',
97
+ reversePorts: [8081],
81
98
  },
82
- android: {
99
+ 'android.release': {
83
100
  type: 'android.apk',
84
- binaryPath: 'SPECIFY_PATH_TO_YOUR_APP_BINARY',
101
+ binaryPath: 'android/app/build/outputs/apk/release/app-release.apk',
102
+ build: 'cd android ; ./gradlew assembleRelease assembleAndroidTest -DtestBuildType=release ; cd -',
85
103
  },
86
104
  },
87
105
  devices: {
88
106
  simulator: {
89
107
  type: 'ios.simulator',
90
108
  device: {
91
- type: 'iPhone 11',
109
+ type: 'iPhone 12',
110
+ },
111
+ },
112
+ attached: {
113
+ type: 'android.attached',
114
+ device: {
115
+ adbName: '.*',
92
116
  },
93
117
  },
94
118
  emulator: {
@@ -99,13 +123,29 @@ function createDefaultConfigurations() {
99
123
  },
100
124
  },
101
125
  configurations: {
102
- ios: {
126
+ 'ios.sim.debug': {
127
+ device: 'simulator',
128
+ app: 'ios.debug',
129
+ },
130
+ 'ios.sim.release': {
103
131
  device: 'simulator',
104
- app: 'ios',
132
+ app: 'ios.release',
133
+ },
134
+ 'android.att.debug': {
135
+ device: 'attached',
136
+ app: 'android.debug',
137
+ },
138
+ 'android.att.release': {
139
+ device: 'attached',
140
+ app: 'android.release',
141
+ },
142
+ 'android.emu.debug': {
143
+ device: 'emulator',
144
+ app: 'android.debug',
105
145
  },
106
- android: {
146
+ 'android.emu.release': {
107
147
  device: 'emulator',
108
- app: 'android',
148
+ app: 'android.release',
109
149
  },
110
150
  },
111
151
  };
@@ -4,7 +4,7 @@ const path = require('path');
4
4
 
5
5
  const fs = require('fs-extra');
6
6
 
7
- const log = require('../src/utils/logger').child({ __filename });
7
+ const log = require('../src/utils/logger').child({ cat: 'cli' });
8
8
 
9
9
  module.exports.command = 'rebuild-framework-cache';
10
10
  module.exports.desc = 'Rebuilds 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)';
@@ -0,0 +1,16 @@
1
+ const { log } = require('../internals');
2
+ const DeviceRegistry = require('../src/devices/DeviceRegistry');
3
+ const { getDetoxLibraryRootPath } = require('../src/utils/environment');
4
+
5
+
6
+ module.exports.command = 'reset-lock-file';
7
+ module.exports.desc = 'Resets all Detox lock files. Useful when you need to run multiple `detox test` commands in parallel with --keepLockFile.';
8
+
9
+ module.exports.handler = async function resetLockFile() {
10
+ await Promise.all([
11
+ DeviceRegistry.forIOS().reset(),
12
+ DeviceRegistry.forAndroid().reset(),
13
+ ]);
14
+
15
+ log.info(`Cleaned lock files from: ${getDetoxLibraryRootPath()}`);
16
+ };
@@ -1,15 +1,18 @@
1
1
  const firstTestContent = require('./firstTestContent');
2
2
 
3
- const runnerConfig = `{
4
- "globalSetup": "detox/runners/jest/globalSetup",
5
- "globalTeardown": "detox/runners/jest/globalTeardown",
6
- "maxWorkers": 1,
7
- "reporters": ["detox/runners/jest/reporter"],
8
- "testEnvironment": "detox/runners/jest/testEnvironment",
9
- "testMatch": ["<rootDir>/e2e/**/*.test.js"],
10
- "testTimeout": 120000,
11
- "verbose": true
12
- }
3
+ const runnerConfig = `\
4
+ /** @type {import('@jest/types').Config.InitialOptions} */
5
+ module.exports = {
6
+ rootDir: '..',
7
+ testMatch: ['<rootDir>/e2e/**/*.test.js'],
8
+ testTimeout: 120000,
9
+ maxWorkers: 1,
10
+ globalSetup: 'detox/runners/jest/globalSetup',
11
+ globalTeardown: 'detox/runners/jest/globalTeardown',
12
+ reporters: ['detox/runners/jest/reporter'],
13
+ testEnvironment: 'detox/runners/jest/testEnvironment',
14
+ verbose: true,
15
+ };
13
16
  `;
14
17
 
15
18
  exports.starter = firstTestContent;
package/local-cli/test.js CHANGED
@@ -3,24 +3,30 @@ const detox = require('../internals');
3
3
  const TestRunnerCommand = require('./testCommand/TestRunnerCommand');
4
4
 
5
5
  module.exports.command = 'test';
6
- module.exports.desc = 'Run your test suite with the test runner specified in package.json';
6
+ module.exports.desc = 'Run your test suites with the test runner specified in the project\'s Detox config';
7
7
  module.exports.builder = require('./testCommand/builder');
8
8
  module.exports.middlewares = require('./testCommand/middlewares').default;
9
9
 
10
10
  module.exports.handler = async function test({ detoxArgs, runnerArgs }) {
11
11
  try {
12
- await detox.globalSetup({
12
+ const opts = {
13
13
  argv: detoxArgs,
14
14
  testRunnerArgv: runnerArgs,
15
- });
15
+ workerId: null,
16
+ };
17
+
18
+ const config = await detox.resolveConfig(opts);
19
+ if (!config.cli.inspectBrk) {
20
+ await detox.init(opts);
21
+ }
16
22
 
17
- const runnerCommand = new TestRunnerCommand()
18
- .setRunnerConfig(detox.config.testRunner)
19
- .setDeviceConfig(detox.config.device)
20
- .replicateCLIConfig(detox.config.cli);
23
+ const runnerCommand = new TestRunnerCommand({
24
+ config,
25
+ env: process.env,
26
+ });
21
27
 
22
28
  await runnerCommand.execute();
23
29
  } finally {
24
- await detox.globalTeardown();
30
+ await detox.cleanup();
25
31
  }
26
32
  };