detox 20.1.0-next-is-hittable-check.0 → 20.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (144) hide show
  1. package/Detox-android/com/wix/detox/{20.1.0-next-is-hittable-check.0/detox-20.1.0-next-is-hittable-check.0-javadoc.jar → 20.1.0/detox-20.1.0-javadoc.jar} +0 -0
  2. package/Detox-android/com/wix/detox/20.1.0/detox-20.1.0-javadoc.jar.md5 +1 -0
  3. package/Detox-android/com/wix/detox/20.1.0/detox-20.1.0-javadoc.jar.sha1 +1 -0
  4. package/Detox-android/com/wix/detox/20.1.0/detox-20.1.0-javadoc.jar.sha256 +1 -0
  5. package/Detox-android/com/wix/detox/20.1.0/detox-20.1.0-javadoc.jar.sha512 +1 -0
  6. package/Detox-android/com/wix/detox/{20.1.0-next-is-hittable-check.0/detox-20.1.0-next-is-hittable-check.0-sources.jar → 20.1.0/detox-20.1.0-sources.jar} +0 -0
  7. package/Detox-android/com/wix/detox/20.1.0/detox-20.1.0-sources.jar.md5 +1 -0
  8. package/Detox-android/com/wix/detox/20.1.0/detox-20.1.0-sources.jar.sha1 +1 -0
  9. package/Detox-android/com/wix/detox/20.1.0/detox-20.1.0-sources.jar.sha256 +1 -0
  10. package/Detox-android/com/wix/detox/20.1.0/detox-20.1.0-sources.jar.sha512 +1 -0
  11. package/Detox-android/com/wix/detox/20.1.0/detox-20.1.0.aar +0 -0
  12. package/Detox-android/com/wix/detox/20.1.0/detox-20.1.0.aar.md5 +1 -0
  13. package/Detox-android/com/wix/detox/20.1.0/detox-20.1.0.aar.sha1 +1 -0
  14. package/Detox-android/com/wix/detox/20.1.0/detox-20.1.0.aar.sha256 +1 -0
  15. package/Detox-android/com/wix/detox/20.1.0/detox-20.1.0.aar.sha512 +1 -0
  16. package/Detox-android/com/wix/detox/{20.1.0-next-is-hittable-check.0/detox-20.1.0-next-is-hittable-check.0.pom → 20.1.0/detox-20.1.0.pom} +1 -1
  17. package/Detox-android/com/wix/detox/20.1.0/detox-20.1.0.pom.md5 +1 -0
  18. package/Detox-android/com/wix/detox/20.1.0/detox-20.1.0.pom.sha1 +1 -0
  19. package/Detox-android/com/wix/detox/20.1.0/detox-20.1.0.pom.sha256 +1 -0
  20. package/Detox-android/com/wix/detox/20.1.0/detox-20.1.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 +0 -1
  29. package/android/detox/src/full/java/com/wix/detox/TestEngineFacade.kt +3 -3
  30. package/android/detox/src/full/java/com/wix/detox/adapters/server/QueryStatusActionHandler.kt +12 -80
  31. package/android/detox/src/full/java/com/wix/detox/espresso/common/UiControllerImplReflected.kt +16 -0
  32. package/android/detox/src/full/java/com/wix/detox/espresso/idlingresources/DescriptiveIdlingResource.kt +8 -0
  33. package/android/detox/src/full/java/com/wix/detox/espresso/registry/BusyResourcesInquirer.kt +48 -0
  34. package/android/detox/src/full/java/com/wix/detox/inquiry/DetoxBusyResource.kt +92 -0
  35. package/android/detox/src/full/java/com/wix/detox/{reactnative/idlingresources/IdlingResourceDescription.kt → inquiry/DetoxBusyResourceDescription.kt} +6 -6
  36. package/android/detox/src/full/java/com/wix/detox/reactnative/idlingresources/AnimatedModuleIdlingResource.java +18 -7
  37. package/android/detox/src/full/java/com/wix/detox/reactnative/idlingresources/AsyncStorageIdlingResource.kt +2 -4
  38. package/android/detox/src/full/java/com/wix/detox/reactnative/idlingresources/BridgeIdlingResource.java +12 -6
  39. package/android/detox/src/full/java/com/wix/detox/reactnative/idlingresources/DetoxBaseIdlingResource.java +2 -0
  40. package/android/detox/src/full/java/com/wix/detox/reactnative/idlingresources/NetworkIdlingResource.java +14 -8
  41. package/android/detox/src/full/java/com/wix/detox/reactnative/idlingresources/timers/TimersIdlingResource.kt +1 -6
  42. package/android/detox/src/full/java/com/wix/detox/reactnative/idlingresources/uimodule/UIManagerModuleReflected.kt +1 -1
  43. package/android/detox/src/full/java/com/wix/detox/reactnative/idlingresources/uimodule/UIModuleIdlingResource.kt +4 -6
  44. package/android/detox/src/testFull/java/com/wix/detox/adapters/server/QueryStatusActionHandlerSpec.kt +35 -94
  45. package/android/detox/src/testFull/java/com/wix/detox/espresso/registry/{IRStatusInquirerTest.kt → BusyResourcesInquirerTest.kt} +46 -7
  46. package/android/detox/src/testFull/java/com/wix/detox/{reactnative/idlingresources/IdlingResourceDescriptionSpec.kt → inquiry/DetoxBusyResourceDescriptionSpec.kt} +6 -6
  47. package/android/detox/src/testFull/java/com/wix/detox/inquiry/DetoxBusyResourceSpec.kt +134 -0
  48. package/android/detox/src/testFull/java/com/wix/detox/reactnative/idlingresources/AsyncStorageIdlingResourceSpec.kt +4 -5
  49. package/android/detox/src/testFull/java/com/wix/detox/reactnative/idlingresources/NetworkIdlingResourcesTest.kt +5 -5
  50. package/android/detox/src/testFull/java/com/wix/detox/reactnative/idlingresources/timers/TimersIdlingResourceSpec.kt +4 -6
  51. package/index.d.ts +102 -18
  52. package/internals.d.ts +34 -9
  53. package/local-cli/cli.js +6 -3
  54. package/local-cli/init.js +1 -1
  55. package/local-cli/test.js +6 -6
  56. package/local-cli/testCommand/TestRunnerCommand.js +97 -94
  57. package/local-cli/testCommand/TestRunnerError.js +17 -0
  58. package/local-cli/testCommand/builder.js +0 -1
  59. package/local-cli/testCommand/middlewares.js +4 -13
  60. package/local-cli/testCommand/warnings.js +0 -3
  61. package/package.json +18 -15
  62. package/runners/deprecation.js +42 -44
  63. package/runners/jest/index.d.ts +60 -0
  64. package/runners/jest/index.js +3 -8
  65. package/runners/jest/reporters/DetoxReporter.js +21 -10
  66. package/runners/jest/testEnvironment/index.js +57 -41
  67. package/runners/jest/testEnvironment/listeners/DetoxCoreListener.js +62 -35
  68. package/runners/jest/testEnvironment/listeners/SpecReporter.js +12 -14
  69. package/runners/jest/testEnvironment/listeners/WorkerAssignReporter.js +1 -5
  70. package/runners/jest/testEnvironment/utils/assertJestCircus27.js +17 -3
  71. package/src/DetoxWorker.js +95 -49
  72. package/src/android/interactions/native.js +3 -2
  73. package/src/artifacts/ArtifactsManager.js +6 -6
  74. package/src/artifacts/utils/temporaryPath.js +32 -2
  75. package/src/client/actions/SyncStatusSchema.json +21 -0
  76. package/src/client/actions/formatters/SyncStatusFormatter.js +2 -0
  77. package/src/client/actions/formatters/sync-resources/BgThreadFormatter.js +5 -0
  78. package/src/configuration/collectCliConfig.js +1 -12
  79. package/src/configuration/composeRunnerConfig.js +5 -4
  80. package/src/devices/allocation/drivers/android/emulator/EmulatorLauncher.js +3 -3
  81. package/src/devices/allocation/drivers/android/emulator/launchEmulatorProcess.js +3 -16
  82. package/src/devices/common/drivers/android/exec/ADB.js +4 -0
  83. package/src/devices/common/drivers/ios/tools/AppleSimUtils.js +1 -1
  84. package/src/devices/lifecycle/GenyGlobalLifecycleHandler.js +4 -0
  85. package/src/devices/runtime/RuntimeDevice.js +3 -3
  86. package/src/errors/DetoxConfigErrorComposer.js +6 -1
  87. package/src/errors/DetoxError.js +5 -1
  88. package/src/ios/expectTwo.js +3 -2
  89. package/src/ipc/IPCClient.js +26 -17
  90. package/src/ipc/IPCServer.js +11 -3
  91. package/src/ipc/SessionState.js +11 -11
  92. package/src/logger/DetoxLogger.js +63 -43
  93. package/src/logger/index.js +1 -0
  94. package/src/logger/utils/BunyanLogger.js +50 -7
  95. package/src/logger/utils/CategoryThreadDispatcher.js +8 -29
  96. package/src/logger/utils/DetoxLogFinalizer.js +166 -0
  97. package/src/logger/utils/MessageStack.js +17 -6
  98. package/src/logger/utils/ThreadDispatcher.js +5 -25
  99. package/src/logger/utils/customConsoleLogger.js +22 -5
  100. package/src/logger/utils/getMainCategory.js +5 -0
  101. package/src/logger/utils/sanitizeBunyanContext.js +3 -1
  102. package/src/logger/utils/streams/BunyanTransformer.js +72 -0
  103. package/src/logger/utils/streams/ChromeTraceTransformer.js +132 -0
  104. package/src/logger/utils/streams/DetoxJSONLParser.js +31 -0
  105. package/src/logger/utils/streams/JSONLStringer.js +55 -0
  106. package/src/logger/utils/streams/index.js +7 -0
  107. package/src/logger/utils/streams/transformers.js +39 -0
  108. package/src/logger/utils/tracerLegacy.js +14 -25
  109. package/src/realms/DetoxContext.js +11 -7
  110. package/src/realms/DetoxInternalsFacade.js +0 -6
  111. package/src/realms/DetoxPrimaryContext.js +42 -87
  112. package/src/realms/DetoxSecondaryContext.js +8 -12
  113. package/src/utils/argparse.js +11 -0
  114. package/src/utils/logger.js +1 -1
  115. package/src/utils/pathUtils.js +11 -0
  116. package/src/utils/shellUtils.js +17 -0
  117. package/src/utils/traceInvocationCall.js +21 -0
  118. package/Detox-android/com/wix/detox/20.1.0-next-is-hittable-check.0/detox-20.1.0-next-is-hittable-check.0-javadoc.jar.md5 +0 -1
  119. package/Detox-android/com/wix/detox/20.1.0-next-is-hittable-check.0/detox-20.1.0-next-is-hittable-check.0-javadoc.jar.sha1 +0 -1
  120. package/Detox-android/com/wix/detox/20.1.0-next-is-hittable-check.0/detox-20.1.0-next-is-hittable-check.0-javadoc.jar.sha256 +0 -1
  121. package/Detox-android/com/wix/detox/20.1.0-next-is-hittable-check.0/detox-20.1.0-next-is-hittable-check.0-javadoc.jar.sha512 +0 -1
  122. package/Detox-android/com/wix/detox/20.1.0-next-is-hittable-check.0/detox-20.1.0-next-is-hittable-check.0-sources.jar.md5 +0 -1
  123. package/Detox-android/com/wix/detox/20.1.0-next-is-hittable-check.0/detox-20.1.0-next-is-hittable-check.0-sources.jar.sha1 +0 -1
  124. package/Detox-android/com/wix/detox/20.1.0-next-is-hittable-check.0/detox-20.1.0-next-is-hittable-check.0-sources.jar.sha256 +0 -1
  125. package/Detox-android/com/wix/detox/20.1.0-next-is-hittable-check.0/detox-20.1.0-next-is-hittable-check.0-sources.jar.sha512 +0 -1
  126. package/Detox-android/com/wix/detox/20.1.0-next-is-hittable-check.0/detox-20.1.0-next-is-hittable-check.0.aar +0 -0
  127. package/Detox-android/com/wix/detox/20.1.0-next-is-hittable-check.0/detox-20.1.0-next-is-hittable-check.0.aar.md5 +0 -1
  128. package/Detox-android/com/wix/detox/20.1.0-next-is-hittable-check.0/detox-20.1.0-next-is-hittable-check.0.aar.sha1 +0 -1
  129. package/Detox-android/com/wix/detox/20.1.0-next-is-hittable-check.0/detox-20.1.0-next-is-hittable-check.0.aar.sha256 +0 -1
  130. package/Detox-android/com/wix/detox/20.1.0-next-is-hittable-check.0/detox-20.1.0-next-is-hittable-check.0.aar.sha512 +0 -1
  131. package/Detox-android/com/wix/detox/20.1.0-next-is-hittable-check.0/detox-20.1.0-next-is-hittable-check.0.pom.md5 +0 -1
  132. package/Detox-android/com/wix/detox/20.1.0-next-is-hittable-check.0/detox-20.1.0-next-is-hittable-check.0.pom.sha1 +0 -1
  133. package/Detox-android/com/wix/detox/20.1.0-next-is-hittable-check.0/detox-20.1.0-next-is-hittable-check.0.pom.sha256 +0 -1
  134. package/Detox-android/com/wix/detox/20.1.0-next-is-hittable-check.0/detox-20.1.0-next-is-hittable-check.0.pom.sha512 +0 -1
  135. package/android/detox/src/full/java/com/wix/detox/espresso/registry/IRStatusInquirer.kt +0 -24
  136. package/android/detox/src/full/java/com/wix/detox/reactnative/idlingresources/DescriptiveIdlingResource.kt +0 -10
  137. package/local-cli/build.test.js +0 -104
  138. package/local-cli/run-server.test.js +0 -23
  139. package/local-cli/test.test.js +0 -569
  140. package/runners/jest/deprecation.js +0 -25
  141. package/runners/jest/testEnvironment/utils/assertJestCircus27.test.js +0 -23
  142. package/src/configuration/utils/warnings.js +0 -12
  143. package/src/logger/utils/streamUtils.js +0 -240
  144. package/src/utils/trace.js +0 -3
