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

Sign up to get free protection for your applications and to get access to all the features.
Files changed (219) hide show
  1. package/Detox-android/com/wix/detox/{19.9.0/detox-19.9.0-javadoc.jar → 21.0.0-breaking.new-global-lifecycle.0/detox-21.0.0-breaking.new-global-lifecycle.0-javadoc.jar} +0 -0
  2. package/Detox-android/com/wix/detox/21.0.0-breaking.new-global-lifecycle.0/detox-21.0.0-breaking.new-global-lifecycle.0-javadoc.jar.md5 +1 -0
  3. package/Detox-android/com/wix/detox/21.0.0-breaking.new-global-lifecycle.0/detox-21.0.0-breaking.new-global-lifecycle.0-javadoc.jar.sha1 +1 -0
  4. package/Detox-android/com/wix/detox/21.0.0-breaking.new-global-lifecycle.0/detox-21.0.0-breaking.new-global-lifecycle.0-javadoc.jar.sha256 +1 -0
  5. package/Detox-android/com/wix/detox/21.0.0-breaking.new-global-lifecycle.0/detox-21.0.0-breaking.new-global-lifecycle.0-javadoc.jar.sha512 +1 -0
  6. package/Detox-android/com/wix/detox/{19.9.0/detox-19.9.0-sources.jar → 21.0.0-breaking.new-global-lifecycle.0/detox-21.0.0-breaking.new-global-lifecycle.0-sources.jar} +0 -0
  7. package/Detox-android/com/wix/detox/21.0.0-breaking.new-global-lifecycle.0/detox-21.0.0-breaking.new-global-lifecycle.0-sources.jar.md5 +1 -0
  8. package/Detox-android/com/wix/detox/21.0.0-breaking.new-global-lifecycle.0/detox-21.0.0-breaking.new-global-lifecycle.0-sources.jar.sha1 +1 -0
  9. package/Detox-android/com/wix/detox/21.0.0-breaking.new-global-lifecycle.0/detox-21.0.0-breaking.new-global-lifecycle.0-sources.jar.sha256 +1 -0
  10. package/Detox-android/com/wix/detox/21.0.0-breaking.new-global-lifecycle.0/detox-21.0.0-breaking.new-global-lifecycle.0-sources.jar.sha512 +1 -0
  11. package/Detox-android/com/wix/detox/21.0.0-breaking.new-global-lifecycle.0/detox-21.0.0-breaking.new-global-lifecycle.0.aar +0 -0
  12. package/Detox-android/com/wix/detox/21.0.0-breaking.new-global-lifecycle.0/detox-21.0.0-breaking.new-global-lifecycle.0.aar.md5 +1 -0
  13. package/Detox-android/com/wix/detox/21.0.0-breaking.new-global-lifecycle.0/detox-21.0.0-breaking.new-global-lifecycle.0.aar.sha1 +1 -0
  14. package/Detox-android/com/wix/detox/21.0.0-breaking.new-global-lifecycle.0/detox-21.0.0-breaking.new-global-lifecycle.0.aar.sha256 +1 -0
  15. package/Detox-android/com/wix/detox/21.0.0-breaking.new-global-lifecycle.0/detox-21.0.0-breaking.new-global-lifecycle.0.aar.sha512 +1 -0
  16. package/Detox-android/com/wix/detox/{19.9.0/detox-19.9.0.pom → 21.0.0-breaking.new-global-lifecycle.0/detox-21.0.0-breaking.new-global-lifecycle.0.pom} +2 -2
  17. package/Detox-android/com/wix/detox/21.0.0-breaking.new-global-lifecycle.0/detox-21.0.0-breaking.new-global-lifecycle.0.pom.md5 +1 -0
  18. package/Detox-android/com/wix/detox/21.0.0-breaking.new-global-lifecycle.0/detox-21.0.0-breaking.new-global-lifecycle.0.pom.sha1 +1 -0
  19. package/Detox-android/com/wix/detox/21.0.0-breaking.new-global-lifecycle.0/detox-21.0.0-breaking.new-global-lifecycle.0.pom.sha256 +1 -0
  20. package/Detox-android/com/wix/detox/21.0.0-breaking.new-global-lifecycle.0/detox-21.0.0-breaking.new-global-lifecycle.0.pom.sha512 +1 -0
  21. package/Detox-android/com/wix/detox/maven-metadata.xml +4 -4
  22. package/Detox-android/com/wix/detox/maven-metadata.xml.md5 +1 -1
  23. package/Detox-android/com/wix/detox/maven-metadata.xml.sha1 +1 -1
  24. package/Detox-android/com/wix/detox/maven-metadata.xml.sha256 +1 -1
  25. package/Detox-android/com/wix/detox/maven-metadata.xml.sha512 +1 -1
  26. package/Detox-ios-src.tbz +0 -0
  27. package/Detox-ios.tbz +0 -0
  28. package/android/build.gradle +2 -2
  29. package/android/detox/build.gradle +2 -2
  30. package/android/detox/publish-pom.gradle +1 -5
  31. package/android/detox/publishing.gradle +7 -9
  32. package/android/detox/src/full/java/com/wix/detox/Detox.java +2 -59
  33. package/android/detox/src/full/java/com/wix/detox/NotificationDataParser.kt +3 -3
  34. package/android/detox/src/full/java/com/wix/detox/adapters/server/WebSocketClient.java +1 -3
  35. package/android/detox/src/full/java/com/wix/detox/espresso/DetoxAction.java +3 -1
  36. package/android/detox/src/full/java/com/wix/detox/espresso/UiAutomatorHelper.java +1 -1
  37. package/android/detox/src/full/java/com/wix/detox/espresso/matcher/ViewMatchers.kt +23 -16
  38. package/android/detox/src/full/java/com/wix/detox/reactnative/ReactNativeLoadingMonitor.kt +8 -54
  39. package/android/detox/src/main/java/com/wix/detox/common/DetoxErrors.java +1 -4
  40. package/android/detox/src/main/java/com/wix/detox/espresso/UiControllerSpy.kt +1 -2
  41. package/android/detox/src/main/java/com/wix/detox/espresso/action/AdjustSliderToPositionAction.kt +36 -0
  42. package/android/detox/src/{full → main}/java/com/wix/detox/espresso/action/GetAttributesAction.kt +1 -13
  43. package/android/detox/src/main/java/com/wix/detox/espresso/action/common/utils/UiControllerUtils.kt +1 -1
  44. package/android/detox/src/testFull/java/com/wix/detox/espresso/action/AdjustSliderToPositionActionTest.kt +59 -0
  45. package/android/detox/src/testFull/java/com/wix/detox/espresso/action/GetAttributesActionTest.kt +3 -15
  46. package/android/gradle/wrapper/gradle-wrapper.properties +1 -2
  47. package/android/gradlew +107 -181
  48. package/index.d.ts +208 -186
  49. package/index.js +1 -0
  50. package/internals.d.ts +124 -0
  51. package/internals.js +4 -0
  52. package/local-cli/build-framework-cache.js +2 -2
  53. package/local-cli/build.js +7 -8
  54. package/local-cli/build.test.js +46 -40
  55. package/local-cli/clean-framework-cache.js +3 -3
  56. package/local-cli/cli.js +0 -1
  57. package/local-cli/init.js +20 -55
  58. package/local-cli/templates/jest.js +9 -34
  59. package/local-cli/test.js +18 -282
  60. package/local-cli/test.test.js +332 -673
  61. package/local-cli/testCommand/TestRunnerCommand.js +157 -0
  62. package/local-cli/{utils/testCommandArgs.js → testCommand/builder.js} +10 -35
  63. package/local-cli/testCommand/middlewares.js +75 -0
  64. package/local-cli/{utils → testCommand}/warnings.js +0 -10
  65. package/local-cli/utils/jestInternals.js +13 -2
  66. package/local-cli/utils/yargsUtils.js +67 -0
  67. package/package.json +28 -22
  68. package/runners/deprecation.js +47 -0
  69. package/runners/jest/JestCircusEnvironment.js +3 -38
  70. package/runners/jest/adapter.d.ts +4 -10
  71. package/runners/jest/adapter.js +3 -6
  72. package/runners/jest/assignReporter.d.ts +4 -1
  73. package/runners/jest/assignReporter.js +3 -6
  74. package/runners/jest/deprecation.js +25 -0
  75. package/runners/jest/globalSetup.js +1 -0
  76. package/runners/jest/globalTeardown.js +1 -0
  77. package/runners/jest/index.js +21 -0
  78. package/runners/jest/reporter.js +1 -0
  79. package/runners/jest/reporters/DetoxReporter.js +5 -0
  80. package/runners/jest/specReporter.d.ts +4 -9
  81. package/runners/jest/specReporter.js +3 -10
  82. package/runners/jest/streamlineReporter.js +3 -22
  83. package/runners/jest/testEnvironment/index.js +155 -0
  84. package/runners/{jest-circus → jest/testEnvironment}/listeners/DetoxCoreListener.js +35 -17
  85. package/runners/{jest-circus → jest/testEnvironment}/listeners/DetoxInitErrorListener.js +1 -1
  86. package/runners/jest/testEnvironment/listeners/DetoxPlatformFilterListener.js +27 -0
  87. package/runners/jest/{SpecReporterImpl.js → testEnvironment/listeners/SpecReporter.js} +61 -7
  88. package/runners/jest/testEnvironment/listeners/WorkerAssignReporter.js +34 -0
  89. package/runners/jest/testEnvironment/listeners/index.js +13 -0
  90. package/runners/{jest-circus → jest/testEnvironment}/utils/assertExistingContext.js +2 -2
  91. package/runners/jest/testEnvironment/utils/assertJestCircus27.js +56 -0
  92. package/runners/jest/testEnvironment/utils/assertJestCircus27.test.js +23 -0
  93. package/runners/jest/{utils → testEnvironment/utils}/getFullTestName.js +0 -0
  94. package/runners/jest/{utils → testEnvironment/utils}/hasTimedOut.js +0 -0
  95. package/runners/jest/{utils → testEnvironment/utils}/index.js +0 -0
  96. package/runners/jest/{utils → testEnvironment/utils}/stdout.js +0 -0
  97. package/runners/jest-circus/environment/index.js +6 -0
  98. package/runners/jest-circus/index.js +1 -10
  99. package/runners/jest-circus/reporter.js +1 -0
  100. package/runners/migration.js +37 -0
  101. package/runners/mocha/DetoxMochaAdapter.js +3 -35
  102. package/runners/mocha/adapter.d.ts +4 -7
  103. package/runners/mocha/adapter.js +3 -5
  104. package/src/{Detox.js → DetoxWorker.js} +131 -164
  105. package/src/artifacts/ArtifactsManager.js +51 -2
  106. package/src/artifacts/log/android/ADBLogcatRecording.js +28 -11
  107. package/src/artifacts/providers/index.js +0 -4
  108. package/src/artifacts/utils/buildDefaultArtifactsRootDirpath.js +2 -4
  109. package/src/artifacts/utils/temporaryPath.js +2 -0
  110. package/src/client/AsyncWebSocket.js +1 -1
  111. package/src/client/actions/actions.js +2 -2
  112. package/src/configuration/collectCliConfig.js +2 -4
  113. package/src/configuration/composeAppsConfig.js +9 -67
  114. package/src/configuration/composeArtifactsConfig.js +6 -32
  115. package/src/configuration/composeBehaviorConfig.js +3 -13
  116. package/src/configuration/composeDeviceConfig.js +37 -62
  117. package/src/configuration/composeLoggerConfig.js +50 -0
  118. package/src/configuration/composeRunnerConfig.js +74 -14
  119. package/src/configuration/composeSessionConfig.js +1 -3
  120. package/src/configuration/index.js +24 -23
  121. package/src/configuration/utils/deviceAppTypes.js +0 -1
  122. package/src/devices/allocation/DeviceAllocator.js +3 -3
  123. package/src/devices/allocation/drivers/android/emulator/EmulatorAllocDriver.js +4 -3
  124. package/src/devices/allocation/drivers/android/emulator/EmulatorLauncher.js +2 -6
  125. package/src/devices/allocation/drivers/android/genycloud/GenyAllocDriver.js +0 -1
  126. package/src/devices/allocation/drivers/ios/SimulatorAllocDriver.js +1 -1
  127. package/src/devices/allocation/drivers/ios/SimulatorLauncher.js +3 -3
  128. package/src/devices/allocation/factories/index.js +0 -1
  129. package/src/devices/common/drivers/DeviceLauncher.js +2 -2
  130. package/src/devices/common/drivers/android/emulator/exec/EmulatorExec.js +1 -1
  131. package/src/devices/common/drivers/android/exec/ADB.js +0 -5
  132. package/src/devices/common/drivers/android/genycloud/services/GenyInstanceNaming.js +4 -9
  133. package/src/devices/common/drivers/ios/tools/AppleSimUtils.js +34 -9
  134. package/src/devices/lifecycle/GenyGlobalLifecycleHandler.js +1 -1
  135. package/src/devices/runtime/RuntimeDevice.js +69 -81
  136. package/src/devices/runtime/drivers/index.js +0 -1
  137. package/src/devices/runtime/drivers/ios/SimulatorDriver.js +3 -2
  138. package/src/devices/runtime/factories/ios.js +1 -8
  139. package/src/devices/runtime/utils/LaunchArgsEditor.js +4 -59
  140. package/src/devices/runtime/utils/Storage.js +4 -0
  141. package/src/environmentFactory.js +0 -8
  142. package/src/errors/DetoxConfigErrorComposer.js +76 -29
  143. package/src/errors/DetoxError.js +4 -0
  144. package/src/errors/DetoxRuntimeError.js +5 -5
  145. package/src/errors/index.js +2 -0
  146. package/src/ipc/IPCClient.js +117 -0
  147. package/src/ipc/IPCServer.js +87 -0
  148. package/src/ipc/state.js +76 -0
  149. package/src/logger/DetoxLogger.js +244 -0
  150. package/src/logger/DetoxTraceEventBuilder.js +21 -0
  151. package/src/logger/DetoxTracer.js +133 -0
  152. package/src/logger/TraceThreadDispatcher.js +52 -0
  153. package/src/{utils → logger}/customConsoleLogger.js +1 -1
  154. package/src/realms/DetoxConstants.js +13 -0
  155. package/src/realms/DetoxContext.js +170 -0
  156. package/src/realms/DetoxInternalsFacade.js +35 -0
  157. package/src/realms/DetoxPrimaryContext.js +229 -0
  158. package/src/realms/DetoxSecondaryContext.js +94 -0
  159. package/src/realms/index.js +10 -0
  160. package/src/realms/primary.js +3 -0
  161. package/src/realms/secondary.js +3 -0
  162. package/src/server/DetoxConnection.js +1 -1
  163. package/src/symbols.js +56 -0
  164. package/src/utils/ChromeTracingExporter.js +5 -6
  165. package/src/utils/Timer.js +14 -6
  166. package/{local-cli/utils/misc.js → src/utils/envUtils.js} +0 -9
  167. package/src/utils/logger.js +2 -162
  168. package/src/utils/shellUtils.js +18 -0
  169. package/src/utils/streamUtils.js +214 -0
  170. package/src/utils/trace.js +9 -44
  171. package/Detox-android/com/wix/detox/19.9.0/detox-19.9.0-javadoc.jar.md5 +0 -1
  172. package/Detox-android/com/wix/detox/19.9.0/detox-19.9.0-javadoc.jar.sha1 +0 -1
  173. package/Detox-android/com/wix/detox/19.9.0/detox-19.9.0-javadoc.jar.sha256 +0 -1
  174. package/Detox-android/com/wix/detox/19.9.0/detox-19.9.0-javadoc.jar.sha512 +0 -1
  175. package/Detox-android/com/wix/detox/19.9.0/detox-19.9.0-sources.jar.md5 +0 -1
  176. package/Detox-android/com/wix/detox/19.9.0/detox-19.9.0-sources.jar.sha1 +0 -1
  177. package/Detox-android/com/wix/detox/19.9.0/detox-19.9.0-sources.jar.sha256 +0 -1
  178. package/Detox-android/com/wix/detox/19.9.0/detox-19.9.0-sources.jar.sha512 +0 -1
  179. package/Detox-android/com/wix/detox/19.9.0/detox-19.9.0.aar +0 -0
  180. package/Detox-android/com/wix/detox/19.9.0/detox-19.9.0.aar.md5 +0 -1
  181. package/Detox-android/com/wix/detox/19.9.0/detox-19.9.0.aar.sha1 +0 -1
  182. package/Detox-android/com/wix/detox/19.9.0/detox-19.9.0.aar.sha256 +0 -1
  183. package/Detox-android/com/wix/detox/19.9.0/detox-19.9.0.aar.sha512 +0 -1
  184. package/Detox-android/com/wix/detox/19.9.0/detox-19.9.0.pom.md5 +0 -1
  185. package/Detox-android/com/wix/detox/19.9.0/detox-19.9.0.pom.sha1 +0 -1
  186. package/Detox-android/com/wix/detox/19.9.0/detox-19.9.0.pom.sha256 +0 -1
  187. package/Detox-android/com/wix/detox/19.9.0/detox-19.9.0.pom.sha512 +0 -1
  188. package/android/detox/src/full/java/com/wix/detox/espresso/action/AdjustSliderToPositionAction.kt +0 -22
  189. package/android/detox/src/full/java/com/wix/detox/espresso/common/SliderHelper.kt +0 -75
  190. package/android/detox/src/main/java/com/wix/detox/espresso/action/common/ReflectUtils.kt +0 -10
  191. package/android/detox/src/testFull/java/com/wix/detox/espresso/common/SliderHelperTest.kt +0 -39
  192. package/local-cli/templates/mocha.js +0 -32
  193. package/local-cli/utils/splitArgv.js +0 -107
  194. package/runners/integration.js +0 -16
  195. package/runners/jest/DetoxAdapterCircus.js +0 -60
  196. package/runners/jest/DetoxAdapterImpl.js +0 -81
  197. package/runners/jest/DetoxAdapterJasmine.js +0 -67
  198. package/runners/jest/DetoxStreamlineJestReporter.js +0 -98
  199. package/runners/jest/FailingTestsReporter.js +0 -16
  200. package/runners/jest/SpecReporterCircus.js +0 -51
  201. package/runners/jest/SpecReporterJasmine.js +0 -39
  202. package/runners/jest/WorkerAssignReporterCircus.js +0 -17
  203. package/runners/jest/WorkerAssignReporterImpl.js +0 -21
  204. package/runners/jest/WorkerAssignReporterJasmine.js +0 -15
  205. package/runners/jest/runnerInfo.js +0 -9
  206. package/runners/jest-circus/environment.js +0 -206
  207. package/runners/jest-circus/utils/assertJestCircus26.js +0 -39
  208. package/runners/jest-circus/utils/wrapErrorWithNoopLifecycle.js +0 -14
  209. package/src/DetoxConstants.js +0 -13
  210. package/src/DetoxExportWrapper.js +0 -140
  211. package/src/artifacts/timeline/TimelineArtifactPlugin.js +0 -95
  212. package/src/devices/allocation/drivers/NoneAllocDriver.js +0 -10
  213. package/src/devices/allocation/factories/none.js +0 -11
  214. package/src/index.js +0 -6
  215. package/src/utils/MissingDetox.js +0 -78
  216. package/src/utils/fakeTimestampsProvider.js +0 -9
  217. package/src/utils/getWorkerId.js +0 -5
  218. package/src/utils/lastFailedTests.js +0 -38
  219. package/src/utils/sh.js +0 -18
