detox 20.0.3-breaking.new-global-lifecycle.0 → 20.0.6-breaking.new-global-lifecycle.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (118) hide show
  1. package/Detox-android/com/wix/detox/{20.0.3-breaking.new-global-lifecycle.0/detox-20.0.3-breaking.new-global-lifecycle.0-javadoc.jar → 20.0.6-breaking.new-global-lifecycle.0/detox-20.0.6-breaking.new-global-lifecycle.0-javadoc.jar} +0 -0
  2. package/Detox-android/com/wix/detox/20.0.6-breaking.new-global-lifecycle.0/detox-20.0.6-breaking.new-global-lifecycle.0-javadoc.jar.md5 +1 -0
  3. package/Detox-android/com/wix/detox/20.0.6-breaking.new-global-lifecycle.0/detox-20.0.6-breaking.new-global-lifecycle.0-javadoc.jar.sha1 +1 -0
  4. package/Detox-android/com/wix/detox/20.0.6-breaking.new-global-lifecycle.0/detox-20.0.6-breaking.new-global-lifecycle.0-javadoc.jar.sha256 +1 -0
  5. package/Detox-android/com/wix/detox/20.0.6-breaking.new-global-lifecycle.0/detox-20.0.6-breaking.new-global-lifecycle.0-javadoc.jar.sha512 +1 -0
  6. package/Detox-android/com/wix/detox/{20.0.3-breaking.new-global-lifecycle.0/detox-20.0.3-breaking.new-global-lifecycle.0-sources.jar → 20.0.6-breaking.new-global-lifecycle.0/detox-20.0.6-breaking.new-global-lifecycle.0-sources.jar} +0 -0
  7. package/Detox-android/com/wix/detox/20.0.6-breaking.new-global-lifecycle.0/detox-20.0.6-breaking.new-global-lifecycle.0-sources.jar.md5 +1 -0
  8. package/Detox-android/com/wix/detox/20.0.6-breaking.new-global-lifecycle.0/detox-20.0.6-breaking.new-global-lifecycle.0-sources.jar.sha1 +1 -0
  9. package/Detox-android/com/wix/detox/20.0.6-breaking.new-global-lifecycle.0/detox-20.0.6-breaking.new-global-lifecycle.0-sources.jar.sha256 +1 -0
  10. package/Detox-android/com/wix/detox/20.0.6-breaking.new-global-lifecycle.0/detox-20.0.6-breaking.new-global-lifecycle.0-sources.jar.sha512 +1 -0
  11. package/Detox-android/com/wix/detox/{20.0.3-breaking.new-global-lifecycle.0/detox-20.0.3-breaking.new-global-lifecycle.0.aar → 20.0.6-breaking.new-global-lifecycle.0/detox-20.0.6-breaking.new-global-lifecycle.0.aar} +0 -0
  12. package/Detox-android/com/wix/detox/{20.0.3-breaking.new-global-lifecycle.0/detox-20.0.3-breaking.new-global-lifecycle.0.aar.md5 → 20.0.6-breaking.new-global-lifecycle.0/detox-20.0.6-breaking.new-global-lifecycle.0.aar.md5} +0 -0
  13. package/Detox-android/com/wix/detox/{20.0.3-breaking.new-global-lifecycle.0/detox-20.0.3-breaking.new-global-lifecycle.0.aar.sha1 → 20.0.6-breaking.new-global-lifecycle.0/detox-20.0.6-breaking.new-global-lifecycle.0.aar.sha1} +0 -0
  14. package/Detox-android/com/wix/detox/{20.0.3-breaking.new-global-lifecycle.0/detox-20.0.3-breaking.new-global-lifecycle.0.aar.sha256 → 20.0.6-breaking.new-global-lifecycle.0/detox-20.0.6-breaking.new-global-lifecycle.0.aar.sha256} +0 -0
  15. package/Detox-android/com/wix/detox/{20.0.3-breaking.new-global-lifecycle.0/detox-20.0.3-breaking.new-global-lifecycle.0.aar.sha512 → 20.0.6-breaking.new-global-lifecycle.0/detox-20.0.6-breaking.new-global-lifecycle.0.aar.sha512} +0 -0
  16. package/Detox-android/com/wix/detox/{20.0.3-breaking.new-global-lifecycle.0/detox-20.0.3-breaking.new-global-lifecycle.0.pom → 20.0.6-breaking.new-global-lifecycle.0/detox-20.0.6-breaking.new-global-lifecycle.0.pom} +1 -1
  17. package/Detox-android/com/wix/detox/20.0.6-breaking.new-global-lifecycle.0/detox-20.0.6-breaking.new-global-lifecycle.0.pom.md5 +1 -0
  18. package/Detox-android/com/wix/detox/20.0.6-breaking.new-global-lifecycle.0/detox-20.0.6-breaking.new-global-lifecycle.0.pom.sha1 +1 -0
  19. package/Detox-android/com/wix/detox/20.0.6-breaking.new-global-lifecycle.0/detox-20.0.6-breaking.new-global-lifecycle.0.pom.sha256 +1 -0
  20. package/Detox-android/com/wix/detox/20.0.6-breaking.new-global-lifecycle.0/detox-20.0.6-breaking.new-global-lifecycle.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/index.d.ts +49 -40
  29. package/internals.d.ts +63 -15
  30. package/local-cli/cli.js +1 -1
  31. package/local-cli/rebuild-framework-cache.js +1 -1
  32. package/local-cli/test.js +3 -2
  33. package/local-cli/test.test.js +1 -1
  34. package/local-cli/testCommand/TestRunnerCommand.js +10 -7
  35. package/package.json +5 -4
  36. package/runners/jest/globalSetup.js +1 -1
  37. package/runners/jest/globalTeardown.js +1 -1
  38. package/runners/jest/testEnvironment/index.js +33 -16
  39. package/runners/jest/testEnvironment/listeners/DetoxCoreListener.js +76 -41
  40. package/runners/jest/testEnvironment/listeners/SpecReporter.js +1 -1
  41. package/runners/jest/testEnvironment/listeners/WorkerAssignReporter.js +1 -1
  42. package/src/DetoxWorker.js +4 -1
  43. package/src/artifacts/ArtifactsManager.js +8 -23
  44. package/src/artifacts/instruments/ios/SimulatorInstrumentsRecording.js +3 -3
  45. package/src/artifacts/log/ios/SimulatorLogRecording.js +1 -1
  46. package/src/artifacts/screenshot/SimulatorScreenshotPlugin.js +1 -1
  47. package/src/artifacts/templates/artifact/Artifact.js +1 -1
  48. package/src/artifacts/templates/plugin/ArtifactPlugin.js +1 -1
  49. package/src/artifacts/utils/temporaryPath.js +18 -7
  50. package/src/artifacts/video/SimulatorRecordVideoPlugin.js +1 -1
  51. package/src/client/AsyncWebSocket.js +8 -17
  52. package/src/client/Client.js +1 -1
  53. package/src/configuration/collectCliConfig.js +1 -1
  54. package/src/configuration/composeDeviceConfig.js +1 -1
  55. package/src/configuration/composeLoggerConfig.js +17 -8
  56. package/src/configuration/composeRunnerConfig.js +1 -1
  57. package/src/configuration/index.js +5 -1
  58. package/src/configuration/loadExternalConfig.js +1 -1
  59. package/src/devices/allocation/DeviceAllocator.js +3 -2
  60. package/src/devices/allocation/drivers/android/emulator/AVDValidator.js +1 -1
  61. package/src/devices/allocation/drivers/android/emulator/EmulatorAllocDriver.js +3 -2
  62. package/src/devices/allocation/drivers/android/emulator/EmulatorAllocationHelper.js +1 -1
  63. package/src/devices/allocation/drivers/android/emulator/EmulatorLauncher.js +3 -2
  64. package/src/devices/allocation/drivers/android/emulator/EmulatorVersionResolver.js +4 -6
  65. package/src/devices/allocation/drivers/android/emulator/launchEmulatorProcess.js +1 -1
  66. package/src/devices/allocation/drivers/android/genycloud/GenyInstanceAllocationHelper.js +1 -1
  67. package/src/devices/common/drivers/android/genycloud/services/GenyInstanceNaming.js +3 -3
  68. package/src/devices/common/drivers/android/genycloud/services/GenyRecipesService.js +1 -1
  69. package/src/devices/common/drivers/android/tools/EmulatorTelnet.js +1 -1
  70. package/src/devices/common/drivers/android/tools/FreeDeviceFinder.js +1 -1
  71. package/src/devices/common/drivers/ios/tools/AppleSimUtils.js +1 -1
  72. package/src/devices/lifecycle/GenyGlobalLifecycleHandler.js +9 -13
  73. package/src/devices/runtime/RuntimeDevice.js +7 -8
  74. package/src/devices/runtime/drivers/DeviceDriverBase.js +1 -1
  75. package/src/devices/runtime/drivers/android/AndroidDriver.js +1 -1
  76. package/src/devices/runtime/drivers/ios/SimulatorDriver.js +1 -1
  77. package/src/ipc/IPCClient.js +3 -8
  78. package/src/ipc/IPCServer.js +11 -11
  79. package/src/ipc/{state.js → SessionState.js} +23 -50
  80. package/src/logger/DetoxLogger.js +264 -155
  81. package/src/logger/index.js +4 -0
  82. package/src/logger/utils/BunyanLogger.js +72 -0
  83. package/src/logger/utils/CategoryThreadDispatcher.js +58 -0
  84. package/src/logger/utils/MessageStack.js +24 -0
  85. package/src/logger/{TraceThreadDispatcher.js → utils/ThreadDispatcher.js} +34 -5
  86. package/src/logger/{customConsoleLogger.js → utils/customConsoleLogger.js} +4 -4
  87. package/src/logger/utils/sanitizeBunyanContext.js +28 -0
  88. package/src/logger/utils/tracerLegacy.js +25 -0
  89. package/src/realms/DetoxContext.js +65 -57
  90. package/src/realms/DetoxInternalsFacade.js +7 -5
  91. package/src/realms/DetoxPrimaryContext.js +125 -40
  92. package/src/realms/DetoxSecondaryContext.js +31 -30
  93. package/src/server/DetoxConnection.js +18 -23
  94. package/src/server/DetoxServer.js +7 -10
  95. package/src/server/DetoxSession.js +6 -6
  96. package/src/server/DetoxSessionManager.js +1 -1
  97. package/src/server/handlers/RegisteredConnectionHandler.js +1 -2
  98. package/src/symbols.js +12 -8
  99. package/src/utils/childProcess/exec.js +1 -1
  100. package/src/utils/childProcess/spawn.js +1 -1
  101. package/src/utils/streamUtils.js +10 -11
  102. package/src/utils/trace.js +2 -18
  103. package/src/utils/traceMethods.js +15 -0
  104. package/Detox-android/com/wix/detox/20.0.3-breaking.new-global-lifecycle.0/detox-20.0.3-breaking.new-global-lifecycle.0-javadoc.jar.md5 +0 -1
  105. package/Detox-android/com/wix/detox/20.0.3-breaking.new-global-lifecycle.0/detox-20.0.3-breaking.new-global-lifecycle.0-javadoc.jar.sha1 +0 -1
  106. package/Detox-android/com/wix/detox/20.0.3-breaking.new-global-lifecycle.0/detox-20.0.3-breaking.new-global-lifecycle.0-javadoc.jar.sha256 +0 -1
  107. package/Detox-android/com/wix/detox/20.0.3-breaking.new-global-lifecycle.0/detox-20.0.3-breaking.new-global-lifecycle.0-javadoc.jar.sha512 +0 -1
  108. package/Detox-android/com/wix/detox/20.0.3-breaking.new-global-lifecycle.0/detox-20.0.3-breaking.new-global-lifecycle.0-sources.jar.md5 +0 -1
  109. package/Detox-android/com/wix/detox/20.0.3-breaking.new-global-lifecycle.0/detox-20.0.3-breaking.new-global-lifecycle.0-sources.jar.sha1 +0 -1
  110. package/Detox-android/com/wix/detox/20.0.3-breaking.new-global-lifecycle.0/detox-20.0.3-breaking.new-global-lifecycle.0-sources.jar.sha256 +0 -1
  111. package/Detox-android/com/wix/detox/20.0.3-breaking.new-global-lifecycle.0/detox-20.0.3-breaking.new-global-lifecycle.0-sources.jar.sha512 +0 -1
  112. package/Detox-android/com/wix/detox/20.0.3-breaking.new-global-lifecycle.0/detox-20.0.3-breaking.new-global-lifecycle.0.pom.md5 +0 -1
  113. package/Detox-android/com/wix/detox/20.0.3-breaking.new-global-lifecycle.0/detox-20.0.3-breaking.new-global-lifecycle.0.pom.sha1 +0 -1
  114. package/Detox-android/com/wix/detox/20.0.3-breaking.new-global-lifecycle.0/detox-20.0.3-breaking.new-global-lifecycle.0.pom.sha256 +0 -1
  115. package/Detox-android/com/wix/detox/20.0.3-breaking.new-global-lifecycle.0/detox-20.0.3-breaking.new-global-lifecycle.0.pom.sha512 +0 -1
  116. package/src/logger/DetoxTraceEventBuilder.js +0 -21
  117. package/src/logger/DetoxTracer.js +0 -133
  118. package/src/utils/ChromeTracingExporter.js +0 -54
