detox 19.13.0 → 20.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (236) hide show
  1. package/Detox-android/com/wix/detox/{19.13.0/detox-19.13.0-javadoc.jar → 20.0.0/detox-20.0.0-javadoc.jar} +0 -0
  2. package/Detox-android/com/wix/detox/20.0.0/detox-20.0.0-javadoc.jar.md5 +1 -0
  3. package/Detox-android/com/wix/detox/20.0.0/detox-20.0.0-javadoc.jar.sha1 +1 -0
  4. package/Detox-android/com/wix/detox/20.0.0/detox-20.0.0-javadoc.jar.sha256 +1 -0
  5. package/Detox-android/com/wix/detox/20.0.0/detox-20.0.0-javadoc.jar.sha512 +1 -0
  6. package/Detox-android/com/wix/detox/{19.13.0/detox-19.13.0-sources.jar → 20.0.0/detox-20.0.0-sources.jar} +0 -0
  7. package/Detox-android/com/wix/detox/20.0.0/detox-20.0.0-sources.jar.md5 +1 -0
  8. package/Detox-android/com/wix/detox/20.0.0/detox-20.0.0-sources.jar.sha1 +1 -0
  9. package/Detox-android/com/wix/detox/20.0.0/detox-20.0.0-sources.jar.sha256 +1 -0
  10. package/Detox-android/com/wix/detox/20.0.0/detox-20.0.0-sources.jar.sha512 +1 -0
  11. package/Detox-android/com/wix/detox/20.0.0/detox-20.0.0.aar +0 -0
  12. package/Detox-android/com/wix/detox/20.0.0/detox-20.0.0.aar.md5 +1 -0
  13. package/Detox-android/com/wix/detox/20.0.0/detox-20.0.0.aar.sha1 +1 -0
  14. package/Detox-android/com/wix/detox/20.0.0/detox-20.0.0.aar.sha256 +1 -0
  15. package/Detox-android/com/wix/detox/20.0.0/detox-20.0.0.aar.sha512 +1 -0
  16. package/Detox-android/com/wix/detox/{19.13.0/detox-19.13.0.pom → 20.0.0/detox-20.0.0.pom} +1 -1
  17. package/Detox-android/com/wix/detox/20.0.0/detox-20.0.0.pom.md5 +1 -0
  18. package/Detox-android/com/wix/detox/20.0.0/detox-20.0.0.pom.sha1 +1 -0
  19. package/Detox-android/com/wix/detox/20.0.0/detox-20.0.0.pom.sha256 +1 -0
  20. package/Detox-android/com/wix/detox/20.0.0/detox-20.0.0.pom.sha512 +1 -0
  21. package/Detox-android/com/wix/detox/maven-metadata.xml +4 -4
  22. package/Detox-android/com/wix/detox/maven-metadata.xml.md5 +1 -1
  23. package/Detox-android/com/wix/detox/maven-metadata.xml.sha1 +1 -1
  24. package/Detox-android/com/wix/detox/maven-metadata.xml.sha256 +1 -1
  25. package/Detox-android/com/wix/detox/maven-metadata.xml.sha512 +1 -1
  26. package/Detox-ios-src.tbz +0 -0
  27. package/Detox-ios.tbz +0 -0
  28. package/README.md +1 -1
  29. package/android/detox/src/full/java/com/wix/detox/Detox.java +2 -59
  30. package/android/detox/src/full/java/com/wix/detox/NotificationDataParser.kt +3 -3
  31. package/index.d.ts +354 -191
  32. package/index.js +1 -0
  33. package/internals.d.ts +298 -0
  34. package/internals.js +4 -0
  35. package/local-cli/build-framework-cache.js +2 -2
  36. package/local-cli/build.js +7 -8
  37. package/local-cli/build.test.js +46 -40
  38. package/local-cli/clean-framework-cache.js +3 -3
  39. package/local-cli/cli.js +8 -7
  40. package/local-cli/init.js +73 -68
  41. package/local-cli/rebuild-framework-cache.js +1 -1
  42. package/local-cli/reset-lock-file.js +16 -0
  43. package/local-cli/templates/jest.js +14 -36
  44. package/local-cli/test.js +24 -282
  45. package/local-cli/test.test.js +394 -648
  46. package/local-cli/testCommand/TestRunnerCommand.js +163 -0
  47. package/local-cli/{utils/testCommandArgs.js → testCommand/builder.js} +10 -36
  48. package/local-cli/testCommand/middlewares.js +66 -0
  49. package/local-cli/{utils → testCommand}/warnings.js +0 -13
  50. package/local-cli/utils/jestInternals.js +13 -2
  51. package/local-cli/utils/yargsUtils.js +67 -0
  52. package/package.json +32 -19
  53. package/runners/deprecation.js +45 -0
  54. package/runners/jest/JestCircusEnvironment.js +3 -38
  55. package/runners/jest/adapter.d.ts +4 -10
  56. package/runners/jest/adapter.js +3 -6
  57. package/runners/jest/assignReporter.d.ts +4 -1
  58. package/runners/jest/assignReporter.js +3 -6
  59. package/runners/jest/globalSetup.js +1 -0
  60. package/runners/jest/globalTeardown.js +1 -0
  61. package/runners/jest/index.d.ts +60 -0
  62. package/runners/jest/index.js +16 -0
  63. package/runners/jest/index.test.js +13 -0
  64. package/runners/jest/reporter.js +1 -0
  65. package/runners/jest/reporters/DetoxReporter.js +36 -0
  66. package/runners/jest/specReporter.d.ts +4 -9
  67. package/runners/jest/specReporter.js +3 -10
  68. package/runners/jest/streamlineReporter.js +3 -22
  69. package/runners/jest/testEnvironment/index.js +205 -0
  70. package/runners/jest/testEnvironment/listeners/DetoxCoreListener.js +166 -0
  71. package/runners/{jest-circus → jest/testEnvironment}/listeners/DetoxInitErrorListener.js +1 -1
  72. package/runners/jest/testEnvironment/listeners/DetoxPlatformFilterListener.js +27 -0
  73. package/runners/jest/{SpecReporterImpl.js → testEnvironment/listeners/SpecReporter.js} +61 -9
  74. package/runners/jest/testEnvironment/listeners/WorkerAssignReporter.js +30 -0
  75. package/runners/jest/testEnvironment/listeners/index.js +13 -0
  76. package/runners/{jest-circus → jest/testEnvironment}/utils/assertExistingContext.js +2 -2
  77. package/runners/jest/testEnvironment/utils/assertJestCircus27.js +70 -0
  78. package/runners/jest/testEnvironment/utils/assertJestCircus27.test.js +22 -0
  79. package/runners/jest/{utils → testEnvironment/utils}/getFullTestName.js +0 -0
  80. package/runners/jest/{utils → testEnvironment/utils}/hasTimedOut.js +0 -0
  81. package/runners/jest/{utils → testEnvironment/utils}/index.js +0 -0
  82. package/runners/jest/{utils → testEnvironment/utils}/stdout.js +0 -0
  83. package/runners/jest-circus/environment/index.js +6 -0
  84. package/runners/jest-circus/index.js +1 -10
  85. package/runners/jest-circus/reporter.js +1 -0
  86. package/runners/migration.js +37 -0
  87. package/runners/mocha/DetoxMochaAdapter.js +3 -35
  88. package/runners/mocha/adapter.d.ts +4 -7
  89. package/runners/mocha/adapter.js +3 -5
  90. package/src/DetoxWorker.js +327 -0
  91. package/src/android/interactions/native.js +2 -1
  92. package/src/artifacts/ArtifactsManager.js +51 -35
  93. package/src/artifacts/instruments/ios/SimulatorInstrumentsRecording.js +3 -3
  94. package/src/artifacts/log/ios/SimulatorLogRecording.js +1 -1
  95. package/src/artifacts/providers/index.js +0 -4
  96. package/src/artifacts/screenshot/SimulatorScreenshotPlugin.js +1 -1
  97. package/src/artifacts/templates/artifact/Artifact.js +1 -1
  98. package/src/artifacts/templates/plugin/ArtifactPlugin.js +1 -1
  99. package/src/artifacts/utils/buildDefaultArtifactsRootDirpath.js +2 -4
  100. package/src/artifacts/utils/temporaryPath.js +18 -5
  101. package/src/artifacts/video/SimulatorRecordVideoPlugin.js +1 -1
  102. package/src/client/AsyncWebSocket.js +8 -17
  103. package/src/client/Client.js +1 -1
  104. package/src/client/actions/actions.js +2 -2
  105. package/src/configuration/collectCliConfig.js +3 -16
  106. package/src/configuration/composeAppsConfig.js +12 -66
  107. package/src/configuration/composeArtifactsConfig.js +6 -32
  108. package/src/configuration/composeBehaviorConfig.js +3 -13
  109. package/src/configuration/composeDeviceConfig.js +38 -63
  110. package/src/configuration/composeLoggerConfig.js +59 -0
  111. package/src/configuration/composeRunnerConfig.js +127 -14
  112. package/src/configuration/composeSessionConfig.js +1 -3
  113. package/src/configuration/index.js +36 -30
  114. package/src/configuration/loadExternalConfig.js +1 -1
  115. package/src/configuration/utils/deviceAppTypes.js +0 -1
  116. package/src/devices/allocation/DeviceAllocator.js +4 -2
  117. package/src/devices/allocation/drivers/android/emulator/AVDValidator.js +1 -1
  118. package/src/devices/allocation/drivers/android/emulator/EmulatorAllocDriver.js +5 -3
  119. package/src/devices/allocation/drivers/android/emulator/EmulatorAllocationHelper.js +1 -1
  120. package/src/devices/allocation/drivers/android/emulator/EmulatorLauncher.js +3 -5
  121. package/src/devices/allocation/drivers/android/emulator/EmulatorVersionResolver.js +4 -6
  122. package/src/devices/allocation/drivers/android/emulator/launchEmulatorProcess.js +1 -1
  123. package/src/devices/allocation/drivers/android/genycloud/GenyInstanceAllocationHelper.js +1 -1
  124. package/src/devices/allocation/drivers/ios/SimulatorAllocDriver.js +1 -1
  125. package/src/devices/allocation/drivers/ios/SimulatorLauncher.js +3 -3
  126. package/src/devices/allocation/factories/index.js +0 -1
  127. package/src/devices/common/drivers/DeviceLauncher.js +2 -2
  128. package/src/devices/common/drivers/android/emulator/exec/EmulatorExec.js +1 -1
  129. package/src/devices/common/drivers/android/genycloud/services/GenyInstanceNaming.js +4 -9
  130. package/src/devices/common/drivers/android/genycloud/services/GenyRecipesService.js +1 -1
  131. package/src/devices/common/drivers/android/tools/EmulatorTelnet.js +1 -1
  132. package/src/devices/common/drivers/android/tools/FreeDeviceFinder.js +1 -1
  133. package/src/devices/common/drivers/ios/tools/AppleSimUtils.js +35 -10
  134. package/src/devices/lifecycle/GenyGlobalLifecycleHandler.js +13 -15
  135. package/src/devices/runtime/RuntimeDevice.js +85 -86
  136. package/src/devices/runtime/drivers/DeviceDriverBase.js +1 -1
  137. package/src/devices/runtime/drivers/android/AndroidDriver.js +3 -3
  138. package/src/devices/runtime/drivers/index.js +0 -1
  139. package/src/devices/runtime/drivers/ios/SimulatorDriver.js +4 -3
  140. package/src/devices/runtime/factories/ios.js +1 -8
  141. package/src/devices/runtime/utils/LaunchArgsEditor.js +4 -59
  142. package/src/devices/runtime/utils/Storage.js +4 -0
  143. package/src/environmentFactory.js +0 -8
  144. package/src/errors/DetoxConfigErrorComposer.js +92 -30
  145. package/src/errors/DetoxError.js +4 -0
  146. package/src/errors/DetoxRuntimeError.js +5 -5
  147. package/src/errors/index.js +2 -0
  148. package/src/ios/expectTwo.js +2 -1
  149. package/src/ipc/IPCClient.js +117 -0
  150. package/src/ipc/IPCServer.js +98 -0
  151. package/src/ipc/SessionState.js +62 -0
  152. package/src/logger/DetoxLogger.js +348 -0
  153. package/src/logger/index.js +5 -0
  154. package/src/logger/utils/BunyanLogger.js +76 -0
  155. package/src/logger/utils/CategoryThreadDispatcher.js +36 -0
  156. package/src/logger/utils/DetoxLogFinalizer.js +140 -0
  157. package/src/logger/utils/MessageStack.js +24 -0
  158. package/src/logger/utils/ThreadDispatcher.js +61 -0
  159. package/src/{utils → logger/utils}/customConsoleLogger.js +5 -4
  160. package/src/logger/utils/sanitizeBunyanContext.js +30 -0
  161. package/src/logger/utils/streamUtils.js +248 -0
  162. package/src/logger/utils/tracerLegacy.js +37 -0
  163. package/src/realms/DetoxConstants.js +13 -0
  164. package/src/realms/DetoxContext.js +183 -0
  165. package/src/realms/DetoxInternalsFacade.js +31 -0
  166. package/src/realms/DetoxPrimaryContext.js +261 -0
  167. package/src/realms/DetoxSecondaryContext.js +91 -0
  168. package/src/realms/index.js +10 -0
  169. package/src/realms/primary.js +3 -0
  170. package/src/realms/secondary.js +3 -0
  171. package/src/server/DetoxConnection.js +18 -23
  172. package/src/server/DetoxServer.js +7 -10
  173. package/src/server/DetoxSession.js +6 -6
  174. package/src/server/DetoxSessionManager.js +1 -1
  175. package/src/server/handlers/RegisteredConnectionHandler.js +1 -2
  176. package/src/symbols.js +50 -0
  177. package/src/utils/Timer.js +58 -33
  178. package/src/utils/argparse.js +11 -0
  179. package/src/utils/childProcess/exec.js +1 -1
  180. package/src/utils/childProcess/spawn.js +1 -1
  181. package/{local-cli/utils/misc.js → src/utils/envUtils.js} +0 -9
  182. package/src/utils/errorUtils.js +20 -0
  183. package/src/utils/logger.js +2 -162
  184. package/src/utils/shellUtils.js +18 -0
  185. package/src/utils/traceInvocationCall.js +21 -0
  186. package/src/utils/traceMethods.js +15 -0
  187. package/Detox-android/com/wix/detox/19.13.0/detox-19.13.0-javadoc.jar.md5 +0 -1
  188. package/Detox-android/com/wix/detox/19.13.0/detox-19.13.0-javadoc.jar.sha1 +0 -1
  189. package/Detox-android/com/wix/detox/19.13.0/detox-19.13.0-javadoc.jar.sha256 +0 -1
  190. package/Detox-android/com/wix/detox/19.13.0/detox-19.13.0-javadoc.jar.sha512 +0 -1
  191. package/Detox-android/com/wix/detox/19.13.0/detox-19.13.0-sources.jar.md5 +0 -1
  192. package/Detox-android/com/wix/detox/19.13.0/detox-19.13.0-sources.jar.sha1 +0 -1
  193. package/Detox-android/com/wix/detox/19.13.0/detox-19.13.0-sources.jar.sha256 +0 -1
  194. package/Detox-android/com/wix/detox/19.13.0/detox-19.13.0-sources.jar.sha512 +0 -1
  195. package/Detox-android/com/wix/detox/19.13.0/detox-19.13.0.aar +0 -0
  196. package/Detox-android/com/wix/detox/19.13.0/detox-19.13.0.aar.md5 +0 -1
  197. package/Detox-android/com/wix/detox/19.13.0/detox-19.13.0.aar.sha1 +0 -1
  198. package/Detox-android/com/wix/detox/19.13.0/detox-19.13.0.aar.sha256 +0 -1
  199. package/Detox-android/com/wix/detox/19.13.0/detox-19.13.0.aar.sha512 +0 -1
  200. package/Detox-android/com/wix/detox/19.13.0/detox-19.13.0.pom.md5 +0 -1
  201. package/Detox-android/com/wix/detox/19.13.0/detox-19.13.0.pom.sha1 +0 -1
  202. package/Detox-android/com/wix/detox/19.13.0/detox-19.13.0.pom.sha256 +0 -1
  203. package/Detox-android/com/wix/detox/19.13.0/detox-19.13.0.pom.sha512 +0 -1
  204. package/local-cli/templates/mocha.js +0 -32
  205. package/local-cli/utils/splitArgv.js +0 -107
  206. package/runners/integration.js +0 -16
  207. package/runners/jest/DetoxAdapterCircus.js +0 -60
  208. package/runners/jest/DetoxAdapterImpl.js +0 -81
  209. package/runners/jest/DetoxAdapterJasmine.js +0 -67
  210. package/runners/jest/DetoxStreamlineJestReporter.js +0 -98
  211. package/runners/jest/FailingTestsReporter.js +0 -16
  212. package/runners/jest/SpecReporterCircus.js +0 -51
  213. package/runners/jest/SpecReporterJasmine.js +0 -39
  214. package/runners/jest/WorkerAssignReporterCircus.js +0 -17
  215. package/runners/jest/WorkerAssignReporterImpl.js +0 -21
  216. package/runners/jest/WorkerAssignReporterJasmine.js +0 -15
  217. package/runners/jest/runnerInfo.js +0 -9
  218. package/runners/jest-circus/environment.js +0 -206
  219. package/runners/jest-circus/listeners/DetoxCoreListener.js +0 -113
  220. package/runners/jest-circus/utils/assertJestCircus26.js +0 -39
  221. package/runners/jest-circus/utils/wrapErrorWithNoopLifecycle.js +0 -14
  222. package/src/Detox.js +0 -317
  223. package/src/DetoxConstants.js +0 -13
  224. package/src/DetoxExportWrapper.js +0 -140
  225. package/src/artifacts/timeline/TimelineArtifactPlugin.js +0 -92
  226. package/src/configuration/utils/warnings.js +0 -12
  227. package/src/devices/allocation/drivers/NoneAllocDriver.js +0 -10
  228. package/src/devices/allocation/factories/none.js +0 -11
  229. package/src/index.js +0 -6
  230. package/src/utils/ChromeTracingExporter.js +0 -54
  231. package/src/utils/MissingDetox.js +0 -78
  232. package/src/utils/fakeTimestampsProvider.js +0 -9
  233. package/src/utils/getWorkerId.js +0 -5
  234. package/src/utils/lastFailedTests.js +0 -38
  235. package/src/utils/sh.js +0 -18
  236. package/src/utils/trace.js +0 -96
