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

Sign up to get free protection for your applications and to get access to all the features.
Files changed (192) hide show
  1. package/Detox-android/com/wix/detox/{20.0.2-breaking.new-global-lifecycle.0/detox-20.0.2-breaking.new-global-lifecycle.0-javadoc.jar → 20.0.2/detox-20.0.2-javadoc.jar} +0 -0
  2. package/Detox-android/com/wix/detox/20.0.2/detox-20.0.2-javadoc.jar.md5 +1 -0
  3. package/Detox-android/com/wix/detox/20.0.2/detox-20.0.2-javadoc.jar.sha1 +1 -0
  4. package/Detox-android/com/wix/detox/20.0.2/detox-20.0.2-javadoc.jar.sha256 +1 -0
  5. package/Detox-android/com/wix/detox/20.0.2/detox-20.0.2-javadoc.jar.sha512 +1 -0
  6. package/Detox-android/com/wix/detox/{20.0.2-breaking.new-global-lifecycle.0/detox-20.0.2-breaking.new-global-lifecycle.0-sources.jar → 20.0.2/detox-20.0.2-sources.jar} +0 -0
  7. package/Detox-android/com/wix/detox/20.0.2/detox-20.0.2-sources.jar.md5 +1 -0
  8. package/Detox-android/com/wix/detox/20.0.2/detox-20.0.2-sources.jar.sha1 +1 -0
  9. package/Detox-android/com/wix/detox/20.0.2/detox-20.0.2-sources.jar.sha256 +1 -0
  10. package/Detox-android/com/wix/detox/20.0.2/detox-20.0.2-sources.jar.sha512 +1 -0
  11. package/Detox-android/com/wix/detox/20.0.2/detox-20.0.2.aar +0 -0
  12. package/Detox-android/com/wix/detox/20.0.2/detox-20.0.2.aar.md5 +1 -0
  13. package/Detox-android/com/wix/detox/20.0.2/detox-20.0.2.aar.sha1 +1 -0
  14. package/Detox-android/com/wix/detox/20.0.2/detox-20.0.2.aar.sha256 +1 -0
  15. package/Detox-android/com/wix/detox/20.0.2/detox-20.0.2.aar.sha512 +1 -0
  16. package/Detox-android/com/wix/detox/{20.0.2-breaking.new-global-lifecycle.0/detox-20.0.2-breaking.new-global-lifecycle.0.pom → 20.0.2/detox-20.0.2.pom} +1 -7
  17. package/Detox-android/com/wix/detox/20.0.2/detox-20.0.2.pom.md5 +1 -0
  18. package/Detox-android/com/wix/detox/20.0.2/detox-20.0.2.pom.sha1 +1 -0
  19. package/Detox-android/com/wix/detox/20.0.2/detox-20.0.2.pom.sha256 +1 -0
  20. package/Detox-android/com/wix/detox/20.0.2/detox-20.0.2.pom.sha512 +1 -0
  21. package/Detox-android/com/wix/detox/maven-metadata.xml +4 -4
  22. package/Detox-android/com/wix/detox/maven-metadata.xml.md5 +1 -1
  23. package/Detox-android/com/wix/detox/maven-metadata.xml.sha1 +1 -1
  24. package/Detox-android/com/wix/detox/maven-metadata.xml.sha256 +1 -1
  25. package/Detox-android/com/wix/detox/maven-metadata.xml.sha512 +1 -1
  26. package/Detox-ios-src.tbz +0 -0
  27. package/Detox-ios.tbz +0 -0
  28. package/README.md +1 -1
  29. package/android/build.gradle +12 -7
  30. package/android/detox/build.gradle +13 -9
  31. package/android/detox/proguard-rules-app.pro +6 -0
  32. package/android/detox/proguard-rules.pro +3 -0
  33. package/android/detox/publishing.gradle +27 -27
  34. package/android/detox/src/full/java/com/wix/detox/DetoxCrashHandler.kt +1 -1
  35. package/android/detox/src/full/java/com/wix/detox/LaunchArgs.java +9 -0
  36. package/android/detox/src/full/java/com/wix/detox/TestEngineFacade.kt +1 -1
  37. package/android/detox/src/full/java/com/wix/detox/reactnative/ReactNativeExtension.kt +15 -2
  38. package/android/detox/src/full/java/com/wix/detox/reactnative/ReactNativeIdlingResources.kt +43 -38
  39. package/android/detox/src/full/java/com/wix/detox/reactnative/idlingresources/IdlingResourceDescription.kt +19 -13
  40. package/android/detox/src/full/java/com/wix/detox/reactnative/idlingresources/NetworkIdlingResource.java +33 -30
  41. package/android/detox/src/full/java/com/wix/detox/reactnative/idlingresources/timers/DelegatedIdleInterrogationStrategy.kt +7 -27
  42. package/android/detox/src/full/java/com/wix/detox/reactnative/idlingresources/timers/IdleInterrogationStrategy.kt +1 -11
  43. package/android/detox/src/main/java/com/wix/detox/common/TextFileReader.kt +1 -1
  44. package/android/detox/src/testFull/java/com/wix/detox/espresso/action/DetoxMultiTapSpec.kt +4 -3
  45. package/android/detox/src/testFull/java/com/wix/detox/reactnative/idlingresources/NetworkIdlingResourcesTest.kt +61 -0
  46. package/android/detox/src/testFull/java/com/wix/detox/reactnative/idlingresources/timers/DelegatedIdleInterrogationStrategySpec.kt +3 -11
  47. package/index.d.ts +195 -59
  48. package/internals.d.ts +216 -49
  49. package/local-cli/build.js +2 -2
  50. package/local-cli/build.test.js +14 -14
  51. package/local-cli/cli.js +11 -6
  52. package/local-cli/init.js +61 -21
  53. package/local-cli/rebuild-framework-cache.js +1 -1
  54. package/local-cli/reset-lock-file.js +16 -0
  55. package/local-cli/templates/jest.js +13 -10
  56. package/local-cli/test.js +14 -8
  57. package/local-cli/test.test.js +143 -62
  58. package/local-cli/testCommand/TestRunnerCommand.js +97 -77
  59. package/local-cli/testCommand/TestRunnerError.js +17 -0
  60. package/local-cli/testCommand/TestRunnerError.test.js +25 -0
  61. package/local-cli/testCommand/builder.js +0 -1
  62. package/local-cli/testCommand/middlewares.js +4 -13
  63. package/local-cli/testCommand/warnings.js +0 -3
  64. package/local-cli/utils/jestInternals.js +4 -1
  65. package/package.json +23 -17
  66. package/runners/deprecation.js +42 -44
  67. package/runners/jest/globalSetup.js +1 -1
  68. package/runners/jest/globalTeardown.js +1 -1
  69. package/runners/jest/index.d.ts +60 -0
  70. package/runners/jest/index.js +3 -8
  71. package/runners/jest/index.test.js +13 -0
  72. package/runners/jest/reporters/DetoxReporter.js +33 -2
  73. package/runners/jest/testEnvironment/index.js +119 -69
  74. package/runners/jest/testEnvironment/listeners/DetoxCoreListener.js +94 -47
  75. package/runners/jest/testEnvironment/listeners/DetoxPlatformFilterListener.js +1 -1
  76. package/runners/jest/testEnvironment/listeners/SpecReporter.js +14 -16
  77. package/runners/jest/testEnvironment/listeners/WorkerAssignReporter.js +2 -6
  78. package/runners/jest/testEnvironment/utils/assertJestCircus27.js +17 -3
  79. package/runners/jest/testEnvironment/utils/assertJestCircus27.test.js +0 -1
  80. package/src/DetoxWorker.js +105 -62
  81. package/src/android/core/NativeElement.js +56 -20
  82. package/src/android/core/NativeExpect.js +28 -9
  83. package/src/android/interactions/native.js +25 -18
  84. package/src/artifacts/ArtifactsManager.js +14 -47
  85. package/src/artifacts/instruments/ios/SimulatorInstrumentsRecording.js +3 -3
  86. package/src/artifacts/log/ios/SimulatorLogRecording.js +1 -1
  87. package/src/artifacts/screenshot/SimulatorScreenshotPlugin.js +1 -1
  88. package/src/artifacts/templates/artifact/Artifact.js +1 -1
  89. package/src/artifacts/templates/plugin/ArtifactPlugin.js +1 -1
  90. package/src/artifacts/timeline/TimelineContextTypes.js +7 -0
  91. package/src/artifacts/utils/temporaryPath.js +49 -8
  92. package/src/artifacts/video/SimulatorRecordVideoPlugin.js +1 -1
  93. package/src/client/AsyncWebSocket.js +8 -17
  94. package/src/client/Client.js +19 -2
  95. package/src/client/actions/formatters/sync-resources/NetworkFormatter.js +1 -1
  96. package/src/configuration/collectCliConfig.js +1 -12
  97. package/src/configuration/composeAppsConfig.js +4 -0
  98. package/src/configuration/composeDeviceConfig.js +1 -1
  99. package/src/configuration/composeLoggerConfig.js +19 -10
  100. package/src/configuration/composeRunnerConfig.js +61 -9
  101. package/src/configuration/index.js +14 -9
  102. package/src/configuration/loadExternalConfig.js +1 -1
  103. package/src/devices/allocation/DeviceAllocator.js +3 -2
  104. package/src/devices/allocation/drivers/android/emulator/AVDValidator.js +5 -5
  105. package/src/devices/allocation/drivers/android/emulator/EmulatorAllocDriver.js +4 -3
  106. package/src/devices/allocation/drivers/android/emulator/EmulatorAllocationHelper.js +1 -1
  107. package/src/devices/allocation/drivers/android/emulator/EmulatorLauncher.js +3 -2
  108. package/src/devices/allocation/drivers/android/emulator/EmulatorVersionResolver.js +4 -6
  109. package/src/devices/allocation/drivers/android/emulator/launchEmulatorProcess.js +1 -1
  110. package/src/devices/allocation/drivers/android/genycloud/GenyInstanceAllocationHelper.js +1 -1
  111. package/src/devices/common/drivers/android/genycloud/services/GenyInstanceNaming.js +3 -3
  112. package/src/devices/common/drivers/android/genycloud/services/GenyRecipesService.js +1 -1
  113. package/src/devices/common/drivers/android/tools/EmulatorTelnet.js +1 -1
  114. package/src/devices/common/drivers/android/tools/FreeDeviceFinder.js +1 -1
  115. package/src/devices/common/drivers/android/tools/MonitoredInstrumentation.js +1 -1
  116. package/src/devices/common/drivers/ios/tools/AppleSimUtils.js +29 -3
  117. package/src/devices/lifecycle/GenyGlobalLifecycleHandler.js +13 -15
  118. package/src/devices/runtime/RuntimeDevice.js +19 -12
  119. package/src/devices/runtime/drivers/DeviceDriverBase.js +1 -1
  120. package/src/devices/runtime/drivers/android/AndroidDriver.js +10 -2
  121. package/src/devices/runtime/drivers/ios/SimulatorDriver.js +1 -1
  122. package/src/errors/DetoxConfigErrorComposer.js +17 -2
  123. package/src/errors/DetoxError.js +5 -1
  124. package/src/ios/expectTwo.js +153 -67
  125. package/src/ipc/IPCClient.js +12 -13
  126. package/src/ipc/IPCServer.js +28 -24
  127. package/src/ipc/{state.js → SessionState.js} +26 -53
  128. package/src/logger/DetoxLogger.js +287 -154
  129. package/src/logger/index.js +5 -0
  130. package/src/logger/utils/BunyanLogger.js +115 -0
  131. package/src/logger/utils/CategoryThreadDispatcher.js +37 -0
  132. package/src/logger/utils/DetoxLogFinalizer.js +162 -0
  133. package/src/logger/utils/MessageStack.js +35 -0
  134. package/src/logger/utils/ThreadDispatcher.js +61 -0
  135. package/src/logger/{customConsoleLogger.js → utils/customConsoleLogger.js} +23 -6
  136. package/src/logger/utils/getMainCategory.js +5 -0
  137. package/src/logger/utils/sanitizeBunyanContext.js +30 -0
  138. package/src/logger/utils/streams/BunyanTransformer.js +72 -0
  139. package/src/logger/utils/streams/ChromeTraceTransformer.js +127 -0
  140. package/src/logger/utils/streams/DetoxJSONLParser.js +31 -0
  141. package/src/logger/utils/streams/JSONLStringer.js +55 -0
  142. package/src/logger/utils/streams/index.js +7 -0
  143. package/src/logger/utils/streams/transformers.js +39 -0
  144. package/src/logger/utils/tracerLegacy.js +37 -0
  145. package/src/realms/DetoxContext.js +79 -65
  146. package/src/realms/DetoxInternalsFacade.js +8 -12
  147. package/src/realms/DetoxPrimaryContext.js +111 -72
  148. package/src/realms/DetoxSecondaryContext.js +29 -32
  149. package/src/server/DetoxConnection.js +18 -23
  150. package/src/server/DetoxServer.js +7 -10
  151. package/src/server/DetoxSession.js +6 -6
  152. package/src/server/DetoxSessionManager.js +1 -1
  153. package/src/server/handlers/RegisteredConnectionHandler.js +1 -2
  154. package/src/symbols.js +16 -22
  155. package/src/utils/Timer.js +55 -38
  156. package/src/utils/argparse.js +11 -0
  157. package/src/utils/childProcess/exec.js +1 -1
  158. package/src/utils/childProcess/spawn.js +1 -1
  159. package/src/utils/errorUtils.js +24 -3
  160. package/src/utils/invocationTraceDescriptions.js +43 -0
  161. package/src/utils/logger.js +1 -1
  162. package/src/utils/pathUtils.js +11 -0
  163. package/src/utils/shellUtils.js +17 -0
  164. package/src/utils/traceInvocationCall.js +21 -0
  165. package/src/utils/traceMethods.js +15 -0
  166. package/Detox-android/com/wix/detox/20.0.2-breaking.new-global-lifecycle.0/detox-20.0.2-breaking.new-global-lifecycle.0-javadoc.jar.md5 +0 -1
  167. package/Detox-android/com/wix/detox/20.0.2-breaking.new-global-lifecycle.0/detox-20.0.2-breaking.new-global-lifecycle.0-javadoc.jar.sha1 +0 -1
  168. package/Detox-android/com/wix/detox/20.0.2-breaking.new-global-lifecycle.0/detox-20.0.2-breaking.new-global-lifecycle.0-javadoc.jar.sha256 +0 -1
  169. package/Detox-android/com/wix/detox/20.0.2-breaking.new-global-lifecycle.0/detox-20.0.2-breaking.new-global-lifecycle.0-javadoc.jar.sha512 +0 -1
  170. package/Detox-android/com/wix/detox/20.0.2-breaking.new-global-lifecycle.0/detox-20.0.2-breaking.new-global-lifecycle.0-sources.jar.md5 +0 -1
  171. package/Detox-android/com/wix/detox/20.0.2-breaking.new-global-lifecycle.0/detox-20.0.2-breaking.new-global-lifecycle.0-sources.jar.sha1 +0 -1
  172. package/Detox-android/com/wix/detox/20.0.2-breaking.new-global-lifecycle.0/detox-20.0.2-breaking.new-global-lifecycle.0-sources.jar.sha256 +0 -1
  173. package/Detox-android/com/wix/detox/20.0.2-breaking.new-global-lifecycle.0/detox-20.0.2-breaking.new-global-lifecycle.0-sources.jar.sha512 +0 -1
  174. package/Detox-android/com/wix/detox/20.0.2-breaking.new-global-lifecycle.0/detox-20.0.2-breaking.new-global-lifecycle.0.aar +0 -0
  175. package/Detox-android/com/wix/detox/20.0.2-breaking.new-global-lifecycle.0/detox-20.0.2-breaking.new-global-lifecycle.0.aar.md5 +0 -1
  176. package/Detox-android/com/wix/detox/20.0.2-breaking.new-global-lifecycle.0/detox-20.0.2-breaking.new-global-lifecycle.0.aar.sha1 +0 -1
  177. package/Detox-android/com/wix/detox/20.0.2-breaking.new-global-lifecycle.0/detox-20.0.2-breaking.new-global-lifecycle.0.aar.sha256 +0 -1
  178. package/Detox-android/com/wix/detox/20.0.2-breaking.new-global-lifecycle.0/detox-20.0.2-breaking.new-global-lifecycle.0.aar.sha512 +0 -1
  179. package/Detox-android/com/wix/detox/20.0.2-breaking.new-global-lifecycle.0/detox-20.0.2-breaking.new-global-lifecycle.0.pom.md5 +0 -1
  180. package/Detox-android/com/wix/detox/20.0.2-breaking.new-global-lifecycle.0/detox-20.0.2-breaking.new-global-lifecycle.0.pom.sha1 +0 -1
  181. package/Detox-android/com/wix/detox/20.0.2-breaking.new-global-lifecycle.0/detox-20.0.2-breaking.new-global-lifecycle.0.pom.sha256 +0 -1
  182. package/Detox-android/com/wix/detox/20.0.2-breaking.new-global-lifecycle.0/detox-20.0.2-breaking.new-global-lifecycle.0.pom.sha512 +0 -1
  183. package/android/detox/src/full/java/com/wix/detox/reactnative/idlingresources/timers/DefaultIdleInterrogationStrategy.kt +0 -84
  184. package/android/detox/src/testFull/java/com/wix/detox/reactnative/idlingresources/timers/DefaultIdleInterrogationStrategySpec.kt +0 -115
  185. package/runners/jest/deprecation.js +0 -25
  186. package/src/configuration/utils/warnings.js +0 -12
  187. package/src/logger/DetoxTraceEventBuilder.js +0 -21
  188. package/src/logger/DetoxTracer.js +0 -133
  189. package/src/logger/TraceThreadDispatcher.js +0 -52
  190. package/src/utils/ChromeTracingExporter.js +0 -54
  191. package/src/utils/streamUtils.js +0 -214
  192. package/src/utils/trace.js +0 -19
