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.
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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 +49 -40
- package/internals.d.ts +63 -15
- package/local-cli/cli.js +1 -1
- package/local-cli/rebuild-framework-cache.js +1 -1
- package/local-cli/test.js +3 -2
- package/local-cli/test.test.js +1 -1
- package/local-cli/testCommand/TestRunnerCommand.js +10 -7
- package/package.json +5 -4
- package/runners/jest/globalSetup.js +1 -1
- package/runners/jest/globalTeardown.js +1 -1
- package/runners/jest/testEnvironment/index.js +33 -16
- package/runners/jest/testEnvironment/listeners/DetoxCoreListener.js +76 -41
- package/runners/jest/testEnvironment/listeners/SpecReporter.js +1 -1
- package/runners/jest/testEnvironment/listeners/WorkerAssignReporter.js +1 -1
- package/src/DetoxWorker.js +4 -1
- package/src/artifacts/ArtifactsManager.js +8 -23
- package/src/artifacts/instruments/ios/SimulatorInstrumentsRecording.js +3 -3
- package/src/artifacts/log/ios/SimulatorLogRecording.js +1 -1
- package/src/artifacts/screenshot/SimulatorScreenshotPlugin.js +1 -1
- package/src/artifacts/templates/artifact/Artifact.js +1 -1
- package/src/artifacts/templates/plugin/ArtifactPlugin.js +1 -1
- package/src/artifacts/utils/temporaryPath.js +18 -7
- package/src/artifacts/video/SimulatorRecordVideoPlugin.js +1 -1
- package/src/client/AsyncWebSocket.js +8 -17
- package/src/client/Client.js +1 -1
- package/src/configuration/collectCliConfig.js +1 -1
- package/src/configuration/composeDeviceConfig.js +1 -1
- package/src/configuration/composeLoggerConfig.js +17 -8
- package/src/configuration/composeRunnerConfig.js +1 -1
- package/src/configuration/index.js +5 -1
- package/src/configuration/loadExternalConfig.js +1 -1
- package/src/devices/allocation/DeviceAllocator.js +3 -2
- package/src/devices/allocation/drivers/android/emulator/AVDValidator.js +1 -1
- package/src/devices/allocation/drivers/android/emulator/EmulatorAllocDriver.js +3 -2
- package/src/devices/allocation/drivers/android/emulator/EmulatorAllocationHelper.js +1 -1
- package/src/devices/allocation/drivers/android/emulator/EmulatorLauncher.js +3 -2
- package/src/devices/allocation/drivers/android/emulator/EmulatorVersionResolver.js +4 -6
- package/src/devices/allocation/drivers/android/emulator/launchEmulatorProcess.js +1 -1
- package/src/devices/allocation/drivers/android/genycloud/GenyInstanceAllocationHelper.js +1 -1
- package/src/devices/common/drivers/android/genycloud/services/GenyInstanceNaming.js +3 -3
- package/src/devices/common/drivers/android/genycloud/services/GenyRecipesService.js +1 -1
- package/src/devices/common/drivers/android/tools/EmulatorTelnet.js +1 -1
- package/src/devices/common/drivers/android/tools/FreeDeviceFinder.js +1 -1
- package/src/devices/common/drivers/ios/tools/AppleSimUtils.js +1 -1
- package/src/devices/lifecycle/GenyGlobalLifecycleHandler.js +9 -13
- package/src/devices/runtime/RuntimeDevice.js +7 -8
- package/src/devices/runtime/drivers/DeviceDriverBase.js +1 -1
- package/src/devices/runtime/drivers/android/AndroidDriver.js +1 -1
- package/src/devices/runtime/drivers/ios/SimulatorDriver.js +1 -1
- package/src/ipc/IPCClient.js +3 -8
- package/src/ipc/IPCServer.js +11 -11
- package/src/ipc/{state.js → SessionState.js} +23 -50
- package/src/logger/DetoxLogger.js +264 -155
- package/src/logger/index.js +4 -0
- package/src/logger/utils/BunyanLogger.js +72 -0
- package/src/logger/utils/CategoryThreadDispatcher.js +58 -0
- package/src/logger/utils/MessageStack.js +24 -0
- package/src/logger/{TraceThreadDispatcher.js → utils/ThreadDispatcher.js} +34 -5
- package/src/logger/{customConsoleLogger.js → utils/customConsoleLogger.js} +4 -4
- package/src/logger/utils/sanitizeBunyanContext.js +28 -0
- package/src/logger/utils/tracerLegacy.js +25 -0
- package/src/realms/DetoxContext.js +65 -57
- package/src/realms/DetoxInternalsFacade.js +7 -5
- package/src/realms/DetoxPrimaryContext.js +125 -40
- package/src/realms/DetoxSecondaryContext.js +31 -30
- package/src/server/DetoxConnection.js +18 -23
- package/src/server/DetoxServer.js +7 -10
- package/src/server/DetoxSession.js +6 -6
- package/src/server/DetoxSessionManager.js +1 -1
- package/src/server/handlers/RegisteredConnectionHandler.js +1 -2
- package/src/symbols.js +12 -8
- package/src/utils/childProcess/exec.js +1 -1
- package/src/utils/childProcess/spawn.js +1 -1
- package/src/utils/streamUtils.js +10 -11
- package/src/utils/trace.js +2 -18
- package/src/utils/traceMethods.js +15 -0
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- package/src/logger/DetoxTraceEventBuilder.js +0 -21
- package/src/logger/DetoxTracer.js +0 -133
- package/src/utils/ChromeTracingExporter.js +0 -54
@@ -1,6 +1,6 @@
|
|
1
1
|
const isUndefined = (x) => x === undefined;
|
2
2
|
|
3
|
-
class
|
3
|
+
class ThreadDispatcher {
|
4
4
|
/**
|
5
5
|
* @param {object} options
|
6
6
|
* @param {Detox.Logger} options.logger
|
@@ -17,14 +17,31 @@ class TraceThreadDispatcher {
|
|
17
17
|
this.threads = [];
|
18
18
|
}
|
19
19
|
|
20
|
-
|
20
|
+
/**
|
21
|
+
* @param {string | number} [id]
|
22
|
+
* @returns {number}
|
23
|
+
*/
|
24
|
+
begin(id) {
|
21
25
|
const tid = this._findTID(id);
|
22
26
|
this.threads[tid] = id;
|
23
27
|
this.stacks[tid] = (this.stacks[tid] || 0) + 1;
|
24
28
|
return this._transpose(tid);
|
25
29
|
}
|
26
30
|
|
27
|
-
|
31
|
+
/**
|
32
|
+
* @param {string | number} [id]
|
33
|
+
* @returns {number}
|
34
|
+
*/
|
35
|
+
resolve(id) {
|
36
|
+
const tid = this._findTID(id);
|
37
|
+
return this._transpose(tid);
|
38
|
+
}
|
39
|
+
|
40
|
+
/**
|
41
|
+
* @param {string | number} [id]
|
42
|
+
* @returns {number}
|
43
|
+
*/
|
44
|
+
end(id) {
|
28
45
|
const tid = this._findTID(id);
|
29
46
|
if (this.stacks[tid] && --this.stacks[tid] === 0) {
|
30
47
|
delete this.threads[tid];
|
@@ -32,9 +49,17 @@ class TraceThreadDispatcher {
|
|
32
49
|
return this._transpose(tid);
|
33
50
|
}
|
34
51
|
|
52
|
+
/**
|
53
|
+
* @param {string | number | undefined} id
|
54
|
+
* @returns {number}
|
55
|
+
* @private
|
56
|
+
*
|
57
|
+
* Memory-efficient finder of a free item index in the threads array.
|
58
|
+
*/
|
35
59
|
_findTID(id) {
|
36
60
|
let tid = this.threads.indexOf(id);
|
37
61
|
if (tid === -1) {
|
62
|
+
// Try to find a recently released slot in the array:
|
38
63
|
tid = this.threads.findIndex(isUndefined);
|
39
64
|
}
|
40
65
|
return tid === -1 ? this.threads.length : tid;
|
@@ -43,10 +68,14 @@ class TraceThreadDispatcher {
|
|
43
68
|
_transpose(id) {
|
44
69
|
const result = this.min + id;
|
45
70
|
if (result > this.max) {
|
46
|
-
this.logger.warn(
|
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
|
+
);
|
47
75
|
}
|
76
|
+
|
48
77
|
return Math.min(result, this.max);
|
49
78
|
}
|
50
79
|
}
|
51
80
|
|
52
|
-
module.exports =
|
81
|
+
module.exports = ThreadDispatcher;
|
@@ -1,6 +1,6 @@
|
|
1
1
|
const util = require('util');
|
2
2
|
|
3
|
-
const callsites = require('
|
3
|
+
const callsites = require('../../utils/callsites');
|
4
4
|
|
5
5
|
const USER_STACK_FRAME_INDEX = 2;
|
6
6
|
|
@@ -25,20 +25,20 @@ function getStackDump() {
|
|
25
25
|
|
26
26
|
function proxyLog(bunyanLoggerFn) {
|
27
27
|
return (...args) => {
|
28
|
-
bunyanLoggerFn({
|
28
|
+
bunyanLoggerFn({ origin: getOrigin() }, util.format(...args));
|
29
29
|
};
|
30
30
|
}
|
31
31
|
|
32
32
|
function proxyTracing(bunyanLoggerFn) {
|
33
33
|
return (...args) => {
|
34
|
-
bunyanLoggerFn({
|
34
|
+
bunyanLoggerFn({ 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({
|
41
|
+
bunyanLoggerFn({ origin: getOrigin() }, 'AssertionError:', util.format(...args));
|
42
42
|
}
|
43
43
|
};
|
44
44
|
}
|
@@ -0,0 +1,28 @@
|
|
1
|
+
const _ = require('lodash');
|
2
|
+
|
3
|
+
const RESERVED_PROPERTIES = [
|
4
|
+
'hostname',
|
5
|
+
'level',
|
6
|
+
'msg',
|
7
|
+
'name',
|
8
|
+
'pid',
|
9
|
+
'time',
|
10
|
+
];
|
11
|
+
|
12
|
+
function hasProperty(p) {
|
13
|
+
return _.has(this, p);
|
14
|
+
}
|
15
|
+
|
16
|
+
function hasReservedProperties(o) {
|
17
|
+
return RESERVED_PROPERTIES.some(hasProperty, o); // eslint-disable-line unicorn/no-array-method-this-argument
|
18
|
+
}
|
19
|
+
|
20
|
+
function escapeCallback(value, key) {
|
21
|
+
return RESERVED_PROPERTIES.includes(key) ? `${key}$` : key;
|
22
|
+
}
|
23
|
+
|
24
|
+
function sanitizeBunyanContext(context) {
|
25
|
+
return hasReservedProperties(context) ? _.mapKeys(context, escapeCallback) : context;
|
26
|
+
}
|
27
|
+
|
28
|
+
module.exports = sanitizeBunyanContext;
|
@@ -0,0 +1,25 @@
|
|
1
|
+
const methods = {
|
2
|
+
startSection(logger) {
|
3
|
+
return (msg, args) => logger.trace.begin(args, msg);
|
4
|
+
},
|
5
|
+
|
6
|
+
endSection(logger) {
|
7
|
+
return (msg, args) => logger.trace.end(args);
|
8
|
+
},
|
9
|
+
|
10
|
+
traceCall(logger) {
|
11
|
+
return (name, action) => logger.trace.complete(name, action);
|
12
|
+
},
|
13
|
+
};
|
14
|
+
|
15
|
+
function installLegacyTracerInterface(logger, target) {
|
16
|
+
target.traceCall = methods.traceCall(logger);
|
17
|
+
target.trace = Object.freeze({
|
18
|
+
startSection: methods.startSection(logger),
|
19
|
+
endSection: methods.endSection(logger),
|
20
|
+
});
|
21
|
+
|
22
|
+
return this;
|
23
|
+
}
|
24
|
+
|
25
|
+
module.exports = { install: installLegacyTracerInterface };
|
@@ -1,48 +1,63 @@
|
|
1
1
|
const funpermaproxy = require('funpermaproxy');
|
2
2
|
|
3
|
+
const temporary = require('../artifacts/utils/temporaryPath');
|
3
4
|
const { DetoxRuntimeError } = require('../errors');
|
4
|
-
const DetoxLogger = require('../logger
|
5
|
-
const DetoxTracer = require('../logger/DetoxTracer');
|
5
|
+
const { DetoxLogger, installLegacyTracerInterface } = require('../logger');
|
6
6
|
const symbols = require('../symbols');
|
7
7
|
|
8
8
|
const DetoxConstants = require('./DetoxConstants');
|
9
9
|
|
10
10
|
const $cleanup = Symbol('cleanup');
|
11
|
-
const $logger = Symbol('logger');
|
12
11
|
const $restoreSessionState = Symbol('restoreSessionState');
|
13
12
|
const $sessionState = Symbol('restoreSessionState');
|
14
|
-
const $
|
15
|
-
|
16
|
-
const _worker = Symbol('worker');
|
13
|
+
const $status = Symbol('status');
|
14
|
+
const $worker = Symbol('worker');
|
17
15
|
|
18
16
|
class DetoxContext {
|
19
17
|
constructor() {
|
20
|
-
|
21
|
-
this[
|
18
|
+
/** @type {DetoxInternals.DetoxStatus} */
|
19
|
+
this[$status] = 'inactive';
|
20
|
+
|
21
|
+
const _init = this[symbols.init].bind(this);
|
22
|
+
this[symbols.init] = async (opts) => {
|
23
|
+
this[$status] = 'init';
|
24
|
+
await _init(opts);
|
25
|
+
this[$status] = 'active';
|
26
|
+
};
|
27
|
+
|
28
|
+
const _cleanup = this[symbols.cleanup].bind(this);
|
29
|
+
this[symbols.cleanup] = async () => {
|
30
|
+
this[$status] = 'cleanup';
|
31
|
+
try {
|
32
|
+
await _cleanup();
|
33
|
+
} finally {
|
34
|
+
this[$status] = 'inactive';
|
35
|
+
}
|
36
|
+
};
|
37
|
+
|
38
|
+
this[symbols.getStatus] = this[symbols.getStatus].bind(this);
|
22
39
|
this[symbols.reportFailedTests] = this[symbols.reportFailedTests].bind(this);
|
23
40
|
this[symbols.resolveConfig] = this[symbols.resolveConfig].bind(this);
|
24
|
-
this[symbols.
|
25
|
-
this[symbols.
|
41
|
+
this[symbols.installWorker] = this[symbols.installWorker].bind(this);
|
42
|
+
this[symbols.uninstallWorker] = this[symbols.uninstallWorker].bind(this);
|
26
43
|
|
27
44
|
this[$sessionState] = this[$restoreSessionState]();
|
28
45
|
|
29
|
-
const loggerConfig = this[$sessionState].detoxConfig
|
30
|
-
? this[$sessionState].detoxConfig.logger
|
31
|
-
: undefined;
|
32
|
-
|
33
46
|
/**
|
34
|
-
* @protected
|
35
47
|
* @type {DetoxLogger & Detox.Logger}
|
36
48
|
*/
|
37
|
-
this[
|
38
|
-
|
39
|
-
|
40
|
-
|
49
|
+
this[symbols.logger] = new DetoxLogger({
|
50
|
+
file: temporary.for.jsonl(`${this[$sessionState].id}.${process.pid}`),
|
51
|
+
userConfig: this[$sessionState].detoxConfig
|
52
|
+
? this[$sessionState].detoxConfig.logger
|
53
|
+
: null,
|
41
54
|
});
|
42
|
-
|
43
|
-
this.
|
55
|
+
|
56
|
+
this.log = this[symbols.logger].child({ cat: 'user' });
|
57
|
+
installLegacyTracerInterface(this.log, this);
|
58
|
+
|
44
59
|
/** @type {import('../DetoxWorker') | null} */
|
45
|
-
this[
|
60
|
+
this[$worker] = null;
|
46
61
|
}
|
47
62
|
|
48
63
|
//#region Public members
|
@@ -62,19 +77,6 @@ class DetoxContext {
|
|
62
77
|
return DetoxConstants;
|
63
78
|
}
|
64
79
|
|
65
|
-
/**
|
66
|
-
* @returns {Detox.Logger}
|
67
|
-
*/
|
68
|
-
get log() {
|
69
|
-
return this[$logger];
|
70
|
-
}
|
71
|
-
|
72
|
-
/**
|
73
|
-
* @returns {Detox.Tracer}
|
74
|
-
*/
|
75
|
-
get trace() {
|
76
|
-
return this[$tracer];
|
77
|
-
}
|
78
80
|
//#endregion
|
79
81
|
|
80
82
|
//#region Internal members
|
@@ -96,57 +98,63 @@ class DetoxContext {
|
|
96
98
|
[symbols.reportFailedTests](_testFilePaths, _permanent) {}
|
97
99
|
/**
|
98
100
|
* @abstract
|
99
|
-
* @param {Partial<DetoxInternals.
|
101
|
+
* @param {Partial<DetoxInternals.DetoxInitOptions>} _opts
|
100
102
|
* @returns {Promise<DetoxInternals.RuntimeConfig>}
|
101
103
|
*/
|
102
104
|
async [symbols.resolveConfig](_opts) { return null; }
|
103
105
|
|
106
|
+
[symbols.getStatus]() {
|
107
|
+
return this[$status];
|
108
|
+
}
|
109
|
+
|
104
110
|
get [symbols.worker]() {
|
105
|
-
if (!this[
|
111
|
+
if (!this[$worker]) {
|
106
112
|
throw new DetoxRuntimeError({
|
107
|
-
message: `Detox worker instance has not been
|
108
|
-
hint: DetoxRuntimeError.reportIssueIfJest + '\n' + 'Otherwise, make sure you call detox.
|
113
|
+
message: `Detox worker instance has not been installed in this context (${this.constructor.name}).`,
|
114
|
+
hint: DetoxRuntimeError.reportIssueIfJest + '\n' + 'Otherwise, make sure you call detox.installWorker() beforehand.',
|
109
115
|
});
|
110
116
|
}
|
111
117
|
|
112
|
-
return this[
|
118
|
+
return this[$worker];
|
113
119
|
}
|
114
120
|
|
115
121
|
/**
|
116
122
|
* @abstract
|
117
|
-
* @param {Partial<DetoxInternals.
|
123
|
+
* @param {Partial<DetoxInternals.DetoxInitOptions>} [_opts]
|
118
124
|
* @returns {Promise<void>}
|
119
125
|
*/
|
120
|
-
async [symbols.
|
126
|
+
async [symbols.init](_opts = {}) {}
|
121
127
|
|
122
128
|
/**
|
123
|
-
* @param {Partial<DetoxInternals.
|
129
|
+
* @param {Partial<DetoxInternals.DetoxInstallWorkerOptions>} [opts]
|
124
130
|
*/
|
125
|
-
async [symbols.
|
126
|
-
|
127
|
-
|
128
|
-
|
131
|
+
async [symbols.installWorker](opts) {
|
132
|
+
if (opts.global) {
|
133
|
+
opts.global['__detox__'] = this;
|
134
|
+
this.log.overrideConsole(opts.global);
|
135
|
+
}
|
129
136
|
|
130
137
|
const DetoxWorker = require('../DetoxWorker');
|
131
|
-
DetoxWorker.global =
|
132
|
-
this[
|
133
|
-
|
138
|
+
DetoxWorker.global = opts.global || global;
|
139
|
+
this[$worker] = new DetoxWorker(this);
|
140
|
+
this[$worker].id = opts.workerId;
|
141
|
+
await this[$worker].init();
|
134
142
|
}
|
135
143
|
|
136
|
-
async [symbols.
|
144
|
+
async [symbols.uninstallWorker]() {
|
137
145
|
try {
|
138
|
-
if (this[
|
139
|
-
await this[
|
146
|
+
if (this[$worker]) {
|
147
|
+
await this[$worker].cleanup();
|
140
148
|
}
|
141
149
|
} finally {
|
142
|
-
this[
|
150
|
+
this[$worker] = null;
|
143
151
|
}
|
144
152
|
}
|
145
153
|
|
146
154
|
/**
|
147
155
|
* @abstract
|
148
156
|
*/
|
149
|
-
async [symbols.
|
157
|
+
async [symbols.cleanup]() {}
|
150
158
|
//#endregion
|
151
159
|
|
152
160
|
//#region Protected members
|
@@ -163,8 +171,8 @@ class DetoxContext {
|
|
163
171
|
module.exports = DetoxContext;
|
164
172
|
module.exports.protected = {
|
165
173
|
$cleanup,
|
166
|
-
$logger,
|
167
174
|
$restoreSessionState,
|
175
|
+
$status,
|
168
176
|
$sessionState,
|
169
|
-
$
|
177
|
+
$worker,
|
170
178
|
};
|
@@ -8,11 +8,12 @@ class DetoxInternalsFacade {
|
|
8
8
|
*/
|
9
9
|
constructor(context) {
|
10
10
|
this.config = context[symbols.config];
|
11
|
-
this.
|
12
|
-
this.
|
13
|
-
this.
|
14
|
-
this.
|
15
|
-
this.
|
11
|
+
this.getStatus = context[symbols.getStatus];
|
12
|
+
this.init = context[symbols.init];
|
13
|
+
this.cleanup = context[symbols.cleanup];
|
14
|
+
this.log = context[symbols.logger];
|
15
|
+
this.installWorker = context[symbols.installWorker];
|
16
|
+
this.uninstallWorker = context[symbols.uninstallWorker];
|
16
17
|
this.onHookFailure = context[symbols.onHookFailure];
|
17
18
|
this.onHookStart = context[symbols.onHookStart];
|
18
19
|
this.onHookSuccess = context[symbols.onHookSuccess];
|
@@ -28,6 +29,7 @@ class DetoxInternalsFacade {
|
|
28
29
|
this.reportFailedTests = context[symbols.reportFailedTests];
|
29
30
|
this.resolveConfig = context[symbols.resolveConfig];
|
30
31
|
this.session = context[symbols.session];
|
32
|
+
this.trace = context.trace;
|
31
33
|
this.worker = funpermaproxy(() => context[symbols.worker]);
|
32
34
|
}
|
33
35
|
}
|
@@ -1,24 +1,34 @@
|
|
1
1
|
const path = require('path');
|
2
2
|
const { URL } = require('url');
|
3
|
+
const { promisify } = require('util');
|
3
4
|
|
4
5
|
const fs = require('fs-extra');
|
6
|
+
const glob = require('glob');
|
5
7
|
const pipe = require('multipipe');
|
8
|
+
const onSignalExit = require('signal-exit');
|
6
9
|
|
7
10
|
const temporary = require('../artifacts/utils/temporaryPath');
|
8
11
|
const { DetoxRuntimeError } = require('../errors');
|
9
|
-
const
|
12
|
+
const SessionState = require('../ipc/SessionState');
|
10
13
|
const symbols = require('../symbols');
|
11
14
|
|
15
|
+
const globAsync = promisify(glob);
|
16
|
+
const globSync = glob.sync;
|
17
|
+
|
12
18
|
const DetoxContext = require('./DetoxContext');
|
13
19
|
|
14
|
-
const { $
|
20
|
+
const { $restoreSessionState, $sessionState, $worker } = DetoxContext.protected;
|
15
21
|
|
16
22
|
const _finalizeLogs = Symbol('finalizeLogs');
|
23
|
+
const _finalizeLogsSync = Symbol('finalizeLogsSync');
|
17
24
|
const _globalLifecycleHandler = Symbol('globalLifecycleHandler');
|
18
25
|
const _ipcServer = Symbol('ipcServer');
|
19
26
|
const _resetLockFile = Symbol('resetLockFile');
|
20
27
|
const _wss = Symbol('wss');
|
21
28
|
const _dirty = Symbol('dirty');
|
29
|
+
const _emergencyTeardown = Symbol('emergencyTeardown');
|
30
|
+
const _areLogsEnabled = Symbol('areLogsEnabled');
|
31
|
+
const _lifecycleLogger = Symbol('lifecycleLogger');
|
22
32
|
|
23
33
|
class DetoxPrimaryContext extends DetoxContext {
|
24
34
|
constructor() {
|
@@ -31,6 +41,8 @@ class DetoxPrimaryContext extends DetoxContext {
|
|
31
41
|
* @type {import('../ipc/IPCServer') | null}
|
32
42
|
*/
|
33
43
|
this[_ipcServer] = null;
|
44
|
+
/** @type {Detox.Logger} */
|
45
|
+
this[_lifecycleLogger] = this[symbols.logger].child({ cat: 'lifecycle' });
|
34
46
|
}
|
35
47
|
|
36
48
|
//#region Internal members
|
@@ -41,7 +53,7 @@ class DetoxPrimaryContext extends DetoxContext {
|
|
41
53
|
}
|
42
54
|
|
43
55
|
async [symbols.resolveConfig](opts = {}) {
|
44
|
-
const session = this[
|
56
|
+
const session = this[$sessionState];
|
45
57
|
if (!session.detoxConfig) {
|
46
58
|
const configuration = require('../configuration');
|
47
59
|
session.detoxConfig = await configuration.composeDetoxConfig(opts);
|
@@ -52,9 +64,9 @@ class DetoxPrimaryContext extends DetoxContext {
|
|
52
64
|
|
53
65
|
/**
|
54
66
|
* @override
|
55
|
-
* @param {Partial<DetoxInternals.
|
67
|
+
* @param {Partial<DetoxInternals.DetoxInitOptions>} [opts]
|
56
68
|
*/
|
57
|
-
async [symbols.
|
69
|
+
async [symbols.init](opts = {}) {
|
58
70
|
if (this[_dirty]) {
|
59
71
|
throw new DetoxRuntimeError({
|
60
72
|
message: 'Cannot initialize primary Detox context more than once.',
|
@@ -63,6 +75,8 @@ class DetoxPrimaryContext extends DetoxContext {
|
|
63
75
|
}
|
64
76
|
|
65
77
|
this[_dirty] = true;
|
78
|
+
onSignalExit(this[_emergencyTeardown]);
|
79
|
+
|
66
80
|
const detoxConfig = await this[symbols.resolveConfig](opts);
|
67
81
|
|
68
82
|
const {
|
@@ -71,18 +85,16 @@ class DetoxPrimaryContext extends DetoxContext {
|
|
71
85
|
logger: loggerConfig,
|
72
86
|
session: sessionConfig
|
73
87
|
} = detoxConfig;
|
74
|
-
await this[
|
88
|
+
await this[symbols.logger].setConfig(loggerConfig);
|
75
89
|
|
76
|
-
this.trace.begin({
|
77
|
-
|
78
|
-
|
79
|
-
name: process.argv.slice(1).join(' '),
|
80
|
-
});
|
90
|
+
this[_lifecycleLogger].trace.begin({
|
91
|
+
data: this[$sessionState],
|
92
|
+
}, process.argv.slice(1).join(' '));
|
81
93
|
|
82
94
|
const IPCServer = require('../ipc/IPCServer');
|
83
95
|
this[_ipcServer] = new IPCServer({
|
84
96
|
sessionState: this[$sessionState],
|
85
|
-
logger: this[
|
97
|
+
logger: this[symbols.logger],
|
86
98
|
});
|
87
99
|
|
88
100
|
await this[_ipcServer].init();
|
@@ -111,63 +123,98 @@ class DetoxPrimaryContext extends DetoxContext {
|
|
111
123
|
}
|
112
124
|
|
113
125
|
if (!sessionConfig.server && this[_wss]) {
|
126
|
+
// @ts-ignore
|
114
127
|
sessionConfig.server = `ws://localhost:${this[_wss].port}`;
|
115
128
|
}
|
116
129
|
|
117
130
|
await fs.writeFile(this[$sessionState].detoxConfigSnapshotPath, this[$sessionState].stringify());
|
118
131
|
process.env.DETOX_CONFIG_SNAPSHOT_PATH = this[$sessionState].detoxConfigSnapshotPath;
|
119
132
|
|
120
|
-
|
133
|
+
if (opts.workerId !== null) {
|
134
|
+
await this[symbols.installWorker](opts);
|
135
|
+
}
|
121
136
|
}
|
122
137
|
|
123
138
|
/**
|
124
139
|
* @override
|
125
|
-
* @param {Partial<DetoxInternals.
|
140
|
+
* @param {Partial<DetoxInternals.DetoxInstallWorkerOptions>} [opts]
|
126
141
|
*/
|
127
|
-
async [symbols.
|
128
|
-
const workerId = opts.workerId ||
|
129
|
-
this[$sessionState].workerId = workerId;
|
142
|
+
async [symbols.installWorker](opts = {}) {
|
143
|
+
const workerId = this[$sessionState].workerId = opts.workerId = opts.workerId || 'worker';
|
130
144
|
this[_ipcServer].onRegisterWorker({ workerId });
|
131
|
-
|
145
|
+
|
146
|
+
await super[symbols.installWorker](opts);
|
132
147
|
}
|
133
148
|
|
134
149
|
/** @override */
|
135
|
-
async [symbols.
|
150
|
+
async [symbols.cleanup]() {
|
151
|
+
try {
|
152
|
+
if (this[$worker]) {
|
153
|
+
await this[symbols.uninstallWorker]();
|
154
|
+
}
|
155
|
+
} finally {
|
156
|
+
if (this[_globalLifecycleHandler]) {
|
157
|
+
await this[_globalLifecycleHandler].globalCleanup();
|
158
|
+
this[_globalLifecycleHandler] = null;
|
159
|
+
}
|
160
|
+
|
161
|
+
if (this[_wss]) {
|
162
|
+
await this[_wss].close();
|
163
|
+
this[_wss] = null;
|
164
|
+
}
|
165
|
+
|
166
|
+
if (this[_ipcServer]) {
|
167
|
+
await this[_ipcServer].dispose();
|
168
|
+
this[_ipcServer] = null;
|
169
|
+
}
|
170
|
+
|
171
|
+
await fs.remove(this[$sessionState].detoxConfigSnapshotPath);
|
172
|
+
|
173
|
+
try {
|
174
|
+
this[_lifecycleLogger].trace.end();
|
175
|
+
await this[_finalizeLogs]();
|
176
|
+
} catch (err) {
|
177
|
+
this[_lifecycleLogger].error({ err }, 'Encountered an error while merging the process logs:');
|
178
|
+
}
|
179
|
+
}
|
180
|
+
}
|
181
|
+
|
182
|
+
[_emergencyTeardown] = (_code, signal) => {
|
183
|
+
if (!signal) {
|
184
|
+
return;
|
185
|
+
}
|
186
|
+
|
136
187
|
if (this[_globalLifecycleHandler]) {
|
137
|
-
|
188
|
+
this[_globalLifecycleHandler].emergencyCleanup();
|
138
189
|
this[_globalLifecycleHandler] = null;
|
139
190
|
}
|
140
191
|
|
141
192
|
if (this[_wss]) {
|
142
|
-
|
143
|
-
this[_wss] = null;
|
193
|
+
this[_wss].close();
|
144
194
|
}
|
145
195
|
|
146
196
|
if (this[_ipcServer]) {
|
147
|
-
|
148
|
-
this[_ipcServer] = null;
|
197
|
+
this[_ipcServer].dispose();
|
149
198
|
}
|
150
199
|
|
151
|
-
await fs.remove(this[$sessionState].detoxConfigSnapshotPath);
|
152
|
-
delete process.env.DETOX_CONFIG_SNAPSHOT_PATH;
|
153
|
-
|
154
200
|
try {
|
155
|
-
this.trace.end({
|
156
|
-
|
201
|
+
this[_lifecycleLogger].trace.end({ abortSignal: signal });
|
202
|
+
this[_finalizeLogsSync]();
|
157
203
|
} catch (err) {
|
158
|
-
this[
|
204
|
+
this[symbols.logger].error({ err }, 'Encountered an error while merging the process logs:');
|
159
205
|
}
|
160
|
-
}
|
206
|
+
};
|
207
|
+
|
161
208
|
//#endregion
|
162
209
|
|
163
210
|
//#region Protected members
|
164
211
|
/**
|
165
212
|
* @protected
|
166
213
|
* @override
|
167
|
-
* @return {
|
214
|
+
* @return {SessionState}
|
168
215
|
*/
|
169
216
|
[$restoreSessionState]() {
|
170
|
-
return new
|
217
|
+
return new SessionState({
|
171
218
|
detoxConfigSnapshotPath: temporary.for.json(),
|
172
219
|
detoxIPCServer: `primary-${process.pid}`,
|
173
220
|
});
|
@@ -176,17 +223,16 @@ class DetoxPrimaryContext extends DetoxContext {
|
|
176
223
|
|
177
224
|
//#region Private members
|
178
225
|
async[_finalizeLogs]() {
|
179
|
-
const
|
226
|
+
const sessionId = this[$sessionState].id;
|
227
|
+
const logs = await globAsync(temporary.for.jsonl(`${sessionId}.*`));
|
180
228
|
if (logs.length === 0) {
|
181
229
|
return;
|
182
230
|
}
|
183
231
|
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
const enabled = rootDir && (typeof logConfig === 'string' ? logConfig !== 'none' : logConfig.enabled);
|
232
|
+
if (this[_areLogsEnabled]()) {
|
233
|
+
const streamUtils = require('../utils/streamUtils');
|
234
|
+
const { rootDir } = this[symbols.config].artifacts;
|
188
235
|
|
189
|
-
if (enabled) {
|
190
236
|
await fs.mkdirp(rootDir);
|
191
237
|
const [out1Stream, out2Stream, out3Stream] = ['detox.log.jsonl', 'detox.log', 'detox.trace.json']
|
192
238
|
.map((filename) => fs.createWriteStream(path.join(rootDir, filename)));
|
@@ -198,7 +244,7 @@ class DetoxPrimaryContext extends DetoxContext {
|
|
198
244
|
|
199
245
|
await Promise.all([
|
200
246
|
pipe(mergedStream, streamUtils.writeJSONL(), out1Stream),
|
201
|
-
pipe(mergedStream, streamUtils.debugStream(this[
|
247
|
+
pipe(mergedStream, streamUtils.debugStream(this[symbols.logger].config.options), out2Stream),
|
202
248
|
pipe(mergedStream, streamUtils.chromeTraceStream(), streamUtils.writeJSON(), out3Stream),
|
203
249
|
]);
|
204
250
|
}
|
@@ -206,6 +252,45 @@ class DetoxPrimaryContext extends DetoxContext {
|
|
206
252
|
await Promise.all(logs.map(filepath => fs.remove(filepath)));
|
207
253
|
}
|
208
254
|
|
255
|
+
async[_finalizeLogsSync]() {
|
256
|
+
const logsEnabled = this[_areLogsEnabled]();
|
257
|
+
|
258
|
+
const { rootDir } = this[symbols.config].artifacts;
|
259
|
+
|
260
|
+
if (logsEnabled) {
|
261
|
+
fs.mkdirpSync(rootDir);
|
262
|
+
}
|
263
|
+
|
264
|
+
const sessionId = this[$sessionState].id;
|
265
|
+
const logs = globSync(temporary.for.jsonl(`${sessionId}.*`));
|
266
|
+
|
267
|
+
for (const log of logs) {
|
268
|
+
if (logsEnabled) {
|
269
|
+
fs.moveSync(log, path.join(rootDir, path.basename(log)));
|
270
|
+
} else {
|
271
|
+
fs.removeSync(log);
|
272
|
+
}
|
273
|
+
}
|
274
|
+
}
|
275
|
+
|
276
|
+
[_areLogsEnabled]() {
|
277
|
+
const { rootDir, plugins } = this[symbols.config].artifacts || {};
|
278
|
+
if (!rootDir || !plugins) {
|
279
|
+
return false;
|
280
|
+
}
|
281
|
+
|
282
|
+
if (!plugins.log.enabled) {
|
283
|
+
return false;
|
284
|
+
}
|
285
|
+
|
286
|
+
if (!plugins.log.keepOnlyFailedTestsArtifacts) {
|
287
|
+
return true;
|
288
|
+
}
|
289
|
+
|
290
|
+
const { failedTestFiles, testFilesToRetry } = this[$sessionState];
|
291
|
+
return failedTestFiles.length + testFilesToRetry.length > 0;
|
292
|
+
}
|
293
|
+
|
209
294
|
async[_resetLockFile]() {
|
210
295
|
const DeviceRegistry = require('../devices/DeviceRegistry');
|
211
296
|
|