detox 20.1.0-next-is-hittable-check.0 → 20.1.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.1.0-next-is-hittable-check.0/detox-20.1.0-next-is-hittable-check.0-javadoc.jar → 20.1.0/detox-20.1.0-javadoc.jar} +0 -0
- package/Detox-android/com/wix/detox/20.1.0/detox-20.1.0-javadoc.jar.md5 +1 -0
- package/Detox-android/com/wix/detox/20.1.0/detox-20.1.0-javadoc.jar.sha1 +1 -0
- package/Detox-android/com/wix/detox/20.1.0/detox-20.1.0-javadoc.jar.sha256 +1 -0
- package/Detox-android/com/wix/detox/20.1.0/detox-20.1.0-javadoc.jar.sha512 +1 -0
- 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.0/detox-20.1.0-sources.jar} +0 -0
- package/Detox-android/com/wix/detox/20.1.0/detox-20.1.0-sources.jar.md5 +1 -0
- package/Detox-android/com/wix/detox/20.1.0/detox-20.1.0-sources.jar.sha1 +1 -0
- package/Detox-android/com/wix/detox/20.1.0/detox-20.1.0-sources.jar.sha256 +1 -0
- package/Detox-android/com/wix/detox/20.1.0/detox-20.1.0-sources.jar.sha512 +1 -0
- package/Detox-android/com/wix/detox/20.1.0/detox-20.1.0.aar +0 -0
- package/Detox-android/com/wix/detox/20.1.0/detox-20.1.0.aar.md5 +1 -0
- package/Detox-android/com/wix/detox/20.1.0/detox-20.1.0.aar.sha1 +1 -0
- package/Detox-android/com/wix/detox/20.1.0/detox-20.1.0.aar.sha256 +1 -0
- package/Detox-android/com/wix/detox/20.1.0/detox-20.1.0.aar.sha512 +1 -0
- 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.0/detox-20.1.0.pom} +1 -1
- package/Detox-android/com/wix/detox/20.1.0/detox-20.1.0.pom.md5 +1 -0
- package/Detox-android/com/wix/detox/20.1.0/detox-20.1.0.pom.sha1 +1 -0
- package/Detox-android/com/wix/detox/20.1.0/detox-20.1.0.pom.sha256 +1 -0
- package/Detox-android/com/wix/detox/20.1.0/detox-20.1.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/android/build.gradle +0 -1
- package/android/detox/src/full/java/com/wix/detox/TestEngineFacade.kt +3 -3
- package/android/detox/src/full/java/com/wix/detox/adapters/server/QueryStatusActionHandler.kt +12 -80
- package/android/detox/src/full/java/com/wix/detox/espresso/common/UiControllerImplReflected.kt +16 -0
- package/android/detox/src/full/java/com/wix/detox/espresso/idlingresources/DescriptiveIdlingResource.kt +8 -0
- package/android/detox/src/full/java/com/wix/detox/espresso/registry/BusyResourcesInquirer.kt +48 -0
- package/android/detox/src/full/java/com/wix/detox/inquiry/DetoxBusyResource.kt +92 -0
- package/android/detox/src/full/java/com/wix/detox/{reactnative/idlingresources/IdlingResourceDescription.kt → inquiry/DetoxBusyResourceDescription.kt} +6 -6
- package/android/detox/src/full/java/com/wix/detox/reactnative/idlingresources/AnimatedModuleIdlingResource.java +18 -7
- package/android/detox/src/full/java/com/wix/detox/reactnative/idlingresources/AsyncStorageIdlingResource.kt +2 -4
- package/android/detox/src/full/java/com/wix/detox/reactnative/idlingresources/BridgeIdlingResource.java +12 -6
- package/android/detox/src/full/java/com/wix/detox/reactnative/idlingresources/DetoxBaseIdlingResource.java +2 -0
- package/android/detox/src/full/java/com/wix/detox/reactnative/idlingresources/NetworkIdlingResource.java +14 -8
- package/android/detox/src/full/java/com/wix/detox/reactnative/idlingresources/timers/TimersIdlingResource.kt +1 -6
- package/android/detox/src/full/java/com/wix/detox/reactnative/idlingresources/uimodule/UIManagerModuleReflected.kt +1 -1
- package/android/detox/src/full/java/com/wix/detox/reactnative/idlingresources/uimodule/UIModuleIdlingResource.kt +4 -6
- package/android/detox/src/testFull/java/com/wix/detox/adapters/server/QueryStatusActionHandlerSpec.kt +35 -94
- package/android/detox/src/testFull/java/com/wix/detox/espresso/registry/{IRStatusInquirerTest.kt → BusyResourcesInquirerTest.kt} +46 -7
- package/android/detox/src/testFull/java/com/wix/detox/{reactnative/idlingresources/IdlingResourceDescriptionSpec.kt → inquiry/DetoxBusyResourceDescriptionSpec.kt} +6 -6
- package/android/detox/src/testFull/java/com/wix/detox/inquiry/DetoxBusyResourceSpec.kt +134 -0
- package/android/detox/src/testFull/java/com/wix/detox/reactnative/idlingresources/AsyncStorageIdlingResourceSpec.kt +4 -5
- package/android/detox/src/testFull/java/com/wix/detox/reactnative/idlingresources/NetworkIdlingResourcesTest.kt +5 -5
- package/android/detox/src/testFull/java/com/wix/detox/reactnative/idlingresources/timers/TimersIdlingResourceSpec.kt +4 -6
- package/index.d.ts +102 -18
- package/internals.d.ts +34 -9
- package/local-cli/cli.js +6 -3
- package/local-cli/init.js +1 -1
- package/local-cli/test.js +6 -6
- package/local-cli/testCommand/TestRunnerCommand.js +97 -94
- package/local-cli/testCommand/TestRunnerError.js +17 -0
- 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 +18 -15
- package/runners/deprecation.js +42 -44
- package/runners/jest/index.d.ts +60 -0
- package/runners/jest/index.js +3 -8
- 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/src/DetoxWorker.js +95 -49
- package/src/android/interactions/native.js +3 -2
- package/src/artifacts/ArtifactsManager.js +6 -6
- package/src/artifacts/utils/temporaryPath.js +32 -2
- package/src/client/actions/SyncStatusSchema.json +21 -0
- package/src/client/actions/formatters/SyncStatusFormatter.js +2 -0
- package/src/client/actions/formatters/sync-resources/BgThreadFormatter.js +5 -0
- package/src/configuration/collectCliConfig.js +1 -12
- package/src/configuration/composeRunnerConfig.js +5 -4
- package/src/devices/allocation/drivers/android/emulator/EmulatorLauncher.js +3 -3
- package/src/devices/allocation/drivers/android/emulator/launchEmulatorProcess.js +3 -16
- package/src/devices/common/drivers/android/exec/ADB.js +4 -0
- package/src/devices/common/drivers/ios/tools/AppleSimUtils.js +1 -1
- package/src/devices/lifecycle/GenyGlobalLifecycleHandler.js +4 -0
- package/src/devices/runtime/RuntimeDevice.js +3 -3
- package/src/errors/DetoxConfigErrorComposer.js +6 -1
- package/src/errors/DetoxError.js +5 -1
- package/src/ios/expectTwo.js +3 -2
- package/src/ipc/IPCClient.js +26 -17
- package/src/ipc/IPCServer.js +11 -3
- package/src/ipc/SessionState.js +11 -11
- package/src/logger/DetoxLogger.js +63 -43
- package/src/logger/index.js +1 -0
- package/src/logger/utils/BunyanLogger.js +50 -7
- package/src/logger/utils/CategoryThreadDispatcher.js +8 -29
- package/src/logger/utils/DetoxLogFinalizer.js +166 -0
- package/src/logger/utils/MessageStack.js +17 -6
- package/src/logger/utils/ThreadDispatcher.js +5 -25
- package/src/logger/utils/customConsoleLogger.js +22 -5
- package/src/logger/utils/getMainCategory.js +5 -0
- package/src/logger/utils/sanitizeBunyanContext.js +3 -1
- package/src/logger/utils/streams/BunyanTransformer.js +72 -0
- package/src/logger/utils/streams/ChromeTraceTransformer.js +132 -0
- package/src/logger/utils/streams/DetoxJSONLParser.js +31 -0
- package/src/logger/utils/streams/JSONLStringer.js +55 -0
- package/src/logger/utils/streams/index.js +7 -0
- package/src/logger/utils/streams/transformers.js +39 -0
- package/src/logger/utils/tracerLegacy.js +14 -25
- package/src/realms/DetoxContext.js +11 -7
- package/src/realms/DetoxInternalsFacade.js +0 -6
- package/src/realms/DetoxPrimaryContext.js +42 -87
- package/src/realms/DetoxSecondaryContext.js +8 -12
- package/src/utils/argparse.js +11 -0
- package/src/utils/logger.js +1 -1
- package/src/utils/pathUtils.js +11 -0
- package/src/utils/shellUtils.js +17 -0
- package/src/utils/traceInvocationCall.js +21 -0
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- package/android/detox/src/full/java/com/wix/detox/espresso/registry/IRStatusInquirer.kt +0 -24
- package/android/detox/src/full/java/com/wix/detox/reactnative/idlingresources/DescriptiveIdlingResource.kt +0 -10
- package/local-cli/build.test.js +0 -104
- package/local-cli/run-server.test.js +0 -23
- package/local-cli/test.test.js +0 -569
- package/runners/jest/deprecation.js +0 -25
- package/runners/jest/testEnvironment/utils/assertJestCircus27.test.js +0 -23
- package/src/configuration/utils/warnings.js +0 -12
- package/src/logger/utils/streamUtils.js +0 -240
- package/src/utils/trace.js +0 -3
@@ -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
|
|
@@ -67,6 +71,45 @@ class BunyanLogger {
|
|
67
71
|
|
68
72
|
return this;
|
69
73
|
}
|
74
|
+
|
75
|
+
async closeFileStreams() {
|
76
|
+
const { _closeStream } = BunyanLogger;
|
77
|
+
const internalBunyanStreams = this._bunyan['streams'];
|
78
|
+
const openFileStreams = _.filter(internalBunyanStreams, this._isOpenFileStream);
|
79
|
+
_.remove(internalBunyanStreams, openFileStreams);
|
80
|
+
|
81
|
+
await Promise.all(openFileStreams.map(_closeStream));
|
82
|
+
}
|
83
|
+
|
84
|
+
/** @private */
|
85
|
+
_isOpenFileStream = (bunyanStream) => {
|
86
|
+
switch (bunyanStream.type) {
|
87
|
+
case 'file':
|
88
|
+
return bunyanStream.path && !bunyanStream.stream.destroyed;
|
89
|
+
case 'raw':
|
90
|
+
/* istanbul ignore next */
|
91
|
+
const stream = bunyanStream.stream === this._debugStream.stream
|
92
|
+
? bunyanStream.stream._out
|
93
|
+
: bunyanStream.stream;
|
94
|
+
|
95
|
+
/* istanbul ignore next */
|
96
|
+
return stream.fd !== undefined && !stream.closed;
|
97
|
+
}
|
98
|
+
};
|
99
|
+
|
100
|
+
/** @private */
|
101
|
+
static _closeStream(bunyanStream) {
|
102
|
+
return new Promise((resolve, reject) => {
|
103
|
+
bunyanStream.stream.end((err) => {
|
104
|
+
/* istanbul ignore next */
|
105
|
+
if (err) {
|
106
|
+
reject(err);
|
107
|
+
} else {
|
108
|
+
resolve();
|
109
|
+
}
|
110
|
+
});
|
111
|
+
});
|
112
|
+
}
|
70
113
|
}
|
71
114
|
|
72
115
|
module.exports = BunyanLogger;
|
@@ -1,23 +1,10 @@
|
|
1
|
-
const _ = require('lodash');
|
2
|
-
|
3
1
|
const ThreadDispatcher = require('./ThreadDispatcher');
|
2
|
+
const getMainCategory = require('./getMainCategory');
|
4
3
|
|
5
4
|
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
|
-
});
|
5
|
+
constructor() {
|
6
|
+
/** @type {Record<string, ThreadDispatcher>} */
|
7
|
+
this._dispatchers = {};
|
21
8
|
}
|
22
9
|
|
23
10
|
/**
|
@@ -38,20 +25,12 @@ class CategoryThreadDispatcher {
|
|
38
25
|
|
39
26
|
/** @returns {ThreadDispatcher} */
|
40
27
|
_resolveDispatcher(cat) {
|
41
|
-
const mainCategory = cat
|
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];
|
28
|
+
const mainCategory = getMainCategory(cat);
|
29
|
+
if (!this._dispatchers[mainCategory]) {
|
30
|
+
this._dispatchers[mainCategory] = new ThreadDispatcher(mainCategory);
|
52
31
|
}
|
53
32
|
|
54
|
-
return
|
33
|
+
return this._dispatchers[mainCategory];
|
55
34
|
}
|
56
35
|
}
|
57
36
|
|
@@ -0,0 +1,166 @@
|
|
1
|
+
const path = require('path');
|
2
|
+
|
3
|
+
const fs = require('fs-extra');
|
4
|
+
|
5
|
+
const temporary = require('../../artifacts/utils/temporaryPath');
|
6
|
+
|
7
|
+
const { BunyanTransformer, ChromeTraceTransformer } = require('./streams');
|
8
|
+
|
9
|
+
/**
|
10
|
+
* @typedef DetoxLogFinalizerConfig
|
11
|
+
* @property {import('../../ipc/SessionState')} session
|
12
|
+
* @property {import('../DetoxLogger')} logger
|
13
|
+
*/
|
14
|
+
|
15
|
+
class DetoxLogFinalizer {
|
16
|
+
/** @param {DetoxLogFinalizerConfig} config */
|
17
|
+
constructor(config) {
|
18
|
+
this._session = config.session;
|
19
|
+
this._bunyanTransformer = new BunyanTransformer(
|
20
|
+
config.logger.child({ cat: 'logger' }),
|
21
|
+
);
|
22
|
+
this._chromeTransformer = new ChromeTraceTransformer();
|
23
|
+
}
|
24
|
+
|
25
|
+
createEventStream() {
|
26
|
+
const sessionId = this._session.id;
|
27
|
+
const logs = temporary.find.jsonl.sync(`${sessionId}.*`);
|
28
|
+
|
29
|
+
const toChromeTrace = this._chromeTransformer.createStream();
|
30
|
+
return this._bunyanTransformer.uniteSessionLogs(logs).pipe(toChromeTrace);
|
31
|
+
}
|
32
|
+
|
33
|
+
async finalize() {
|
34
|
+
const sessionId = this._session.id;
|
35
|
+
const logs = await temporary.find.jsonl.async(`${sessionId}.*`);
|
36
|
+
if (logs.length === 0) {
|
37
|
+
return;
|
38
|
+
}
|
39
|
+
|
40
|
+
if (this._shouldSaveLogs()) {
|
41
|
+
const rootDir = this._config.artifacts.rootDir;
|
42
|
+
|
43
|
+
await fs.mkdirp(rootDir);
|
44
|
+
|
45
|
+
const firstPass = this._bunyanTransformer.uniteSessionLogs(logs);
|
46
|
+
await this._chromeTransformer.scanThreadIDs(firstPass);
|
47
|
+
|
48
|
+
const secondPass = this._bunyanTransformer.uniteSessionLogs(logs);
|
49
|
+
const outStreams = [this._createPlainFileStream(), this._createChromeTraceStream()];
|
50
|
+
|
51
|
+
await Promise.all(outStreams.map(stream => {
|
52
|
+
return new Promise((resolve, reject) => {
|
53
|
+
stream.target
|
54
|
+
.on('finish', resolve)
|
55
|
+
.on('error', reject);
|
56
|
+
|
57
|
+
secondPass.pipe(stream.writable);
|
58
|
+
});
|
59
|
+
}));
|
60
|
+
}
|
61
|
+
|
62
|
+
await Promise.all(logs.map(filepath => fs.remove(filepath)));
|
63
|
+
}
|
64
|
+
|
65
|
+
finalizeSync() {
|
66
|
+
const sessionId = this._session.id;
|
67
|
+
const logs = temporary.find.jsonl.sync(`${sessionId}.*`);
|
68
|
+
if (logs.length === 0) {
|
69
|
+
return;
|
70
|
+
}
|
71
|
+
|
72
|
+
const shouldSaveLogs = this._shouldSaveLogs(true);
|
73
|
+
const rootDir = shouldSaveLogs ? this._config.artifacts.rootDir : '';
|
74
|
+
if (shouldSaveLogs) {
|
75
|
+
fs.mkdirpSync(rootDir);
|
76
|
+
}
|
77
|
+
|
78
|
+
for (const log of logs) {
|
79
|
+
if (shouldSaveLogs) {
|
80
|
+
const dest = path.join(rootDir, path.basename(log));
|
81
|
+
this._safeMoveSync(log, dest);
|
82
|
+
} else {
|
83
|
+
this._safeRemoveSync(log);
|
84
|
+
}
|
85
|
+
}
|
86
|
+
}
|
87
|
+
|
88
|
+
_createPlainFileStream() {
|
89
|
+
const rootDir = this._config.artifacts.rootDir;
|
90
|
+
const bunyanOptions = this._config.logger.options;
|
91
|
+
const transformer = this._bunyanTransformer.createPlainTransformer(bunyanOptions);
|
92
|
+
const fileStream = fs.createWriteStream(path.join(rootDir, 'detox.log'));
|
93
|
+
transformer.readable.pipe(fileStream);
|
94
|
+
|
95
|
+
return { writable: transformer.writable, target: fileStream };
|
96
|
+
}
|
97
|
+
|
98
|
+
_createChromeTraceStream() {
|
99
|
+
const rootDir = this._config.artifacts.rootDir;
|
100
|
+
const transformer = this._chromeTransformer.createSerializedStream();
|
101
|
+
const fileStream = fs.createWriteStream(path.join(rootDir, 'detox.trace.json'));
|
102
|
+
transformer.readable.pipe(fileStream);
|
103
|
+
|
104
|
+
return { writable: transformer.writable, target: fileStream };
|
105
|
+
}
|
106
|
+
|
107
|
+
/* istanbul ignore next */
|
108
|
+
_safeMoveSync(src, dest) {
|
109
|
+
// Using console.* instead of logger.* because this is the end of the execution,
|
110
|
+
// and the logger is already closed.
|
111
|
+
|
112
|
+
try {
|
113
|
+
fs.moveSync(src, dest);
|
114
|
+
} catch (moveError) {
|
115
|
+
console.warn(`Failed to move a log file from: ${src}.\nReason: ${moveError.message}`);
|
116
|
+
try {
|
117
|
+
fs.copySync(src, dest);
|
118
|
+
} catch (copyError) {
|
119
|
+
console.warn(`Attempt to copy the file also failed.\nReason: ${copyError.message}`);
|
120
|
+
}
|
121
|
+
}
|
122
|
+
}
|
123
|
+
|
124
|
+
/* istanbul ignore next */
|
125
|
+
_safeRemoveSync(filepath) {
|
126
|
+
try {
|
127
|
+
fs.removeSync(filepath);
|
128
|
+
} catch (removeError) {
|
129
|
+
console.warn(`Failed to remove a log file at: ${filepath}.\nReason: ${removeError.message}`);
|
130
|
+
}
|
131
|
+
}
|
132
|
+
|
133
|
+
/** @private */
|
134
|
+
get _config() {
|
135
|
+
// The config appears later in the lifecycle, so we need to access it lazily
|
136
|
+
return this._session.detoxConfig;
|
137
|
+
}
|
138
|
+
|
139
|
+
/** @private */
|
140
|
+
_shouldSaveLogs(isEmergencyExit = false) {
|
141
|
+
if (!this._config) {
|
142
|
+
return false;
|
143
|
+
}
|
144
|
+
|
145
|
+
const { rootDir, plugins } = this._config.artifacts;
|
146
|
+
if (!rootDir || !plugins) {
|
147
|
+
return false;
|
148
|
+
}
|
149
|
+
|
150
|
+
if (!plugins.log.enabled) {
|
151
|
+
return false;
|
152
|
+
}
|
153
|
+
|
154
|
+
if (!plugins.log.keepOnlyFailedTestsArtifacts) {
|
155
|
+
return true;
|
156
|
+
}
|
157
|
+
|
158
|
+
if (isEmergencyExit) {
|
159
|
+
return true;
|
160
|
+
}
|
161
|
+
|
162
|
+
return this._session.testResults.some(r => !r.success);
|
163
|
+
}
|
164
|
+
}
|
165
|
+
|
166
|
+
module.exports = DetoxLogFinalizer;
|
@@ -1,24 +1,35 @@
|
|
1
|
+
const getMainCategory = require('./getMainCategory');
|
2
|
+
|
1
3
|
class MessageStack {
|
2
4
|
constructor() {
|
3
5
|
this._map = {};
|
4
6
|
}
|
5
7
|
|
6
|
-
push(
|
7
|
-
|
8
|
-
|
8
|
+
push(context, msg) {
|
9
|
+
const hash = this._hash(context);
|
10
|
+
|
11
|
+
if (this._map[hash] == null) {
|
12
|
+
this._map[hash] = [];
|
9
13
|
}
|
10
14
|
|
11
|
-
return this._map[
|
15
|
+
return this._map[hash].push(msg);
|
12
16
|
}
|
13
17
|
|
14
|
-
pop(
|
15
|
-
const
|
18
|
+
pop(context) {
|
19
|
+
const hash = this._hash(context);
|
20
|
+
const stack = this._map[hash];
|
16
21
|
if (stack == null || stack.length === 0) {
|
17
22
|
return ['<no begin message>'];
|
18
23
|
}
|
19
24
|
|
20
25
|
return stack.pop();
|
21
26
|
}
|
27
|
+
|
28
|
+
_hash(context) {
|
29
|
+
const cat = getMainCategory(context.cat);
|
30
|
+
const tid = context.tid;
|
31
|
+
return `${cat}:${tid}`;
|
32
|
+
}
|
22
33
|
}
|
23
34
|
|
24
35
|
module.exports = MessageStack;
|
@@ -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
|
}
|
@@ -47,19 +47,36 @@ function overrideConsoleMethods(console, bunyanLogger) {
|
|
47
47
|
if (!console.__detox_log__) {
|
48
48
|
const log = bunyanLogger;
|
49
49
|
|
50
|
+
console.__detox_log__ = {
|
51
|
+
log: console.log,
|
52
|
+
info: console.info,
|
53
|
+
warn: console.warn,
|
54
|
+
trace: console.trace,
|
55
|
+
error: console.error,
|
56
|
+
debug: console.debug,
|
57
|
+
assert: console.assert,
|
58
|
+
};
|
59
|
+
|
50
60
|
override(console, 'log', log.info.bind(log));
|
61
|
+
override(console, 'info', log.info.bind(log));
|
51
62
|
override(console, 'warn', log.warn.bind(log));
|
52
63
|
override(console, 'trace', log.info.bind(log));
|
53
64
|
override(console, 'error', log.error.bind(log));
|
54
65
|
override(console, 'debug', log.debug.bind(log));
|
55
66
|
override(console, 'assert', log.error.bind(log));
|
56
|
-
|
57
|
-
console.__detox_log__ = log;
|
58
67
|
}
|
59
68
|
|
60
69
|
return console;
|
61
70
|
}
|
62
71
|
|
72
|
+
function restoreConsoleMethods(console) {
|
73
|
+
if (console.__detox_log__) {
|
74
|
+
Object.assign(console, console.__detox_log__);
|
75
|
+
delete console.__detox_log__;
|
76
|
+
}
|
77
|
+
}
|
78
|
+
|
63
79
|
module.exports = {
|
64
80
|
overrideConsoleMethods,
|
81
|
+
restoreConsoleMethods,
|
65
82
|
};
|
@@ -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;
|
@@ -0,0 +1,72 @@
|
|
1
|
+
const fs = require('fs');
|
2
|
+
const { PassThrough } = require('stream');
|
3
|
+
|
4
|
+
const bunyanDebugStream = require('bunyan-debug-stream');
|
5
|
+
const multiSort = require('multi-sort-stream');
|
6
|
+
const pipe = require('multipipe');
|
7
|
+
const stripAnsi = require('strip-ansi');
|
8
|
+
|
9
|
+
const DetoxJSONLParser = require('./DetoxJSONLParser');
|
10
|
+
const { mapTransform, through } = require('./transformers');
|
11
|
+
|
12
|
+
class BunyanTransformer {
|
13
|
+
/**
|
14
|
+
* @param {Detox.Logger} log
|
15
|
+
*/
|
16
|
+
constructor(log) {
|
17
|
+
this._jsonlParser = new DetoxJSONLParser(log);
|
18
|
+
}
|
19
|
+
|
20
|
+
/**
|
21
|
+
* @param {string[]} logFilePaths
|
22
|
+
*/
|
23
|
+
uniteSessionLogs(logFilePaths) {
|
24
|
+
const intermediate = mapTransform(BunyanTransformer.normalizeBunyanRecord);
|
25
|
+
const reemitError = (err) => intermediate.emit('error', err);
|
26
|
+
|
27
|
+
const jsonlStreams = logFilePaths.map(filePath => {
|
28
|
+
const { readable, writable } = this._jsonlParser.createTransformer();
|
29
|
+
fs.createReadStream(filePath)
|
30
|
+
.on('error', reemitError)
|
31
|
+
.pipe(writable);
|
32
|
+
|
33
|
+
return readable;
|
34
|
+
});
|
35
|
+
|
36
|
+
const multisorted = multiSort(jsonlStreams, BunyanTransformer.compareTimestamps);
|
37
|
+
return pipe(multisorted, intermediate, through());
|
38
|
+
}
|
39
|
+
|
40
|
+
createPlainTransformer(bunyanOptions) {
|
41
|
+
/** @type {*} */
|
42
|
+
const readable = new PassThrough({ encoding: 'utf8', objectMode: false });
|
43
|
+
const writable = bunyanDebugStream.default({
|
44
|
+
...bunyanOptions,
|
45
|
+
|
46
|
+
colors: false,
|
47
|
+
out: readable,
|
48
|
+
});
|
49
|
+
|
50
|
+
writable.on('error', /* istanbul ignore next */ (err) => readable.emit('error', err));
|
51
|
+
writable.on('finish', () => readable.end());
|
52
|
+
|
53
|
+
return {
|
54
|
+
writable,
|
55
|
+
readable,
|
56
|
+
};
|
57
|
+
}
|
58
|
+
|
59
|
+
static normalizeBunyanRecord(record) {
|
60
|
+
const value = record.value;
|
61
|
+
value.msg = stripAnsi(value.msg);
|
62
|
+
value.time = new Date(value.time);
|
63
|
+
|
64
|
+
return value;
|
65
|
+
}
|
66
|
+
|
67
|
+
static compareTimestamps(a, b) {
|
68
|
+
return +(a.value.time > b.value.time) - +(a.value.time < b.value.time);
|
69
|
+
}
|
70
|
+
}
|
71
|
+
|
72
|
+
module.exports = BunyanTransformer;
|