@@ -5,51 +5,86 @@ const parser = require('yargs-parser');
5
5
  const unparse = require('yargs-unparser');
6
6
 
7
7
  const detox = require('../../internals');
8
- const { DetoxRuntimeError } = require('../../src/errors');
8
+ const log = detox.log.child({ cat: ['lifecycle', 'cli'] });
9
9
  const { printEnvironmentVariables, prependNodeModulesBinToPATH } = require('../../src/utils/envUtils');
10
- 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');
11
14
 
12
15
  class TestRunnerCommand {
13
- constructor() {
14
- this._argv = {};
15
- this._env = {};
16
- this._envHint = {};
17
- this._retries = 0;
18
- /** @type {Detox.DetoxDeviceConfig} */
19
- this._deviceConfig = null;
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);
29
+ this._envFwd = {};
30
+ if (runnerConfig.forwardEnv) {
31
+ this._envFwd = this._buildEnvOverride(cliConfig, deviceConfig);
32
+ Object.assign(this._envHint, this._envFwd);
33
+ }
20
34
  }
21
35
 
22
- /**
23
- * @param {Detox.DetoxDeviceConfig} config
24
- * @returns {this}
25
- */
26
- setDeviceConfig(config) {
27
- this._deviceConfig = config;
36
+ async execute() {
37
+ let runsLeft = 1 + this._retries;
38
+ let launchError = null;
28
39
 
29
- return this;
30
- }
40
+ do {
41
+ try {
42
+ await this._spawnTestRunner();
43
+ launchError = null;
44
+ } catch (e) {
45
+ launchError = e;
31
46
 
32
- /**
33
- * @param {Detox.DetoxTestRunnerConfig} config
34
- * @returns {this}
35
- */
36
- setRunnerConfig(config) {
37
- this._argv = config.args;
38
- this._retries = config.retries;
47
+ const failedTestFiles = detox.session.testResults.filter(r => !r.success);
48
+
49
+ const { bail } = detox.config.testRunner;
50
+ if (bail && failedTestFiles.some(r => r.isPermanentFailure)) {
51
+ throw e;
52
+ }
53
+
54
+ const testFilesToRetry = failedTestFiles.filter(r => !r.isPermanentFailure).map(r => r.testFilePath);
55
+ if (_.isEmpty(testFilesToRetry)) {
56
+ throw e;
57
+ }
39
58
 
40
- if (config.inspectBrk === true) {
41
- this._env = this._envHint;
59
+ if (--runsLeft > 0) {
60
+ // @ts-ignore
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);
65
+ }
66
+ }
67
+ } while (launchError && runsLeft > 0);
68
+
69
+ if (launchError) {
70
+ throw launchError;
42
71
  }
72
+ }
43
73
 
44
- return this;
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();
45
80
  }