package/index.d.ts CHANGED
@@ -32,7 +32,7 @@ declare global {
32
32
  }
33
33
 
34
34
  namespace Detox {
35
- // region DetoxConfig
35
+ //#region DetoxConfig
36
36
 
37
37
  interface DetoxConfig extends DetoxConfigurationCommon {
38
38
  /**
@@ -82,15 +82,19 @@ declare global {
82
82
  */
83
83
  exposeGlobals?: boolean;
84
84
  /**
85
- * By default, Detox will uninstall and install the app upon the initialization.
85
+ * By default, Detox will uninstall and install the app upon initialization.
86
86
  * If you wish to reuse the existing app for a faster run, set the property to
87
87
  * `false`.
88
88
  */
89
89
  reinstallApp?: boolean;
90
90
  /**
91
- * If you wish to run multiple "detox test" commands in parallel,
92
- * make sure they don't delete the shared lock file only the
93
- * first command should reset the lock file.
91
+ * When false, `detox test` command always deletes the shared lock file on start,
92
+ * assuming it had been left from the previous, already finished test session.
93
+ * The lock file contains information about busy and free devices and ensures
94
+ * no device can be used simultaneously by multiple test workers.
95
+ *
96
+ * Setting it to **true** might be useful when if you need to run multiple
97
+ * `detox test` commands in parallel, e.g. test a few configurations at once.
94
98
  *
95
99
  * @default false
96
100
  */
@@ -102,13 +106,43 @@ declare global {
102
106
  };
103
107
  }
104
108
 
109
+ type _DetoxLoggerOptions = Omit<BunyanDebugStreamOptions, 'out'>;
110
+
105
111
  interface DetoxLoggerConfig {
112
+ /**
113
+ * Log level filters the messages printed to your terminal,
114
+ * and it does not affect the logs written to the artifacts.
115
+ *
116
+ * Use `info` by default.
117
+ * Use `error` or warn when you want to make the output as silent as possible.
118
+ * Use `debug` to control what generally is happening under the hood.
119
+ * Use `trace` when troubleshooting specific issues.
120
+ *
121
+ * @default 'info'
122
+ */
106
123
  level?: DetoxLogLevel;
107
124
  /**
125
+ * When enabled, hijacks all the console methods (console.log, console.warn, etc)
126
+ * so that the messages printed via them are formatted and saved as Detox logs.
127
+ *
108
128
  * @default true
109
129
  */
110
130
  overrideConsole?: boolean;
111
- options?: BunyanDebugStreamOptions | ((config: Partial<DetoxLoggerConfig>) => BunyanDebugStreamOptions);
131
+ /**
132
+ * Since Detox is using
133
+ * {@link https://www.npmjs.com/package/bunyan-debug-stream bunyan-debug-stream}
134
+ * for printing logs, all its options are exposed for sake of simplicity
135
+ * of customization.
136
+ *
137
+ * The only exception is {@link BunyanDebugStreamOptions#out} option,
138
+ * which is always set to `process.stdout`.
139
+ *
140
+ * You can also pass a callback function to override the logger config
141
+ * programmatically, e.g. depending on the selected log level.
142
+ *
143
+ * @see {@link BunyanDebugStreamOptions}
144
+ */
145
+ options?: _DetoxLoggerOptions | ((config: Partial<DetoxLoggerConfig>) => _DetoxLoggerOptions);
112
146
  }
113
147
 
114
148
  interface DetoxSessionConfig {
@@ -133,25 +167,78 @@ declare global {
133
167
  */
134
168
  [prop: string]: unknown;
135
169
  };
170
+
136
171
  /**
137
- * Configuration of custom integration features
138
- * between Detox and Jest
172
+ * This is an add-on section used by our Jest integration code (but not Detox core itself).
173
+ * In other words, if you’re implementing (or using) a custom integration with some other test runner, feel free to define a section for yourself (e.g. `testRunner.mocha`)
139
174
  */
140
175
  jest?: {
141
176
  /**
142
177
  * Environment setup timeout
178
+ *
179
+ * As a part of the environment setup, Detox boots the device and installs the apps.
180
+ * If that takes longer than the specified value, the entire test suite will be considered as failed, e.g.:
181
+ * ```plain text
182
+ * FAIL e2e/starter.test.js
183
+ * ● Test suite failed to run
184
+ *
185
+ * Exceeded timeout of 300000ms while setting up Detox environment
186
+ * ```
187
+ *
188
+ * The default value is 5 minutes.
189
+ *
190
+ * @default 300000
191
+ * @see {@link https://jestjs.io/docs/configuration/#testenvironment-string}
143
192
  */
144
193
  setupTimeout?: number | undefined;
145
194
  /**
146
- * Environment teardown timeout
195
+ * Environemnt teardown timeout
196
+ *
197
+ * If the environment teardown takes longer than the specified value, Detox will throw a timeout error.
198
+ * The default value is half a minute.
199
+ *
200
+ * @default 30000 (30 seconds)
201
+ * @see {@link https://jestjs.io/docs/configuration/#testenvironment-string}
147
202
  */
148
203
  teardownTimeout?: number | undefined;
149
204
  /**
150
- * Insist on CLI-based retry mechanism even when the failed tests have been handled
151
- * by jest.retryTimes(n) mechanism from Jest Circus.
205
+ * Jest provides an API to re-run individual failed tests: `jest.retryTimes(count)`.
206
+ * When Detox detects the use of this API, it suppresses its own CLI retry mechanism controlled via `detox test … --retries <N>` or {@link DetoxTestRunnerConfig#retries}.
207
+ * The motivation is simple – activating the both mechanisms is apt to increase your test duration dramatically, if your tests are flaky.
208
+ * If you wish nevertheless to use both the mechanisms simultaneously, set it to `true`.
209
+ *
210
+ * @default false
211
+ * @see {@link https://jestjs.io/docs/29.0/jest-object#jestretrytimesnumretries-options}
152
212
  */
153
213
  retryAfterCircusRetries?: boolean;
214
+ /**
215
+ * By default, Jest prints the test names and their status (_passed_ or _failed_) at the very end of the test session.
216
+ * When enabled, it makes Detox to print messages like these each time the new test starts and ends:
217
+ * ```plain text
218
+ * 18:03:36.258 detox[40125] i Sanity: should have welcome screen
219
+ * 18:03:37.495 detox[40125] i Sanity: should have welcome screen [OK]
220
+ * 18:03:37.496 detox[40125] i Sanity: should show hello screen after tap
221
+ * 18:03:38.928 detox[40125] i Sanity: should show hello screen after tap [OK]
222
+ * 18:03:38.929 detox[40125] i Sanity: should show world screen after tap
223
+ * 18:03:40.351 detox[40125] i Sanity: should show world screen after tap [OK]
224
+ * ```
225
+ * By default, it is enabled automatically in test sessions with a single worker.
226
+ * And vice versa, if multiple tests are executed concurrently, Detox turns it off to avoid confusion in the log.
227
+ * Use boolean values, `true` or `false`, to turn off the automatic choice.
228
+ *
229
+ * @default undefined
230
+ */
154
231
  reportSpecs?: boolean | undefined;
232
+ /**
233
+ * In the environment setup phase, Detox boots the device and installs the apps.
234
+ * This flag tells Detox to print messages like these every time the device gets assigned to a specific suite:
235
+ *
236
+ * ```plain text
237
+ * 18:03:29.869 detox[40125] i starter.test.js is assigned to 4EC84833-C7EA-4CA3-A6E9-5C30A29EA596 (iPhone 12 Pro Max)
238
+ * ```
239
+ *
240
+ * @default true
241
+ */
155
242
  reportWorkerAssign?: boolean | undefined;
156
243
  };
157
244
  /**
@@ -321,8 +408,6 @@ declare global {
321
408
  os: string;
322
409
  }
323
410
 
324
- type DetoxKnownDeviceType = DetoxBuiltInDeviceConfig['type'];
325
-
326
411
  type DetoxConfiguration = DetoxConfigurationCommon & (
327
412
  | DetoxConfigurationSingleApp
328
413
  | DetoxConfigurationMultiApps
@@ -342,7 +427,7 @@ declare global {
342
427
 
343
428
  type DetoxAliasedApp = string | DetoxAppConfig;
344
429
 
345
- // endregion DetoxConfig
430
+ //#endregion
346
431
 
347
432
  interface DetoxExportWrapper {
348
433
  readonly device: Device;
@@ -387,8 +472,6 @@ declare global {
387
472
  readonly startSection: (name: string) => void;
388
473
  /** @deprecated */
389
474
  readonly endSection: (name: string) => void;
390
- /** @private */
391
- readonly invocationCall: (...args: unknown[]) => unknown;
392
475
  };
393
476
 
394
477
  /**
@@ -399,7 +482,7 @@ declare global {
399
482
  * @param promiseOrFunction Promise or a function that provides a promise.
400
483
  * @param args Optional arguments to pass to the trace.
401
484
  * @returns The returned value of the traced call.
402
- * @see https://wix.github.io/Detox/docs/next/api/detox-object-api/#detoxtracecall.
485
+ * @see https://wix.github.io/Detox/docs/19.x/api/detox-object-api/#detoxtracecall
403
486
  */
404
487
  readonly traceCall: <T>(event: string, action: () => Promise<T>, args?: Record<string, unknown>) => Promise<T>;
405
488
  }