@@ -7,6 +7,8 @@ const { getFullTestName, hasTimedOut } = require('../utils');
7
7
 
8
8
  const RETRY_TIMES = Symbol.for('RETRY_TIMES');
9
9
 
10
+ const log = detoxInternals.log.child({ cat: 'lifecycle,jest-environment' });
11
+
10
12
  class DetoxCoreListener {
11
13
  constructor({ env }) {
12
14
  this._startedTests = new WeakSet();
@@ -15,11 +17,6 @@ class DetoxCoreListener {
15
17
  this._testRunTimes = 1;
16
18
  }
17
19
 
18
- _getTestInvocations(test) {
19
- const { testSessionIndex } = detoxInternals.session;
20
- return testSessionIndex * this._testRunTimes + test.invocations;
21
- }
22
-
23
20
  async setup() {
24
21
  // Workaround to override Jest's expect
25
22
  if (detoxInternals.config.behavior.init.exposeGlobals) {
@@ -27,15 +24,19 @@ class DetoxCoreListener {
27
24
  }
28
25
  }
29
26
 
30
- async run_describe_start({ describeBlock: { name, children } }) {
31
- if (children.length) {
32
- await detoxInternals.onRunDescribeStart({ name });
27
+ async run_describe_start({ describeBlock }) {
28
+ if (describeBlock.children.length) {
29
+ log.trace.begin(describeBlock.parent ? describeBlock.name : 'run the tests');
30
+ await detoxInternals.onRunDescribeStart({
31
+ name: describeBlock.name,
32
+ });
33
33
  }
34
34
  }
35
35
 
36
- async run_describe_finish({ describeBlock: { name, children } }) {
37
- if (children.length) {
38
- await detoxInternals.onRunDescribeFinish({ name });
36
+ async run_describe_finish({ describeBlock }) {
37
+ if (describeBlock.children.length) {
38
+ await detoxInternals.onRunDescribeFinish({ name: describeBlock.name });
39
+ log.trace.end();
39
40
  }
40
41
  }
41
42
 
@@ -48,61 +49,87 @@ class DetoxCoreListener {
48
49
  this._testRunTimes = isNaN(circusRetryTimes) ? 1 : 1 + circusRetryTimes;
49
50
  }
50
51
 
51
- async hook_start(_event, state) {
52
+ async hook_start(event, state) {
52
53
  await this._onBeforeActualTestStart(state.currentlyRunningTest);
54
+ log.trace.begin({ functionCode: event.hook.fn.toString() }, event.hook.type);
55
+ }
56
+
57
+ async hook_success() {
58
+ log.trace.end({ success: true });
53
59
  }
54
60
 
55
- async hook_failure({ error, hook }) {
56
- await detoxInternals.onHookFailure({
57
- error,
58
- hook: hook.type,
59
- });
61
+ async hook_failure({ error }) {
62
+ log.trace.end({ success: false, error });
60
63
  }
61
64
 
62
65
  async test_fn_start({ test }) {
63
66
  await this._onBeforeActualTestStart(test);
67
+ log.trace.begin({ functionCode: test.fn.toString() }, 'test_fn');
64
68
  }
65
69
 
66
- async test_fn_failure({ error }) {
67
- await detoxInternals.onTestFnFailure({ error });
70
+ async test_fn_success() {
71
+ log.trace.end({ success: true });
68
72
  }
69
73
 
70
- async _onBeforeActualTestStart(test) {
71
- if (!test || test.status === 'skip' || this._startedTests.has(test) || this._testsFailedBeforeStart.has(test)) {
72
- return;
73
- }
74
-
75
- this._startedTests.add(test);
76
-
77
- await detoxInternals.onTestStart({
78
- title: test.name,
79
- fullName: getFullTestName(test),
80
- status: 'running',
81
- invocations: this._getTestInvocations(test),
82
- });
74
+ async test_fn_failure({ error }) {
75
+ await detoxInternals.onTestFnFailure({ error });
76
+ log.trace.end({ success: false, error });
83
77
  }
84
78
 
85
79
  async test_done({ test }) {
86
80
  if (this._startedTests.has(test)) {
87
- await detoxInternals.onTestDone({
88
- title: test.name,
89
- fullName: getFullTestName(test),
90
- status: test.errors.length ? 'failed' : 'passed',
91
- invocations: this._getTestInvocations(test),
92
- timedOut: hasTimedOut(test)
93
- });
94
-
81
+ const failed = test.errors.length > 0;
82
+ const metadata = {
83
+ ...this._getTestMetadata(test),
84
+ status: failed ? 'failed' : 'passed',
85
+ timedOut: failed ? hasTimedOut(test) : undefined,
86
+ };
87
+
88
+ await detoxInternals.onTestDone(metadata);
95
89
  this._startedTests.delete(test);
90
+ log.trace.end({
91
+ status: metadata.status,
92
+ timedOut: metadata.timedOut,
93
+ });
96
94
  }
97
95
  }
98
96
 
99
97
  async run_finish(_event, state) {
100
- if (this._hasFailedTests(state.rootDescribeBlock)) {
98
+ const hasFailedTests = this._hasFailedTests(state.rootDescribeBlock);
99
+ if (hasFailedTests) {
101
100
  const handledByJestCircus = this._testRunTimes > 1 && !detoxInternals.config.testRunner.jest.retryAfterCircusRetries;
102
101
  await detoxInternals.reportFailedTests([this._env.testPath], handledByJestCircus);
103
102
  }
104
103
  }
105
104
 
105
+ async _onBeforeActualTestStart(test) {
106
+ if (!test || test.status === 'skip' || this._startedTests.has(test) || this._testsFailedBeforeStart.has(test)) {
107
+ return false;
108
+ }
109
+
110
+ const metadata = {
111
+ ...this._getTestMetadata(test),
112
+ status: 'running',
113
+ };
114
+
115
+ this._startedTests.add(test);
116
+
117
+ log.trace.begin({
118
+ context: 'test',
119
+ status: metadata.status,
120
+ fullName: metadata.fullName,
121
+ invocations: metadata.invocations,
122
+ }, metadata.title);
123
+
124
+ await detoxInternals.onTestStart(metadata);
125
+ return true;
126
+ }
127
+
128
+ _getTestInvocations(test) {
129
+ const { testSessionIndex } = detoxInternals.session;
130
+ return testSessionIndex * this._testRunTimes + test.invocations;
131
+ }
132
+
106
133
  _hasFailedTests(block) {
107
134
  if (block.children) {
108
135
  for (const child of block.children) {
@@ -114,6 +141,14 @@ class DetoxCoreListener {
114
141
 
115
142
  return block.errors ? block.errors.length > 0 : false;
116
143
  }
144
+
145
+ _getTestMetadata(test) {
146
+ return {
147
+ title: test.name,
148
+ fullName: getFullTestName(test),
149
+ invocations: this._getTestInvocations(test),
150
+ };
151
+ }
117
152
  }
118
153
 
119
154
  module.exports = DetoxCoreListener;
@@ -118,7 +118,7 @@ class SpecReporter {
118
118
  const retriesDescription = (invocations > 1) ? chalk.gray(` [Retry #${invocations - 1}]`) : '';
119
119
  const status = chalk.gray(_status ? ` [${_status}]` : '');
120
120
  const desc = this._suitesDesc + testDescription + retriesDescription + status;
121
- log.info({ event: 'SPEC_STATE_CHANGE' }, desc);
121
+ log.info({ cat: 'lifecycle' }, desc);
122
122
  }
123
123
  }
124
124
 
@@ -13,7 +13,7 @@ class WorkerAssignReporter {
13
13
 
14
14
  run_start() {
15
15
  if (config.testRunner.jest.reportWorkerAssign) {
16
- log.info({ event: 'WORKER_ASSIGN' }, `${this._formatTestName()} is assigned to ${this._formatDeviceName()}`);
16
+ log.info({ cat: 'lifecycle' }, `${this._formatTestName()} is assigned to ${this._formatDeviceName()}`);
17
17
  }
18
18
  }
19
19
 
@@ -32,6 +32,8 @@ class DetoxWorker {
32
32
  onError: this._onEmitError.bind(this),
33
33
  });
34
34
 
35
+ /** @type {string} */
36
+ this.id = 'worker';
35
37
  /** @type {Detox.Device} */
36
38
  this.device = null;
37
39
  /** @type {Detox.ElementFacade} */
@@ -63,14 +65,15 @@ class DetoxWorker {
63
65
  device: deviceConfig,
64
66
  session: sessionConfig
65
67
  } = this._config;
68
+
66
69
  this._appsConfig = appsConfig;
67
70
  this._artifactsConfig = artifactsConfig;
68
71
  this._behaviorConfig = behaviorConfig;
69
72
  this._deviceConfig = deviceConfig;
70
73
  this._sessionConfig = sessionConfig;
74
+ this._sessionConfig.sessionId = sessionConfig.sessionId || uuid.UUID();
71
75
  this._runtimeErrorComposer.appsConfig = this._appsConfig;
72
76
 
73
- sessionConfig.sessionId = sessionConfig.sessionId || uuid.UUID();
74
77
  this._client = new Client(sessionConfig);
75
78
  this._client.terminateApp = async () => {
76
79
  // @ts-ignore
@@ -1,14 +1,13 @@
1
1
  const EventEmitter = require('events');
2
2
  const path = require('path');
3
- const util = require('util');
4
3
 
5
4
  const fs = require('fs-extra');
6
5
  const _ = require('lodash');
7
6
 
8
7
  const DetoxRuntimeError = require('../errors/DetoxRuntimeError');
9
- const log = require('../utils/logger').child({ __filename });
8
+ const log = require('../utils/logger').child({ cat: 'artifacts-manager,artifact' });
10
9
  const resolveModuleFromPath = require('../utils/resolveModuleFromPath');
11
- const { traceMethods } = require('../utils/trace');
10
+ const traceMethods = require('../utils/traceMethods');
12
11
 
13
12
  const FileArtifact = require('./templates/artifact/FileArtifact');
14
13
  const ArtifactPathBuilder = require('./utils/ArtifactPathBuilder');
@@ -23,7 +22,7 @@ class ArtifactsManager extends EventEmitter {
23
22
  this._artifactPlugins = {};
24
23
  this._pathBuilder = this._resolveArtifactsPathBuilder(pathBuilder, rootDir);
25
24
 
26
- traceMethods(this, 'artifacts-manager,artifacts', [
25
+ traceMethods(log, this, [
27
26
  'onAppReady',
28
27
  'onBeforeCleanup',
29
28
  'onBeforeLaunchApp',
@@ -228,27 +227,21 @@ class ArtifactsManager extends EventEmitter {
228
227
  }
229
228
 
230
229
  async _callSinglePlugin(pluginId, methodName, ...args) {
231
- const callSignature = this._composeCallSignature('artifactsManager', methodName, args);
232
- log.trace(Object.assign({ event: 'ARTIFACTS_LIFECYCLE', fn: methodName }, ...args), callSignature);
233
-
234
230
  const plugin = this._artifactPlugins[pluginId];
235
231
  try {
236
232
  await plugin[methodName](...args);
237
233
  } catch (e) {
238
- this._unhandledPluginExceptionHandler(e, { plugin, methodName, args });
234
+ this._unhandledPluginExceptionHandler(e, { plugin, methodName });
239
235
  }
240
236
  }
241
237
 
242
238
  async _callPlugins(strategy, methodName, ...args) {
243
- const callSignature = this._composeCallSignature('artifactsManager', methodName, args);
244
- log.trace(Object.assign({ event: 'ARTIFACTS_LIFECYCLE', fn: methodName }, ...args), callSignature);
245
-
246
239
  for (const pluginGroup of this._groupPlugins(strategy)) {
247
240
  await Promise.all(pluginGroup.map(async (plugin) => {
248
241
  try {
249
242
  await plugin[methodName](...args);
250
243
  } catch (e) {
251
- this._unhandledPluginExceptionHandler(e, { plugin, methodName, args });
244
+ this._unhandledPluginExceptionHandler(e, { plugin, methodName });
252
245
  }
253
246
  }));
254
247
  }
@@ -278,28 +271,20 @@ class ArtifactsManager extends EventEmitter {
278
271
  }
279
272
  }
280
273
 
281
- _composeCallSignature(object, methodName, args) {
282
- const argsString = args.map(arg => util.inspect(arg)).join(', ');
283
- return `${object}.${methodName}(${argsString})`;
284
- }
285
-
286
- _unhandledPluginExceptionHandler(err, { plugin, methodName, args }) {
274
+ _unhandledPluginExceptionHandler(err, { plugin, methodName }) {
287
275
  const logObject = {
288
- event: 'ERROR',
289
276
  plugin: plugin.name,
290
- err,
291
277
  methodName,
278
+ err,
292
279
  };
293
280
 
294
- const callSignature = this._composeCallSignature(plugin.name, methodName, args);
295
- log.warn(logObject, `Suppressed error inside function call: ${callSignature}`);
281
+ log.warn(logObject, `Suppressed error inside function call.`);
296
282
  }
297
283
 
298
284
  _idleCallbackErrorHandle(err, caller) {
299
285
  this._unhandledPluginExceptionHandler(err, {
300
286
  plugin: caller,
301
287
  methodName: 'onIdleCallback',
302
- args: []
303
288
  });
304
289
  }
305
290
  }
@@ -2,7 +2,7 @@
2
2
  const fs = require('fs-extra');
3
3
  const _ = require('lodash');
4
4
 
5
- const log = require('../../../utils/logger').child({ __filename });
5
+ const log = require('../../../utils/logger').child({ cat: 'artifact' });
6
6
  const FileArtifact = require('../../templates/artifact/FileArtifact');
7
7
  const InstrumentsArtifactRecording = require('../InstrumentsArtifactRecording');
8
8
 
@@ -37,9 +37,9 @@ class SimulatorInstrumentsRecording extends InstrumentsArtifactRecording {
37
37
  SimulatorInstrumentsRecording.hintAboutDetoxInstruments = _.once(() => {
38
38
  log.warn(`Make sure either:
39
39
  1. You have installed Detox Instruments:
40
- https://github.com/wix/DetoxInstruments#installation
40
+ https://github.com/wix/DetoxInstruments#installation
41
41
  2. You have integrated Detox Instruments in your app:
42
- https://github.com/wix/DetoxInstruments/blob/master/Documentation/XcodeIntegrationGuide.md
42
+ https://github.com/wix/DetoxInstruments/blob/master/Documentation/XcodeIntegrationGuide.md
43
43
  3. You have set the environment variable with your custom Detox Instruments location:
44
44
  export DETOX_INSTRUMENTS_PATH="/path/to/Detox Instruments.app"`);
45
45
  });
@@ -2,7 +2,7 @@
2
2
  const fs = require('fs-extra');
3
3
 
4
4
  const childProcess = require('../../../utils/childProcess');
5
- const log = require('../../../utils/logger').child({ __filename });
5
+ const log = require('../../../utils/logger').child({ cat: 'artifact' });
6
6
  const sleep = require('../../../utils/sleep');
7
7
  const Artifact = require('../../templates/artifact/Artifact');
8
8
  const FileArtifact = require('../../templates/artifact/FileArtifact');
@@ -1,7 +1,7 @@
1
1
  const path = require('path');
2
2
 
3
3
  const fs = require('../../utils/fsext');
4
- const log = require('../../utils/logger').child({ __filename });
4
+ const log = require('../../utils/logger').child({ cat: 'artifacts-plugin,artifacts' });
5
5
  const FileArtifact = require('../templates/artifact/FileArtifact');
6
6
  const temporaryPath = require('../utils/temporaryPath');
7
7
 
@@ -1,5 +1,5 @@
1
1
  // @ts-nocheck
2
- const log = require('../../../utils/logger').child({ __filename });
2
+ const log = require('../../../utils/logger').child({ cat: 'artifact' });
3
3
 
4
4
  class Artifact {
5
5
  constructor(template) {
@@ -3,7 +3,7 @@
3
3
 
4
4
  const _ = require('lodash');
5
5
 
6
- const log = require('../../../utils/logger').child({ __filename });
6
+ const log = require('../../../utils/logger').child({ cat: 'artifacts-plugin,artifacts' });
7
7
 
8
8
  /***
9
9
  * Almost non-opinionated building block for any artifact type
@@ -2,15 +2,26 @@ const path = require('path');
2
2
 
3
3
  const tempfile = require('tempfile');
4
4
 
5
+ function createTempFileBuilderFn(fileExtension) {
6
+ /**
7
+ * @param {string} [basename]
8
+ */
9
+ return (basename) => {
10
+ return basename
11
+ ? path.join(path.dirname(tempfile()), `${basename}.detox.${fileExtension}`)
12
+ : tempfile(`.detox.${fileExtension}`);
13
+ };
14
+ }
15
+
5
16
  module.exports = {
6
17
  for: {
7
- json: () => tempfile('.detox.json'),
8
- jsonl: () => tempfile('.detox.jsonl'),
9
- png: () => tempfile('.detox.png'),
10
- log: () => tempfile('.detox.log'),
11
- mp4: () => tempfile('.detox.mp4'),
12
- dtxrec: () => tempfile('.detox.dtxrec'),
13
- viewhierarchy: () => tempfile('.detox.viewhierarchy'),
18
+ json: createTempFileBuilderFn('json'),
19
+ jsonl: createTempFileBuilderFn('jsonl'),
20
+ png: createTempFileBuilderFn('png'),
21
+ log: createTempFileBuilderFn('log'),
22
+ mp4: createTempFileBuilderFn('mp4'),
23
+ dtxrec: createTempFileBuilderFn('dtxrec'),
24
+ viewhierarchy: createTempFileBuilderFn('viewhierarchy'),
14
25
  },
15
26
  mask: () => path.join(tempfile(), '..') + path.sep + '*.detox.*',
16
27
  };
@@ -1,7 +1,7 @@
1
1
  const fs = require('fs-extra');
2
2
 
3
3
  const { interruptProcess } = require('../../utils/childProcess');
4
- const log = require('../../utils/logger').child({ __filename });
4
+ const log = require('../../utils/logger').child({ cat: 'artifacts-plugin,artifact' });
5
5
  const Artifact = require('../templates/artifact/Artifact');
6
6
  const FileArtifact = require('../templates/artifact/FileArtifact');
7
7
  const temporaryPath = require('../utils/temporaryPath');
@@ -5,25 +5,16 @@ const WebSocket = require('ws');
5
5
  const DetoxInternalError = require('../errors/DetoxInternalError');
6
6
  const DetoxRuntimeError = require('../errors/DetoxRuntimeError');
7
7
  const Deferred = require('../utils/Deferred');
8
- const log = require('../utils/logger').child({ __filename, cat: 'ws-client,ws' });
8
+ const log = require('../utils/logger').child({ cat: 'ws-client,ws' });
9
9
 
10
10
  const InflightRequest = require('./InflightRequest');
11
11
 
12
- const EVENTS = {
13
- OPEN: Object.freeze({ event: 'WS_OPEN' }),
14
- ERROR: Object.freeze({ event: 'WS_ERROR' }),
15
- MESSAGE: Object.freeze({ event: 'WS_MESSAGE' }),
16
- SEND: Object.freeze({ event: 'WS_SEND' }),
17
- LATE_RESPONSE: Object.freeze({ event: 'WS_LATE_RESPONSE' }),
18
- };
19
-
20
12
  const DEFAULT_SEND_OPTIONS = {
21
13
  timeout: 0,
22
14
  };
23
15
 
24
16
  class AsyncWebSocket {
25
17
  constructor(url) {
26
- this._log = log.child({ url });
27
18
  this._url = url;
28
19
  this._ws = null;
29
20
  this._eventCallbacks = {};
@@ -99,9 +90,9 @@ class AsyncWebSocket {
99
90
 
100
91
  this.handleMultipleNonAtomicPendingActions();
101
92
 
102
- const messageAsString = JSON.stringify(message);
103
- this._log.trace(EVENTS.SEND, messageAsString);
104
- this._ws.send(messageAsString);
93
+ const payload = JSON.stringify(message);
94
+ log.trace({ data: payload }, 'send message');
95
+ this._ws.send(payload);
105
96
 
106
97
  return inFlight.promise;
107
98
  }
@@ -157,7 +148,7 @@ class AsyncWebSocket {
157
148
  }
158
149
 
159
150
  if (!hasPendingActions) {
160
- log.error(EVENTS.ERROR, DetoxRuntimeError.format(error));
151
+ log.error({ error });
161
152
  }
162
153
  }
163
154
 
@@ -186,7 +177,7 @@ class AsyncWebSocket {
186
177
  * @private
187
178
  */
188
179
  _onOpen(event) { // eslint-disable-line no-unused-vars
189
- this._log.trace(EVENTS.OPEN, `opened web socket to: ${this._url}`);
180
+ log.trace(`opened web socket to: ${this._url}`);
190
181
  this._opening.resolve();
191
182
  this._opening = null;
192
183
  }
@@ -234,7 +225,7 @@ class AsyncWebSocket {
234
225
  const data = event && event.data || null;
235
226
 
236
227
  try {
237
- this._log.trace(EVENTS.MESSAGE, data);
228
+ log.trace({ data }, 'get message');
238
229
 
239
230
  const json = JSON.parse(data);
240
231
  if (!json || !json.type) {
@@ -259,7 +250,7 @@ class AsyncWebSocket {
259
250
 
260
251
  if (!handled) {
261
252
  if (this._abortedMessageIds.has(json.messageId)) {
262
- log.debug(EVENTS.LATE_RESPONSE, `Received late response for messageId=${json.messageId}`);
253
+ log.debug({ messageId: json.messageId }, `late response`);
263
254
  } else {
264
255
  throw new DetoxRuntimeError('Unexpected message received over the web socket: ' + json.type);
265
256
  }
@@ -9,7 +9,7 @@ const DetoxRuntimeError = require('../errors/DetoxRuntimeError');
9
9
  const failedToReachTheApp = require('../errors/longreads/failedToReachTheApp');
10
10
  const Deferred = require('../utils/Deferred');
11
11
  const { asError, createErrorWithUserStack, replaceErrorStack } = require('../utils/errorUtils');
12
- const log = require('../utils/logger').child({ __filename });
12
+ const log = require('../utils/logger').child({ cat: 'ws-client,ws' });
13
13
 
14
14
  const AsyncWebSocket = require('./AsyncWebSocket');
15
15
  const actions = require('./actions/actions');
@@ -1,7 +1,7 @@
1
1
  const _ = require('lodash');
2
2
 
3
3
  const argparse = require('../utils/argparse');
4
- const log = require('../utils/logger').child({ __filename });
4
+ const log = require('../utils/logger').child({ cat: 'config' });
5
5
 
6
6
  const { DEVICE_LAUNCH_ARGS_GENERIC_DEPRECATION } = require('./utils/warnings');
7
7
 
@@ -2,7 +2,7 @@
2
2
  const _ = require('lodash');
3
3
 
4
4
  const environmentFactory = require('../environmentFactory');
5
- const log = require('../utils/logger').child({ __filename });
5
+ const log = require('../utils/logger').child({ cat: 'config' });
6
6
 
7
7
  /**
8
8
  * @param {DetoxConfigErrorComposer} opts.errorComposer
@@ -7,25 +7,34 @@ const { castLevel, defaultOptions } = require('../logger/DetoxLogger');
7
7
  * @param {Detox.DetoxConfig} opts.globalConfig
8
8
  * @param {Detox.DetoxConfiguration} opts.localConfig
9
9
  * @param {*} opts.cliConfig
10
- * @returns {Detox.DetoxLoggerConfig}
11
10
  */
12
11
  function composeLoggerConfig(opts) {
13
12
  const { globalConfig, localConfig, cliConfig } = opts;
14
13
 
15
- return _.merge(
14
+ const items = [
16
15
  {
17
16
  level: 'info',
18
17
  overrideConsole: 'sandbox',
19
- options: {
20
- ...defaultOptions,
21
- prefixers: {
22
- ...defaultOptions.prefixers,
23
- },
24
- },
18
+ options: defaultOptions,
25
19
  },
26
20
  globalConfig.logger,
27
21
  localConfig.logger,
28
22
  adaptCLI(cliConfig),
23
+ ];
24
+
25
+ return items.reduce(
26
+ /**
27
+ * @param {Partial<Detox.DetoxLoggerConfig>} acc
28
+ * @param config
29
+ */
30
+ (acc, config) => {
31
+ if (!config) return acc;
32
+ const { options } = config;
33
+ return _.merge(acc, {
34
+ options: typeof options === 'function' ? options(acc) : options
35
+ });
36
+ },
37
+ items.reduce((a, b) => _.merge(a, _.omit(b, 'options')))
29
38
  );
30
39
  }
31
40
 
@@ -8,7 +8,7 @@ const log = require('../utils/logger');
8
8
  * @param {object} opts
9
9
  * @param {Detox.DetoxConfig} opts.globalConfig
10
10
  * @param {Detox.DetoxConfiguration} opts.localConfig
11
- * @param {DetoxInternals.DetoxCLIConfig} opts.cliConfig
11
+ * @param {DetoxInternals.CLIConfig} opts.cliConfig
12
12
  * @param {Record<string, any>} opts.testRunnerArgv
13
13
  * @param {import('../errors/DetoxConfigErrorComposer')} opts.errorComposer
14
14
  * @returns {Detox.DetoxTestRunnerConfig} opts.testRunnerArgv
@@ -106,7 +106,6 @@ async function composeDetoxConfig({
106
106
 
107
107
  const result = {
108
108
  configurationName,
109
- errorComposer,
110
109
 
111
110
  apps: appsConfig,
112
111
  artifacts: artifactsConfig,
@@ -118,6 +117,11 @@ async function composeDetoxConfig({
118
117
  session: sessionConfig,
119
118
  };
120
119
 
120
+ Object.defineProperty(result, 'errorComposer', {
121
+ enumerable: false,
122
+ value: errorComposer,
123
+ });
124
+
121
125
  return result;
122
126
  }
123
127
 
@@ -6,7 +6,7 @@ const fs = require('fs-extra');
6
6
  const _ = require('lodash');
7
7
  const resolveFrom = require('resolve-from');
8
8
 
9
- const log = require('../utils/logger').child({ __filename });
9
+ const log = require('../utils/logger').child({ cat: 'config' });
10
10
 
11
11
  async function locateExternalConfig(cwd) {
12
12
  return findUp([
@@ -1,5 +1,6 @@
1
1
  // @ts-nocheck
2
- const { traceMethods } = require('../../utils/trace');
2
+ const log = require('../../utils/logger').child({ cat: 'device' });
3
+ const traceMethods = require('../../utils/traceMethods');
3
4
 
4
5
  class DeviceAllocator {
5
6
  /**
@@ -7,7 +8,7 @@ class DeviceAllocator {
7
8
  */
8
9
  constructor(allocationDriver) {
9
10
  this._driver = allocationDriver;
10
- traceMethods(this, 'device', ['allocate', 'free']);
11
+ traceMethods(log, this, ['allocate', 'free']);
11
12
  }
12
13
 
13
14
  /**
@@ -2,7 +2,7 @@ const _ = require('lodash');
2
2
 
3
3
  const DetoxRuntimeError = require('../../../../../errors/DetoxRuntimeError');
4
4
  const environment = require('../../../../../utils/environment');
5
- const logger = require('../../../../../utils/logger').child({ __filename });
5
+ const logger = require('../../../../../utils/logger').child({ cat: 'device' });
6
6
 
7
7
  const REQUIRED_EMULATOR_MAJOR = 29;
8
8
 
@@ -1,7 +1,8 @@
1
1
  // @ts-nocheck
2
2
  const _ = require('lodash');
3
3
 
4
- const { traceMethods } = require('../../../../../utils/trace');
4
+ const log = require('../../../../../utils/logger').child({ cat: 'device' });
5
+ const traceMethods = require('../../../../../utils/traceMethods');
5
6
  const AndroidEmulatorCookie = require('../../../../cookies/AndroidEmulatorCookie');
6
7
  const AllocationDriverBase = require('../../AllocationDriverBase');
7
8
 
@@ -23,7 +24,7 @@ class EmulatorAllocDriver extends AllocationDriverBase {
23
24
  this._emulatorLauncher = emulatorLauncher;
24
25
  this._allocationHelper = allocationHelper;
25
26
 
26
- traceMethods(this, 'device', ['_launchEmulator']);
27
+ traceMethods(log, this, ['_launchEmulator']);
27
28
  }
28
29
 
29
30
  /**
@@ -1,4 +1,4 @@
1
- const logger = require('../../../../../utils/logger').child({ __filename });
1
+ const logger = require('../../../../../utils/logger').child({ cat: 'device' });
2
2
  const DeviceAllocationHelper = require('../../../../common/drivers/DeviceAllocationHelper');
3
3
 
4
4
  const DetoxEmulatorsPortRange = {