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
package/local-cli/init.js CHANGED
@@ -1,47 +1,20 @@
1
1
  const fs = require('fs');
2
2
  const path = require('path');
3
+ const util = require('util');
3
4
 
4
- const DetoxRuntimeError = require('../src/errors/DetoxRuntimeError');
5
- const log = require('../src/utils/logger').child({ __filename });
5
+ const detox = require('../internals');
6
6
 
7
7
  const jestTemplates = require('./templates/jest');
8
- const mochaTemplates = require('./templates/mocha');
9
8
 
10
9
  let exitCode = 0;
11
10
 
12
11
  module.exports.command = 'init';
13
- module.exports.desc = 'Scaffold initial E2E test folder structure for a specified test runner';
14
- module.exports.builder = {
15
- runner: {
16
- alias: 'r',
17
- demandOption: true,
18
- describe: 'test runner name (supported values: mocha, jest)',
19
- group: 'Configuration:',
20
- default: 'jest',
21
- }
22
- };
23
-
24
- module.exports.handler = async function init(argv) {
25
- const { runner } = argv;
26
-
27
- switch (runner) {
28
- case 'mocha':
29
- createMochaFolderE2E();
30
- break;
31
- case 'jest':
32
- createJestFolderE2E();
33
- break;
34
- default:
35
- throw new DetoxRuntimeError([
36
- `Convenience scaffolding for \`${runner}\` test runner is not supported currently.\n`,
37
- 'Supported runners at the moment are: `mocha` and `jest`:',
38
- '* detox init -r mocha',
39
- '* detox init -r jest\n',
40
- `If it is not a typo, and you plan to work with \`${runner}\` runner, then you have to create test setup files manually.`,
41
- 'HINT: Try running one of the commands above, look what it does, and take similar steps for your use case.',
42
- ].join('\n'));
43
- }
12
+ module.exports.desc = 'Creates template files to get you started with Detox';
13
+ module.exports.builder = {};
44
14
 
15
+ module.exports.handler = async function init() {
16
+ createDetoxConfig();
17
+ createJestFolderE2E();
45
18
  process.exit(exitCode); // eslint-disable-line
46
19
  };
47
20
 
@@ -72,58 +45,74 @@ function createFile(filename, content) {
72
45
 
73
46
  try {
74
47
  fs.writeFileSync(filename, content);
75
- log.info(`Created a file at path: ${filename}`);
48
+ detox.log.info(`Created a file at path: ${filename}`);
76
49
  } catch (err) {
77
50
  reportError({ err }, `Failed to create a file at path: ${filename}`);
78
51
  }
79
52
  }
80
53
 
81
- function createMochaFolderE2E() {
82
- createFolder('e2e', {
83
- '.mocharc.json': mochaTemplates.runnerConfig,
84
- 'init.js': mochaTemplates.initjs,
85
- 'firstTest.spec.js': mochaTemplates.firstTest
86
- });
87
-
88
- createFile('.detoxrc.json', JSON.stringify({
89
- testRunner: 'mocha',
90
- runnerConfig: 'e2e/.mocharc.json',
91
- ...createDefaultConfigurations(),
92
- }, null, 2));
93
- }
94
-
95
54
  function createJestFolderE2E() {
96
55
  createFolder('e2e', {
97
- 'config.json': jestTemplates.runnerConfig,
98
- 'environment.js': jestTemplates.environment,
99
- 'firstTest.e2e.js': jestTemplates.firstTest,
56
+ 'jest.config.js': jestTemplates.runnerConfig,
57
+ 'starter.test.js': jestTemplates.starter,
100
58
  });
59
+ }
101
60
 
102
- createFile('.detoxrc.json', JSON.stringify({
103
- testRunner: 'jest',
104
- runnerConfig: 'e2e/config.json',
105
- skipLegacyWorkersInjection: true,
106
- ...createDefaultConfigurations(),
107
- }, null, 2));
61
+ function createDetoxConfig() {
62
+ createFile('.detoxrc.js',
63
+ '/** @type {Detox.DetoxConfig} */\n' +
64
+ 'module.exports = ' +
65
+ util.inspect(createDefaultConfigurations(), { compact: false, depth: Infinity }) +
66
+ ';\n'
67
+ );
108
68
  }
109
69
 
70
+ /** @returns {Detox.DetoxConfig} */
110
71
  function createDefaultConfigurations() {
111
72
  return {
73
+ testRunner: {
74
+ args: {
75
+ $0: 'jest',
76
+ config: 'e2e/jest.config.js',
77
+ },
78
+ jest: {
79
+ setupTimeout: 120000,
80
+ },
81
+ },
112
82
  apps: {
113
- ios: {
83
+ 'ios.debug': {
114
84
  type: 'ios.app',
115
- binaryPath: 'SPECIFY_PATH_TO_YOUR_APP_BINARY',
85
+ binaryPath: 'ios/build/Build/Products/Debug-iphonesimulator/YOUR_APP.app',
86
+ build: 'xcodebuild -workspace ios/YOUR_APP.xcworkspace -scheme YOUR_APP -configuration Debug -sdk iphonesimulator -derivedDataPath ios/build',
116
87
  },
117
- android: {
88
+ 'ios.release': {
89
+ type: 'ios.app',
90
+ binaryPath: 'ios/build/Build/Products/Release-iphonesimulator/YOUR_APP.app',
91
+ build: 'xcodebuild -workspace ios/YOUR_APP.xcworkspace -scheme YOUR_APP -configuration Release -sdk iphonesimulator -derivedDataPath ios/build',
92
+ },
93
+ 'android.debug': {
94
+ type: 'android.apk',
95
+ binaryPath: 'android/app/build/outputs/apk/debug/app-debug.apk',
96
+ build: 'cd android ; ./gradlew assembleDebug assembleAndroidTest -DtestBuildType=debug ; cd -',
97
+ reversePorts: [8081],
98
+ },
99
+ 'android.release': {
118
100
  type: 'android.apk',
119
- binaryPath: 'SPECIFY_PATH_TO_YOUR_APP_BINARY',
101
+ binaryPath: 'android/app/build/outputs/apk/release/app-release.apk',
102
+ build: 'cd android ; ./gradlew assembleRelease assembleAndroidTest -DtestBuildType=release ; cd -',
120
103
  },
121
104
  },
122
105
  devices: {
123
106
  simulator: {
124
107
  type: 'ios.simulator',
125
108
  device: {
126
- type: 'iPhone 11',
109
+ type: 'iPhone 12',
110
+ },
111
+ },
112
+ attached: {
113
+ type: 'android.attached',
114
+ device: {
115
+ adbName: '.*',
127
116
  },
128
117
  },
129
118
  emulator: {
@@ -134,19 +123,35 @@ function createDefaultConfigurations() {
134
123
  },
135
124
  },
136
125
  configurations: {
137
- ios: {
126
+ 'ios.sim.debug': {
138
127
  device: 'simulator',
139
- app: 'ios',
128
+ app: 'ios.debug',
129
+ },
130
+ 'ios.sim.release': {
131
+ device: 'simulator',
132
+ app: 'ios.release',
133
+ },
134
+ 'android.att.debug': {
135
+ device: 'attached',
136
+ app: 'android.debug',
137
+ },
138
+ 'android.att.release': {
139
+ device: 'attached',
140
+ app: 'android.release',
141
+ },
142
+ 'android.emu.debug': {
143
+ device: 'emulator',
144
+ app: 'android.debug',
140
145
  },
141
- android: {
146
+ 'android.emu.release': {
142
147
  device: 'emulator',
143
- app: 'android',
148
+ app: 'android.release',
144
149
  },
145
150
  },
146
151
  };
147
152
  }
148
153
 
149
154
  function reportError(...args) {
150
- log.error(...args);
155
+ detox.log.error(...args);
151
156
  exitCode = 1;
152
157
  }
@@ -4,7 +4,7 @@ const path = require('path');
4
4
 
5
5
  const fs = require('fs-extra');
6
6
 
7
- const log = require('../src/utils/logger').child({ __filename });
7
+ const log = require('../src/utils/logger').child({ cat: 'cli' });
8
8
 
9
9
  module.exports.command = 'rebuild-framework-cache';
10
10
  module.exports.desc = 'Rebuilds a cached Detox framework for the current environment in ~/Library/Detox. The cached framework is unique for each combination of Xcode and Detox version. (macOS only)';
@@ -0,0 +1,16 @@
1
+ const { log } = require('../internals');
2
+ const DeviceRegistry = require('../src/devices/DeviceRegistry');
3
+ const { getDetoxLibraryRootPath } = require('../src/utils/environment');
4
+
5
+
6
+ module.exports.command = 'reset-lock-file';
7
+ module.exports.desc = 'Resets all Detox lock files. Useful when you need to run multiple `detox test` commands in parallel with --keepLockFile.';
8
+
9
+ module.exports.handler = async function resetLockFile() {
10
+ await Promise.all([
11
+ DeviceRegistry.forIOS().reset(),
12
+ DeviceRegistry.forAndroid().reset(),
13
+ ]);
14
+
15
+ log.info(`Cleaned lock files from: ${getDetoxLibraryRootPath()}`);
16
+ };
@@ -1,41 +1,19 @@
1
1
  const firstTestContent = require('./firstTestContent');
2
2
 
3
- const runnerConfig = `{
4
- "maxWorkers": 1,
5
- "testEnvironment": "./environment",
6
- "testRunner": "jest-circus/runner",
7
- "testTimeout": 120000,
8
- "testRegex": "\\\\.e2e\\\\.js$",
9
- "reporters": ["detox/runners/jest/streamlineReporter"],
10
- "verbose": true
11
- }
3
+ const runnerConfig = `\
4
+ /** @type {import('@jest/types').Config.InitialOptions} */
5
+ module.exports = {
6
+ rootDir: '..',
7
+ testMatch: ['<rootDir>/e2e/**/*.test.js'],
8
+ testTimeout: 120000,
9
+ maxWorkers: 1,
10
+ globalSetup: 'detox/runners/jest/globalSetup',
11
+ globalTeardown: 'detox/runners/jest/globalTeardown',
12
+ reporters: ['detox/runners/jest/reporter'],
13
+ testEnvironment: 'detox/runners/jest/testEnvironment',
14
+ verbose: true,
15
+ };
12
16
  `;
13
17
 
14
- const environmentJsContent = `const {
15
- DetoxCircusEnvironment,
16
- SpecReporter,
17
- WorkerAssignReporter,
18
- } = require('detox/runners/jest-circus');
19
-
20
- class CustomDetoxEnvironment extends DetoxCircusEnvironment {
21
- constructor(config, context) {
22
- super(config, context);
23
-
24
- // Can be safely removed, if you are content with the default value (=300000ms)
25
- this.initTimeout = 300000;
26
-
27
- // This takes care of generating status logs on a per-spec basis. By default, Jest only reports at file-level.
28
- // This is strictly optional.
29
- this.registerListeners({
30
- SpecReporter,
31
- WorkerAssignReporter,
32
- });
33
- }
34
- }
35
-
36
- module.exports = CustomDetoxEnvironment;
37
- `;
38
-
39
- exports.environment = environmentJsContent;
40
- exports.firstTest = firstTestContent;
18
+ exports.starter = firstTestContent;
41
19
  exports.runnerConfig = runnerConfig;
package/local-cli/test.js CHANGED
@@ -1,290 +1,32 @@
1
- // @ts-nocheck
2
- const cp = require('child_process');
3
- const path = require('path');
1
+ const detox = require('../internals');
4
2
 
5
- const _ = require('lodash');
6
- const whichSync = require('which').sync;
7
- const unparse = require('yargs-unparser');
8
-
9
- const { composeDetoxConfig } = require('../src/configuration');
10
- const DeviceRegistry = require('../src/devices/DeviceRegistry');
11
- const GenyDeviceRegistryFactory = require('../src/devices/allocation/drivers/android/genycloud/GenyDeviceRegistryFactory');
12
- const DetoxRuntimeError = require('../src/errors/DetoxRuntimeError');
13
- const { loadLastFailedTests, resetLastFailedTests } = require('../src/utils/lastFailedTests');
14
- const log = require('../src/utils/logger').child({ __filename });
15
- const { parse, quote } = require('../src/utils/shellQuote');
16
-
17
- const { readJestConfig } = require('./utils/jestInternals');
18
- const { getPlatformSpecificString, printEnvironmentVariables } = require('./utils/misc');
19
- const { prependNodeModulesBinToPATH } = require('./utils/misc');
20
- const splitArgv = require('./utils/splitArgv');
21
- const { DETOX_ARGV_OVERRIDE_NOTICE, DEVICE_LAUNCH_ARGS_DEPRECATION } = require('./utils/warnings');
3
+ const TestRunnerCommand = require('./testCommand/TestRunnerCommand');
22
4
 
23
5
  module.exports.command = 'test';
24
- module.exports.desc = 'Run your test suite with the test runner specified in package.json';
25
- module.exports.builder = require('./utils/testCommandArgs');
26
- module.exports.handler = async function test(argv) {
27
- const { detoxArgs, runnerArgs } = splitArgv.detox(argv);
28
- const { cliConfig, deviceConfig, runnerConfig } = await composeDetoxConfig({ argv: detoxArgs });
29
- const [platform] = deviceConfig.type.split('.');
30
- const runner = deduceTestRunner(runnerConfig.testRunner);
31
-
32
- const prepareArgs = choosePrepareArgs({
33
- cliConfig,
34
- runner,
35
- detoxArgs,
36
- });
37
-
38
- const forwardedArgs = await prepareArgs({
39
- cliConfig,
40
- deviceConfig,
41
- runnerConfig,
42
- runnerArgs,
43
- platform,
44
- });
6
+ module.exports.desc = 'Run your test suites with the test runner specified in the project\'s Detox config';
7
+ module.exports.builder = require('./testCommand/builder');
8
+ module.exports.middlewares = require('./testCommand/middlewares').default;
9
+
10
+ module.exports.handler = async function test({ detoxArgs, runnerArgs }) {
11
+ try {
12
+ const opts = {
13
+ argv: detoxArgs,
14
+ testRunnerArgv: runnerArgs,
15
+ workerId: null,
16
+ };
17
+
18
+ const config = await detox.resolveConfig(opts);
19
+ if (!config.cli.inspectBrk) {
20
+ await detox.init(opts);
21
+ }
45
22
 
46
- if (detoxArgs['inspect-brk']) {
47
- const runnerBinary = whichSync(runner, {
48
- path: prependNodeModulesBinToPATH({ ...process.env }),
23
+ const runnerCommand = new TestRunnerCommand({
24
+ config,
25
+ env: process.env,
49
26
  });
50
27
 
51
- forwardedArgs.argv.$0 = `node --inspect-brk ${require.resolve(runnerBinary)}`;
52
- } else {
53
- forwardedArgs.argv.$0 = runnerConfig.testRunner;
28
+ await runnerCommand.execute();
29
+ } finally {
30
+ await detox.cleanup();
54
31
  }
55
-
56
- const retries = runner === 'jest' ? detoxArgs.retries : 0;
57
- await runTestRunnerWithRetries(forwardedArgs, {
58
- keepLockFile: cliConfig.keepLockFile,
59
- platform,
60
- retries,
61
- });
62
32
  };
63
-
64
- module.exports.middlewares = [
65
- function applyEnvironmentVariableAddendum(argv, yargs) {
66
- if (process.env.DETOX_ARGV_OVERRIDE) {
67
- log.warn(DETOX_ARGV_OVERRIDE_NOTICE);
68
-
69
- return yargs.parse([
70
- ...process.argv.slice(2),
71
- ...parse(process.env.DETOX_ARGV_OVERRIDE),
72
- ]);
73
- }
74
-
75
- return argv;
76
- },
77
-
78
- function warnDeviceAppLaunchArgsDeprecation(argv) {
79
- if (argv['device-boot-args'] && process.argv.some(a => a.startsWith('--device-launch-args'))) {
80
- log.warn(DEVICE_LAUNCH_ARGS_DEPRECATION);
81
- }
82
-
83
- return argv;
84
- }
85
- ];
86
-
87
- function choosePrepareArgs({ cliConfig, detoxArgs, runner }) {
88
- if (runner === 'mocha') {
89
- if (cliConfig.workers) {
90
- log.warn('Cannot use -w, --workers. Parallel test execution is only supported with Jest');
91
- }
92
-
93
- if (detoxArgs.retries > 0) {
94
- log.warn('Cannot use -R, --retries. The test retry mechanism is only supported with Jest runner');
95
- }
96
-
97
- if (cliConfig.recordTimeline) {
98
- log.warn('Cannot use --record-timeline. This artifact type is only supported with Jest runner');
99
- }
100
-
101
- return prepareMochaArgs;
102
- }
103
-
104
- if (runner === 'jest') {
105
- return prepareJestArgs;
106
- }
107
-
108
- throw new DetoxRuntimeError({
109
- message: `"${runner}" is not supported in Detox CLI tools.`,
110
- hint: `You can still run your tests with the runner's own CLI tool`
111
- });
112
- }
113
-
114
- function deduceTestRunner(command) {
115
- if (command.includes('mocha')) {
116
- return 'mocha';
117
- }
118
-
119
- if (command.includes('jest')) {
120
- return 'jest';
121
- }
122
-
123
- return command;
124
- }
125
-
126
- function prepareMochaArgs({ cliConfig, runnerArgs, runnerConfig, platform }) {
127
- const { specs, passthrough } = splitArgv.mocha(runnerArgs);
128
- const configParam = path.extname(runnerConfig.runnerConfig) === '.opts'
129
- ? 'opts'
130
- : 'config';
131
-
132
- const platformFilter = getPlatformSpecificString(platform);
133
-
134
- return {
135
- argv: {
136
- [configParam]: runnerConfig.runnerConfig /* istanbul ignore next */ || undefined,
137
- cleanup: Boolean(cliConfig.cleanup) || undefined,
138
- colors: !cliConfig.noColor && undefined,
139
- configuration: cliConfig.configuration || undefined,
140
- gpu: cliConfig.gpu || undefined,
141
- // TODO: check if we can --grep from user
142
- grep: platformFilter || undefined,
143
- invert: Boolean(platformFilter) || undefined,
144
- headless: Boolean(cliConfig.headless) || undefined,
145
- loglevel: cliConfig.loglevel || undefined,
146
- reuse: cliConfig.reuse || undefined,
147
- 'artifacts-location': cliConfig.artifactsLocation || undefined,
148
- 'config-path': cliConfig.configPath /* istanbul ignore next */ || undefined,
149
- 'debug-synchronization': isFinite(cliConfig.debugSynchronization) ? cliConfig.debugSynchronization : undefined,
150
- 'device-name': cliConfig.deviceName || undefined,
151
- 'force-adb-install': platform === 'android' && cliConfig.forceAdbInstall || undefined,
152
- 'record-logs': cliConfig.recordLogs || undefined,
153
- 'record-performance': cliConfig.recordPerformance || undefined,
154
- 'record-videos': cliConfig.recordVideos || undefined,
155
- 'take-screenshots': cliConfig.takeScreenshots || undefined,
156
- 'capture-view-hierarchy': cliConfig.captureViewHierarchy || undefined,
157
- 'use-custom-logger': cliConfig.useCustomLogger && 'true' || undefined,
158
-
159
- ...passthrough,
160
- },
161
- env: _.omitBy({
162
- DETOX_APP_LAUNCH_ARGS: cliConfig.appLaunchArgs,
163
- DETOX_DEVICE_BOOT_ARGS: cliConfig.deviceBootArgs,
164
- }, _.isUndefined),
165
- specs: _.isEmpty(specs) ? [runnerConfig.specs] : specs,
166
- };
167
- }
168
-
169
- async function prepareJestArgs({ cliConfig, deviceConfig, runnerArgs, runnerConfig, platform }) {
170
- const { specs, passthrough } = splitArgv.jest(runnerArgs);
171
- const platformFilter = getPlatformSpecificString(platform);
172
-
173
- const argv = _.omitBy({
174
- color: !cliConfig.noColor && undefined,
175
- config: runnerConfig.runnerConfig /* istanbul ignore next */ || undefined,
176
- testNamePattern: platformFilter ? `^((?!${platformFilter}).)*$` : undefined,
177
- maxWorkers: cliConfig.workers || (runnerConfig.skipLegacyWorkersInjection ? undefined : 1),
178
-
179
- ...passthrough,
180
- }, _.isUndefined);
181
-
182
- const hasMultipleWorkers = runnerConfig.skipLegacyWorkersInjection
183
- ? (await readJestConfig(argv)).globalConfig.maxWorkers > 1
184
- : cliConfig.workers > 1;
185
-
186
- return {
187
- argv,
188
-
189
- env: _.omitBy({
190
- DETOX_APP_LAUNCH_ARGS: cliConfig.appLaunchArgs,
191
- DETOX_ARTIFACTS_LOCATION: cliConfig.artifactsLocation,
192
- DETOX_CAPTURE_VIEW_HIERARCHY: cliConfig.captureViewHierarchy,
193
- DETOX_CLEANUP: cliConfig.cleanup,
194
- DETOX_CONFIGURATION: cliConfig.configuration,
195
- DETOX_CONFIG_PATH: cliConfig.configPath,
196
- DETOX_DEBUG_SYNCHRONIZATION: cliConfig.debugSynchronization,
197
- DETOX_DEVICE_BOOT_ARGS: cliConfig.deviceBootArgs,
198
- DETOX_DEVICE_NAME: cliConfig.deviceName,
199
- DETOX_FORCE_ADB_INSTALL: platform === 'android' ? cliConfig.forceAdbInstall : undefined,
200
- DETOX_GPU: cliConfig.gpu,
201
- DETOX_HEADLESS: cliConfig.headless,
202
- DETOX_LOGLEVEL: cliConfig.loglevel,
203
- DETOX_READ_ONLY_EMU: deviceConfig.type === 'android.emulator' && hasMultipleWorkers ? true : undefined,
204
- DETOX_RECORD_LOGS: cliConfig.recordLogs,
205
- DETOX_RECORD_PERFORMANCE: cliConfig.recordPerformance,
206
- DETOX_RECORD_TIMELINE: cliConfig.recordTimeline,
207
- DETOX_RECORD_VIDEOS: cliConfig.recordVideos,
208
- DETOX_REPORT_SPECS: _.isUndefined(cliConfig.jestReportSpecs)
209
- ? !hasMultipleWorkers
210
- : `${cliConfig.jestReportSpecs}` === 'true',
211
- DETOX_REUSE: cliConfig.reuse,
212
- DETOX_START_TIMESTAMP: Date.now(),
213
- DETOX_TAKE_SCREENSHOTS: cliConfig.takeScreenshots,
214
- DETOX_USE_CUSTOM_LOGGER: cliConfig.useCustomLogger,
215
- }, _.isUndefined),
216
-
217
- specs: _.isEmpty(specs) ? [runnerConfig.specs] : specs,
218
- };
219
- }
220
-
221
- async function resetLockFile({ platform }) {
222
- if (platform === 'ios') {
223
- await DeviceRegistry.forIOS().reset();
224
- }
225
-
226
- if (platform === 'android') {
227
- await DeviceRegistry.forAndroid().reset();
228
- await GenyDeviceRegistryFactory.forGlobalShutdown().reset();
229
- }
230
- }
231
-
232
- function launchTestRunner({ argv, env, specs }) {
233
- const { $0: command, ...restArgv } = argv;
234
- const fullCommand = [
235
- command,
236
- quote(unparse(_.omitBy(restArgv, _.isUndefined))),
237
- specs.join(' ')
238
- ].join(' ');
239
-
240
- log.info(printEnvironmentVariables(env) + fullCommand);
241
-
242
- cp.execSync(fullCommand, {
243
- stdio: 'inherit',
244
- env: _({})
245
- .assign(process.env)
246
- .assign(env)
247
- .omitBy(_.isUndefined)
248
- .tap(prependNodeModulesBinToPATH)
249
- .value()
250
- });
251
- }
252
-
253
- async function runTestRunnerWithRetries(forwardedArgs, { keepLockFile, platform, retries }) {
254
- let runsLeft = 1 + retries;
255
- let launchError;
256
-
257
- do {
258
- try {
259
- if (launchError) {
260
- const list = forwardedArgs.specs.map((file, index) => ` ${index + 1}. ${file}`).join('\n');
261
- log.error(
262
- `There were failing tests in the following files:\n${list}\n\n` +
263
- 'Detox CLI is going to restart the test runner with those files...\n'
264
- );
265
- }
266
-
267
- if (!keepLockFile) {
268
- await resetLockFile({ platform });
269
- }
270
-
271
- await resetLastFailedTests();
272
- launchTestRunner(forwardedArgs);
273
- launchError = null;
274
- } catch (e) {
275
- launchError = e;
276
-
277
- const lastFailedTests = await loadLastFailedTests();
278
- if (_.isEmpty(lastFailedTests)) {
279
- throw e;
280
- }
281
-
282
- forwardedArgs.specs = lastFailedTests;
283
- forwardedArgs.env.DETOX_RERUN_INDEX = 1 + (forwardedArgs.env.DETOX_RERUN_INDEX || 0);
284
- }
285
- } while (launchError && --runsLeft > 0);
286
-
287
- if (launchError) {
288
- throw launchError;
289
- }
290
- }