@@ -596,10 +679,11 @@ declare global {
596
679
  * Relaunch the app. Convenience method that calls {@link Device#launchApp}
597
680
  * with { newInstance: true } override.
598
681
  *
682
+ * @deprecated
599
683
  * @param config
600
684
  * @see Device#launchApp
601
685
  */
602
- relaunchApp(config?: Omit<DeviceLaunchAppConfig, 'newInstance'>): Promise<void>;
686
+ relaunchApp(config?: DeviceLaunchAppConfig): Promise<void>;
603
687
 
604
688
  /**
605
689
  * Access the user-defined launch-arguments predefined through static scopes such as the Detox configuration file and
package/internals.d.ts CHANGED
@@ -6,40 +6,48 @@ declare global {
6
6
  type DetoxStatus = 'inactive' | 'init' | 'active' | 'cleanup';
7
7
 
8
8
  type Facade = {
9
- // region Initialization
9
+ //#region Initialization
10
10
  /**
11
11
  * Use with a caution, when you still have no config, yet need to avoid {@link Facade#init}
12
12
  */
13
13
  resolveConfig(options?: Partial<DetoxInitOptions>): Promise<RuntimeConfig>;
14
14
 
15
15
  /**
16
+ * Returns one of statuses depending on what’s going with the current Detox context:
16
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.
17
22
  */
18
23
  getStatus(): DetoxStatus;
19
24
 
20
25
  /**
21
- * This is the phase where Detox reads its configuration, starts a server.
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.
22
28
  */
23
29
  init(options?: Partial<DetoxInitOptions>): Promise<void>;
24
30
 
25
31
  /**
26
- * This is the phase where Detox loads its expectation library and starts a 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.
27
34
  */
28
35
  installWorker(options?: Partial<DetoxInstallWorkerOptions>): Promise<void>;
29
36
 
30
37
  /**
31
38
  * Deallocates the device.
39
+ * Most Client API (device, by, element, expect) will stop working, except for the logger.
32
40
  */
33
41
  uninstallWorker(): Promise<void>;
34
42
 
35
43
  /**
36
- * The global cleanup phase should happen after all the tests have finished.
37
- * This is the phase where the Detox server shuts down.
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.
38
46
  */
39
47
  cleanup(): Promise<void>;
40
- // endregion
48
+ //#endregion
41
49
 
42
- // region Lifecycle
50
+ //#region Lifecycle
43
51
  /**
44
52
  * Reports that the test runner started executing a test suite, e.g. a `beforeAll` hook or a first test.
45
53
  */
@@ -114,7 +122,7 @@ declare global {
114
122
  * @param testResults - reports about test files
115
123
  */
116
124
  reportTestResults(testResults: DetoxTestFileReport[]): Promise<void>;
117
- // endregion
125
+ //#endregion
118
126
 
119
127
  readonly config: RuntimeConfig;
120
128
  readonly log: Detox.Logger;
@@ -131,6 +139,10 @@ declare global {
131
139
  createEventStream(): NodeJS.ReadableStream;
132
140
  };
133
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
+ */
134
146
  readonly worker: Worker;
135
147
  }
136
148
 
@@ -230,7 +242,7 @@ declare global {
230
242
  * or equal to "default" if the name is not configured.
231
243
  */
232
244
  apps: Record<string, Readonly<Detox.DetoxAppConfig>>;
233
- artifacts: Readonly<Detox.DetoxArtifactsConfig>;
245
+ artifacts: Readonly<RuntimeArtifactsConfig>;
234
246
  behavior: Readonly<Detox.DetoxBehaviorConfig>;
235
247
  cli: Readonly<CLIConfig>;
236
248
  device: Readonly<Detox.DetoxDeviceConfig>;
@@ -239,6 +251,19 @@ declare global {
239
251
  session: Readonly<Detox.DetoxSessionConfig>;
240
252
  }>;
241
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
+
242
267
  type CLIConfig = Readonly<Partial<{
243
268
  appLaunchArgs: string;
244
269
  artifactsLocation: string;
package/local-cli/cli.js CHANGED
@@ -28,9 +28,12 @@ yargs
28
28
  .wrap(yargs.terminalWidth() * 0.9)
29
29
  .fail(function(msg, err, program) {
30
30
  if (err) {
31
- logger.error(DetoxError.format(err));
32
- // eslint-disable-next-line no-console
33
- console.error('');
31
+ const message = DetoxError.format(err);
32
+ if (message) {
33
+ logger.error(message);
34
+ process.stderr.write('\n');
35
+ }
36
+
34
37
  // @ts-ignore
35
38
  _.attempt(() => fs.unlinkSync(logger.file));
36
39
  // eslint-disable-next-line no-process-exit
package/local-cli/init.js CHANGED
@@ -9,7 +9,7 @@ const jestTemplates = require('./templates/jest');
9
9
  let exitCode = 0;
10
10
 
11
11
  module.exports.command = 'init';
12
- module.exports.desc = 'Scaffold initial E2E test folder structure for Detox';
12
+ module.exports.desc = 'Creates template files to get you started with Detox';
13
13
  module.exports.builder = {};
14
14
 
15
15
  module.exports.handler = async function init() {
package/local-cli/test.js CHANGED
@@ -3,7 +3,7 @@ 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
 
@@ -16,14 +16,14 @@ module.exports.handler = async function test({ detoxArgs, runnerArgs }) {
16
16
  };
17
17
 
18
18
  const config = await detox.resolveConfig(opts);
19
- if (!detoxArgs['inspect-brk']) {
19
+ if (!config.cli.inspectBrk) {
20
20
  await detox.init(opts);
21
21
  }
22
22
 
23
- const runnerCommand = new TestRunnerCommand()
24
- .setDeviceConfig(config.device)
25
- .replicateCLIConfig(config.cli)
26
- .setRunnerConfig(config.testRunner);
23
+ const runnerCommand = new TestRunnerCommand({
24
+ config,
25
+ env: process.env,
26
+ });
27
27
 
28
28
  await runnerCommand.execute();
29
29
  } finally {
@@ -6,103 +6,40 @@ const unparse = require('yargs-unparser');
6
6
 
7
7
  const detox = require('../../internals');
8
8
  const log = detox.log.child({ cat: ['lifecycle', 'cli'] });
9
- const { DetoxRuntimeError } = require('../../src/errors');
10
9
  const { printEnvironmentVariables, prependNodeModulesBinToPATH } = require('../../src/utils/envUtils');
11
- const { escapeSpaces } = require('../../src/utils/shellUtils');
10
+ const { toSimplePath } = require('../../src/utils/pathUtils');
11
+ const { escapeSpaces, useForwardSlashes } = require('../../src/utils/shellUtils');
12
+
13
+ const TestRunnerError = require('./TestRunnerError');
12
14
 
13
15
  class TestRunnerCommand {
14
- constructor() {
15
- this._argv = {};
16
- this._cli2env = {};
17
- this._envHint = {};
16
+ /*
17
+ @param {object} opts
18
+ @param {DetoxInternals.RuntimeConfig} opts.config
19
+ @param {ProcessEnv} opts.env
20
+ */
21
+ constructor(opts) {
22
+ const cliConfig = opts.config.cli;
23
+ const deviceConfig = opts.config.device;
24
+ const runnerConfig = opts.config.testRunner;
25
+
26
+ this._argv = runnerConfig.args;
27
+ this._retries = runnerConfig.retries;
28
+ this._envHint = this._buildEnvHint(opts.env);
18
29
  this._envFwd = {};
19
- this._retries = 0;
20
- /** @type {Detox.DetoxDeviceConfig} */
21
- this._deviceConfig = null;
22
- }
23
-
24
- /**
25
- * @param {Partial<Readonly<DetoxInternals.CLIConfig>>} cliConfig
26
- * @returns {this}
27
- */
28
- replicateCLIConfig(cliConfig) {
29
- this._cli2env = _.omitBy({
30
- DETOX_APP_LAUNCH_ARGS: cliConfig.appLaunchArgs,
31
- DETOX_ARTIFACTS_LOCATION: cliConfig.artifactsLocation,
32
- DETOX_CAPTURE_VIEW_HIERARCHY: cliConfig.captureViewHierarchy,
33
- DETOX_CLEANUP: cliConfig.cleanup,
34
- DETOX_CONFIGURATION: cliConfig.configuration,
35
- DETOX_CONFIG_PATH: cliConfig.configPath,
36
- DETOX_DEBUG_SYNCHRONIZATION: cliConfig.debugSynchronization,
37
- DETOX_DEVICE_BOOT_ARGS: cliConfig.deviceBootArgs,
38
- DETOX_DEVICE_NAME: cliConfig.deviceName,
39
- DETOX_FORCE_ADB_INSTALL: this._deviceConfig.type.startsWith('android.')
40
- ? cliConfig.forceAdbInstall
41
- : undefined,
42
- DETOX_GPU: cliConfig.gpu,
43
- DETOX_HEADLESS: cliConfig.headless,
44
- DETOX_KEEP_LOCKFILE: cliConfig.keepLockFile,
45
- DETOX_LOGLEVEL: cliConfig.loglevel,
46
- DETOX_READ_ONLY_EMU: cliConfig.readonlyEmu,
47
- DETOX_RECORD_LOGS: cliConfig.recordLogs,
48
- DETOX_RECORD_PERFORMANCE: cliConfig.recordPerformance,
49
- DETOX_RECORD_VIDEOS: cliConfig.recordVideos,
50
- DETOX_REPORT_SPECS: cliConfig.jestReportSpecs,
51
- DETOX_RETRIES: cliConfig.retries,
52
- DETOX_REUSE: cliConfig.reuse,
53
- DETOX_TAKE_SCREENSHOTS: cliConfig.takeScreenshots,
54
- DETOX_USE_CUSTOM_LOGGER: cliConfig.useCustomLogger,
55
- }, _.isUndefined);
56
-
57
- this._envHint = _(process.env)
58
- .mapKeys((_value, key) => key.toUpperCase())
59
- .pickBy((_value, key) => key.startsWith('DETOX_'))
60
- .omit(['DETOX_CONFIG_SNAPSHOT_PATH'])
61
- .value();
62
-
63
- return this;
64
- }
65
-
66
- /**
67
- * @param {Detox.DetoxDeviceConfig} config
68
- * @returns {this}
69
- */
70
- setDeviceConfig(config) {
71
- this._deviceConfig = config;
72
-
73
- return this;
74
- }
75
-
76
- /**
77
- * @param {Detox.DetoxTestRunnerConfig} config
78
- * @returns {this}
79
- */
80
- setRunnerConfig(config) {
81
- this._argv = config.args;
82
- this._retries = config.inspectBrk ? 0 : config.retries;
83
- if (config.forwardEnv) {
84
- this._envFwd = this._cli2env;
85
- Object.assign(this._envHint, this._cli2env);
30
+ if (runnerConfig.forwardEnv) {
31
+ this._envFwd = this._buildEnvOverride(cliConfig, deviceConfig);
32
+ Object.assign(this._envHint, this._envFwd);
86
33
  }
87
-
88
- return this;
89
34
  }
90
35
 
91
36
  async execute() {
92
37
  let runsLeft = 1 + this._retries;
93
- let launchError;
38
+ let launchError = null;
94
39
 
95
40
  do {
96
41
  try {
97
- if (launchError) {
98
- const list = this._argv._.map((file, index) => ` ${index + 1}. ${file}`).join('\n');
99
- log.error(
100
- `There were failing tests in the following files:\n${list}\n\n` +
101
- 'Detox CLI is going to restart the test runner with those files...\n'
102
- );
103
- }
104
-
105
- await this._doExecute();
42
+ await this._spawnTestRunner();
106
43
  launchError = null;
107
44
  } catch (e) {
108
45
  launchError = e;
@@ -120,9 +57,11 @@ class TestRunnerCommand {
120
57
  }
121
58
 
122
59
  if (--runsLeft > 0) {
123
- this._argv._ = testFilesToRetry;
124
60
  // @ts-ignore
125
- detox.session.testSessionIndex++; // it is always a primary context, so we can update it
61
+ detox.session.testSessionIndex++; // it is always the primary context, so we can update it
62
+
63
+ this._argv._ = testFilesToRetry.map(useForwardSlashes);
64
+ this._logRelaunchError(testFilesToRetry);
126
65
  }
127
66
  }
128
67
  } while (launchError && runsLeft > 0);
@@ -132,11 +71,53 @@ class TestRunnerCommand {
132
71
  }
133
72
  }
134
73
 
135
- async _doExecute() {
74
+ _buildEnvHint(env) {
75
+ return _(env)
76
+ .mapKeys((_value, key) => key.toUpperCase())
77
+ .pickBy((_value, key) => key.startsWith('DETOX_'))
78
+ .omit(['DETOX_CONFIG_SNAPSHOT_PATH'])
79
+ .value();
80
+ }
81
+
82
+ /**
83
+ * @param {DetoxInternals.CLIConfig} cliConfig
84
+ * @param {Detox.DetoxDeviceConfig} deviceConfig
85
+ */
86
+ _buildEnvOverride(cliConfig, deviceConfig) {
87
+ return _.omitBy({
88
+ DETOX_APP_LAUNCH_ARGS: cliConfig.appLaunchArgs,
89
+ DETOX_ARTIFACTS_LOCATION: cliConfig.artifactsLocation,
90
+ DETOX_CAPTURE_VIEW_HIERARCHY: cliConfig.captureViewHierarchy,
91
+ DETOX_CLEANUP: cliConfig.cleanup,
92
+ DETOX_CONFIGURATION: cliConfig.configuration,
93
+ DETOX_CONFIG_PATH: cliConfig.configPath,
94
+ DETOX_DEBUG_SYNCHRONIZATION: cliConfig.debugSynchronization,
95
+ DETOX_DEVICE_BOOT_ARGS: cliConfig.deviceBootArgs,
96
+ DETOX_DEVICE_NAME: cliConfig.deviceName,
97
+ DETOX_FORCE_ADB_INSTALL: deviceConfig.type.startsWith('android.')
98
+ ? cliConfig.forceAdbInstall
99
+ : undefined,
100
+ DETOX_GPU: cliConfig.gpu,
101
+ DETOX_HEADLESS: cliConfig.headless,
102
+ DETOX_KEEP_LOCKFILE: cliConfig.keepLockFile,
103
+ DETOX_LOGLEVEL: cliConfig.loglevel,
104
+ DETOX_READ_ONLY_EMU: cliConfig.readonlyEmu,
105
+ DETOX_RECORD_LOGS: cliConfig.recordLogs,
106
+ DETOX_RECORD_PERFORMANCE: cliConfig.recordPerformance,
107
+ DETOX_RECORD_VIDEOS: cliConfig.recordVideos,
108
+ DETOX_REPORT_SPECS: cliConfig.jestReportSpecs,
109
+ DETOX_RETRIES: cliConfig.retries,
110
+ DETOX_REUSE: cliConfig.reuse,
111
+ DETOX_TAKE_SCREENSHOTS: cliConfig.takeScreenshots,
112
+ DETOX_USE_CUSTOM_LOGGER: cliConfig.useCustomLogger,
113
+ }, _.isUndefined);
114
+ }
115
+
116
+ async _spawnTestRunner() {
136
117
  const fullCommand = this._buildSpawnArguments().map(escapeSpaces);
137
118
  const fullCommandWithHint = printEnvironmentVariables(this._envHint) + fullCommand.join(' ');
138
119
 
139
- log.info({ env: this._envHint }, fullCommandWithHint);
120
+ log.info.begin({ env: this._envHint }, fullCommandWithHint);
140
121
 
141
122
  return new Promise((resolve, reject) => {
142
123
  cp.spawn(fullCommand[0], fullCommand.slice(1), {
@@ -149,15 +130,26 @@ class TestRunnerCommand {
149
130
  .tap(prependNodeModulesBinToPATH)
150
131
  .value()
151
132
  })
152
- .on('error', (err) => reject(err))
153
- .on('exit', (code) => code === 0
154
- ? resolve()
155
- : reject(new DetoxRuntimeError(`Command failed with exit code = ${code}:\n${fullCommandWithHint}`)
156
- ));
133
+ .on('error', /* istanbul ignore next */ (err) => reject(err))
134
+ .on('exit', (code, signal) => {
135
+ if (code === 0) {
136
+ log.trace.end({ success: true });
137
+ resolve();
138
+ } else {
139
+ const error = new TestRunnerError({
140
+ command: fullCommandWithHint,
141
+ code,
142
+ signal,
143
+ });
144
+ log.error.end({ success: false, code, signal }, error.message);
145
+ reject(error);
146
+ }
147
+ });
157
148
  });
158
149
  }
159
150
 
160
151
  _buildSpawnArguments() {
152
+ /* istanbul ignore next */
161
153
  const { _: specs = [], '--': passthrough = [], $0, ...argv } = this._argv;
162
154
  const { _: $0_, ...$0argv } = parser($0);
163
155
 
@@ -168,6 +160,17 @@ class TestRunnerCommand {
168
160
  ...unparse({ _: [...passthrough, ...specs] }),
169
161
  ].map(String);
170
162
  }
163
+
164
+ _logRelaunchError(filePaths) {
165
+ const list = filePaths.map((file, index) => {
166
+ return ` ${index + 1}. ${toSimplePath(file)}`;
167
+ }).join('\n');
168
+
169
+ log.error(
170
+ `There were failing tests in the following files:\n${list}\n\n` +
171
+ 'Detox CLI is going to restart the test runner with those files...\n'
172
+ );
173
+ }
171
174
  }
172
175
 
173
176
  module.exports = TestRunnerCommand;
@@ -0,0 +1,17 @@
1
+ const { DetoxError } = require('../../src/errors');
2
+
3
+ class TestRunnerError extends DetoxError {
4
+ constructor({ command, code, signal }) {
5
+ super(`Command failed with exit code = ${code}:\n${command}`);
6
+
7
+ this.code = code;
8
+ this.signal = signal;
9
+ this.name = 'TestRunnerError';
10
+ }
11
+
12
+ format() {
13
+ return '';
14
+ }
15
+ }
16
+
17
+ module.exports = TestRunnerError;
@@ -109,7 +109,6 @@ module.exports = {
109
109
  describe: 'Override the device name specified in a configuration. Useful for running a single build configuration on multiple devices.',
110
110
  },
111
111
  'device-boot-args': {
112
- alias: 'device-launch-args',
113
112
  group: 'Execution:',
114
113
  describe: 'Custom arguments to pass (through) onto the device (emulator/simulator) binary when booted.',
115
114
  },