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

Sign up to get free protection for your applications and to get access to all the features.
Files changed (169) hide show
  1. package/.eslintrc.js +2 -7
  2. package/Detox-android/com/wix/detox/{20.1.0-next-is-hittable-check.0/detox-20.1.0-next-is-hittable-check.0-javadoc.jar → 20.1.1/detox-20.1.1-javadoc.jar} +0 -0
  3. package/Detox-android/com/wix/detox/20.1.1/detox-20.1.1-javadoc.jar.md5 +1 -0
  4. package/Detox-android/com/wix/detox/20.1.1/detox-20.1.1-javadoc.jar.sha1 +1 -0
  5. package/Detox-android/com/wix/detox/20.1.1/detox-20.1.1-javadoc.jar.sha256 +1 -0
  6. package/Detox-android/com/wix/detox/20.1.1/detox-20.1.1-javadoc.jar.sha512 +1 -0
  7. package/Detox-android/com/wix/detox/{20.1.0-next-is-hittable-check.0/detox-20.1.0-next-is-hittable-check.0-sources.jar → 20.1.1/detox-20.1.1-sources.jar} +0 -0
  8. package/Detox-android/com/wix/detox/20.1.1/detox-20.1.1-sources.jar.md5 +1 -0
  9. package/Detox-android/com/wix/detox/20.1.1/detox-20.1.1-sources.jar.sha1 +1 -0
  10. package/Detox-android/com/wix/detox/20.1.1/detox-20.1.1-sources.jar.sha256 +1 -0
  11. package/Detox-android/com/wix/detox/20.1.1/detox-20.1.1-sources.jar.sha512 +1 -0
  12. package/Detox-android/com/wix/detox/20.1.1/detox-20.1.1.aar +0 -0
  13. package/Detox-android/com/wix/detox/20.1.1/detox-20.1.1.aar.md5 +1 -0
  14. package/Detox-android/com/wix/detox/20.1.1/detox-20.1.1.aar.sha1 +1 -0
  15. package/Detox-android/com/wix/detox/20.1.1/detox-20.1.1.aar.sha256 +1 -0
  16. package/Detox-android/com/wix/detox/20.1.1/detox-20.1.1.aar.sha512 +1 -0
  17. package/Detox-android/com/wix/detox/{20.1.0-next-is-hittable-check.0/detox-20.1.0-next-is-hittable-check.0.pom → 20.1.1/detox-20.1.1.pom} +1 -1
  18. package/Detox-android/com/wix/detox/20.1.1/detox-20.1.1.pom.md5 +1 -0
  19. package/Detox-android/com/wix/detox/20.1.1/detox-20.1.1.pom.sha1 +1 -0
  20. package/Detox-android/com/wix/detox/20.1.1/detox-20.1.1.pom.sha256 +1 -0
  21. package/Detox-android/com/wix/detox/20.1.1/detox-20.1.1.pom.sha512 +1 -0
  22. package/Detox-android/com/wix/detox/maven-metadata.xml +4 -4
  23. package/Detox-android/com/wix/detox/maven-metadata.xml.md5 +1 -1
  24. package/Detox-android/com/wix/detox/maven-metadata.xml.sha1 +1 -1
  25. package/Detox-android/com/wix/detox/maven-metadata.xml.sha256 +1 -1
  26. package/Detox-android/com/wix/detox/maven-metadata.xml.sha512 +1 -1
  27. package/Detox-ios-src.tbz +0 -0
  28. package/Detox-ios.tbz +0 -0
  29. package/android/build.gradle +0 -1
  30. package/android/detox/src/full/java/com/wix/detox/TestEngineFacade.kt +3 -3
  31. package/android/detox/src/full/java/com/wix/detox/adapters/server/QueryStatusActionHandler.kt +12 -80
  32. package/android/detox/src/full/java/com/wix/detox/espresso/common/UiControllerImplReflected.kt +16 -0
  33. package/android/detox/src/full/java/com/wix/detox/espresso/idlingresources/DescriptiveIdlingResource.kt +8 -0
  34. package/android/detox/src/full/java/com/wix/detox/espresso/registry/BusyResourcesInquirer.kt +48 -0
  35. package/android/detox/src/full/java/com/wix/detox/inquiry/DetoxBusyResource.kt +92 -0
  36. package/android/detox/src/full/java/com/wix/detox/{reactnative/idlingresources/IdlingResourceDescription.kt → inquiry/DetoxBusyResourceDescription.kt} +6 -6
  37. package/android/detox/src/full/java/com/wix/detox/reactnative/idlingresources/AnimatedModuleIdlingResource.java +18 -7
  38. package/android/detox/src/full/java/com/wix/detox/reactnative/idlingresources/AsyncStorageIdlingResource.kt +3 -4
  39. package/android/detox/src/full/java/com/wix/detox/reactnative/idlingresources/BridgeIdlingResource.java +12 -6
  40. package/android/detox/src/full/java/com/wix/detox/reactnative/idlingresources/DetoxBaseIdlingResource.java +2 -0
  41. package/android/detox/src/full/java/com/wix/detox/reactnative/idlingresources/NetworkIdlingResource.java +14 -8
  42. package/android/detox/src/full/java/com/wix/detox/reactnative/idlingresources/timers/TimersIdlingResource.kt +2 -6
  43. package/android/detox/src/full/java/com/wix/detox/reactnative/idlingresources/uimodule/UIManagerModuleReflected.kt +1 -1
  44. package/android/detox/src/full/java/com/wix/detox/reactnative/idlingresources/uimodule/UIModuleIdlingResource.kt +4 -6
  45. package/android/detox/src/testFull/java/com/wix/detox/adapters/server/QueryStatusActionHandlerSpec.kt +35 -94
  46. package/android/detox/src/testFull/java/com/wix/detox/espresso/registry/{IRStatusInquirerTest.kt → BusyResourcesInquirerTest.kt} +46 -7
  47. package/android/detox/src/testFull/java/com/wix/detox/{reactnative/idlingresources/IdlingResourceDescriptionSpec.kt → inquiry/DetoxBusyResourceDescriptionSpec.kt} +6 -6
  48. package/android/detox/src/testFull/java/com/wix/detox/inquiry/DetoxBusyResourceSpec.kt +134 -0
  49. package/android/detox/src/testFull/java/com/wix/detox/reactnative/idlingresources/AsyncStorageIdlingResourceSpec.kt +4 -5
  50. package/android/detox/src/testFull/java/com/wix/detox/reactnative/idlingresources/NetworkIdlingResourcesTest.kt +5 -5
  51. package/android/detox/src/testFull/java/com/wix/detox/reactnative/idlingresources/timers/TimersIdlingResourceSpec.kt +4 -6
  52. package/index.d.ts +102 -18
  53. package/index.js +12 -1
  54. package/internals.d.ts +34 -9
  55. package/internals.js +10 -3
  56. package/local-cli/cli.js +6 -3
  57. package/local-cli/init.js +1 -1
  58. package/local-cli/test.js +6 -6
  59. package/local-cli/testCommand/TestRunnerCommand.js +97 -94
  60. package/local-cli/testCommand/TestRunnerError.js +17 -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/package.json +31 -16
  65. package/runners/deprecation.js +42 -44
  66. package/runners/jest/index.d.ts +60 -0
  67. package/runners/jest/index.js +3 -8
  68. package/runners/jest/reporters/DetoxReporter.js +21 -10
  69. package/runners/jest/testEnvironment/index.js +57 -41
  70. package/runners/jest/testEnvironment/listeners/DetoxCoreListener.js +62 -35
  71. package/runners/jest/testEnvironment/listeners/SpecReporter.js +12 -14
  72. package/runners/jest/testEnvironment/listeners/WorkerAssignReporter.js +1 -5
  73. package/runners/jest/testEnvironment/utils/assertJestCircus27.js +17 -3
  74. package/src/DetoxWorker.js +96 -50
  75. package/src/android/core/NativeMatcher.js +14 -10
  76. package/src/android/espressoapi/EspressoDetox.js +1 -1
  77. package/src/android/espressoapi/web/WebElement.js +1 -1
  78. package/src/android/interactions/native.js +3 -2
  79. package/src/android/matchers/native.js +1 -2
  80. package/src/artifacts/ArtifactsManager.js +6 -6
  81. package/src/artifacts/templates/plugin/ArtifactPlugin.js +1 -1
  82. package/src/artifacts/templates/plugin/TwoSnapshotsPerTestPlugin.js +2 -1
  83. package/src/artifacts/templates/plugin/WholeTestRecorderPlugin.js +3 -2
  84. package/src/artifacts/utils/temporaryPath.js +32 -2
  85. package/src/client/AsyncWebSocket.js +3 -2
  86. package/src/client/actions/SyncStatusSchema.json +21 -0
  87. package/src/client/actions/formatters/SyncStatusFormatter.js +2 -0
  88. package/src/client/actions/formatters/sync-resources/BgThreadFormatter.js +5 -0
  89. package/src/configuration/collectCliConfig.js +2 -13
  90. package/src/configuration/composeLoggerConfig.js +1 -0
  91. package/src/configuration/composeRunnerConfig.js +5 -4
  92. package/src/devices/allocation/drivers/AllocationDriverBase.js +4 -2
  93. package/src/devices/allocation/drivers/android/emulator/EmulatorLauncher.js +3 -3
  94. package/src/devices/allocation/drivers/android/emulator/launchEmulatorProcess.js +3 -16
  95. package/src/devices/allocation/factories/base.js +1 -1
  96. package/src/devices/common/drivers/android/exec/ADB.js +4 -0
  97. package/src/devices/common/drivers/android/tools/AppInstallHelper.js +4 -4
  98. package/src/devices/common/drivers/android/tools/{FileXfer.js → FileTransfer.js} +2 -2
  99. package/src/devices/common/drivers/android/tools/TempFileTransfer.js +14 -0
  100. package/src/devices/common/drivers/ios/tools/AppleSimUtils.js +1 -1
  101. package/src/devices/lifecycle/GenyGlobalLifecycleHandler.js +2 -0
  102. package/src/devices/runtime/RuntimeDevice.js +3 -3
  103. package/src/devices/runtime/drivers/android/AndroidDriver.js +7 -6
  104. package/src/devices/runtime/factories/android.js +6 -5
  105. package/src/devices/runtime/factories/base.js +3 -2
  106. package/src/errors/DetoxConfigErrorComposer.js +6 -1
  107. package/src/errors/DetoxError.js +5 -1
  108. package/src/ios/expectTwo.js +22 -13
  109. package/src/ipc/IPCClient.js +26 -17
  110. package/src/ipc/IPCServer.js +11 -3
  111. package/src/ipc/SessionState.js +11 -11
  112. package/src/logger/DetoxLogger.js +67 -47
  113. package/src/logger/index.js +1 -0
  114. package/src/logger/utils/BunyanLogger.js +54 -10
  115. package/src/logger/utils/CategoryThreadDispatcher.js +8 -29
  116. package/src/logger/utils/DetoxLogFinalizer.js +166 -0
  117. package/src/logger/utils/MessageStack.js +17 -6
  118. package/src/logger/utils/ThreadDispatcher.js +5 -25
  119. package/src/logger/utils/customConsoleLogger.js +22 -5
  120. package/src/logger/utils/getMainCategory.js +5 -0
  121. package/src/logger/utils/sanitizeBunyanContext.js +3 -1
  122. package/src/logger/utils/streams/BunyanTransformer.js +72 -0
  123. package/src/logger/utils/streams/ChromeTraceTransformer.js +132 -0
  124. package/src/logger/utils/streams/DetoxJSONLParser.js +31 -0
  125. package/src/logger/utils/streams/JSONLStringer.js +55 -0
  126. package/src/logger/utils/streams/index.js +7 -0
  127. package/src/logger/utils/streams/transformers.js +39 -0
  128. package/src/logger/utils/tracerLegacy.js +14 -25
  129. package/src/realms/DetoxContext.js +16 -9
  130. package/src/realms/DetoxInternalsFacade.js +1 -7
  131. package/src/realms/DetoxPrimaryContext.js +42 -87
  132. package/src/realms/DetoxSecondaryContext.js +9 -13
  133. package/src/{symbols.js → realms/symbols.js} +0 -0
  134. package/src/servicelocator/android/index.js +2 -2
  135. package/src/utils/ExclusiveLockfile.js +1 -0
  136. package/src/utils/argparse.js +11 -27
  137. package/src/utils/logger.js +1 -1
  138. package/src/utils/pathUtils.js +11 -0
  139. package/src/utils/shellUtils.js +17 -0
  140. package/src/utils/traceInvocationCall.js +21 -0
  141. package/Detox-android/com/wix/detox/20.1.0-next-is-hittable-check.0/detox-20.1.0-next-is-hittable-check.0-javadoc.jar.md5 +0 -1
  142. package/Detox-android/com/wix/detox/20.1.0-next-is-hittable-check.0/detox-20.1.0-next-is-hittable-check.0-javadoc.jar.sha1 +0 -1
  143. package/Detox-android/com/wix/detox/20.1.0-next-is-hittable-check.0/detox-20.1.0-next-is-hittable-check.0-javadoc.jar.sha256 +0 -1
  144. package/Detox-android/com/wix/detox/20.1.0-next-is-hittable-check.0/detox-20.1.0-next-is-hittable-check.0-javadoc.jar.sha512 +0 -1
  145. package/Detox-android/com/wix/detox/20.1.0-next-is-hittable-check.0/detox-20.1.0-next-is-hittable-check.0-sources.jar.md5 +0 -1
  146. package/Detox-android/com/wix/detox/20.1.0-next-is-hittable-check.0/detox-20.1.0-next-is-hittable-check.0-sources.jar.sha1 +0 -1
  147. package/Detox-android/com/wix/detox/20.1.0-next-is-hittable-check.0/detox-20.1.0-next-is-hittable-check.0-sources.jar.sha256 +0 -1
  148. package/Detox-android/com/wix/detox/20.1.0-next-is-hittable-check.0/detox-20.1.0-next-is-hittable-check.0-sources.jar.sha512 +0 -1
  149. package/Detox-android/com/wix/detox/20.1.0-next-is-hittable-check.0/detox-20.1.0-next-is-hittable-check.0.aar +0 -0
  150. package/Detox-android/com/wix/detox/20.1.0-next-is-hittable-check.0/detox-20.1.0-next-is-hittable-check.0.aar.md5 +0 -1
  151. package/Detox-android/com/wix/detox/20.1.0-next-is-hittable-check.0/detox-20.1.0-next-is-hittable-check.0.aar.sha1 +0 -1
  152. package/Detox-android/com/wix/detox/20.1.0-next-is-hittable-check.0/detox-20.1.0-next-is-hittable-check.0.aar.sha256 +0 -1
  153. package/Detox-android/com/wix/detox/20.1.0-next-is-hittable-check.0/detox-20.1.0-next-is-hittable-check.0.aar.sha512 +0 -1
  154. package/Detox-android/com/wix/detox/20.1.0-next-is-hittable-check.0/detox-20.1.0-next-is-hittable-check.0.pom.md5 +0 -1
  155. package/Detox-android/com/wix/detox/20.1.0-next-is-hittable-check.0/detox-20.1.0-next-is-hittable-check.0.pom.sha1 +0 -1
  156. package/Detox-android/com/wix/detox/20.1.0-next-is-hittable-check.0/detox-20.1.0-next-is-hittable-check.0.pom.sha256 +0 -1
  157. package/Detox-android/com/wix/detox/20.1.0-next-is-hittable-check.0/detox-20.1.0-next-is-hittable-check.0.pom.sha512 +0 -1
  158. package/android/detox/src/full/java/com/wix/detox/espresso/registry/IRStatusInquirer.kt +0 -24
  159. package/android/detox/src/full/java/com/wix/detox/reactnative/idlingresources/DescriptiveIdlingResource.kt +0 -10
  160. package/local-cli/build.test.js +0 -104
  161. package/local-cli/run-server.test.js +0 -23
  162. package/local-cli/test.test.js +0 -569
  163. package/runners/jest/deprecation.js +0 -25
  164. package/runners/jest/testEnvironment/utils/assertJestCircus27.test.js +0 -23
  165. package/src/configuration/utils/warnings.js +0 -12
  166. package/src/devices/common/drivers/android/tools/TempFileXfer.js +0 -16
  167. package/src/logger/utils/streamUtils.js +0 -240
  168. package/src/realms/index.js +0 -10
  169. package/src/utils/trace.js +0 -3