@@ -1,38 +1,3 @@
1
- const maybeNodeEnvironment = require('jest-environment-node'); // eslint-disable-line node/no-extraneous-require
2
- // @ts-ignore
3
- const NodeEnvironment = maybeNodeEnvironment.default || maybeNodeEnvironment;
4
-
5
- /**
6
- * @see https://www.npmjs.com/package/jest-circus#overview
7
- */
8
- class JestCircusEnvironment extends NodeEnvironment {
9
- constructor(config) {
10
- super(config);
11
- this.testEventListeners = [];
12
-
13
- // Enable access to this instance (single in each worker's scope) by exposing a get-function.
14
- // Note: whatever's set into this.global will be exported in that way. The reason behind it is that
15
- // each suite is run inside a sandboxed JS context which scope is in fact this specific instance. See
16
- // NodeEnvironment's constructor for more info, or https://jestjs.io/docs/en/configuration#testenvironment-string
17
- // for additional ref.
18
- this.global.detoxCircus = {
19
- getEnv: () => this,
20
- };
21
- }
22
-
23
- addEventsListener(listener) {
24
- this.testEventListeners.push(listener);
25
- }
26
-
27
- async handleTestEvent(event, state) {
28
- const name = event.name;
29
-
30
- for (const listener of this.testEventListeners) {
31
- if (typeof listener[name] === 'function') {
32
- await listener[name](event, state);
33
- }
34
- }
35
- }
36
- }
37
-
38
- module.exports = JestCircusEnvironment;
1
+ /** @deprecated */
2
+ /** @type {never} */
3
+ module.exports = require('../deprecation');
@@ -1,12 +1,6 @@
1
- interface DetoxJestAdapter extends Detox.CircusTestEventListenerBase {
2
- detox: Detox.DetoxExportWrapper;
3
- beforeEach: () => Promise<void>;
4
- afterAll: () => Promise<void>;
5
- // These are not publicly used, but are defined in order to overlap with the jasmine.CustomReporter interface (which is a weak interface)
6
- specDone: () => void;
7
- specStarted: () => void;
8
- }
9
-
10
- declare const adapter: DetoxJestAdapter;
1
+ /***
2
+ * @deprecated Detox does not support old Jest integrations since v20.0.0
3
+ */
4
+ declare const adapter: never;
11
5
 
