detox 20.0.1-breaking.new-global-lifecycle.0 → 20.0.1
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.1-breaking.new-global-lifecycle.0/detox-20.0.1-breaking.new-global-lifecycle.0-javadoc.jar → 20.0.1/detox-20.0.1-javadoc.jar} +0 -0
- package/Detox-android/com/wix/detox/20.0.1/detox-20.0.1-javadoc.jar.md5 +1 -0
- package/Detox-android/com/wix/detox/20.0.1/detox-20.0.1-javadoc.jar.sha1 +1 -0
- package/Detox-android/com/wix/detox/20.0.1/detox-20.0.1-javadoc.jar.sha256 +1 -0
- package/Detox-android/com/wix/detox/20.0.1/detox-20.0.1-javadoc.jar.sha512 +1 -0
- package/Detox-android/com/wix/detox/{20.0.1-breaking.new-global-lifecycle.0/detox-20.0.1-breaking.new-global-lifecycle.0-sources.jar → 20.0.1/detox-20.0.1-sources.jar} +0 -0
- package/Detox-android/com/wix/detox/20.0.1/detox-20.0.1-sources.jar.md5 +1 -0
- package/Detox-android/com/wix/detox/20.0.1/detox-20.0.1-sources.jar.sha1 +1 -0
- package/Detox-android/com/wix/detox/20.0.1/detox-20.0.1-sources.jar.sha256 +1 -0
- package/Detox-android/com/wix/detox/20.0.1/detox-20.0.1-sources.jar.sha512 +1 -0
- package/Detox-android/com/wix/detox/20.0.1/detox-20.0.1.aar +0 -0
- package/Detox-android/com/wix/detox/20.0.1/detox-20.0.1.aar.md5 +1 -0
- package/Detox-android/com/wix/detox/20.0.1/detox-20.0.1.aar.sha1 +1 -0
- package/Detox-android/com/wix/detox/20.0.1/detox-20.0.1.aar.sha256 +1 -0
- package/Detox-android/com/wix/detox/20.0.1/detox-20.0.1.aar.sha512 +1 -0
- package/Detox-android/com/wix/detox/{20.0.1-breaking.new-global-lifecycle.0/detox-20.0.1-breaking.new-global-lifecycle.0.pom → 20.0.1/detox-20.0.1.pom} +1 -7
- package/Detox-android/com/wix/detox/20.0.1/detox-20.0.1.pom.md5 +1 -0
- package/Detox-android/com/wix/detox/20.0.1/detox-20.0.1.pom.sha1 +1 -0
- package/Detox-android/com/wix/detox/20.0.1/detox-20.0.1.pom.sha256 +1 -0
- package/Detox-android/com/wix/detox/20.0.1/detox-20.0.1.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/README.md +1 -1
- package/android/build.gradle +12 -7
- package/android/detox/build.gradle +13 -9
- package/android/detox/proguard-rules-app.pro +6 -0
- package/android/detox/proguard-rules.pro +3 -0
- package/android/detox/publishing.gradle +27 -27
- package/android/detox/src/full/java/com/wix/detox/DetoxCrashHandler.kt +1 -1
- package/android/detox/src/full/java/com/wix/detox/LaunchArgs.java +9 -0
- package/android/detox/src/full/java/com/wix/detox/TestEngineFacade.kt +1 -1
- package/android/detox/src/full/java/com/wix/detox/reactnative/ReactNativeExtension.kt +15 -2
- package/android/detox/src/full/java/com/wix/detox/reactnative/ReactNativeIdlingResources.kt +43 -38
- package/android/detox/src/full/java/com/wix/detox/reactnative/idlingresources/IdlingResourceDescription.kt +19 -13
- package/android/detox/src/full/java/com/wix/detox/reactnative/idlingresources/NetworkIdlingResource.java +33 -30
- package/android/detox/src/full/java/com/wix/detox/reactnative/idlingresources/timers/DelegatedIdleInterrogationStrategy.kt +7 -27
- package/android/detox/src/full/java/com/wix/detox/reactnative/idlingresources/timers/IdleInterrogationStrategy.kt +1 -11
- package/android/detox/src/main/java/com/wix/detox/common/TextFileReader.kt +1 -1
- package/android/detox/src/testFull/java/com/wix/detox/espresso/action/DetoxMultiTapSpec.kt +4 -3
- package/android/detox/src/testFull/java/com/wix/detox/reactnative/idlingresources/NetworkIdlingResourcesTest.kt +61 -0
- package/android/detox/src/testFull/java/com/wix/detox/reactnative/idlingresources/timers/DelegatedIdleInterrogationStrategySpec.kt +3 -11
- package/index.d.ts +198 -57
- package/internals.d.ts +219 -45
- package/local-cli/build.js +2 -2
- package/local-cli/build.test.js +14 -14
- package/local-cli/cli.js +8 -6
- package/local-cli/init.js +61 -21
- package/local-cli/rebuild-framework-cache.js +1 -1
- package/local-cli/reset-lock-file.js +16 -0
- package/local-cli/templates/jest.js +13 -10
- package/local-cli/test.js +14 -8
- package/local-cli/test.test.js +148 -61
- package/local-cli/testCommand/TestRunnerCommand.js +78 -72
- 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/local-cli/utils/jestInternals.js +4 -1
- package/package.json +23 -16
- package/runners/deprecation.js +42 -44
- package/runners/jest/globalSetup.js +1 -1
- package/runners/jest/globalTeardown.js +1 -1
- 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 +33 -2
- package/runners/jest/testEnvironment/index.js +119 -69
- package/runners/jest/testEnvironment/listeners/DetoxCoreListener.js +94 -51
- package/runners/jest/testEnvironment/listeners/DetoxPlatformFilterListener.js +1 -1
- package/runners/jest/testEnvironment/listeners/SpecReporter.js +14 -16
- package/runners/jest/testEnvironment/listeners/WorkerAssignReporter.js +2 -6
- package/runners/jest/testEnvironment/utils/assertJestCircus27.js +17 -3
- package/runners/jest/testEnvironment/utils/assertJestCircus27.test.js +0 -1
- package/src/DetoxWorker.js +105 -62
- package/src/android/core/NativeElement.js +56 -20
- package/src/android/core/NativeExpect.js +28 -9
- package/src/android/interactions/native.js +25 -18
- package/src/artifacts/ArtifactsManager.js +14 -47
- 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/timeline/TimelineContextTypes.js +7 -0
- 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 +19 -2
- package/src/client/actions/formatters/sync-resources/NetworkFormatter.js +1 -1
- package/src/configuration/collectCliConfig.js +1 -12
- package/src/configuration/composeAppsConfig.js +4 -0
- package/src/configuration/composeDeviceConfig.js +1 -1
- package/src/configuration/composeLoggerConfig.js +19 -10
- package/src/configuration/composeRunnerConfig.js +62 -9
- package/src/configuration/index.js +14 -9
- package/src/configuration/loadExternalConfig.js +1 -1
- package/src/devices/allocation/DeviceAllocator.js +3 -2
- package/src/devices/allocation/drivers/android/emulator/AVDValidator.js +5 -5
- package/src/devices/allocation/drivers/android/emulator/EmulatorAllocDriver.js +4 -3
- 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/android/tools/MonitoredInstrumentation.js +1 -1
- package/src/devices/common/drivers/ios/tools/AppleSimUtils.js +29 -3
- package/src/devices/lifecycle/GenyGlobalLifecycleHandler.js +13 -15
- package/src/devices/runtime/RuntimeDevice.js +19 -12
- package/src/devices/runtime/drivers/DeviceDriverBase.js +1 -1
- package/src/devices/runtime/drivers/android/AndroidDriver.js +10 -2
- package/src/devices/runtime/drivers/ios/SimulatorDriver.js +1 -1
- package/src/errors/DetoxConfigErrorComposer.js +17 -2
- package/src/ios/expectTwo.js +153 -67
- package/src/ipc/IPCClient.js +12 -12
- package/src/ipc/IPCServer.js +29 -18
- package/src/ipc/{state.js → SessionState.js} +26 -40
- package/src/logger/DetoxLogger.js +261 -157
- package/src/logger/index.js +5 -0
- package/src/logger/utils/BunyanLogger.js +76 -0
- package/src/logger/utils/CategoryThreadDispatcher.js +36 -0
- package/src/logger/utils/DetoxLogFinalizer.js +140 -0
- package/src/logger/utils/MessageStack.js +24 -0
- package/src/logger/utils/ThreadDispatcher.js +61 -0
- package/src/logger/{customConsoleLogger.js → utils/customConsoleLogger.js} +5 -4
- package/src/logger/utils/sanitizeBunyanContext.js +30 -0
- package/src/{utils → logger/utils}/streamUtils.js +51 -17
- package/src/logger/utils/tracerLegacy.js +37 -0
- package/src/realms/DetoxContext.js +78 -65
- package/src/realms/DetoxInternalsFacade.js +8 -12
- package/src/realms/DetoxPrimaryContext.js +104 -72
- package/src/realms/DetoxSecondaryContext.js +29 -32
- 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 +16 -22
- package/src/utils/Timer.js +55 -38
- package/src/utils/argparse.js +11 -0
- package/src/utils/childProcess/exec.js +1 -1
- package/src/utils/childProcess/spawn.js +1 -1
- package/src/utils/errorUtils.js +24 -3
- package/src/utils/invocationTraceDescriptions.js +43 -0
- package/src/utils/logger.js +1 -1
- package/src/utils/traceInvocationCall.js +21 -0
- package/src/utils/traceMethods.js +15 -0
- package/Detox-android/com/wix/detox/20.0.1-breaking.new-global-lifecycle.0/detox-20.0.1-breaking.new-global-lifecycle.0-javadoc.jar.md5 +0 -1
- package/Detox-android/com/wix/detox/20.0.1-breaking.new-global-lifecycle.0/detox-20.0.1-breaking.new-global-lifecycle.0-javadoc.jar.sha1 +0 -1
- package/Detox-android/com/wix/detox/20.0.1-breaking.new-global-lifecycle.0/detox-20.0.1-breaking.new-global-lifecycle.0-javadoc.jar.sha256 +0 -1
- package/Detox-android/com/wix/detox/20.0.1-breaking.new-global-lifecycle.0/detox-20.0.1-breaking.new-global-lifecycle.0-javadoc.jar.sha512 +0 -1
- package/Detox-android/com/wix/detox/20.0.1-breaking.new-global-lifecycle.0/detox-20.0.1-breaking.new-global-lifecycle.0-sources.jar.md5 +0 -1
- package/Detox-android/com/wix/detox/20.0.1-breaking.new-global-lifecycle.0/detox-20.0.1-breaking.new-global-lifecycle.0-sources.jar.sha1 +0 -1
- package/Detox-android/com/wix/detox/20.0.1-breaking.new-global-lifecycle.0/detox-20.0.1-breaking.new-global-lifecycle.0-sources.jar.sha256 +0 -1
- package/Detox-android/com/wix/detox/20.0.1-breaking.new-global-lifecycle.0/detox-20.0.1-breaking.new-global-lifecycle.0-sources.jar.sha512 +0 -1
- package/Detox-android/com/wix/detox/20.0.1-breaking.new-global-lifecycle.0/detox-20.0.1-breaking.new-global-lifecycle.0.aar +0 -0
- package/Detox-android/com/wix/detox/20.0.1-breaking.new-global-lifecycle.0/detox-20.0.1-breaking.new-global-lifecycle.0.aar.md5 +0 -1
- package/Detox-android/com/wix/detox/20.0.1-breaking.new-global-lifecycle.0/detox-20.0.1-breaking.new-global-lifecycle.0.aar.sha1 +0 -1
- package/Detox-android/com/wix/detox/20.0.1-breaking.new-global-lifecycle.0/detox-20.0.1-breaking.new-global-lifecycle.0.aar.sha256 +0 -1
- package/Detox-android/com/wix/detox/20.0.1-breaking.new-global-lifecycle.0/detox-20.0.1-breaking.new-global-lifecycle.0.aar.sha512 +0 -1
- package/Detox-android/com/wix/detox/20.0.1-breaking.new-global-lifecycle.0/detox-20.0.1-breaking.new-global-lifecycle.0.pom.md5 +0 -1
- package/Detox-android/com/wix/detox/20.0.1-breaking.new-global-lifecycle.0/detox-20.0.1-breaking.new-global-lifecycle.0.pom.sha1 +0 -1
- package/Detox-android/com/wix/detox/20.0.1-breaking.new-global-lifecycle.0/detox-20.0.1-breaking.new-global-lifecycle.0.pom.sha256 +0 -1
- package/Detox-android/com/wix/detox/20.0.1-breaking.new-global-lifecycle.0/detox-20.0.1-breaking.new-global-lifecycle.0.pom.sha512 +0 -1
- package/android/detox/src/full/java/com/wix/detox/reactnative/idlingresources/timers/DefaultIdleInterrogationStrategy.kt +0 -84
- package/android/detox/src/testFull/java/com/wix/detox/reactnative/idlingresources/timers/DefaultIdleInterrogationStrategySpec.kt +0 -115
- package/runners/jest/deprecation.js +0 -25
- package/src/configuration/utils/warnings.js +0 -12
- package/src/logger/DetoxTraceEventBuilder.js +0 -21
- package/src/logger/DetoxTracer.js +0 -133
- package/src/logger/TraceThreadDispatcher.js +0 -52
- package/src/utils/ChromeTracingExporter.js +0 -54
- package/src/utils/trace.js +0 -19
@@ -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;
|
@@ -0,0 +1,24 @@
|
|
1
|
+
class MessageStack {
|
2
|
+
constructor() {
|
3
|
+
this._map = {};
|
4
|
+
}
|
5
|
+
|
6
|
+
push(tid, msg) {
|
7
|
+
if (this._map[tid] == null) {
|
8
|
+
this._map[tid] = [];
|
9
|
+
}
|
10
|
+
|
11
|
+
return this._map[tid].push(msg);
|
12
|
+
}
|
13
|
+
|
14
|
+
pop(tid) {
|
15
|
+
const stack = this._map[tid];
|
16
|
+
if (stack == null || stack.length === 0) {
|
17
|
+
return ['<no begin message>'];
|
18
|
+
}
|
19
|
+
|
20
|
+
return stack.pop();
|
21
|
+
}
|
22
|
+
}
|
23
|
+
|
24
|
+
module.exports = MessageStack;
|
@@ -0,0 +1,61 @@
|
|
1
|
+
const isUndefined = (x) => x === undefined;
|
2
|
+
|
3
|
+
class ThreadDispatcher {
|
4
|
+
/**
|
5
|
+
* @param {string} name
|
6
|
+
*/
|
7
|
+
constructor(name) {
|
8
|
+
this.name = name;
|
9
|
+
this.stacks = [];
|
10
|
+
this.threads = [];
|
11
|
+
}
|
12
|
+
|
13
|
+
/**
|
14
|
+
* @param {string | number} [id]
|
15
|
+
* @returns {number}
|
16
|
+
*/
|
17
|
+
begin(id) {
|
18
|
+
const tid = this._findTID(id);
|
19
|
+
this.threads[tid] = id;
|
20
|
+
this.stacks[tid] = (this.stacks[tid] || 0) + 1;
|
21
|
+
return tid;
|
22
|
+
}
|
23
|
+
|
24
|
+
/**
|
25
|
+
* @param {string | number} [id]
|
26
|
+
* @returns {number}
|
27
|
+
*/
|
28
|
+
resolve(id) {
|
29
|
+
return this._findTID(id);
|
30
|
+
}
|
31
|
+
|
32
|
+
/**
|
33
|
+
* @param {string | number} [id]
|
34
|
+
* @returns {number}
|
35
|
+
*/
|
36
|
+
end(id) {
|
37
|
+
const tid = this._findTID(id);
|
38
|
+
if (this.stacks[tid] && --this.stacks[tid] === 0) {
|
39
|
+
delete this.threads[tid];
|
40
|
+
}
|
41
|
+
return tid;
|
42
|
+
}
|
43
|
+
|
44
|
+
/**
|
45
|
+
* @param {string | number | undefined} id
|
46
|
+
* @returns {number}
|
47
|
+
* @private
|
48
|
+
*
|
49
|
+
* Memory-efficient finder of a free item index in the threads array.
|
50
|
+
*/
|
51
|
+
_findTID(id) {
|
52
|
+
let tid = this.threads.indexOf(id);
|
53
|
+
if (tid === -1) {
|
54
|
+
// Try to find a recently released slot in the array:
|
55
|
+
tid = this.threads.findIndex(isUndefined);
|
56
|
+
}
|
57
|
+
return tid === -1 ? this.threads.length : tid;
|
58
|
+
}
|
59
|
+
}
|
60
|
+
|
61
|
+
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({ cat: 'user', origin: getOrigin() }, util.format(...args));
|
29
29
|
};
|
30
30
|
}
|
31
31
|
|
32
32
|
function proxyTracing(bunyanLoggerFn) {
|
33
33
|
return (...args) => {
|
34
|
-
bunyanLoggerFn({
|
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({
|
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));
|
@@ -0,0 +1,30 @@
|
|
1
|
+
const _ = require('lodash');
|
2
|
+
|
3
|
+
const RESERVED_PROPERTIES = [
|
4
|
+
'hostname',
|
5
|
+
'level',
|
6
|
+
'msg',
|
7
|
+
'name',
|
8
|
+
'pid',
|
9
|
+
'tid',
|
10
|
+
'ph',
|
11
|
+
'time',
|
12
|
+
];
|
13
|
+
|
14
|
+
function hasProperty(p) {
|
15
|
+
return _.has(this, p);
|
16
|
+
}
|
17
|
+
|
18
|
+
function hasReservedProperties(o) {
|
19
|
+
return RESERVED_PROPERTIES.some(hasProperty, o); // eslint-disable-line unicorn/no-array-method-this-argument
|
20
|
+
}
|
21
|
+
|
22
|
+
function escapeCallback(value, key) {
|
23
|
+
return RESERVED_PROPERTIES.includes(key) ? `${key}$` : key;
|
24
|
+
}
|
25
|
+
|
26
|
+
function sanitizeBunyanContext(context) {
|
27
|
+
return context && hasReservedProperties(context) ? _.mapKeys(context, escapeCallback) : context;
|
28
|
+
}
|
29
|
+
|
30
|
+
module.exports = sanitizeBunyanContext;
|
@@ -2,15 +2,14 @@ const { PassThrough, Transform } = require('stream');
|
|
2
2
|
|
3
3
|
const bunyanDebugStream = require('bunyan-debug-stream');
|
4
4
|
const duplexify = require('duplexify');
|
5
|
+
const fs = require('fs-extra');
|
5
6
|
const multiSort = require('multi-sort-stream');
|
6
7
|
const pipe = require('multipipe');
|
7
8
|
const JsonlParser = require('stream-json/jsonl/Parser');
|
8
9
|
const stripAnsi = require('strip-ansi');
|
9
10
|
const { AbstractEventBuilder } = require('trace-event-lib');
|
10
11
|
|
11
|
-
const
|
12
|
-
|
13
|
-
const log = require('./logger').child({ __filename });
|
12
|
+
const log = require('../../utils/logger').child({ cat: 'logger' });
|
14
13
|
|
15
14
|
function compareTimestamps(a, b) {
|
16
15
|
return +(a.value.time > b.value.time) - +(a.value.time < b.value.time);
|
@@ -136,37 +135,60 @@ class JsonlStringer extends Transform {
|
|
136
135
|
|
137
136
|
class SimpleEventBuilder extends AbstractEventBuilder {
|
138
137
|
events = [];
|
138
|
+
|
139
139
|
send(event) {
|
140
140
|
this.events.push(event);
|
141
141
|
}
|
142
142
|
}
|
143
143
|
|
144
|
-
|
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) {
|
145
164
|
const knownPids = new Set();
|
146
165
|
const knownTids = new Set();
|
166
|
+
const fixTID = tidHashMap ? getFixedTID.bind(null, tidHashMap) : (x) => x.tid;
|
147
167
|
|
148
168
|
return flatMapTransform((data) => {
|
149
169
|
// eslint-disable-next-line no-unused-vars, @typescript-eslint/no-unused-vars
|
150
|
-
const {
|
151
|
-
const tid = trace ? trace.tid : DetoxTracer.threadize(args.cat);
|
170
|
+
const { cat: rawCat, msg: name, ph = 'i', pid, tid: _tid, time, name: _name, hostname: _hostname, ...args } = data;
|
152
171
|
const ts = new Date(time).getTime() * 1E3;
|
172
|
+
const cat = rawCat || 'undefined';
|
173
|
+
const tid = fixTID(data);
|
153
174
|
|
154
175
|
const builder = new SimpleEventBuilder();
|
155
176
|
if (!knownPids.has(pid)) {
|
156
|
-
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 } });
|
157
179
|
knownPids.add(pid);
|
158
180
|
}
|
159
181
|
|
160
|
-
|
161
|
-
|
162
|
-
builder.
|
163
|
-
builder.
|
164
|
-
knownTids.add(
|
182
|
+
if (!knownTids.has(tid)) {
|
183
|
+
const primaryCategory = cat.split(',', 1)[0];
|
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);
|
165
187
|
}
|
166
188
|
|
167
|
-
const event = { ph
|
168
|
-
if (
|
169
|
-
event.name
|
189
|
+
const event = { ph, name, pid, tid, cat, ts, args };
|
190
|
+
if (ph === 'E') {
|
191
|
+
delete event.name;
|
170
192
|
}
|
171
193
|
|
172
194
|
builder.events.push(event);
|
@@ -190,11 +212,11 @@ function preventErrorSubscriptions(emitter) {
|
|
190
212
|
}
|
191
213
|
|
192
214
|
function readJSONL() {
|
193
|
-
const readable =
|
215
|
+
const readable = through();
|
194
216
|
const writable = JsonlParser.make({ checkErrors: true })
|
195
217
|
.on('error', (err) => {
|
196
218
|
if (err instanceof SyntaxError) {
|
197
|
-
log.debug({
|
219
|
+
log.debug({ err });
|
198
220
|
readable.end();
|
199
221
|
} else {
|
200
222
|
readable.emit('error', err);
|
@@ -204,6 +226,17 @@ function readJSONL() {
|
|
204
226
|
return duplexify.obj(preventErrorSubscriptions(writable), writable.pipe(readable));
|
205
227
|
}
|
206
228
|
|
229
|
+
/**
|
230
|
+
* @param {string[]} logs
|
231
|
+
* @returns {NodeJS.ReadableStream}
|
232
|
+
*/
|
233
|
+
function uniteSessionLogs(logs) {
|
234
|
+
const readable = through();
|
235
|
+
const jsonlStreams = logs.map(filePath => fs.createReadStream(filePath).pipe(readJSONL()));
|
236
|
+
mergeSortedJSONL(jsonlStreams).pipe(readable);
|
237
|
+
return readable;
|
238
|
+
}
|
239
|
+
|
207
240
|
module.exports = {
|
208
241
|
readJSONL,
|
209
242
|
writeJSON,
|
@@ -211,4 +244,5 @@ module.exports = {
|
|
211
244
|
mergeSortedJSONL,
|
212
245
|
debugStream,
|
213
246
|
chromeTraceStream,
|
247
|
+
uniteSessionLogs,
|
214
248
|
};
|
@@ -0,0 +1,37 @@
|
|
1
|
+
const methods = {
|
2
|
+
startSection(logger) {
|
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
|
+
};
|
10
|
+
},
|
11
|
+
|
12
|
+
endSection(logger) {
|
13
|
+
return (_msg, args) => {
|
14
|
+
if (args !== undefined) {
|
15
|
+
return logger.trace.end(args);
|
16
|
+
} else {
|
17
|
+
return logger.trace.end();
|
18
|
+
}
|
19
|
+
};
|
20
|
+
},
|
21
|
+
|
22
|
+
traceCall(logger) {
|
23
|
+
return (name, action, args = {}) => logger.trace.complete(args, name, action);
|
24
|
+
},
|
25
|
+
};
|
26
|
+
|
27
|
+
function installLegacyTracerInterface(logger, target) {
|
28
|
+
target.traceCall = methods.traceCall(logger);
|
29
|
+
target.trace = Object.freeze({
|
30
|
+
startSection: methods.startSection(logger),
|
31
|
+
endSection: methods.endSection(logger),
|
32
|
+
});
|
33
|
+
|
34
|
+
return this;
|
35
|
+
}
|
36
|
+
|
37
|
+
module.exports = { install: installLegacyTracerInterface };
|
@@ -1,48 +1,70 @@
|
|
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, DetoxLogFinalizer, installLegacyTracerInterface } = require('../logger');
|
6
6
|
const symbols = require('../symbols');
|
7
7
|
|
8
8
|
const DetoxConstants = require('./DetoxConstants');
|
9
9
|
|
10
|
+
//#region Protected symbols
|
10
11
|
const $cleanup = Symbol('cleanup');
|
11
|
-
const $
|
12
|
+
const $logFinalizer = Symbol('logFinalizer');
|
12
13
|
const $restoreSessionState = Symbol('restoreSessionState');
|
13
14
|
const $sessionState = Symbol('restoreSessionState');
|
14
|
-
const $
|
15
|
-
|
16
|
-
|
15
|
+
const $status = Symbol('status');
|
16
|
+
const $worker = Symbol('worker');
|
17
|
+
//#endregion
|
17
18
|
|
18
19
|
class DetoxContext {
|
19
20
|
constructor() {
|
20
|
-
|
21
|
-
this[
|
22
|
-
|
21
|
+
/** @type {DetoxInternals.DetoxStatus} */
|
22
|
+
this[$status] = 'inactive';
|
23
|
+
|
24
|
+
const _init = this[symbols.init].bind(this);
|
25
|
+
this[symbols.init] = async (opts) => {
|
26
|
+
this[$status] = 'init';
|
27
|
+
await _init(opts);
|
28
|
+
this[$status] = 'active';
|
29
|
+
};
|
30
|
+
|
31
|
+
const _cleanup = this[symbols.cleanup].bind(this);
|
32
|
+
this[symbols.cleanup] = async () => {
|
33
|
+
this[$status] = 'cleanup';
|
34
|
+
try {
|
35
|
+
await _cleanup();
|
36
|
+
} finally {
|
37
|
+
this[$status] = 'inactive';
|
38
|
+
}
|
39
|
+
};
|
40
|
+
|
41
|
+
this[symbols.getStatus] = this[symbols.getStatus].bind(this);
|
42
|
+
this[symbols.reportTestResults] = this[symbols.reportTestResults].bind(this);
|
23
43
|
this[symbols.resolveConfig] = this[symbols.resolveConfig].bind(this);
|
24
|
-
this[symbols.
|
25
|
-
this[symbols.
|
44
|
+
this[symbols.installWorker] = this[symbols.installWorker].bind(this);
|
45
|
+
this[symbols.uninstallWorker] = this[symbols.uninstallWorker].bind(this);
|
26
46
|
|
27
47
|
this[$sessionState] = this[$restoreSessionState]();
|
28
48
|
|
29
|
-
const loggerConfig = this[$sessionState].detoxConfig
|
30
|
-
? this[$sessionState].detoxConfig.loggerConfig
|
31
|
-
: undefined;
|
32
|
-
|
33
49
|
/**
|
34
|
-
* @protected
|
35
50
|
* @type {DetoxLogger & Detox.Logger}
|
36
51
|
*/
|
37
|
-
this[
|
38
|
-
|
39
|
-
|
40
|
-
|
52
|
+
this[symbols.logger] = new DetoxLogger({
|
53
|
+
file: temporary.for.jsonl(`${this[$sessionState].id}.${process.pid}`),
|
54
|
+
userConfig: this[$sessionState].detoxConfig
|
55
|
+
? this[$sessionState].detoxConfig.logger
|
56
|
+
: null,
|
41
57
|
});
|
42
|
-
|
43
|
-
this.
|
58
|
+
|
59
|
+
this.log = this[symbols.logger].child({ cat: 'user' });
|
60
|
+
installLegacyTracerInterface(this.log, this);
|
61
|
+
|
62
|
+
this[$logFinalizer] = new DetoxLogFinalizer({
|
63
|
+
session: this[$sessionState]
|
64
|
+
});
|
65
|
+
|
44
66
|
/** @type {import('../DetoxWorker') | null} */
|
45
|
-
this[
|
67
|
+
this[$worker] = null;
|
46
68
|
}
|
47
69
|
|
48
70
|
//#region Public members
|
@@ -62,91 +84,81 @@ class DetoxContext {
|
|
62
84
|
return DetoxConstants;
|
63
85
|
}
|
64
86
|
|
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
87
|
//#endregion
|
79
88
|
|
80
89
|
//#region Internal members
|
81
|
-
[symbols.onRunStart] = (...args) => this[symbols.worker].onRunStart(...args);
|
82
90
|
[symbols.onRunDescribeStart] = (...args) => this[symbols.worker].onRunDescribeStart(...args);
|
83
91
|
[symbols.onTestStart] = (...args) => this[symbols.worker].onTestStart(...args);
|
84
|
-
[symbols.onHookStart] = (...args) => this[symbols.worker].onHookStart(...args);
|
85
92
|
[symbols.onHookFailure] = (...args) => this[symbols.worker].onHookFailure(...args);
|
86
|
-
[symbols.onHookSuccess] = (...args) => this[symbols.worker].onHookSuccess(...args);
|
87
|
-
[symbols.onTestFnStart] = (...args) => this[symbols.worker].onTestFnStart(...args);
|
88
93
|
[symbols.onTestFnFailure] = (...args) => this[symbols.worker].onTestFnFailure(...args);
|
89
|
-
[symbols.onTestFnSuccess] = (...args) => this[symbols.worker].onTestFnSuccess(...args);
|
90
94
|
[symbols.onTestDone] = (...args) => this[symbols.worker].onTestDone(...args);
|
91
95
|
[symbols.onRunDescribeFinish] = (...args) => this[symbols.worker].onRunDescribeFinish(...args);
|
92
|
-
[symbols.onRunFinish] = (...args) => this[symbols.worker].onRunFinish(...args);
|
93
96
|
[symbols.config] = funpermaproxy(() => this[symbols.session].detoxConfig);
|
94
97
|
[symbols.session] = funpermaproxy(() => this[$sessionState]);
|
98
|
+
[symbols.tracing] = Object.freeze({
|
99
|
+
createEventStream: () => this[$logFinalizer].createEventStream(),
|
100
|
+
});
|
95
101
|
/** @abstract */
|
96
|
-
[symbols.
|
102
|
+
[symbols.reportTestResults](_testResults) {}
|
97
103
|
/**
|
98
104
|
* @abstract
|
99
|
-
* @param {Partial<DetoxInternals.
|
105
|
+
* @param {Partial<DetoxInternals.DetoxInitOptions>} _opts
|
100
106
|
* @returns {Promise<DetoxInternals.RuntimeConfig>}
|
101
107
|
*/
|
102
108
|
async [symbols.resolveConfig](_opts) { return null; }
|
103
109
|
|
110
|
+
[symbols.getStatus]() {
|
111
|
+
return this[$status];
|
112
|
+
}
|
113
|
+
|
104
114
|
get [symbols.worker]() {
|
105
|
-
if (!this[
|
115
|
+
if (!this[$worker]) {
|
106
116
|
throw new DetoxRuntimeError({
|
107
|
-
message: `Detox worker instance has not been
|
108
|
-
hint: DetoxRuntimeError.reportIssueIfJest + '\n' + 'Otherwise, make sure you call detox.
|
117
|
+
message: `Detox worker instance has not been installed in this context (${this.constructor.name}).`,
|
118
|
+
hint: DetoxRuntimeError.reportIssueIfJest + '\n' + 'Otherwise, make sure you call detox.installWorker() beforehand.',
|
109
119
|
});
|
110
120
|
}
|
111
121
|
|
112
|
-
return this[
|
122
|
+
return this[$worker];
|
113
123
|
}
|
114
124
|
|
115
125
|
/**
|
116
126
|
* @abstract
|
117
|
-
* @param {Partial<DetoxInternals.
|
127
|
+
* @param {Partial<DetoxInternals.DetoxInitOptions>} [_opts]
|
118
128
|
* @returns {Promise<void>}
|
119
129
|
*/
|
120
|
-
async [symbols.
|
130
|
+
async [symbols.init](_opts = {}) {}
|
121
131
|
|
122
132
|
/**
|
123
|
-
* @param {Partial<DetoxInternals.
|
133
|
+
* @param {Partial<DetoxInternals.DetoxInstallWorkerOptions>} [opts]
|
124
134
|
*/
|
125
|
-
async [symbols.
|
126
|
-
|
127
|
-
|
128
|
-
|
135
|
+
async [symbols.installWorker](opts) {
|
136
|
+
if (opts.global) {
|
137
|
+
opts.global['__detox__'] = this;
|
138
|
+
this.log.overrideConsole(opts.global);
|
139
|
+
}
|
129
140
|
|
130
141
|
const DetoxWorker = require('../DetoxWorker');
|
131
|
-
DetoxWorker.global =
|
132
|
-
this[
|
133
|
-
|
142
|
+
DetoxWorker.global = opts.global || global;
|
143
|
+
this[$worker] = new DetoxWorker(this);
|
144
|
+
this[$worker].id = opts.workerId;
|
145
|
+
await this[$worker].init();
|
134
146
|
}
|
135
147
|
|
136
|
-
async [symbols.
|
148
|
+
async [symbols.uninstallWorker]() {
|
137
149
|
try {
|
138
|
-
if (this[
|
139
|
-
await this[
|
150
|
+
if (this[$worker]) {
|
151
|
+
await this[$worker].cleanup();
|
140
152
|
}
|
141
153
|
} finally {
|
142
|
-
this[
|
154
|
+
this[$worker] = null;
|
143
155
|
}
|
144
156
|
}
|
145
157
|
|
146
158
|
/**
|
147
159
|
* @abstract
|
148
160
|
*/
|
149
|
-
async [symbols.
|
161
|
+
async [symbols.cleanup]() {}
|
150
162
|
//#endregion
|
151
163
|
|
152
164
|
//#region Protected members
|
@@ -163,8 +175,9 @@ class DetoxContext {
|
|
163
175
|
module.exports = DetoxContext;
|
164
176
|
module.exports.protected = {
|
165
177
|
$cleanup,
|
166
|
-
$
|
178
|
+
$logFinalizer,
|
167
179
|
$restoreSessionState,
|
180
|
+
$status,
|
168
181
|
$sessionState,
|
169
|
-
$
|
182
|
+
$worker,
|
170
183
|
};
|