@@ -1,45 +1,34 @@
1
1
  const methods = {
2
2
  startSection(logger) {
3
- return (msg, args) => logger.trace.begin(args, msg);
3
+ return (msg, args) => {
4
+ if (args !== undefined) {
5
+ return logger.trace.begin(args, msg);
6
+ } else {
7
+ return logger.trace.begin(msg);
8
+ }
9
+ };
4
10
  },
5
11
 
6
12
  endSection(logger) {
7
- return (msg, args) => logger.trace.end(args);
13
+ return (_msg, args) => {
14
+ if (args !== undefined) {
15
+ return logger.trace.end(args);
16
+ } else {
17
+ return logger.trace.end();
18
+ }
19
+ };
8
20
  },
9
21
 
10
22
  traceCall(logger) {
11
23
  return (name, action, args = {}) => logger.trace.complete(args, name, action);
12
24
  },
13
-
14
- invocationCall(logger) {
15
- return (sectionName, invocation, action) => {
16
- return logger.trace.complete({
17
- cat: 'ws-client,ws-client-invocation',
18
- data: invocation,
19
- stack: _getCallStackTrace(),
20
- }, sectionName, action);
21
- };
22
- },
23
25
  };
24
26
 
25
- function _getCallStackTrace() {
26
- return new Error().stack
27
- .split('\n')
28
- .slice(1) // Ignore Error message
29
- .map(line => line
30
- .replace(/^\s*at\s+/, '')
31
- .replace(process.cwd(), '')
32
- )
33
- .filter(line => !line.includes('/detox/src')) // Ignore detox internal calls
34
- .join('\n');
35
- }
36
-
37
27
  function installLegacyTracerInterface(logger, target) {
38
28
  target.traceCall = methods.traceCall(logger);
39
29
  target.trace = Object.freeze({
40
30
  startSection: methods.startSection(logger),
41
31
  endSection: methods.endSection(logger),
42
- invocationCall: methods.invocationCall(logger),
43
32
  });
44
33
 
45
34
  return this;
@@ -2,16 +2,19 @@ const funpermaproxy = require('funpermaproxy');
2
2
 
3
3
  const temporary = require('../artifacts/utils/temporaryPath');
4
4
  const { DetoxRuntimeError } = require('../errors');
5
- const { DetoxLogger, installLegacyTracerInterface } = require('../logger');
6
- const symbols = require('../symbols');
5
+ const { DetoxLogger, DetoxLogFinalizer, installLegacyTracerInterface } = require('../logger');
7
6
 
8
7
  const DetoxConstants = require('./DetoxConstants');
8
+ const symbols = require('./symbols');
9
9
 
10
+ //#region Protected symbols
10
11
  const $cleanup = Symbol('cleanup');
12
+ const $logFinalizer = Symbol('logFinalizer');
11
13
  const $restoreSessionState = Symbol('restoreSessionState');
12
14
  const $sessionState = Symbol('restoreSessionState');
13
15
  const $status = Symbol('status');
14
16
  const $worker = Symbol('worker');
17
+ //#endregion
15
18
 
16
19
  class DetoxContext {
17
20
  constructor() {
@@ -56,6 +59,11 @@ class DetoxContext {
56
59
  this.log = this[symbols.logger].child({ cat: 'user' });
57
60
  installLegacyTracerInterface(this.log, this);
58
61
 
62
+ this[$logFinalizer] = new DetoxLogFinalizer({
63
+ session: this[$sessionState],
64
+ logger: this[symbols.logger],
65
+ });
66
+
59
67
  /** @type {import('../DetoxWorker') | null} */
60
68
  this[$worker] = null;
61
69
  }
@@ -89,12 +97,7 @@ class DetoxContext {
89
97
  [symbols.config] = funpermaproxy(() => this[symbols.session].detoxConfig);
90
98
  [symbols.session] = funpermaproxy(() => this[$sessionState]);
91
99
  [symbols.tracing] = Object.freeze({
92
- createEventStream: () => {
93
- const streamUtils = require('../logger/utils/streamUtils');
94
- return streamUtils
95
- .uniteSessionLogs(this[$sessionState].id)
96
- .pipe(streamUtils.chromeTraceStream());
97
- },
100
+ createEventStream: () => this[$logFinalizer].createEventStream(),
98
101
  });
99
102
  /** @abstract */
100
103
  [symbols.reportTestResults](_testResults) {}
@@ -132,7 +135,10 @@ class DetoxContext {
132
135
  */
133
136
  async [symbols.installWorker](opts) {
134
137
  if (opts.global) {
135
- opts.global['__detox__'] = this;
138
+ opts.global['__detox__'] = {
139
+ clientApi: require('../../index'),
140
+ internalsApi: require('../../internals'),
141
+ };
136
142
  this.log.overrideConsole(opts.global);
137
143
  }
138
144
 
@@ -173,6 +179,7 @@ class DetoxContext {
173
179
  module.exports = DetoxContext;
174
180
  module.exports.protected = {
175
181
  $cleanup,
182
+ $logFinalizer,
176
183
  $restoreSessionState,
177
184
  $status,
178
185
  $sessionState,
@@ -1,6 +1,6 @@
1
1
  const funpermaproxy = require('funpermaproxy');
2
2
 
3
- const symbols = require('../symbols');
3
+ const symbols = require('./symbols');
4
4
 
5
5
  class DetoxInternalsFacade {
6
6
  /**
@@ -15,16 +15,10 @@ class DetoxInternalsFacade {
15
15
  this.installWorker = context[symbols.installWorker];
16
16
  this.uninstallWorker = context[symbols.uninstallWorker];
17
17
  this.onHookFailure = context[symbols.onHookFailure];
18
- this.onHookStart = context[symbols.onHookStart];
19
- this.onHookSuccess = context[symbols.onHookSuccess];
20
18
  this.onRunDescribeFinish = context[symbols.onRunDescribeFinish];
21
19
  this.onRunDescribeStart = context[symbols.onRunDescribeStart];
22
- this.onRunFinish = context[symbols.onRunFinish];
23
- this.onRunStart = context[symbols.onRunStart];
24
20
  this.onTestDone = context[symbols.onTestDone];
25
21
  this.onTestFnFailure = context[symbols.onTestFnFailure];
26
- this.onTestFnStart = context[symbols.onTestFnStart];
27
- this.onTestFnSuccess = context[symbols.onTestFnSuccess];
28
22
  this.onTestStart = context[symbols.onTestStart];
29
23
  this.reportTestResults = context[symbols.reportTestResults];
30
24
  this.resolveConfig = context[symbols.resolveConfig];
@@ -1,34 +1,31 @@
1
- const path = require('path');
2
1
  const { URL } = require('url');
3
- const { promisify } = require('util');
4
2
 
5
3
  const fs = require('fs-extra');
6
- const glob = require('glob');
7
- const pipe = require('multipipe');
8
4
  const onSignalExit = require('signal-exit');
9
5
 
10
6
  const temporary = require('../artifacts/utils/temporaryPath');
11
7
  const { DetoxRuntimeError } = require('../errors');
12
8
  const SessionState = require('../ipc/SessionState');
13
- const symbols = require('../symbols');
14
-
15
- const globAsync = promisify(glob);
16
- const globSync = glob.sync;
9
+ const { getCurrentCommand } = require('../utils/argparse');
10
+ const uuid = require('../utils/uuid');
17
11
 
18
12
  const DetoxContext = require('./DetoxContext');
13
+ const symbols = require('./symbols');
19
14
 
20
- const { $restoreSessionState, $sessionState, $worker } = DetoxContext.protected;
15
+ // Protected symbols
16
+ const { $logFinalizer, $restoreSessionState, $sessionState, $worker } = DetoxContext.protected;
21
17
 
22
- const _finalizeLogs = Symbol('finalizeLogs');
23
- const _finalizeLogsSync = Symbol('finalizeLogsSync');
18
+ //#region Private symbols
24
19
  const _globalLifecycleHandler = Symbol('globalLifecycleHandler');
25
20
  const _ipcServer = Symbol('ipcServer');
26
21
  const _resetLockFile = Symbol('resetLockFile');
27
22
  const _wss = Symbol('wss');
28
23
  const _dirty = Symbol('dirty');
29
24
  const _emergencyTeardown = Symbol('emergencyTeardown');
30
- const _areLogsEnabled = Symbol('areLogsEnabled');
31
25
  const _lifecycleLogger = Symbol('lifecycleLogger');
26
+ const _sessionFile = Symbol('sessionFile');
27
+ const _logFinalError = Symbol('logFinalError');
28
+ //#endregion
32
29
 
33
30
  class DetoxPrimaryContext extends DetoxContext {
34
31
  constructor() {
@@ -37,6 +34,8 @@ class DetoxPrimaryContext extends DetoxContext {
37
34
  this[_dirty] = false;
38
35
  this[_wss] = null;
39
36
  this[_globalLifecycleHandler] = null;
37
+ /** Path to file where the initial session object is serialized */
38
+ this[_sessionFile] = '';
40
39
  /**
41
40
  * @type {import('../ipc/IPCServer') | null}
42
41
  */
@@ -88,9 +87,11 @@ class DetoxPrimaryContext extends DetoxContext {
88
87
  await this[symbols.logger].setConfig(loggerConfig);
89
88
 
90
89
  this[_lifecycleLogger].trace.begin({
90
+ cwd: process.cwd(),
91
91
  data: this[$sessionState],
92
- }, process.argv.slice(1).join(' '));
92
+ }, getCurrentCommand());
93
93
 
94
+ // TODO: IPC Server creation ought to be delegated to a generator/factory.
94
95
  const IPCServer = require('../ipc/IPCServer');
95
96
  this[_ipcServer] = new IPCServer({
96
97
  sessionState: this[$sessionState],
@@ -110,6 +111,7 @@ class DetoxPrimaryContext extends DetoxContext {
110
111
  await this[_resetLockFile]();
111
112
  }
112
113
 
114
+ // TODO: Detox-server creation ought to be delegated to a generator/factory.
113
115
  const DetoxServer = require('../server/DetoxServer');
114
116
  if (sessionConfig.autoStart) {
115
117
  this[_wss] = new DetoxServer({
@@ -122,13 +124,16 @@ class DetoxPrimaryContext extends DetoxContext {
122
124
  await this[_wss].open();
123
125
  }
124
126
 
127
+ // TODO: double check that this config is indeed propogated onto the client create at the detox-worker side
125
128
  if (!sessionConfig.server && this[_wss]) {
126
129
  // @ts-ignore
127
130
  sessionConfig.server = `ws://localhost:${this[_wss].port}`;
128
131
  }
129
132
 
130
- await fs.writeFile(this[$sessionState].detoxConfigSnapshotPath, this[$sessionState].stringify());
131
- process.env.DETOX_CONFIG_SNAPSHOT_PATH = this[$sessionState].detoxConfigSnapshotPath;
133
+ this[_sessionFile] = temporary.for.json(this[$sessionState].id);
134
+ await fs.writeFile(this[_sessionFile], this[$sessionState].stringify());
135
+ process.env.DETOX_CONFIG_SNAPSHOT_PATH = this[_sessionFile];
136
+ this[_lifecycleLogger].trace(`Serialized the session state at: ${this[_sessionFile]}`);
132
137
 
133
138
  if (opts.workerId !== null) {
134
139
  await this[symbols.installWorker](opts);
@@ -140,10 +145,12 @@ class DetoxPrimaryContext extends DetoxContext {
140
145
  * @param {Partial<DetoxInternals.DetoxInstallWorkerOptions>} [opts]
141
146
  */
142
147
  async [symbols.installWorker](opts = {}) {
143
- const workerId = this[$sessionState].workerId = opts.workerId = opts.workerId || 'worker';
148
+ const workerId = opts.workerId || 'worker';
149
+
150
+ this[$sessionState].workerId = workerId;
144
151
  this[_ipcServer].onRegisterWorker({ workerId });
145
152
 
146
- await super[symbols.installWorker](opts);
153
+ await super[symbols.installWorker]({ ...opts, workerId });
147
154
  }
148
155
 
149
156
  /** @override */
@@ -168,14 +175,17 @@ class DetoxPrimaryContext extends DetoxContext {
168
175
  this[_ipcServer] = null;
169
176
  }
170
177
 
171
- await fs.remove(this[$sessionState].detoxConfigSnapshotPath);
178
+ if (this[_sessionFile]) {
179
+ await fs.remove(this[_sessionFile]);
180
+ }
172
181
 
173
182
  if (this[_dirty]) {
174
183
  try {
175
184
  this[_lifecycleLogger].trace.end();
176
- await this[_finalizeLogs]();
185
+ await this[symbols.logger].close();
186
+ await this[$logFinalizer].finalize();
177
187
  } catch (err) {
178
- this[_lifecycleLogger].error({ err }, 'Encountered an error while merging the process logs:');
188
+ this[_logFinalError](err);
179
189
  }
180
190
  }
181
191
  }
@@ -199,14 +209,23 @@ class DetoxPrimaryContext extends DetoxContext {
199
209
  this[_ipcServer].dispose();
200
210
  }
201
211
 
212
+ if (this[_sessionFile]) {
213
+ fs.removeSync(this[_sessionFile]);
214
+ }
215
+
202
216
  try {
203
217
  this[_lifecycleLogger].trace.end({ abortSignal: signal });
204
- this[_finalizeLogsSync]();
218
+ this[symbols.logger].close().catch(this[_logFinalError]);
219
+ this[$logFinalizer].finalizeSync();
205
220
  } catch (err) {
206
- this[symbols.logger].error({ err }, 'Encountered an error while merging the process logs:');
221
+ this[_logFinalError](err);
207
222
  }
208
223
  };
209
224
 
225
+ [_logFinalError] = (err) => {
226
+ this[_lifecycleLogger].error(err, 'Encountered an error while merging the process logs:');
227
+ };
228
+
210
229
  //#endregion
211
230
 
212
231
  //#region Protected members
@@ -217,77 +236,13 @@ class DetoxPrimaryContext extends DetoxContext {
217
236
  */
218
237
  [$restoreSessionState]() {
219
238
  return new SessionState({
220
- detoxConfigSnapshotPath: temporary.for.json(),
239
+ id: uuid.UUID(),
221
240
  detoxIPCServer: `primary-${process.pid}`,
222
241
  });
223
242
  }
224
243
  //#endregion
225
244
 
226
245
  //#region Private members
227
- async[_finalizeLogs]() {
228
- const sessionId = this[$sessionState].id;
229
- const logs = await globAsync(temporary.for.jsonl(`${sessionId}.*`));
230
- if (logs.length === 0) {
231
- return;
232
- }
233
-
234
- if (this[_areLogsEnabled]()) {
235
- const streamUtils = require('../logger/utils/streamUtils');
236
- const { rootDir } = this[symbols.config].artifacts;
237
-
238
- await fs.mkdirp(rootDir);
239
- const [out1Stream, out2Stream] = ['detox.log', 'detox.trace.json']
240
- .map((filename) => fs.createWriteStream(path.join(rootDir, filename)));
241
-
242
- const mergedStream = streamUtils.uniteSessionLogs(sessionId);
243
-
244
- await Promise.all([
245
- pipe(mergedStream, streamUtils.debugStream(this[symbols.logger].config.options), out1Stream),
246
- pipe(mergedStream, streamUtils.chromeTraceStream(), streamUtils.writeJSON(), out2Stream),
247
- ]);
248
- }
249
-
250
- await Promise.all(logs.map(filepath => fs.remove(filepath)));
251
- }
252
-
253
- async[_finalizeLogsSync]() {
254
- const logsEnabled = this[_areLogsEnabled]();
255
-
256
- const { rootDir } = this[symbols.config].artifacts;
257
-
258
- if (logsEnabled) {
259
- fs.mkdirpSync(rootDir);
260
- }
261
-
262
- const sessionId = this[$sessionState].id;
263
- const logs = globSync(temporary.for.jsonl(`${sessionId}.*`));
264
-
265
- for (const log of logs) {
266
- if (logsEnabled) {
267
- fs.moveSync(log, path.join(rootDir, path.basename(log)));
268
- } else {
269
- fs.removeSync(log);
270
- }
271
- }
272
- }
273
-
274
- [_areLogsEnabled]() {
275
- const { rootDir, plugins } = this[symbols.config].artifacts || {};
276
- if (!rootDir || !plugins) {
277
- return false;
278
- }
279
-
280
- if (!plugins.log.enabled) {
281
- return false;
282
- }
283
-
284
- if (!plugins.log.keepOnlyFailedTestsArtifacts) {
285
- return true;
286
- }
287
-
288
- return this[$sessionState].testResults.some(r => !r.success);
289
- }
290
-
291
246
  async[_resetLockFile]() {
292
247
  const DeviceRegistry = require('../devices/DeviceRegistry');
293
248
 
@@ -1,14 +1,17 @@
1
- const fs = require('fs');
1
+ const fs = require('fs-extra');
2
2
 
3
3
  const { DetoxInternalError } = require('../errors');
4
4
  const SessionState = require('../ipc/SessionState');
5
- const symbols = require('../symbols');
6
5
 
7
6
  const DetoxContext = require('./DetoxContext');
7
+ const symbols = require('./symbols');
8
8
 
9
+ // Protected symbols
9
10
  const { $restoreSessionState, $sessionState, $worker } = DetoxContext.protected;
11
+
12
+ //#region Private symbols
10
13
  const _ipcClient = Symbol('ipcClient');
11
- const _shortLifecycle = Symbol('shortLifecycle');
14
+ //#endregion
12
15
 
13
16
  class DetoxSecondaryContext extends DetoxContext {
14
17
  constructor() {
@@ -19,13 +22,6 @@ class DetoxSecondaryContext extends DetoxContext {
19
22
  * @type {import('../ipc/IPCClient')}
20
23
  */
21
24
  this[_ipcClient] = null;
22
- /**
23
- * @private
24
- * @type {undefined | boolean}
25
- *
26
- * TODO: explain what is short lifecycle and why we need it
27
- */
28
- this[_shortLifecycle] = false;
29
25
  }
30
26
 
31
27
  //#region Internal members
@@ -47,7 +43,7 @@ class DetoxSecondaryContext extends DetoxContext {
47
43
 
48
44
  this[_ipcClient] = new IPCClient({
49
45
  id: `secondary-${process.pid}`,
50
- state: this[$sessionState],
46
+ sessionState: this[$sessionState],
51
47
  logger: this[symbols.logger],
52
48
  });
53
49
 
@@ -74,9 +70,9 @@ class DetoxSecondaryContext extends DetoxContext {
74
70
 
75
71
  /** @override */
76
72
  async [symbols.installWorker](opts = {}) {
77
- const workerId = opts.workerId = opts.workerId || 'worker';
73
+ const workerId = opts.workerId || 'worker';
78
74
  await this[_ipcClient].registerWorker(workerId);
79
- await super[symbols.installWorker](opts);
75
+ await super[symbols.installWorker]({ ...opts, workerId });
80
76
  }
81
77
  //#endregion
82
78
 
File without changes
@@ -3,7 +3,7 @@ const DeviceRegistry = require('../../devices/DeviceRegistry');
3
3
  const AAPT = require('../../devices/common/drivers/android/exec/AAPT');
4
4
  const ADB = require('../../devices/common/drivers/android/exec/ADB');
5
5
  const ApkValidator = require('../../devices/common/drivers/android/tools/ApkValidator');
6
- const TempFileXfer = require('../../devices/common/drivers/android/tools/TempFileXfer');
6
+ const { TempFileTransfer } = require('../../devices/common/drivers/android/tools/TempFileTransfer');
7
7
 
8
8
  const AndroidServiceLocator = {
9
9
  get emulator() {
@@ -18,7 +18,7 @@ const AndroidServiceLocator = {
18
18
  AndroidServiceLocator.adb = new ADB();
19
19
  AndroidServiceLocator.aapt = new AAPT();
20
20
  AndroidServiceLocator.apkValidator = new ApkValidator(AndroidServiceLocator.aapt);
21
- AndroidServiceLocator.fileXfer = new TempFileXfer(AndroidServiceLocator.adb);
21
+ AndroidServiceLocator.fileTransfer = new TempFileTransfer(AndroidServiceLocator.adb);
22
22
  AndroidServiceLocator.deviceRegistry = DeviceRegistry.forAndroid();
23
23
  AndroidServiceLocator.devicePathBuilder = new AndroidDevicePathBuilder();
24
24
 
@@ -86,6 +86,7 @@ class ExclusiveLockfile {
86
86
  */
87
87
  _doRead() {
88
88
  const contents = fs.readFileSync(this._lockFilePath, this._options.read);
89
+ // @ts-ignore Node.js can parse buffer as JSON
89
90
  return JSON.parse(contents);
90
91
  }
91
92
 
@@ -1,13 +1,9 @@
1
+ const path = require('path');
2
+
1
3
  const _ = require('lodash');
2
- const argv = require('minimist')(process.argv.slice(2));
3
4
 
4
5
  const { escape } = require('./pipeCommands');
5
6
 
6
- function getArgValue(key, alias) {
7
- const value = _getArgvValue(key, alias);
8
- return value === undefined ? getEnvValue(key) : value;
9
- }
10
-
11
7
  function getEnvValue(key) {
12
8
  const envKey = _.findKey(process.env, matchesKey(
13
9
  `DETOX_${_.snakeCase(key)}`.toUpperCase()
@@ -21,31 +17,12 @@ function getEnvValue(key) {
21
17
  return value;
22
18
  }
23
19
 
24
- function _getArgvValue(...aliases) {
25
- if (!argv) {
26
- return;
27
- }
28
-
29
- for (const alias of aliases) {
30
- if (alias && argv[alias]) {
31
- return argv[alias];
32
- }
33
- }
34
- }
35
-
36
20
  function matchesKey(key) {
37
21
  return /* istanbul ignore next */ process.platform === 'win32'
38
22
  ? (value, envKey) => envKey.toUpperCase() === key
39
23
  : (value, envKey) => envKey === key;
40
24
  }
41
25
 
42
- function getFlag(key) {
43
- if (argv && argv[key]) {
44
- return true;
45
- }
46
- return false;
47
- }
48
-
49
26
  const DEFAULT_JOIN_ARGUMENTS_OPTIONS = {
50
27
  prefix: '--',
51
28
  joiner: ' ',
@@ -81,9 +58,16 @@ function joinArgs(keyValues, options = DEFAULT_JOIN_ARGUMENTS_OPTIONS) {
81
58
  return argArray.join(' ');
82
59
  }
83
60
 
61
+ function getCurrentCommand() {
62
+ const cwd = process.cwd();
63
+
64
+ return process.argv.slice(1).map((value, index) => {
65
+ return index ? value : path.relative(cwd, value);
66
+ }).join(' ');
67
+ }
68
+
84
69
  module.exports = {
85
- getArgValue,
86
70
  getEnvValue,
87
- getFlag,
88
71
  joinArgs,
72
+ getCurrentCommand,
89
73
  };
@@ -1,4 +1,4 @@
1
1
  /**
2
2
  * @type {Detox.Logger}
3
3
  */
4
- module.exports = require('../..').log;
4
+ module.exports = require('../../internals').log;
@@ -0,0 +1,11 @@
1
+ const path = require('path');
2
+
3
+ function toSimplePath(filePath, cwd = process.cwd()) {
4
+ const relativePath = path.relative(cwd, filePath);
5
+ const isOutsideCwd = relativePath.split(path.sep, 1)[0] === '..';
6
+ return isOutsideCwd ? filePath : relativePath;
7
+ }
8
+
9
+ module.exports = {
10
+ toSimplePath,
11
+ };
@@ -1,5 +1,6 @@
1
1
  const SPACE = ' ';
2
2
  const BACK_SLASH = '\\';
3
+ const FORWARD_SLASH = '/';
3
4
  const SINGLE_QUOTE = "'";
4
5
  const DOUBLE_QUOTE = '"';
5
6
 
@@ -64,6 +65,14 @@ function autoEscapeCmd(str) {
64
65
  return escapeWithDoubleQuotedString(str);
65
66
  }
66
67
 
68
+ function useForwardSlashesCMD(str) {
69
+ return str.split(BACK_SLASH).join(FORWARD_SLASH);
70
+ }
71
+
72
+ function useForwardSlashesShell(str) {
73
+ return str; // already POSIX, so no-op
74
+ }
75
+
67
76
  const hasUnsafeChars = isRunningInCMDEXE()
68
77
  /* istanbul ignore next */ ? hasUnsafeCMDChars
69
78
  /* istanbul ignore next */ : hasUnsafeShellChars;
@@ -76,6 +85,10 @@ const escapeSpaces = isRunningInCMDEXE()
76
85
  /* istanbul ignore next */ ? escapeSpacesCMD
77
86
  /* istanbul ignore next */ : escapeSpacesShell;
78
87
 
88
+ const usePosixSlashes = isRunningInCMDEXE()
89
+ /* istanbul ignore next */ ? useForwardSlashesCMD
90
+ /* istanbul ignore next */ : useForwardSlashesShell;
91
+
79
92
  module.exports = {
80
93
  escapeInDoubleQuotedString,
81
94
  escapeInDoubleQuotedRegexp,
@@ -94,4 +107,8 @@ module.exports = {
94
107
  cmd: autoEscapeCmd,
95
108
  shell: autoEscapeShell,
96
109
  }),
110
+ useForwardSlashes: Object.assign(usePosixSlashes, {
111
+ cmd: useForwardSlashesCMD,
112
+ shell: useForwardSlashesShell,
113
+ }),
97
114
  };
@@ -0,0 +1,21 @@
1
+ function _getCallStackTrace() {
2
+ return new Error().stack
3
+ .split('\n')
4
+ .slice(1) // Ignore Error message
5
+ .map(line => line
6
+ .replace(/^\s*at\s+/, '')
7
+ .replace(process.cwd(), '')
8
+ )
9
+ .filter(line => !line.includes('/detox/src')) // Ignore detox internal calls
10
+ .join('\n');
11
+ }
12
+
13
+ function invocationCall(logger, sectionName, invocation, action) {
14
+ return logger.trace.complete({
15
+ cat: 'ws-client,ws-client-invocation',
16
+ data: invocation,
17
+ stack: _getCallStackTrace(),
18
+ }, sectionName, action);
19
+ }
20
+
21
+ module.exports = invocationCall;
@@ -1 +0,0 @@
1
- 251b43c4d9cac5fbae87a75c015c577257212beb1c9a0ab294981f8d12310019
@@ -1 +0,0 @@
1
- 08cc04feb00bd8b233b990b7127b42af544865adf28b2cb57601c791d313672f0dbe20c5673d393395edeb970d8d11127c7eb098add143b13b044a62999d60a9
@@ -1 +0,0 @@
1
- ebd8dbf8bb38883b6988fd82932ce0a09f287e13501ec31d80677abe8c077589
@@ -1 +0,0 @@
1
- 35852565ad133c30234f00c3e518761068bf749a47e7c600e768b6b9756e76ed5fe40bfb139d5cdce27f30b9b76792c8cc2218f7086b39e68ac4658609eb75a5
@@ -1 +0,0 @@
1
- 52342d1b0d1fae681b2ea1e6f9ac6f6278299ed70d7867fd60b95d63eb7a9ec3
@@ -1 +0,0 @@
1
- 5dfa73d84d647fd870a2e915d9943c9502c967abfd89a834ef7dee50a2a77d5a8b0be7b13407a34a6b97cbc10e9ed6f5e608fe7366d5a3041e462e3322d5b10d
@@ -1 +0,0 @@
1
- 76bdd7d38a6da78a81a590e378879fcb0f66c432af1bd280e0fdb60b37da7d79