12
6
  export = adapter;
@@ -1,6 +1,3 @@
1
- const detox = require('../../src/index');
2
-
3
- const runnerInfo = require('./runnerInfo');
4
- const DetoxAdapter = runnerInfo.isJestCircus ? require('./DetoxAdapterCircus') : require('./DetoxAdapterJasmine');
5
-
6
- module.exports = new DetoxAdapter(detox);
1
+ /** @deprecated */
2
+ /** @type {never} */
3
+ module.exports = require('../deprecation');
@@ -1,3 +1,6 @@
1
- declare const assignReporter: Detox.CircusTestEventListenerBase;
1
+ /***
2
+ * @deprecated Detox does not support old Jest integrations since v20.0.0
3
+ */
4
+ declare const assignReporter: never;
2
5
 
3
6
  export = assignReporter;
@@ -1,6 +1,3 @@
1
- const detox = require('../../src/index');
2
-
3
- const runnerInfo = require('./runnerInfo');
4
-
5
- const Reporter = runnerInfo.isJestCircus ? require('./WorkerAssignReporterCircus') : require('./WorkerAssignReporterJasmine');
6
- module.exports = new Reporter({ detox });
1
+ /** @deprecated */
2
+ /** @type {never} */
3
+ module.exports = require('../deprecation');
@@ -0,0 +1 @@
1
+ module.exports = async () => require('../../internals').init({ workerId: null });
@@ -0,0 +1 @@
1
+ module.exports = async () => require('../../internals').cleanup();
@@ -0,0 +1,60 @@
1
+ declare module 'detox/runners/jest' {
2
+ import type NodeEnvironment from 'jest-environment-node';
3
+
4
+ export function globalSetup(): Promise<void>;
5
+ export function globalTeardown(): Promise<void>;
6
+
7
+ export type DetoxCircusListenerConstructorOpts = {
8
+ readonly env: DetoxCircusEnvironment;
9
+ }
10
+
11
+ /**
12
+ * @example
13
+ * class CustomListener implements DetoxCircusListener {
14
+ * constructor(opts: DetoxCircusListenerConstructorOpts) {
15
+ * console.log('Current test path is:', opts.env.testPath);
16
+ * }
17
+ * }
18
+ */
19
+ export interface DetoxCircusListener {
20
+ start_describe_definition?(event: unknown, state: unknown): void;
21
+ finish_describe_definition?(event: unknown, state: unknown): void;
22
+ add_hook?(event: unknown, state: unknown): void;
23
+ add_test?(event: unknown, state: unknown): void;
24
+ error?(event: unknown, state: unknown): void;
25
+
26
+ setup?(event: unknown, state: unknown): void | Promise<void>;
27
+ include_test_location_in_result?(event: unknown, state: unknown): void | Promise<void>;
28
+ hook_start?(event: unknown, state: unknown): void | Promise<void>;
29
+ hook_success?(event: unknown, state: unknown): void | Promise<void>;
30
+ hook_failure?(event: unknown, state: unknown): void | Promise<void>;
31
+ test_fn_start?(event: unknown, state: unknown): void | Promise<void>;
32
+ test_fn_success?(event: unknown, state: unknown): void | Promise<void>;
33
+ test_fn_failure?(event: unknown, state: unknown): void | Promise<void>;
34
+ test_retry?(event: unknown, state: unknown): void | Promise<void>;
35
+ test_start?(event: unknown, state: unknown): void | Promise<void>;
36
+ test_skip?(event: unknown, state: unknown): void | Promise<void>;
37
+ test_todo?(event: unknown, state: unknown): void | Promise<void>;
38
+ test_done?(event: unknown, state: unknown): void | Promise<void>;
39
+ run_describe_start?(event: unknown, state: unknown): void | Promise<void>;
40
+ run_describe_finish?(event: unknown, state: unknown): void | Promise<void>;
41
+ run_start?(event: unknown, state: unknown): void | Promise<void>;
42
+ run_finish?(event: unknown, state: unknown): void | Promise<void>;
43
+ teardown?(event: unknown, state: unknown): void | Promise<void>;
44
+ }
45
+
46
+ export interface DetoxListenerFactory {
47
+ new (opts: DetoxCircusListenerConstructorOpts): DetoxCircusListener;
48
+ }
49
+
50
+ export class DetoxCircusEnvironment extends NodeEnvironment {
51
+ public readonly handleTestEvent: (event: unknown, state: unknown) => void | Promise<void>;
52
+ public readonly testPath: string;
53
+
54
+ protected registerListeners(map: Record<string, DetoxListenerFactory>): void;
55
+ protected setupTimeout: number;
56
+ protected teardownTimeout: number;
57
+ protected initDetox(): Promise<DetoxInternals.Worker>;
58
+ protected cleanupDetox(): Promise<void>;
59
+ }
60
+ }
@@ -0,0 +1,16 @@
1
+ // Lazy require() is used to avoid initializing a bare Detox context when it is not needed.
2
+ // At the moment, this safety measure is not really needed, but it's better to be on the safe side.
3
+
4
+ module.exports = {
5
+ get DetoxCircusEnvironment() {
6
+ return require('./testEnvironment');
7
+ },
8
+
9
+ get globalSetup() {
10
+ return require('./globalSetup');
11
+ },
12
+
13
+ get globalTeardown() {
14
+ return require('./globalTeardown');
15
+ },
16
+ };
@@ -0,0 +1,13 @@
1
+ describe('detox/runners/jest', () => {
2
+ it('should lazily require the exported modules', () => {
3
+ const index = require('./index');
4
+
5
+ jest.mock('./testEnvironment', () => 0);
6
+ jest.mock('./globalSetup', () => 1);
7
+ jest.mock('./globalTeardown', () => 2);
8
+
9
+ expect(index.DetoxCircusEnvironment).toBe(0);
10
+ expect(index.globalSetup).toBe(1);
11
+ expect(index.globalTeardown).toBe(2);
12
+ });
13
+ });
@@ -0,0 +1 @@
1
+ module.exports = require('./reporters/DetoxReporter');
@@ -0,0 +1,36 @@
1
+ const resolveFrom = require('resolve-from');
2
+ /** @type {typeof import('@jest/reporters').VerboseReporter} */
3
+ const JestVerboseReporter = require(resolveFrom(process.cwd(), '@jest/reporters')).VerboseReporter;
4
+
5
+ const { config, reportTestResults } = require('../../../internals');
6
+
7
+ class DetoxReporter extends JestVerboseReporter {
8
+ /**
9
+ * @param {import('@jest/test-result').AggregatedResult} results
10
+ */
11
+ // @ts-ignore
12
+ async onRunComplete(_contexts, results) {
13
+ // @ts-ignore
14
+ await super.onRunComplete(_contexts, results);
15
+
16
+ await reportTestResults(results.testResults.map(r => ({
17
+ success: !r.failureMessage,
18
+ testFilePath: r.testFilePath,
19
+ testExecError: r.testExecError,
20
+ isPermanentFailure: this._isPermanentFailure(r),
21
+ })));
22
+ }
23
+
24
+ /**
25
+ * @param {import('@jest/test-result').TestResult} testResult
26
+ */
27
+ _isPermanentFailure(testResult) {
28
+ if (config.testRunner.jest.retryAfterCircusRetries) {
29
+ return false;
30
+ }
31
+
32
+ return testResult.testResults.some(r => r.status === 'failed' && r.invocations > 1);
33
+ }
34
+ }
35
+
36
+ module.exports = DetoxReporter;
@@ -1,11 +1,6 @@
1
- interface SpecReporter extends Detox.CircusTestEventListenerBase {
2
- // These are not publicly used, but are defined in order to overlap with the jasmine.CustomReporter interface (which is a weak interface)
3
- suiteStarted: () => void;
4
- suiteDone: () => void;
5
- specDone: () => void;
6
- specStarted: () => void;
7
- }
8
-
9
- declare const specReporter: SpecReporter;
1
+ /***
2
+ * @deprecated Detox does not support old Jest integrations since v20.0.0
3
+ */
4
+ declare const specReporter: never;
10
5
 