46
81
 
47
82
  /**
48
- * @param {Partial<Readonly<DetoxInternals.DetoxCLIConfig>>} cliConfig
49
- * @returns {this}
83
+ * @param {DetoxInternals.CLIConfig} cliConfig
84
+ * @param {Detox.DetoxDeviceConfig} deviceConfig
50
85
  */
51
- replicateCLIConfig(cliConfig) {
52
- this._envHint = _.omitBy({
86
+ _buildEnvOverride(cliConfig, deviceConfig) {
87
+ return _.omitBy({
53
88
  DETOX_APP_LAUNCH_ARGS: cliConfig.appLaunchArgs,
54
89
  DETOX_ARTIFACTS_LOCATION: cliConfig.artifactsLocation,
55
90
  DETOX_CAPTURE_VIEW_HIERARCHY: cliConfig.captureViewHierarchy,
@@ -59,7 +94,7 @@ class TestRunnerCommand {
59
94
  DETOX_DEBUG_SYNCHRONIZATION: cliConfig.debugSynchronization,
60
95
  DETOX_DEVICE_BOOT_ARGS: cliConfig.deviceBootArgs,
61
96
  DETOX_DEVICE_NAME: cliConfig.deviceName,
62
- DETOX_FORCE_ADB_INSTALL: this._deviceConfig.type.startsWith('android.')
97
+ DETOX_FORCE_ADB_INSTALL: deviceConfig.type.startsWith('android.')
63
98
  ? cliConfig.forceAdbInstall
64
99
  : undefined,
65
100
  DETOX_GPU: cliConfig.gpu,
@@ -76,50 +111,13 @@ class TestRunnerCommand {
76
111
  DETOX_TAKE_SCREENSHOTS: cliConfig.takeScreenshots,
77
112
  DETOX_USE_CUSTOM_LOGGER: cliConfig.useCustomLogger,
78
113
  }, _.isUndefined);
79
-
80
- return this;
81
- }
82
-
83
- async execute() {
84
- let runsLeft = 1 + this._retries;
85
- let launchError;
86
-
87
- do {
88
- try {
89
- if (launchError) {
90
- const list = this._argv._.map((file, index) => ` ${index + 1}. ${file}`).join('\n');
91
- detox.log.error({ event: 'RETRY_RUN' },
92
- `There were failing tests in the following files:\n${list}\n\n` +
93
- 'Detox CLI is going to restart the test runner with those files...\n'
94
- );
95
- }
96
-
97
- await this._doExecute();
98
- launchError = null;
99
- } catch (e) {
100
- launchError = e;
101
-
102
- const { failedTestFiles, testFilesToRetry } = detox.session;
103
- if (!_.isEmpty(failedTestFiles) || _.isEmpty(testFilesToRetry)) {
104
- throw e;
105
- }
106
-
107
- this._argv._ = testFilesToRetry.splice(0, Infinity);
108
- // @ts-ignore
109
- detox.session.testSessionIndex++; // it is always a primary context, so we can update it
110
- }
111
- } while (launchError && --runsLeft > 0);
112
-
113
- if (launchError) {
114
- throw launchError;
115
- }
116
114
  }
117
115
 
118
- async _doExecute() {
116
+ async _spawnTestRunner() {
119
117
  const fullCommand = this._buildSpawnArguments().map(escapeSpaces);
120
118
  const fullCommandWithHint = printEnvironmentVariables(this._envHint) + fullCommand.join(' ');
121
119
 
122
- detox.log.info({ event: 'RUN_START', env: this._envHint }, fullCommandWithHint);
120
+ log.info.begin({ env: this._envHint }, fullCommandWithHint);
123
121
 
124
122
  return new Promise((resolve, reject) => {
125
123
  cp.spawn(fullCommand[0], fullCommand.slice(1), {
@@ -127,20 +125,31 @@ class TestRunnerCommand {
127
125
  stdio: 'inherit',
128
126
  env: _({})
129
127
  .assign(process.env)
130
- .assign(this._env)
128
+ .assign(this._envFwd)
131
129
  .omitBy(_.isUndefined)
132
130
  .tap(prependNodeModulesBinToPATH)
133
131
  .value()
134
132
  })
135
- .on('error', (err) => reject(err))
136
- .on('exit', (code) => code === 0
137
- ? resolve()
138
- : reject(new DetoxRuntimeError(`Command failed with exit code = ${code}:\n${fullCommandWithHint}`)
139
- ));
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
+ });
140
148
  });
141
149
  }
142
150
 
143
151
  _buildSpawnArguments() {
152
+ /* istanbul ignore next */
144
153
  const { _: specs = [], '--': passthrough = [], $0, ...argv } = this._argv;
145
154
  const { _: $0_, ...$0argv } = parser($0);
146
155
 
@@ -151,6 +160,17 @@ class TestRunnerCommand {
151
160
  ...unparse({ _: [...passthrough, ...specs] }),
152
161
  ].map(String);
153
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
+ }
154
174
  }
155
175
 
156
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;
@@ -0,0 +1,25 @@
1
+ const { DetoxError } = require('../../src/errors');
2
+
3
+ const TestRunnerError = require('./TestRunnerError');
4
+
5
+ describe('TestRunnerError', () => {
6
+ let error;
7
+
8
+ beforeAll(() => {
9
+ error = new TestRunnerError({ command: 'foo', code: 1, signal: null });
10
+ });
11
+
12
+ it('should format an error message', () => {
13
+ expect(`${error}`).toMatch(/Command failed with exit code = 1:\nfoo/);
14
+ });
15
+
16
+ it('should assign properties (code, signal)', () => {
17
+ expect(error.code).toBe(1);
18
+ expect(error.signal).toBe(null);
19
+ });
20
+
21
+ it('should be formatted to an empty string', () => {
22
+ // So that the try-catch block in cli.js will not print it for the second time
23
+ expect(DetoxError.format(error)).toBe('');
24
+ });
25
+ });
@@ -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
  },
@@ -5,7 +5,7 @@ const { getJestBooleanArgs } = require('../utils/jestInternals');
5
5
  const { simpleUnquote, extractKnownKeys, disengageBooleanArgs } = require('../utils/yargsUtils');
6
6
 
7
7
  const testCommandArgs = require('./builder');
8
- const { DETOX_ARGV_OVERRIDE_NOTICE, DEVICE_LAUNCH_ARGS_DEPRECATION } = require('./warnings');
8
+ const { DETOX_ARGV_OVERRIDE_NOTICE } = require('./warnings');
9
9
 
10
10
  function applyEnvironmentVariableAddendum(argv, yargs) {
11
11
  if (process.env.DETOX_ARGV_OVERRIDE) {
@@ -13,12 +13,13 @@ function applyEnvironmentVariableAddendum(argv, yargs) {
13
13
 
14
14
  const { _: positional, '--': passthrough, ...named } = yargs.parse(process.env.DETOX_ARGV_OVERRIDE);
15
15
 
16
- if (positional) {
16
+ if (!_.isEmpty(positional)) {
17
+ /* istanbul ignore next */
17
18
  argv._ = argv._ || [];
18
19
  argv._.push(...positional.map(simpleUnquote));
19
20
  }
20
21
 
21
- if (passthrough) {
22
+ if (!_.isEmpty(passthrough)) {
22
23
  argv['--'] = argv['--'] || [];
23
24
  argv['--'].push(...passthrough.map(simpleUnquote));
24
25
  }
@@ -29,14 +30,6 @@ function applyEnvironmentVariableAddendum(argv, yargs) {
29
30
  return argv;
30
31
  }
31
32
 
32
- function warnDeviceAppLaunchArgsDeprecation(argv) {
33
- if (argv['device-boot-args'] && process.argv.some(a => a.startsWith('--device-launch-args'))) {
34
- log.warn(DEVICE_LAUNCH_ARGS_DEPRECATION);
35
- }
36
-
37
- return argv;
38
- }
39
-
40
33
  /**
41
34
  * @param {Record<string, *>} argv
42
35
  * @returns {{
@@ -64,12 +57,10 @@ function splitArgv(argv) {
64
57
  // noinspection JSUnusedGlobalSymbols
65
58
  module.exports = {
66
59
  applyEnvironmentVariableAddendum,
67
- warnDeviceAppLaunchArgsDeprecation,
68
60
  splitArgv,
69
61
  };
70
62
 
71
63
  module.exports.default = [
72
64
  applyEnvironmentVariableAddendum,
73
- warnDeviceAppLaunchArgsDeprecation,
74
65
  splitArgv,
75
66
  ];
@@ -1,5 +1,3 @@
1
- const { DEVICE_LAUNCH_ARGS_DEPRECATION } = require('../../src/configuration/utils/warnings');
2
-
3
1
  const DETOX_ARGV_OVERRIDE_NOTICE = `
4
2
  _____ _____ ___________
5
3
  / ___|_ _| _ | ___ \\ $DETOX_ARGV_OVERRIDE is detected
@@ -22,5 +20,4 @@ const DETOX_ARGV_OVERRIDE_NOTICE = `
22
20
 
23
21
  module.exports = {
24
22
  DETOX_ARGV_OVERRIDE_NOTICE,
25
- DEVICE_LAUNCH_ARGS_DEPRECATION,
26
23
  };
@@ -4,6 +4,7 @@ const path = require('path');
4
4
 
5
5
  const _ = require('lodash');
6
6
  const resolveFrom = require('resolve-from');
7
+ const semver = require('semver');
7
8
 
8
9
  const { DetoxRuntimeError } = require('../../src/errors');
9
10
 
@@ -50,7 +51,9 @@ function resolveJestCliArgs() {
50
51
 
51
52
  try {
52
53
  const jestCliManifest = resolveJestDependency(jestLocation, 'jest-cli/package.json');
53
- const argsJsFile = path.join(path.dirname(jestCliManifest), 'build/cli/args.js');
54
+ const jestCliVersion = require(jestCliManifest).version;
55
+ const argsJsFilePath = semver.gt(jestCliVersion, '29.1.2') ? 'build/args.js' : 'build/cli/args.js';
56
+ const argsJsFile = path.join(path.dirname(jestCliManifest), argsJsFilePath);
54
57
 
55
58
  return require(argsJsFile);
56
59
  } catch (e) {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "detox",
3
3
  "description": "E2E tests and automation for mobile",
4
- "version": "20.0.2-breaking.new-global-lifecycle.0",
4
+ "version": "20.0.2",
5
5
  "bin": {
6
6
  "detox": "local-cli/cli.js"
7
7
  },
@@ -35,8 +35,8 @@
35
35
  "@types/bunyan": "^1.8.8",
36
36
  "@types/child-process-promise": "^2.2.1",
37
37
  "@types/fs-extra": "^9.0.13",
38
- "@types/jest": "^27.0.3",
39
- "@types/node": "^12.20.37",
38
+ "@types/jest": "^28.1.8",
39
+ "@types/node": "^14.18.33",
40
40
  "@types/node-ipc": "^9.2.0",
41
41
  "@types/ws": "^7.4.0",
42
42
  "@typescript-eslint/eslint-plugin": "^5.4.0",
@@ -46,10 +46,10 @@
46
46
  "eslint-plugin-no-only-tests": "^2.6.0",
47
47
  "eslint-plugin-node": "^11.1.0",
48
48
  "eslint-plugin-unicorn": "^39.0.0",
49
- "jest": "^28.0.0",
49
+ "jest": "^28.1.3",
50
50
  "mockdate": "^2.0.1",
51
51
  "prettier": "1.7.0",
52
- "react-native": "0.68.2",
52
+ "react-native": "0.69.7",
53
53
  "react-native-codegen": "^0.0.8",
54
54
  "typescript": "^4.5.2",
55
55
  "wtfnode": "^0.9.1"
@@ -57,13 +57,14 @@
57
57
  "dependencies": {
58
58
  "ajv": "^8.6.3",
59
59
  "bunyan": "^1.8.12",
60
- "bunyan-debug-stream": "^3.0.2",
60
+ "bunyan-debug-stream": "^3.1.0",
61
+ "caf": "^15.0.1",
61
62
  "chalk": "^2.4.2",
62
63
  "child-process-promise": "^2.2.0",
63
- "duplexify": "^4.1.2",
64
64
  "find-up": "^4.1.0",
65
65
  "fs-extra": "^4.0.2",
66
- "funpermaproxy": "^1.0.1",
66
+ "funpermaproxy": "^1.1.0",
67
+ "glob": "^8.0.3",
67
68
  "ini": "^1.3.4",
68
69
  "json-cycle": "^1.3.0",
69
70
  "lodash": "^4.17.5",
@@ -83,7 +84,7 @@
83
84
  "tail": "^2.0.0",
84
85
  "telnet-client": "1.2.8",
85
86
  "tempfile": "^2.0.0",
86
- "trace-event-lib": "^1.1.0",
87
+ "trace-event-lib": "^1.3.1",
87
88
  "which": "^1.3.1",
88
89
  "ws": "^7.0.0",
89
90
  "yargs": "^16.0.3",
@@ -91,7 +92,7 @@
91
92
  "yargs-unparser": "^2.0.0"
92
93
  },
93
94
  "peerDependencies": {
94
- "jest": "28.x.x || ^27.2.5"
95
+ "jest": "29.x.x || 28.x.x || ^27.2.5"
95
96
  },
96
97
  "peerDependenciesMeta": {
97
98
  "jest": {
@@ -99,7 +100,7 @@
99
100
  }
100
101
  },
101
102
  "engines": {
102
- "node": ">=12.10.0"
103
+ "node": ">=14.5.0"
103
104
  },
104
105
  "jest": {
105
106
  "setupFiles": [
@@ -158,7 +159,12 @@
158
159
  "src/utils/pipeCommands.js",
159
160
  "src/utils/pressAnyKey.js",
160
161
  "src/utils/shellUtils.js",
161
- "runners/jest/.*.js"
162
+ "runners/jest/reporters",
163
+ "runners/jest/testEnvironment",
164
+ "src/DetoxWorker.js",
165
+ "src/logger/utils/streamUtils.js",
166
+ "src/ipc",
167
+ "src/realms"
162
168
  ],
163
169
  "resetMocks": true,
164
170
  "resetModules": true,
@@ -176,12 +182,12 @@
176
182
  ],
177
183
  "coverageThreshold": {
178
184
  "global": {
179
- "statements": 0,
180
- "branches": 0,
181
- "functions": 0,
182
- "lines": 0
185
+ "statements": 100,
186
+ "branches": 100,
187
+ "functions": 100,
188
+ "lines": 100
183
189
  }
184
190
  }
185
191
  },
186
- "gitHead": "cda5a555ec90aaeafe8c557157270e36a2b27688"
192
+ "gitHead": "caef3fd2ce6fe7ad2a8267102ee521153abbcbb2"
187
193
  }
@@ -1,47 +1,45 @@
1
1
  const chalk = require('chalk');
2
2
 
3
3
  // @ts-ignore
4
- console.error(chalk.yellow(`
5
- ========================= THE NEW JOURNEY BEGINS =============================
6
-
7
- https://github.com/wix/Detox/blob/master/docs/Guide.Jest.md
8
-
9
- _.-;-._ Sorry, traveler from the lands of Detox 19!
10
- ;_.JL___;
11
- F"-/\\_-7L Detox 20 comes without old adapters for Jest
12
- | a/ e | \\ and Mocha test runners. You have to rearrange
13
- ,L,c;,.='/;, your init code before you can continue your
14
- _,-;;S:;:S;;:' '--._ journey.
15
- ;. \\;;s:::s;;: .' /\\
16
- / \\ ;::::;; / / \\ Navigate to the link above and follow the
17
- / , k ;S';;'S.' j __,l migration guide steps.
18
- ,---/| / /S /S '. |' ;
19
- ,Ljjj |/|.' s .' s \\ L | Sincerely yours,
20
- LL,_ ]( \\ / '. '.|| ; Detox team.
21
- ||\\ > / ;-.'_.-.___\\.-'(|=="(
22
- JJ," / |_ [ ] _]| /
23
- LL\\/ ,' '--'-'-----' \\ (
24
- || ; | | >
25
- JJ | |\\ |,/
26
- LL | || ' |
27
- || | || . |
28
- JJ /_ || ;_|
29
- LL L "==='|i======='_|
30
- || i----' '-------';
31
- JJ ';-----.------,-'
32
- LL L_.__J,'---;'
33
- || | ,| (
34
- JJ .'= (| ,_|
35
- LL / .'L_ \\
36
- snd || '---' '.___>
37
- Credit: "Gimli" by Shanaka Dias
38
-
39
- https://github.com/wix/Detox/blob/master/docs/Guide.Jest.md
40
-
41
- ========================= THE NEW JOURNEY BEGINS =============================
42
-
43
- `));
44
-
45
- throw Object.assign(new Error(
46
- '\n\nPlease follow the new Jest setup guide:\nhttps://github.com/wix/Detox/blob/master/docs/Guide.Jest.md\n\n'
47
- ), { stack: '' });
4
+ const bold = chalk.bold;
5
+
6
+ function getMaxWidth(text) {
7
+ const lines = text.split('\n');
8
+ return lines.reduce((acc, line) => Math.max(acc, line.length), 0);
9
+ }
10
+
11
+ function centerText(text, maxWidth = getMaxWidth(text)) {
12
+ return text
13
+ .split('\n')
14
+ .map(line => {
15
+ const padStart = Math.max(0, Math.floor((maxWidth - line.length) / 2));
16
+ const padEnd = Math.max(0, maxWidth - line.length - padStart);
17
+ return ' '.repeat(padStart) + line + ' '.repeat(padEnd);
18
+ })
19
+ .join('\n');
20
+ }
21
+
22
+ const header = `\
23
+ ========================= THE NEW JOURNEY BEGINS =============================`;
24
+
25
+ console.error(centerText(`\
26
+
27
+ ${bold(header)}
28
+
29
+ https://wix.github.io/Detox/docs/guide/migration
30
+
31
+ Sorry to say that Detox 20 comes without old adapters for Jest.
32
+ You have to rearrange your init code before you can continue your journey.
33
+
34
+ Navigate to the link and follow the migration guide steps.
35
+
36
+ Sincerely yours,
37
+ Detox team.
38
+
39
+ ${bold(header)}
40
+
41
+ `, header.length));
42
+
43
+ const error = new Error('\nPlease follow the migration guide:\nhttps://wix.github.io/Detox/docs/guide/migration\n\n');
44
+ error.stack = '';
45
+ throw error;
@@ -1 +1 @@
1
- module.exports = async () => require('../../internals').globalSetup();
1
+ module.exports = async () => require('../../internals').init({ workerId: null });
@@ -1 +1 @@
1
- module.exports = async () => require('../../internals').globalTeardown();
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
+ }
@@ -1,14 +1,11 @@
1
- module.exports = {
2
- //#region *** Runner Realm ***
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
3
 
4
+ module.exports = {
4
5
  get DetoxCircusEnvironment() {
5
6
  return require('./testEnvironment');
6
7
  },
7
8
 
8
- //#endregion
9
-
10
- //#region *** Worker Realm ***
11
-
12
9
  get globalSetup() {
13
10
  return require('./globalSetup');
14
11
  },
@@ -16,6 +13,4 @@ module.exports = {
16
13
  get globalTeardown() {
17
14
  return require('./globalTeardown');
18
15
  },
19
-
20
- //#endregion
21
16
  };