package/index.js ADDED
@@ -0,0 +1 @@
1
+ module.exports = require('./src/realms');
package/internals.d.ts ADDED
@@ -0,0 +1,124 @@
1
+ /// <reference types="node" />
2
+ /// <reference path="index.d.ts"/>
3
+
4
+ declare global {
5
+ namespace DetoxInternals {
6
+ type Facade = {
7
+ // region Initialization
8
+ /**
9
+ * Use with a caution, when you still have no config, yet need to avoid {@link Facade#globalSetup}
10
+ */
11
+ resolveConfig(options?: Partial<DetoxGlobalSetupOptions>): Promise<RuntimeConfig>;
12
+
13
+ /**
14
+ * This is the phase where Detox reads its configuration, starts a server.
15
+ */
16
+ globalSetup(options?: Partial<DetoxGlobalSetupOptions>): Promise<void>;
17
+
18
+ /**
19
+ * This is the phase where Detox loads its expection library and starts a device.
20
+ */
21
+ setup(options?: Partial<DetoxConfigurationSetupOptions>): Promise<void>;
22
+
23
+ /**
24
+ * The teardown phase deallocates the device.
25
+ */
26
+ teardown(): Promise<void>;
27
+
28
+ /**
29
+ * The global cleanup phase should happen after all the tests have finished.
30
+ * This is the phase where the Detox server shuts down.
31
+ */
32
+ globalTeardown(): Promise<void>;
33
+ // endregion
34
+
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>;
48
+
49
+ /**
50
+ * Powers the "--retries <N>" of Detox CLI under the hood.
51
+ */
52
+ reportFailedTests(testFilePaths: string[]): Promise<void>;
53
+ // endregion
54
+
55
+ readonly config: RuntimeConfig;
56
+ readonly log: Detox.Logger;
57
+ readonly trace: Detox.Tracer;
58
+ readonly session: SessionState;
59
+
60
+ readonly worker: unknown;
61
+ }
62
+
63
+ type DetoxGlobalSetupOptions = {
64
+ cwd: string;
65
+ argv: Record<string, unknown>;
66
+ testRunnerArgv: Record<string, unknown>;
67
+ override: Partial<Detox.DetoxConfig>;
68
+ };
69
+
70
+ type DetoxConfigurationSetupOptions = {
71
+ global: NodeJS.Global;
72
+ workerId: number;
73
+ };
74
+
75
+ type SessionState = Readonly<{
76
+ failedTestFiles: string[];
77
+ workersCount: number;
78
+ }>;
79
+
80
+ type RuntimeConfig = Readonly<{
81
+ configurationName: string;
82
+
83
+ appsConfig: Record<string, Readonly<Detox.DetoxAppConfig>>;
84
+ artifactsConfig: Detox.DetoxArtifactsConfig;
85
+ behaviorConfig: Detox.DetoxBehaviorConfig;
86
+ cliConfig: DetoxCLIConfig;
87
+ deviceConfig: Detox.DetoxDeviceConfig;
88
+ loggerConfig: Detox.DetoxLoggerConfig;
89
+ runnerConfig: Detox.DetoxTestRunnerConfig;
90
+ sessionConfig: Detox.DetoxSessionConfig;
91
+ }>;
92
+
93
+ type DetoxCLIConfig = Readonly<Partial<{
94
+ appLaunchArgs: string;
95
+ artifactsLocation: string;
96
+ captureViewHierarchy: string;
97
+ cleanup: boolean;
98
+ configPath: string;
99
+ configuration: string;
100
+ debugSynchronization: number;
101
+ deviceBootArgs: string;
102
+ deviceName: string;
103
+ forceAdbInstall: boolean;
104
+ gpu: string;
105
+ inspectBrk: boolean;
106
+ headless: boolean;
107
+ jestReportSpecs: boolean;
108
+ keepLockFile: boolean;
109
+ loglevel: string;
110
+ readonlyEmu: boolean;
111
+ recordLogs: string;
112
+ recordPerformance: string;
113
+ recordVideos: string;
114
+ retries: number;
115
+ reuse: string;
116
+ takeScreenshots: string;
117
+ useCustomLogger: string;
118
+ }>>;
119
+ }
120
+ }
121
+
122
+ declare const detox: DetoxInternals.Facade;
123
+ export = detox;
124
+
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 { 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('\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");
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
+ appsConfig: {},
18
+ artifactsConfig: {},
19
+ behaviorConfig: {},
20
+ errorComposer: new DetoxConfigErrorComposer(),
21
+ deviceConfig: {},
22
+ sessionConfig: {}
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.appsConfig.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.appsConfig.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.appsConfig.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.appsConfig.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.appsConfig.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.appsConfig.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.appsConfig.app1 = { binaryPath: tempfile(), build: ':' };
91
+ detox.config.appsConfig.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.appsConfig.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,5 +1,4 @@
1
1
  #!/usr/bin/env node
2
- global.DETOX_CLI = true;
3
2
  const yargs = require('yargs');
4
3
 
5
4
  const DetoxError = require('../src/errors/DetoxError');
package/local-cli/init.js CHANGED
@@ -1,47 +1,18 @@
1
1
  const fs = require('fs');
2
2
  const path = require('path');
3
3
 
4
- const DetoxRuntimeError = require('../src/errors/DetoxRuntimeError');
5
- const log = require('../src/utils/logger').child({ __filename });
4
+ const detox = require('../internals');
6
5
 
7
6
  const jestTemplates = require('./templates/jest');
8
- const mochaTemplates = require('./templates/mocha');
9
7
 
10
8
  let exitCode = 0;
11
9
 
12
10
  module.exports.command = 'init';
13
- module.exports.desc = 'Scaffold initial E2E test folder structure for a specified test runner';
14
- module.exports.builder = {
15
- runner: {
16
- alias: 'r',
17
- demandOption: true,
18
- describe: 'test runner name (supported values: mocha, jest)',
19
- group: 'Configuration:',
20
- default: 'jest',
21
- }
22
- };
23
-
24
- module.exports.handler = async function init(argv) {
25
- const { runner } = argv;
26
-
27
- switch (runner) {
28
- case 'mocha':
29
- createMochaFolderE2E();
30
- break;
31
- case 'jest':
32
- createJestFolderE2E();
33
- break;
34
- default:
35
- throw new DetoxRuntimeError([
36
- `Convenience scaffolding for \`${runner}\` test runner is not supported currently.\n`,
37
- 'Supported runners at the moment are: `mocha` and `jest`:',
38
- '* detox init -r mocha',
39
- '* detox init -r jest\n',
40
- `If it is not a typo, and you plan to work with \`${runner}\` runner, then you have to create test setup files manually.`,
41
- 'HINT: Try running one of the commands above, look what it does, and take similar steps for your use case.',
42
- ].join('\n'));
43
- }
11
+ module.exports.desc = 'Scaffold initial E2E test folder structure for Detox';
12
+ module.exports.builder = {};
44
13
 
14
+ module.exports.handler = async function init() {
15
+ createJestFolderE2E();
45
16
  process.exit(exitCode); // eslint-disable-line
46
17
  };
47
18
 
@@ -72,43 +43,37 @@ function createFile(filename, content) {
72
43
 
73
44
  try {
74
45
  fs.writeFileSync(filename, content);
75
- log.info(`Created a file at path: ${filename}`);
46
+ detox.log.info(`Created a file at path: ${filename}`);
76
47
  } catch (err) {
77
48
  reportError({ err }, `Failed to create a file at path: ${filename}`);
78
49
  }
79
50
  }
80
51
 
81
- function createMochaFolderE2E() {
82
- createFolder('e2e', {
83
- '.mocharc.json': mochaTemplates.runnerConfig,
84
- 'init.js': mochaTemplates.initjs,
85
- 'firstTest.spec.js': mochaTemplates.firstTest
86
- });
87
-
88
- createFile('.detoxrc.json', JSON.stringify({
89
- testRunner: 'mocha',
90
- runnerConfig: 'e2e/.mocharc.json',
91
- ...createDefaultConfigurations(),
92
- }, null, 2));
93
- }
94
-
95
52
  function createJestFolderE2E() {
96
53
  createFolder('e2e', {
97
54
  'config.json': jestTemplates.runnerConfig,
98
- 'environment.js': jestTemplates.environment,
99
- 'firstTest.e2e.js': jestTemplates.firstTest,
55
+ 'starter.test.js': jestTemplates.starter,
100
56
  });
101
57
 
102
58
  createFile('.detoxrc.json', JSON.stringify({
103
- testRunner: 'jest',
104
- runnerConfig: 'e2e/config.json',
105
- skipLegacyWorkersInjection: true,
59
+ testRunner: {
60
+ args: {
61
+ config: 'e2e/config.json'
62
+ },
63
+ },
64
+
106
65
  ...createDefaultConfigurations(),
107
66
  }, null, 2));
108
67
  }
109
68
 
110
69
  function createDefaultConfigurations() {
111
70
  return {
71
+ testRunner: {
72
+ args: {
73
+ $0: 'jest',
74
+ config: 'e2e/config.json',
75
+ },
76
+ },
112
77
  apps: {
113
78
  ios: {
114
79
  type: 'ios.app',
@@ -147,6 +112,6 @@ function createDefaultConfigurations() {
147
112
  }
148
113
 
149
114
  function reportError(...args) {
150
- log.error(...args);
115
+ detox.log.error(...args);
151
116
  exitCode = 1;
152
117
  }
@@ -1,41 +1,16 @@
1
1
  const firstTestContent = require('./firstTestContent');
2
2
 
3
3
  const runnerConfig = `{
4
- "maxWorkers": 1,
5
- "testEnvironment": "./environment",
6
- "testRunner": "jest-circus/runner",
7
- "testTimeout": 120000,
8
- "testRegex": "\\\\.e2e\\\\.js$",
9
- "reporters": ["detox/runners/jest/streamlineReporter"],
10
- "verbose": true
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
11
12
  }
12
13
  `;
13
14
 
14
- const environmentJsContent = `const {
15
- DetoxCircusEnvironment,
16
- SpecReporter,
17
- WorkerAssignReporter,
18
- } = require('detox/runners/jest-circus');
19
-
20
- class CustomDetoxEnvironment extends DetoxCircusEnvironment {
21
- constructor(config, context) {
22
- super(config, context);
23
-
24
- // Can be safely removed, if you are content with the default value (=300000ms)
25
- this.initTimeout = 300000;
26
-
27
- // This takes care of generating status logs on a per-spec basis. By default, Jest only reports at file-level.
28
- // This is strictly optional.
29
- this.registerListeners({
30
- SpecReporter,
31
- WorkerAssignReporter,
32
- });
33
- }
34
- }
35
-
36
- module.exports = CustomDetoxEnvironment;
37
- `;
38
-
39
- exports.environment = environmentJsContent;
40
- exports.firstTest = firstTestContent;
15
+ exports.starter = firstTestContent;
41
16
  exports.runnerConfig = runnerConfig;