11
6
  export = specReporter;
@@ -1,10 +1,3 @@
1
- const argparse = require('../../src/utils/argparse');
2
-
3
- const runnerInfo = require('./runnerInfo');
4
-
5
- if (argparse.getArgValue('reportSpecs') === 'true') {
6
- const Reporter = runnerInfo.isJestCircus ? require('./SpecReporterCircus') : require('./SpecReporterJasmine');
7
- module.exports = new Reporter();
8
- } else {
9
- module.exports = {};
10
- }
1
+ /** @deprecated */
2
+ /** @type {never} */
3
+ module.exports = require('../deprecation');
@@ -1,22 +1,3 @@
1
- // @ts-nocheck
2
- /*
3
- * This is here to make it easier for users to apply this reporter in config.json (naming-wise)
4
- * TODO: rename this file to reporter.js in the next major version (Detox 18)
5
- */
6
-
7
- const DetoxStreamlineJestReporter = require('./DetoxStreamlineJestReporter');
8
- const FailingTestsReporter = require('./FailingTestsReporter');
9
-
10
- class DetoxReporter extends DetoxStreamlineJestReporter {
11
- constructor(globalConfig) {
12
- super(globalConfig);
13
- this._failingTestsReporter = new FailingTestsReporter();
14
- }
15
-
16
- async onRunComplete(contexts, results) {
17
- await super.onRunComplete(contexts, results);
18
- await this._failingTestsReporter.onRunComplete(contexts, results);
19
- }
20
- }
21
-
22
- module.exports = DetoxReporter;
1
+ /** @deprecated */
2
+ /** @type {never} */
3
+ module.exports = require('../deprecation');
@@ -0,0 +1,205 @@
1
+ const path = require('path');
2
+
3
+ const resolveFrom = require('resolve-from');
4
+ const maybeNodeEnvironment = require(resolveFrom(process.cwd(), 'jest-environment-node'));
5
+ /** @type {typeof import('@jest/environment').JestEnvironment} */
6
+ const NodeEnvironment = maybeNodeEnvironment.default || maybeNodeEnvironment;
7
+
8
+ const detox = require('../../../internals');
9
+ const Timer = require('../../../src/utils/Timer');
10
+
11
+ const {
12
+ DetoxCoreListener,
13
+ DetoxInitErrorListener,
14
+ DetoxPlatformFilterListener,
15
+ SpecReporter,
16
+ WorkerAssignReporter
17
+ } = require('./listeners');
18
+ const assertExistingContext = require('./utils/assertExistingContext');
19
+ const { assertJestCircus27 } = require('./utils/assertJestCircus27');
20
+
21
+ const SYNC_CIRCUS_EVENTS = new Set([
22
+ 'start_describe_definition',
23
+ 'finish_describe_definition',
24
+ 'add_hook',
25
+ 'add_test',
26
+ 'error',
27
+ ]);
28
+
29
+ const log = detox.log.child({ cat: 'lifecycle,jest-environment' });
30
+
31
+ /**
32
+ * @see https://www.npmjs.com/package/jest-circus#overview
33
+ */
34
+ class DetoxCircusEnvironment extends NodeEnvironment {
35
+ constructor(config, context) {
36
+ super(assertJestCircus27(config), assertExistingContext(context));
37
+
38
+ /** @private */
39
+ this._shouldManageDetox = detox.getStatus() === 'inactive';
40
+ /** @private */
41
+ this._timer = new Timer();
42
+
43
+ /** @internal */
44
+ this.testPath = path.relative(process.cwd(), context.testPath);
45
+ /** @protected */
46
+ this.testEventListeners = [];
47
+ /** @protected */
48
+ this.setupTimeout = detox.config.testRunner.jest.setupTimeout;
49
+ /** @protected */
50
+ this.teardownTimeout = detox.config.testRunner.jest.teardownTimeout;
51
+
52
+ log.trace.begin(this.testPath);
53
+
54
+ this.setup = this._wrapSetup(this.setup);
55
+ this.teardown = this._wrapTeardown(this.teardown);
56
+
57
+ this.registerListeners({
58
+ DetoxInitErrorListener,
59
+ DetoxPlatformFilterListener,
60
+ DetoxCoreListener,
61
+ SpecReporter,
62
+ WorkerAssignReporter,
63
+ });
64
+ }
65
+
66
+ /** @override */
67
+ async setup() {
68
+ await super.setup();
69
+ await this.initDetox();
70
+ }
71
+
72
+ handleTestEvent = async (event, state) => {
73
+ this._timer.schedule(state.testTimeout != null ? state.testTimeout : this.setupTimeout);
74
+
75
+ if (SYNC_CIRCUS_EVENTS.has(event.name)) {
76
+ this._handleTestEventSync(event, state);
77
+ } else {
78
+ await this._handleTestEventAsync(event, state);
79
+ }
80
+ };
81
+
82
+ /** @override */
83
+ async teardown() {
84
+ try {
85
+ await this.cleanupDetox();
86
+ } finally {
87
+ await super.teardown();
88
+ }
89
+ }
90
+
91
+ /** @protected */
92
+ registerListeners(map) {
93
+ for (const Listener of Object.values(map)) {
94
+ this.testEventListeners.push(new Listener({
95
+ env: this,
96
+ }));
97
+ }
98
+ }
99
+
100
+ /**
101
+ * @protected
102
+ */
103
+ async initDetox() {
104
+ const opts = {
105
+ global: this.global,
106
+ workerId: `w${process.env.JEST_WORKER_ID}`,
107
+ };
108
+
109
+ if (this._shouldManageDetox) {
110
+ await detox.init(opts);
111
+ } else {
112
+ await detox.installWorker(opts);
113
+ }
114
+
115
+ return detox.worker;
116
+ }
117
+
118
+ /** @protected */
119
+ async cleanupDetox() {
120
+ if (this._shouldManageDetox) {
121
+ await detox.cleanup();
122
+ } else {
123
+ await detox.uninstallWorker();
124
+ }
125
+ }
126
+
127
+ /** @private */
128
+ _handleTestEventSync(event, state) {
129
+ const { name } = event;
130
+
131
+ for (const listener of this.testEventListeners) {
132
+ if (typeof listener[name] === 'function') {
133
+ listener[name](event, state);
134
+ }
135
+ }
136
+ }
137
+
138
+ /** @private */
139
+ async _handleTestEventAsync(event, state = null) {
140
+ const description = `handling ${state ? 'jest-circus' : 'jest-environment'} "${event.name}" event`;
141
+
142
+ for (const listener of this.testEventListeners) {
143
+ if (typeof listener[event.name] !== 'function') {
144
+ continue;
145
+ }
146
+
147
+ try {
148
+ await this._timer.run(description, () => listener[event.name](event, state));
149
+ } catch (listenerError) {
150
+ log.error(listenerError);
151
+ if (this._timer.expired) {
152
+ break;
153
+ }
154
+ }
155
+ }
156
+ }
157
+
158
+ _wrapSetup(fn) {
159
+ const _setup = fn.bind(this);
160
+
161
+ return async () => {
162
+ await log.trace.complete('set up environment', async () => {
163
+ try {
164
+ this._timer.schedule(this.setupTimeout);
165
+ await this._handleTestEventAsync({ name: 'environment_setup_start' });
166
+ await this._timer.run(`setting up Detox environment`, _setup);
167
+ await this._handleTestEventAsync({ name: 'environment_setup_success' });
168
+ } catch (error) {
169
+ this._timer.schedule(this.teardownTimeout);
170
+ await this._handleTestEventAsync({ name: 'environment_setup_failure', error });
171
+ throw error;
172
+ } finally {
173
+ this._timer.clear();
174
+ }
175
+ });
176
+ };
177
+ }
178
+
179
+ _wrapTeardown(fn) {
180
+ const _teardown = fn.bind(this);
181
+
182
+ return async () => {
183
+ await log.trace.complete('tear down environment', async () => {
184
+ try {
185
+ this._timer.schedule(this.teardownTimeout);
186
+ await this._handleTestEventAsync({ name: 'environment_teardown_start' });
187
+ await this._timer.run(`tearing down Detox environment`, _teardown);
188
+ await this._handleTestEventAsync({ name: 'environment_teardown_success' });
189
+ } catch (error) {
190
+ if (this._timer.expired) {
191
+ this._timer.schedule(this.teardownTimeout);
192
+ }
193
+
194
+ await this._handleTestEventAsync({ name: 'environment_teardown_failure', error });
195
+ throw error;
196
+ } finally {
197
+ this._timer.clear();
198
+ log.trace.end();
199
+ }
200
+ });
201
+ };
202
+ }
203
+ }
204
+
205
+ module.exports = DetoxCircusEnvironment;
@@ -0,0 +1,166 @@
1
+ // @ts-nocheck
2
+ const _ = require('lodash');
3
+
4
+ const detox = require('../../../..');
5
+ const detoxInternals = require('../../../../internals');
6
+ const { getFullTestName, hasTimedOut } = require('../utils');
7
+
8
+ const RETRY_TIMES = Symbol.for('RETRY_TIMES');
9
+
10
+ const log = detoxInternals.log.child({ cat: 'lifecycle,jest-environment' });
11
+
12
+ class DetoxCoreListener {
13
+ constructor({ env }) {
14
+ this._startedTests = new Set();
15
+ this._testsFailedBeforeStart = new Set();
16
+ this._env = env;
17
+ this._circusRetryTimes = 1;
18
+ }
19
+
20
+ async setup() {
21
+ // Workaround to override Jest's expect
22
+ if (detoxInternals.config.behavior.init.exposeGlobals) {
23
+ this._env.global.expect = detox.expect;
24
+ }
25
+ }
26
+
27
+ async run_describe_start({ describeBlock }) {
28
+ if (describeBlock.children.length) {
29
+ log.trace.begin(describeBlock.parent ? describeBlock.name : 'run the tests');
30
+ await detoxInternals.onRunDescribeStart({
31
+ name: describeBlock.name,
32
+ });
33
+ }
34
+ }
35
+
36
+ async run_describe_finish({ describeBlock }) {
37
+ if (describeBlock.children.length) {
38
+ await detoxInternals.onRunDescribeFinish({ name: describeBlock.name });
39
+ log.trace.end();
40
+ }
41
+ }
42
+
43
+ async test_start({ test }) {
44
+ const metadata = this._getTestMetadata(test);
45
+ if (metadata.status === 'failed') {
46
+ this._testsFailedBeforeStart.add(test);
47
+ }
48
+
49
+ const logTrace = this._isTestSkipped(test)
50
+ ? log.trace
51
+ : log.trace.begin;
52
+
53
+ logTrace({
54
+ context: 'test',
55
+ status: metadata.status,
56
+ fullName: metadata.fullName,
57
+ invocations: metadata.invocations,
58
+ }, metadata.title);
59
+
60
+ const circusRetryTimes = +this._env.global[RETRY_TIMES];
61
+ this._circusRetryTimes = isNaN(circusRetryTimes) ? 1 : 1 + circusRetryTimes;
62
+ }
63
+
64
+ async hook_start(event, state) {
65
+ await this._onBeforeActualTestStart(state.currentlyRunningTest);
66
+ log.trace.begin({ functionCode: event.hook.fn.toString() }, event.hook.type);
67
+ }
68
+
69
+ async hook_success() {
70
+ log.trace.end({ success: true });
71
+ }
72
+
73
+ async hook_failure({ error, hook }) {
74
+ await detoxInternals.onHookFailure({
75
+ error,
76
+ hook: hook.type,
77
+ });
78
+
79
+ log.trace.end({ success: false, error });
80
+ }
81
+
82
+ async test_fn_start({ test }) {
83
+ await this._onBeforeActualTestStart(test);
84
+
85
+ if (!this._testsFailedBeforeStart.has(test)) {
86
+ // Jest bug workaround: beforeAll hook errors result into an unterminated test_fn_start event.
87
+ log.trace.begin({ functionCode: test.fn.toString() }, 'test_fn');
88
+ }
89
+ }
90
+
91
+ async test_fn_success() {
92
+ log.trace.end({ success: true });
93
+ }
94
+
95
+ async test_fn_failure({ error }) {
96
+ await detoxInternals.onTestFnFailure({ error });
97
+ log.trace.end({ success: false, error });
98
+ }
99
+
100
+ async test_done({ test }) {
101
+ const metadata = this._getTestMetadata(test);
102
+
103
+ if (this._startedTests.has(test)) {
104
+ await detoxInternals.onTestDone(metadata);
105
+ this._startedTests.delete(test);
106
+ }
107
+
108
+ log.trace.end(_.pick(metadata, ['status', 'timedOut']));
109
+ }
110
+
111
+ async _onBeforeActualTestStart(test) {
112
+ if (!this._isTestActuallyStarting(test)) {
113
+ return;
114
+ }
115
+
116
+ this._startedTests.add(test);
117
+ await detoxInternals.onTestStart(this._getTestMetadata(test));
118
+ }
119
+
120
+ _isTestActuallyStarting(test) {
121
+ return test && !this._isTestSkipped(test) && !this._startedTests.has(test) && !this._testsFailedBeforeStart.has(test);
122
+ }
123
+
124
+ _isTestSkipped(test) {
125
+ return test && (test.mode === 'skip' || test.mode === 'todo');
126
+ }
127
+
128
+ _getTestMetadata(test) {
129
+ const result = {
130
+ title: test.name,
131
+ fullName: getFullTestName(test),
132
+ status: this._getTestStatus(test),
133
+ invocations: this._getTestInvocations(test),
134
+ };
135
+
136
+ if (result.status === 'failed') {
137
+ result.timedOut = hasTimedOut(test);
138
+ }
139
+
140
+ return result;
141
+ }
142
+
143
+ /** @returns { 'failed' | 'passed' | 'running' | 'skip' | 'todo' } */
144
+ _getTestStatus(test) {
145
+ if (!_.isEmpty(test.errors)) {
146
+ return 'failed';
147
+ }
148
+
149
+ if (this._isTestSkipped(test)) {
150
+ return test.mode;
151
+ }
152
+
153
+ if (test.status === 'done') {
154
+ return 'passed';
155
+ } else {
156
+ return test.status || 'running';
157
+ }
158
+ }
159
+
160
+ _getTestInvocations(test) {
161
+ const { testSessionIndex } = detoxInternals.session;
162
+ return testSessionIndex * this._circusRetryTimes + test.invocations;
163
+ }
164
+ }
165
+
166
+ module.exports = DetoxCoreListener;
@@ -15,7 +15,7 @@ class DetoxInitErrorListener {
15
15
  if (!_.isEmpty(unhandledErrors)) {
16
16
  const currentTest = _.last(currentDescribeBlock.children);
17
17
  const dummyError = new Error('Environment setup failed. See the detailed error below.');
18
- delete dummyError.stack;
18
+ dummyError.stack = '';
19
19
 
20
20
  currentTest.errors.push(dummyError);
21
21
  }