detox 20.0.14-next-is-hittable-check-2.0 → 20.0.15-prerelease.0
Sign up to get free protection for your applications and to get access to all the features.
- package/Detox-android/com/wix/detox/{20.0.14-next-is-hittable-check-2.0/detox-20.0.14-next-is-hittable-check-2.0-javadoc.jar → 20.0.15-prerelease.0/detox-20.0.15-prerelease.0-javadoc.jar} +0 -0
- package/Detox-android/com/wix/detox/20.0.15-prerelease.0/detox-20.0.15-prerelease.0-javadoc.jar.md5 +1 -0
- package/Detox-android/com/wix/detox/20.0.15-prerelease.0/detox-20.0.15-prerelease.0-javadoc.jar.sha1 +1 -0
- package/Detox-android/com/wix/detox/20.0.15-prerelease.0/detox-20.0.15-prerelease.0-javadoc.jar.sha256 +1 -0
- package/Detox-android/com/wix/detox/20.0.15-prerelease.0/detox-20.0.15-prerelease.0-javadoc.jar.sha512 +1 -0
- package/Detox-android/com/wix/detox/{20.0.14-next-is-hittable-check-2.0/detox-20.0.14-next-is-hittable-check-2.0-sources.jar → 20.0.15-prerelease.0/detox-20.0.15-prerelease.0-sources.jar} +0 -0
- package/Detox-android/com/wix/detox/20.0.15-prerelease.0/detox-20.0.15-prerelease.0-sources.jar.md5 +1 -0
- package/Detox-android/com/wix/detox/20.0.15-prerelease.0/detox-20.0.15-prerelease.0-sources.jar.sha1 +1 -0
- package/Detox-android/com/wix/detox/20.0.15-prerelease.0/detox-20.0.15-prerelease.0-sources.jar.sha256 +1 -0
- package/Detox-android/com/wix/detox/20.0.15-prerelease.0/detox-20.0.15-prerelease.0-sources.jar.sha512 +1 -0
- package/Detox-android/com/wix/detox/{20.0.14-next-is-hittable-check-2.0/detox-20.0.14-next-is-hittable-check-2.0.aar → 20.0.15-prerelease.0/detox-20.0.15-prerelease.0.aar} +0 -0
- package/Detox-android/com/wix/detox/{20.0.14-next-is-hittable-check-2.0/detox-20.0.14-next-is-hittable-check-2.0.aar.md5 → 20.0.15-prerelease.0/detox-20.0.15-prerelease.0.aar.md5} +0 -0
- package/Detox-android/com/wix/detox/{20.0.14-next-is-hittable-check-2.0/detox-20.0.14-next-is-hittable-check-2.0.aar.sha1 → 20.0.15-prerelease.0/detox-20.0.15-prerelease.0.aar.sha1} +0 -0
- package/Detox-android/com/wix/detox/{20.0.14-next-is-hittable-check-2.0/detox-20.0.14-next-is-hittable-check-2.0.aar.sha256 → 20.0.15-prerelease.0/detox-20.0.15-prerelease.0.aar.sha256} +0 -0
- package/Detox-android/com/wix/detox/{20.0.14-next-is-hittable-check-2.0/detox-20.0.14-next-is-hittable-check-2.0.aar.sha512 → 20.0.15-prerelease.0/detox-20.0.15-prerelease.0.aar.sha512} +0 -0
- package/Detox-android/com/wix/detox/{20.0.14-next-is-hittable-check-2.0/detox-20.0.14-next-is-hittable-check-2.0.pom → 20.0.15-prerelease.0/detox-20.0.15-prerelease.0.pom} +1 -1
- package/Detox-android/com/wix/detox/20.0.15-prerelease.0/detox-20.0.15-prerelease.0.pom.md5 +1 -0
- package/Detox-android/com/wix/detox/20.0.15-prerelease.0/detox-20.0.15-prerelease.0.pom.sha1 +1 -0
- package/Detox-android/com/wix/detox/20.0.15-prerelease.0/detox-20.0.15-prerelease.0.pom.sha256 +1 -0
- package/Detox-android/com/wix/detox/20.0.15-prerelease.0/detox-20.0.15-prerelease.0.pom.sha512 +1 -0
- package/Detox-android/com/wix/detox/maven-metadata.xml +4 -4
- package/Detox-android/com/wix/detox/maven-metadata.xml.md5 +1 -1
- package/Detox-android/com/wix/detox/maven-metadata.xml.sha1 +1 -1
- package/Detox-android/com/wix/detox/maven-metadata.xml.sha256 +1 -1
- package/Detox-android/com/wix/detox/maven-metadata.xml.sha512 +1 -1
- package/Detox-ios-src.tbz +0 -0
- package/Detox-ios.tbz +0 -0
- package/index.d.ts +3 -6
- package/internals.d.ts +26 -5
- package/local-cli/cli.js +1 -1
- package/local-cli/init.js +1 -1
- package/local-cli/test.js +6 -6
- package/local-cli/test.test.js +61 -28
- package/local-cli/testCommand/TestRunnerCommand.js +77 -87
- package/local-cli/testCommand/builder.js +0 -1
- package/local-cli/testCommand/middlewares.js +4 -13
- package/local-cli/testCommand/warnings.js +0 -3
- package/package.json +14 -8
- package/runners/deprecation.js +42 -44
- package/runners/jest/index.d.ts +60 -0
- package/runners/jest/index.js +3 -8
- package/runners/jest/index.test.js +13 -0
- package/runners/jest/reporters/DetoxReporter.js +21 -10
- package/runners/jest/testEnvironment/index.js +57 -41
- package/runners/jest/testEnvironment/listeners/DetoxCoreListener.js +62 -35
- package/runners/jest/testEnvironment/listeners/SpecReporter.js +12 -14
- package/runners/jest/testEnvironment/listeners/WorkerAssignReporter.js +1 -5
- package/runners/jest/testEnvironment/utils/assertJestCircus27.js +17 -3
- package/runners/jest/testEnvironment/utils/assertJestCircus27.test.js +0 -1
- package/src/DetoxWorker.js +84 -46
- package/src/android/interactions/native.js +3 -2
- package/src/artifacts/ArtifactsManager.js +6 -6
- package/src/configuration/collectCliConfig.js +1 -12
- package/src/configuration/composeRunnerConfig.js +4 -3
- package/src/devices/common/drivers/ios/tools/AppleSimUtils.js +1 -1
- package/src/devices/lifecycle/GenyGlobalLifecycleHandler.js +2 -0
- package/src/devices/runtime/RuntimeDevice.js +3 -3
- package/src/errors/DetoxConfigErrorComposer.js +6 -1
- package/src/ios/expectTwo.js +3 -2
- package/src/ipc/SessionState.js +7 -5
- package/src/logger/DetoxLogger.js +32 -41
- package/src/logger/index.js +1 -0
- package/src/logger/utils/BunyanLogger.js +11 -7
- package/src/logger/utils/CategoryThreadDispatcher.js +7 -29
- package/src/logger/utils/DetoxLogFinalizer.js +140 -0
- package/src/logger/utils/ThreadDispatcher.js +5 -25
- package/src/logger/utils/customConsoleLogger.js +4 -3
- package/src/logger/utils/sanitizeBunyanContext.js +3 -1
- package/src/logger/utils/streamUtils.js +34 -26
- package/src/logger/utils/tracerLegacy.js +14 -25
- package/src/realms/DetoxContext.js +8 -7
- package/src/realms/DetoxPrimaryContext.js +22 -82
- package/src/realms/DetoxSecondaryContext.js +0 -8
- package/src/utils/argparse.js +11 -0
- package/src/utils/logger.js +1 -1
- package/src/utils/traceInvocationCall.js +21 -0
- package/Detox-android/com/wix/detox/20.0.14-next-is-hittable-check-2.0/detox-20.0.14-next-is-hittable-check-2.0-javadoc.jar.md5 +0 -1
- package/Detox-android/com/wix/detox/20.0.14-next-is-hittable-check-2.0/detox-20.0.14-next-is-hittable-check-2.0-javadoc.jar.sha1 +0 -1
- package/Detox-android/com/wix/detox/20.0.14-next-is-hittable-check-2.0/detox-20.0.14-next-is-hittable-check-2.0-javadoc.jar.sha256 +0 -1
- package/Detox-android/com/wix/detox/20.0.14-next-is-hittable-check-2.0/detox-20.0.14-next-is-hittable-check-2.0-javadoc.jar.sha512 +0 -1
- package/Detox-android/com/wix/detox/20.0.14-next-is-hittable-check-2.0/detox-20.0.14-next-is-hittable-check-2.0-sources.jar.md5 +0 -1
- package/Detox-android/com/wix/detox/20.0.14-next-is-hittable-check-2.0/detox-20.0.14-next-is-hittable-check-2.0-sources.jar.sha1 +0 -1
- package/Detox-android/com/wix/detox/20.0.14-next-is-hittable-check-2.0/detox-20.0.14-next-is-hittable-check-2.0-sources.jar.sha256 +0 -1
- package/Detox-android/com/wix/detox/20.0.14-next-is-hittable-check-2.0/detox-20.0.14-next-is-hittable-check-2.0-sources.jar.sha512 +0 -1
- package/Detox-android/com/wix/detox/20.0.14-next-is-hittable-check-2.0/detox-20.0.14-next-is-hittable-check-2.0.pom.md5 +0 -1
- package/Detox-android/com/wix/detox/20.0.14-next-is-hittable-check-2.0/detox-20.0.14-next-is-hittable-check-2.0.pom.sha1 +0 -1
- package/Detox-android/com/wix/detox/20.0.14-next-is-hittable-check-2.0/detox-20.0.14-next-is-hittable-check-2.0.pom.sha256 +0 -1
- package/Detox-android/com/wix/detox/20.0.14-next-is-hittable-check-2.0/detox-20.0.14-next-is-hittable-check-2.0.pom.sha512 +0 -1
- package/runners/jest/deprecation.js +0 -25
- package/src/configuration/utils/warnings.js +0 -12
- package/src/utils/trace.js +0 -3
@@ -2,7 +2,6 @@ const path = require('path');
|
|
2
2
|
|
3
3
|
const _ = require('lodash');
|
4
4
|
|
5
|
-
const temporaryPath = require('../artifacts/utils/temporaryPath');
|
6
5
|
const { DetoxInternalError, DetoxError } = require('../errors');
|
7
6
|
const { shortFormat } = require('../utils/dateUtils');
|
8
7
|
const isPromise = require('../utils/isPromise');
|
@@ -16,7 +15,7 @@ const sanitizeBunyanContext = require('./utils/sanitizeBunyanContext');
|
|
16
15
|
/**
|
17
16
|
* @typedef SharedLoggerConfig
|
18
17
|
* @property {string} file
|
19
|
-
* @property {Detox.DetoxLoggerConfig} userConfig
|
18
|
+
* @property {Detox.DetoxLoggerConfig} [userConfig]
|
20
19
|
* @property {CategoryThreadDispatcher} [dispatcher]
|
21
20
|
* @property {BunyanLogger} [bunyan]
|
22
21
|
* @property {MessageStack} [messageStack]
|
@@ -71,25 +70,7 @@ class DetoxLogger {
|
|
71
70
|
.installFileStream(this.file)
|
72
71
|
.installDebugStream(this.config);
|
73
72
|
|
74
|
-
this._sharedConfig.dispatcher = new CategoryThreadDispatcher(
|
75
|
-
logger: this,
|
76
|
-
categories: {
|
77
|
-
'lifecycle': [0],
|
78
|
-
'cli': [1],
|
79
|
-
'logger': [2],
|
80
|
-
'ipc': [29],
|
81
|
-
'ws-server': [50, 99],
|
82
|
-
'ws-client': [100, 149],
|
83
|
-
'device': [150, 159],
|
84
|
-
'artifacts-manager': [300],
|
85
|
-
'artifacts-plugin': [310, 349],
|
86
|
-
'artifact': [350, 399],
|
87
|
-
'child-process': [400, 499],
|
88
|
-
'default': [999],
|
89
|
-
'user': [10000, 10999]
|
90
|
-
},
|
91
|
-
});
|
92
|
-
|
73
|
+
this._sharedConfig.dispatcher = new CategoryThreadDispatcher();
|
93
74
|
this._sharedConfig.messageStack = new MessageStack();
|
94
75
|
|
95
76
|
this.overrideConsole();
|
@@ -110,7 +91,7 @@ class DetoxLogger {
|
|
110
91
|
* @returns {DetoxLogger}
|
111
92
|
*/
|
112
93
|
child(overrides) {
|
113
|
-
const merged = this._mergeContexts(this._context, overrides);
|
94
|
+
const merged = this._mergeContexts(this._context, sanitizeBunyanContext(overrides));
|
114
95
|
return new DetoxLogger(this._sharedConfig, merged);
|
115
96
|
}
|
116
97
|
|
@@ -134,7 +115,6 @@ class DetoxLogger {
|
|
134
115
|
}
|
135
116
|
|
136
117
|
_.merge(this.config, config);
|
137
|
-
this._sharedConfig.file = temporaryPath.for.jsonl();
|
138
118
|
this._sharedConfig.bunyan.installDebugStream(this.config);
|
139
119
|
this.overrideConsole();
|
140
120
|
}
|
@@ -156,14 +136,23 @@ class DetoxLogger {
|
|
156
136
|
*/
|
157
137
|
_mergeContexts(...contexts) {
|
158
138
|
const context = Object.assign({}, ...contexts);
|
139
|
+
const categories = _(contexts).flatMap((c) => {
|
140
|
+
if (c && c.cat) {
|
141
|
+
return _.isArray(c.cat) ? c.cat : c.cat.split(',');
|
142
|
+
}
|
143
|
+
|
144
|
+
return [];
|
145
|
+
}).uniq().join(',');
|
159
146
|
|
160
147
|
if (context.error || context.err) {
|
161
148
|
context.error = DetoxError.format(context.error || context.err);
|
162
149
|
delete context.err;
|
163
150
|
}
|
164
151
|
|
165
|
-
if (
|
166
|
-
context.cat =
|
152
|
+
if (categories) {
|
153
|
+
context.cat = categories;
|
154
|
+
} else {
|
155
|
+
delete context.cat;
|
167
156
|
}
|
168
157
|
|
169
158
|
if (context.__filename) {
|
@@ -171,15 +160,13 @@ class DetoxLogger {
|
|
171
160
|
}
|
172
161
|
|
173
162
|
context.ph = context.ph || 'i';
|
174
|
-
context.cat = context.cat || '';
|
175
|
-
|
176
163
|
context.tid = this._sharedConfig.dispatcher.resolve(
|
177
164
|
context.ph,
|
178
165
|
context.cat,
|
179
166
|
context.id || 0
|
180
167
|
);
|
181
168
|
|
182
|
-
return
|
169
|
+
return context;
|
183
170
|
}
|
184
171
|
|
185
172
|
/**
|
@@ -200,6 +187,11 @@ class DetoxLogger {
|
|
200
187
|
/** @private */
|
201
188
|
_begin(level, ...args) {
|
202
189
|
const { context, msg } = this._parseArgs({ ph: 'B' }, args);
|
190
|
+
this._beginInternal(level, context, msg);
|
191
|
+
}
|
192
|
+
|
193
|
+
/** @private */
|
194
|
+
_beginInternal(level, context, msg) {
|
203
195
|
this._sharedConfig.messageStack.push(context.tid, msg);
|
204
196
|
this._sharedConfig.bunyan.logger[level](context, ...msg);
|
205
197
|
}
|
@@ -207,8 +199,14 @@ class DetoxLogger {
|
|
207
199
|
/** @private */
|
208
200
|
_end(level, ...args) {
|
209
201
|
let { context, msg } = this._parseArgs({ ph: 'E' }, args);
|
202
|
+
this._endInternal(level, context, msg);
|
203
|
+
}
|
204
|
+
|
205
|
+
/** @private */
|
206
|
+
_endInternal(level, context, msg) {
|
207
|
+
const beginMsg = this._sharedConfig.messageStack.pop(context.tid);
|
210
208
|
if (msg.length === 0) {
|
211
|
-
msg =
|
209
|
+
msg = beginMsg;
|
212
210
|
}
|
213
211
|
|
214
212
|
this._sharedConfig.bunyan.logger[level](context, ...msg);
|
@@ -239,14 +237,14 @@ class DetoxLogger {
|
|
239
237
|
});
|
240
238
|
|
241
239
|
let result;
|
242
|
-
this
|
240
|
+
this._beginInternal(level, { ...context, ph: 'B' }, msg);
|
243
241
|
try {
|
244
242
|
result = typeof action === 'function'
|
245
243
|
? action()
|
246
244
|
: action;
|
247
245
|
|
248
246
|
if (!isPromise(result)) {
|
249
|
-
end(
|
247
|
+
end({ success: true });
|
250
248
|
} else {
|
251
249
|
result.then(
|
252
250
|
() => end({ success: true }),
|
@@ -268,20 +266,13 @@ class DetoxLogger {
|
|
268
266
|
: _.isObject(args[0])
|
269
267
|
? args[0]
|
270
268
|
: undefined;
|
271
|
-
const msg = userContext !== undefined ? args.slice(1) : args;
|
272
269
|
|
273
|
-
|
274
|
-
delete userContext.pid;
|
275
|
-
delete userContext.tid;
|
276
|
-
delete userContext.ts;
|
277
|
-
delete userContext.time;
|
278
|
-
delete userContext.ph;
|
279
|
-
}
|
270
|
+
const msg = userContext !== undefined ? args.slice(1) : args;
|
280
271
|
|
281
272
|
const context = this._mergeContexts(
|
282
273
|
this._context,
|
283
274
|
boundContext,
|
284
|
-
userContext,
|
275
|
+
sanitizeBunyanContext(userContext),
|
285
276
|
);
|
286
277
|
|
287
278
|
return { context, msg };
|
@@ -298,7 +289,7 @@ class DetoxLogger {
|
|
298
289
|
: undefined;
|
299
290
|
|
300
291
|
const cat = level === 'trace' || level === 'debug'
|
301
|
-
? (value) => require('chalk').yellow(
|
292
|
+
? (value) => require('chalk').yellow(`${value}`.split(',', 1)[0])
|
302
293
|
: undefined;
|
303
294
|
|
304
295
|
const event = level === 'trace' || level === 'debug'
|
package/src/logger/index.js
CHANGED
@@ -27,8 +27,6 @@ class BunyanLogger {
|
|
27
27
|
* @returns {this}
|
28
28
|
*/
|
29
29
|
installDebugStream(config) {
|
30
|
-
const level = config.level || 'info';
|
31
|
-
|
32
30
|
if (this._debugStream) {
|
33
31
|
_.remove(this._bunyan['streams'], this._debugStream);
|
34
32
|
// @ts-ignore
|
@@ -36,13 +34,17 @@ class BunyanLogger {
|
|
36
34
|
this._debugStream = null;
|
37
35
|
}
|
38
36
|
|
37
|
+
const streamOptions = { out: null, ...config.options };
|
38
|
+
/* istanbul ignore next */
|
39
|
+
if (!streamOptions.out) {
|
40
|
+
// This is a default if-else branch, used everywhere except for the unit tests.
|
41
|
+
streamOptions.out = new PassThrough().pipe(process.stderr);
|
42
|
+
}
|
43
|
+
|
39
44
|
this._debugStream = {
|
40
45
|
type: 'raw',
|
41
|
-
level,
|
42
|
-
stream: bds.default(
|
43
|
-
...config.options,
|
44
|
-
out: new PassThrough().pipe(process.stderr),
|
45
|
-
}),
|
46
|
+
level: config.level,
|
47
|
+
stream: bds.default(streamOptions),
|
46
48
|
};
|
47
49
|
|
48
50
|
this._bunyan.addStream(this._debugStream);
|
@@ -54,7 +56,9 @@ class BunyanLogger {
|
|
54
56
|
* @returns {this}
|
55
57
|
*/
|
56
58
|
installFileStream(file) {
|
59
|
+
/* istanbul ignore next */
|
57
60
|
if (this._fileStream) {
|
61
|
+
// This is an impossible condition, but we keep it here for the sake of completeness.
|
58
62
|
throw new DetoxInternalError('Trying to install a second file stream inside already initialized Bunyan logger');
|
59
63
|
}
|
60
64
|
|
@@ -1,23 +1,9 @@
|
|
1
|
-
const _ = require('lodash');
|
2
|
-
|
3
1
|
const ThreadDispatcher = require('./ThreadDispatcher');
|
4
2
|
|
5
3
|
class CategoryThreadDispatcher {
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
* @param {Detox.Logger} config.logger
|
10
|
-
*/
|
11
|
-
constructor(config) {
|
12
|
-
this.categories = config.categories;
|
13
|
-
this.dispatchers = _.mapValues(this.categories, (range, name) => {
|
14
|
-
return new ThreadDispatcher({
|
15
|
-
name,
|
16
|
-
logger: config.logger,
|
17
|
-
min: range[0],
|
18
|
-
max: range[1] || range[0],
|
19
|
-
});
|
20
|
-
});
|
4
|
+
constructor() {
|
5
|
+
/** @type {Record<string, ThreadDispatcher>} */
|
6
|
+
this._dispatchers = {};
|
21
7
|
}
|
22
8
|
|
23
9
|
/**
|
@@ -38,20 +24,12 @@ class CategoryThreadDispatcher {
|
|
38
24
|
|
39
25
|
/** @returns {ThreadDispatcher} */
|
40
26
|
_resolveDispatcher(cat) {
|
41
|
-
const mainCategory = cat ? cat.split(',', 1)[0] : '';
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
categorize(tid) {
|
46
|
-
return _.findKey(this.categories, ([min, max]) => min <= tid && tid <= max) || 'default';
|
47
|
-
}
|
48
|
-
|
49
|
-
threadize(cat) {
|
50
|
-
if (!cat) {
|
51
|
-
return this.categories.default[0];
|
27
|
+
const mainCategory = cat ? cat.split(',', 1)[0] : 'undefined';
|
28
|
+
if (!this._dispatchers[mainCategory]) {
|
29
|
+
this._dispatchers[mainCategory] = new ThreadDispatcher(mainCategory);
|
52
30
|
}
|
53
31
|
|
54
|
-
return
|
32
|
+
return this._dispatchers[mainCategory];
|
55
33
|
}
|
56
34
|
}
|
57
35
|
|
@@ -0,0 +1,140 @@
|
|
1
|
+
const path = require('path');
|
2
|
+
const { promisify } = require('util');
|
3
|
+
|
4
|
+
const fs = require('fs-extra');
|
5
|
+
const glob = require('glob');
|
6
|
+
const pipe = require('multipipe');
|
7
|
+
|
8
|
+
const temporary = require('../../artifacts/utils/temporaryPath');
|
9
|
+
|
10
|
+
const globAsync = promisify(glob);
|
11
|
+
const globSync = glob.sync;
|
12
|
+
const streamUtils = () => require('../../logger/utils/streamUtils');
|
13
|
+
|
14
|
+
/**
|
15
|
+
* @typedef DetoxLogFinalizerConfig
|
16
|
+
* @property {import('../../ipc/SessionState')} session
|
17
|
+
*/
|
18
|
+
|
19
|
+
class DetoxLogFinalizer {
|
20
|
+
/** @param {DetoxLogFinalizerConfig} config */
|
21
|
+
constructor(config) {
|
22
|
+
this._session = config.session;
|
23
|
+
}
|
24
|
+
|
25
|
+
createEventStream() {
|
26
|
+
const sessionId = this._session.id;
|
27
|
+
const logs = globSync(temporary.for.jsonl(`${sessionId}.*`));
|
28
|
+
|
29
|
+
return streamUtils()
|
30
|
+
.uniteSessionLogs(logs)
|
31
|
+
.pipe(streamUtils().chromeTraceStream());
|
32
|
+
}
|
33
|
+
|
34
|
+
async finalize() {
|
35
|
+
const sessionId = this._session.id;
|
36
|
+
const logs = await globAsync(temporary.for.jsonl(`${sessionId}.*`));
|
37
|
+
if (logs.length === 0) {
|
38
|
+
return;
|
39
|
+
}
|
40
|
+
|
41
|
+
if (this._areLogsEnabled()) {
|
42
|
+
const rootDir = this._config.artifacts.rootDir;
|
43
|
+
|
44
|
+
await fs.mkdirp(rootDir);
|
45
|
+
const [out1Stream, out2Stream] = ['detox.log', 'detox.trace.json']
|
46
|
+
.map((filename) => fs.createWriteStream(path.join(rootDir, filename)));
|
47
|
+
|
48
|
+
const tidHashMap = await this._scanForThreadIds(logs);
|
49
|
+
const mergedStream = streamUtils().uniteSessionLogs(logs);
|
50
|
+
|
51
|
+
await Promise.all([
|
52
|
+
pipe(mergedStream, streamUtils().debugStream(this._config.logger.options), out1Stream),
|
53
|
+
pipe(mergedStream, streamUtils().chromeTraceStream(tidHashMap), streamUtils().writeJSON(), out2Stream),
|
54
|
+
]);
|
55
|
+
}
|
56
|
+
|
57
|
+
await Promise.all(logs.map(filepath => fs.remove(filepath)));
|
58
|
+
}
|
59
|
+
|
60
|
+
finalizeSync() {
|
61
|
+
const sessionId = this._session.id;
|
62
|
+
const logs = globSync(temporary.for.jsonl(`${sessionId}.*`));
|
63
|
+
if (logs.length === 0) {
|
64
|
+
return;
|
65
|
+
}
|
66
|
+
|
67
|
+
const logsEnabled = this._areLogsEnabled();
|
68
|
+
const rootDir = logsEnabled ? this._config.artifacts.rootDir : '';
|
69
|
+
if (logsEnabled) {
|
70
|
+
fs.mkdirpSync(rootDir);
|
71
|
+
}
|
72
|
+
|
73
|
+
for (const log of logs) {
|
74
|
+
if (logsEnabled) {
|
75
|
+
fs.moveSync(log, path.join(rootDir, path.basename(log)));
|
76
|
+
} else {
|
77
|
+
fs.removeSync(log);
|
78
|
+
}
|
79
|
+
}
|
80
|
+
}
|
81
|
+
|
82
|
+
/** @private */
|
83
|
+
get _config() {
|
84
|
+
// The config appears later in the lifecycle, so we need to access it lazily
|
85
|
+
return this._session.detoxConfig;
|
86
|
+
}
|
87
|
+
|
88
|
+
/** @private */
|
89
|
+
_areLogsEnabled() {
|
90
|
+
if (!this._config) {
|
91
|
+
return false;
|
92
|
+
}
|
93
|
+
|
94
|
+
const { rootDir, plugins } = this._config.artifacts;
|
95
|
+
if (!rootDir || !plugins) {
|
96
|
+
return false;
|
97
|
+
}
|
98
|
+
|
99
|
+
if (!plugins.log.enabled) {
|
100
|
+
return false;
|
101
|
+
}
|
102
|
+
|
103
|
+
if (!plugins.log.keepOnlyFailedTestsArtifacts) {
|
104
|
+
return true;
|
105
|
+
}
|
106
|
+
|
107
|
+
return this._session.testResults.some(r => !r.success);
|
108
|
+
}
|
109
|
+
|
110
|
+
/** @private */
|
111
|
+
async _scanForThreadIds(logs) {
|
112
|
+
const processes = await new Promise((resolve, reject) => {
|
113
|
+
const result = {};
|
114
|
+
streamUtils().uniteSessionLogs(logs)
|
115
|
+
.on('end', () => resolve(result))
|
116
|
+
.on('error', /* istanbul ignore next */ (err) => reject(err))
|
117
|
+
.on('data', (event) => {
|
118
|
+
const { ph, pid, tid, cat } = event;
|
119
|
+
if (ph === 'B' || ph === 'i') {
|
120
|
+
const categories = (result[pid] = result[pid] || {});
|
121
|
+
const mainCategory = String(cat).split(',')[0];
|
122
|
+
const tids = (categories[mainCategory] = categories[mainCategory] || []);
|
123
|
+
if (!tids.includes(tid)) {
|
124
|
+
tids.push(tid);
|
125
|
+
}
|
126
|
+
}
|
127
|
+
});
|
128
|
+
});
|
129
|
+
|
130
|
+
const tidArray = Object.entries(processes).flatMap(([pid, categories]) => {
|
131
|
+
return Object.entries(categories).flatMap(([category, tids]) => {
|
132
|
+
return tids.map(tid => `${pid}:${category}:${tid}`);
|
133
|
+
});
|
134
|
+
});
|
135
|
+
|
136
|
+
return new Map(tidArray.map((hash, index) => [hash, index]));
|
137
|
+
}
|
138
|
+
}
|
139
|
+
|
140
|
+
module.exports = DetoxLogFinalizer;
|
@@ -2,17 +2,10 @@ const isUndefined = (x) => x === undefined;
|
|
2
2
|
|
3
3
|
class ThreadDispatcher {
|
4
4
|
/**
|
5
|
-
* @param {
|
6
|
-
* @param {Detox.Logger} options.logger
|
7
|
-
* @param {string} options.name
|
8
|
-
* @param {number} options.min
|
9
|
-
* @param {number} [options.max]
|
5
|
+
* @param {string} name
|
10
6
|
*/
|
11
|
-
constructor(
|
12
|
-
this.logger = logger;
|
7
|
+
constructor(name) {
|
13
8
|
this.name = name;
|
14
|
-
this.min = min;
|
15
|
-
this.max = max;
|
16
9
|
this.stacks = [];
|
17
10
|
this.threads = [];
|
18
11
|
}
|
@@ -25,7 +18,7 @@ class ThreadDispatcher {
|
|
25
18
|
const tid = this._findTID(id);
|
26
19
|
this.threads[tid] = id;
|
27
20
|
this.stacks[tid] = (this.stacks[tid] || 0) + 1;
|
28
|
-
return
|
21
|
+
return tid;
|
29
22
|
}
|
30
23
|
|
31
24
|
/**
|
@@ -33,8 +26,7 @@ class ThreadDispatcher {
|
|
33
26
|
* @returns {number}
|
34
27
|
*/
|
35
28
|
resolve(id) {
|
36
|
-
|
37
|
-
return this._transpose(tid);
|
29
|
+
return this._findTID(id);
|
38
30
|
}
|
39
31
|
|
40
32
|
/**
|
@@ -46,7 +38,7 @@ class ThreadDispatcher {
|
|
46
38
|
if (this.stacks[tid] && --this.stacks[tid] === 0) {
|
47
39
|
delete this.threads[tid];
|
48
40
|
}
|
49
|
-
return
|
41
|
+
return tid;
|
50
42
|
}
|
51
43
|
|
52
44
|
/**
|
@@ -64,18 +56,6 @@ class ThreadDispatcher {
|
|
64
56
|
}
|
65
57
|
return tid === -1 ? this.threads.length : tid;
|
66
58
|
}
|
67
|
-
|
68
|
-
_transpose(id) {
|
69
|
-
const result = this.min + id;
|
70
|
-
if (result > this.max) {
|
71
|
-
this.logger.warn(
|
72
|
-
{ cat: ['logger', 'thread-dispatcher'] },
|
73
|
-
`${this.name} trace thread dispatcher has run out of available thread IDs: ${this.min}..${this.max}`
|
74
|
-
);
|
75
|
-
}
|
76
|
-
|
77
|
-
return Math.min(result, this.max);
|
78
|
-
}
|
79
59
|
}
|
80
60
|
|
81
61
|
module.exports = ThreadDispatcher;
|
@@ -25,20 +25,20 @@ function getStackDump() {
|
|
25
25
|
|
26
26
|
function proxyLog(bunyanLoggerFn) {
|
27
27
|
return (...args) => {
|
28
|
-
bunyanLoggerFn({ origin: getOrigin() }, util.format(...args));
|
28
|
+
bunyanLoggerFn({ cat: 'user', origin: getOrigin() }, util.format(...args));
|
29
29
|
};
|
30
30
|
}
|
31
31
|
|
32
32
|
function proxyTracing(bunyanLoggerFn) {
|
33
33
|
return (...args) => {
|
34
|
-
bunyanLoggerFn({ origin: getOrigin(), stack: getStackDump() }, util.format(...args));
|
34
|
+
bunyanLoggerFn({ cat: 'user', origin: getOrigin(), stack: getStackDump() }, util.format(...args));
|
35
35
|
};
|
36
36
|
}
|
37
37
|
|
38
38
|
function proxyAssert(bunyanLoggerFn) {
|
39
39
|
return (condition, ...args) => {
|
40
40
|
if (!condition) {
|
41
|
-
bunyanLoggerFn({ origin: getOrigin() }, 'AssertionError:', util.format(...args));
|
41
|
+
bunyanLoggerFn({ cat: 'user', origin: getOrigin() }, 'AssertionError:', util.format(...args));
|
42
42
|
}
|
43
43
|
};
|
44
44
|
}
|
@@ -48,6 +48,7 @@ function overrideConsoleMethods(console, bunyanLogger) {
|
|
48
48
|
const log = bunyanLogger;
|
49
49
|
|
50
50
|
override(console, 'log', log.info.bind(log));
|
51
|
+
override(console, 'info', log.info.bind(log));
|
51
52
|
override(console, 'warn', log.warn.bind(log));
|
52
53
|
override(console, 'trace', log.info.bind(log));
|
53
54
|
override(console, 'error', log.error.bind(log));
|
@@ -6,6 +6,8 @@ const RESERVED_PROPERTIES = [
|
|
6
6
|
'msg',
|
7
7
|
'name',
|
8
8
|
'pid',
|
9
|
+
'tid',
|
10
|
+
'ph',
|
9
11
|
'time',
|
10
12
|
];
|
11
13
|
|
@@ -22,7 +24,7 @@ function escapeCallback(value, key) {
|
|
22
24
|
}
|
23
25
|
|
24
26
|
function sanitizeBunyanContext(context) {
|
25
|
-
return hasReservedProperties(context) ? _.mapKeys(context, escapeCallback) : context;
|
27
|
+
return context && hasReservedProperties(context) ? _.mapKeys(context, escapeCallback) : context;
|
26
28
|
}
|
27
29
|
|
28
30
|
module.exports = sanitizeBunyanContext;
|
@@ -3,14 +3,12 @@ const { PassThrough, Transform } = require('stream');
|
|
3
3
|
const bunyanDebugStream = require('bunyan-debug-stream');
|
4
4
|
const duplexify = require('duplexify');
|
5
5
|
const fs = require('fs-extra');
|
6
|
-
const glob = require('glob');
|
7
6
|
const multiSort = require('multi-sort-stream');
|
8
7
|
const pipe = require('multipipe');
|
9
8
|
const JsonlParser = require('stream-json/jsonl/Parser');
|
10
9
|
const stripAnsi = require('strip-ansi');
|
11
10
|
const { AbstractEventBuilder } = require('trace-event-lib');
|
12
11
|
|
13
|
-
const temporary = require('../../artifacts/utils/temporaryPath');
|
14
12
|
const log = require('../../utils/logger').child({ cat: 'logger' });
|
15
13
|
|
16
14
|
function compareTimestamps(a, b) {
|
@@ -143,27 +141,49 @@ class SimpleEventBuilder extends AbstractEventBuilder {
|
|
143
141
|
}
|
144
142
|
}
|
145
143
|
|
146
|
-
|
144
|
+
const ERROR_TID = 37707;
|
145
|
+
|
146
|
+
function getTidHash({ pid, tid, cat }) {
|
147
|
+
const mainCategory = String(cat).split(',')[0];
|
148
|
+
return `${pid}:${mainCategory}:${tid}`;
|
149
|
+
}
|
150
|
+
|
151
|
+
function getFixedTID(tidHashMap, event) {
|
152
|
+
let tid = tidHashMap.get(getTidHash(event));
|
153
|
+
if (tid === undefined) {
|
154
|
+
tid = ERROR_TID;
|
155
|
+
}
|
156
|
+
|
157
|
+
return tid;
|
158
|
+
}
|
159
|
+
|
160
|
+
/**
|
161
|
+
* @param {Map<string, number>} [tidHashMap]
|
162
|
+
*/
|
163
|
+
function chromeTraceStream(tidHashMap) {
|
147
164
|
const knownPids = new Set();
|
148
165
|
const knownTids = new Set();
|
166
|
+
const fixTID = tidHashMap ? getFixedTID.bind(null, tidHashMap) : (x) => x.tid;
|
149
167
|
|
150
168
|
return flatMapTransform((data) => {
|
151
169
|
// eslint-disable-next-line no-unused-vars, @typescript-eslint/no-unused-vars
|
152
|
-
const { cat
|
170
|
+
const { cat: rawCat, msg: name, ph = 'i', pid, tid: _tid, time, name: _name, hostname: _hostname, ...args } = data;
|
153
171
|
const ts = new Date(time).getTime() * 1E3;
|
172
|
+
const cat = rawCat || 'undefined';
|
173
|
+
const tid = fixTID(data);
|
154
174
|
|
155
175
|
const builder = new SimpleEventBuilder();
|
156
176
|
if (!knownPids.has(pid)) {
|
157
|
-
builder.
|
177
|
+
builder.metadata({ pid, ts, name: 'process_name', args: { name: pid === process.pid ? 'primary' : 'secondary' } });
|
178
|
+
builder.metadata({ pid, ts, name: 'process_sort_index', args: { sort_index: knownPids.size } });
|
158
179
|
knownPids.add(pid);
|
159
180
|
}
|
160
181
|
|
161
|
-
|
162
|
-
if (!knownTids.has(tidHash)) {
|
182
|
+
if (!knownTids.has(tid)) {
|
163
183
|
const primaryCategory = cat.split(',', 1)[0];
|
164
|
-
builder.
|
165
|
-
builder.
|
166
|
-
knownTids.add(
|
184
|
+
builder.metadata({ pid, tid, ts, name: 'thread_name', args: { name: primaryCategory } });
|
185
|
+
builder.metadata({ pid, tid, ts, name: 'thread_sort_index', args: { sort_index: tid } });
|
186
|
+
knownTids.add(tid);
|
167
187
|
}
|
168
188
|
|
169
189
|
const event = { ph, name, pid, tid, cat, ts, args };
|
@@ -207,25 +227,13 @@ function readJSONL() {
|
|
207
227
|
}
|
208
228
|
|
209
229
|
/**
|
210
|
-
* @param {string}
|
230
|
+
* @param {string[]} logs
|
211
231
|
* @returns {NodeJS.ReadableStream}
|
212
232
|
*/
|
213
|
-
function uniteSessionLogs(
|
233
|
+
function uniteSessionLogs(logs) {
|
214
234
|
const readable = through();
|
215
|
-
|
216
|
-
|
217
|
-
if (err) {
|
218
|
-
return readable.emit('error', err);
|
219
|
-
}
|
220
|
-
|
221
|
-
if (logs.length === 0) {
|
222
|
-
return;
|
223
|
-
}
|
224
|
-
|
225
|
-
const jsonlStreams = logs.map(filePath => fs.createReadStream(filePath).pipe(readJSONL()));
|
226
|
-
mergeSortedJSONL(jsonlStreams).pipe(readable);
|
227
|
-
});
|
228
|
-
|
235
|
+
const jsonlStreams = logs.map(filePath => fs.createReadStream(filePath).pipe(readJSONL()));
|
236
|
+
mergeSortedJSONL(jsonlStreams).pipe(readable);
|
229
237
|
return readable;
|
230
238
|
}
|
231
239
|
|
@@ -1,45 +1,34 @@
|
|
1
1
|
const methods = {
|
2
2
|
startSection(logger) {
|
3
|
-
return (msg, args) =>
|
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 (
|
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;
|