detox 19.13.0 → 20.0.0
Sign up to get free protection for your applications and to get access to all the features.
- package/Detox-android/com/wix/detox/{19.13.0/detox-19.13.0-javadoc.jar → 20.0.0/detox-20.0.0-javadoc.jar} +0 -0
- package/Detox-android/com/wix/detox/20.0.0/detox-20.0.0-javadoc.jar.md5 +1 -0
- package/Detox-android/com/wix/detox/20.0.0/detox-20.0.0-javadoc.jar.sha1 +1 -0
- package/Detox-android/com/wix/detox/20.0.0/detox-20.0.0-javadoc.jar.sha256 +1 -0
- package/Detox-android/com/wix/detox/20.0.0/detox-20.0.0-javadoc.jar.sha512 +1 -0
- package/Detox-android/com/wix/detox/{19.13.0/detox-19.13.0-sources.jar → 20.0.0/detox-20.0.0-sources.jar} +0 -0
- package/Detox-android/com/wix/detox/20.0.0/detox-20.0.0-sources.jar.md5 +1 -0
- package/Detox-android/com/wix/detox/20.0.0/detox-20.0.0-sources.jar.sha1 +1 -0
- package/Detox-android/com/wix/detox/20.0.0/detox-20.0.0-sources.jar.sha256 +1 -0
- package/Detox-android/com/wix/detox/20.0.0/detox-20.0.0-sources.jar.sha512 +1 -0
- package/Detox-android/com/wix/detox/20.0.0/detox-20.0.0.aar +0 -0
- package/Detox-android/com/wix/detox/20.0.0/detox-20.0.0.aar.md5 +1 -0
- package/Detox-android/com/wix/detox/20.0.0/detox-20.0.0.aar.sha1 +1 -0
- package/Detox-android/com/wix/detox/20.0.0/detox-20.0.0.aar.sha256 +1 -0
- package/Detox-android/com/wix/detox/20.0.0/detox-20.0.0.aar.sha512 +1 -0
- package/Detox-android/com/wix/detox/{19.13.0/detox-19.13.0.pom → 20.0.0/detox-20.0.0.pom} +1 -1
- package/Detox-android/com/wix/detox/20.0.0/detox-20.0.0.pom.md5 +1 -0
- package/Detox-android/com/wix/detox/20.0.0/detox-20.0.0.pom.sha1 +1 -0
- package/Detox-android/com/wix/detox/20.0.0/detox-20.0.0.pom.sha256 +1 -0
- package/Detox-android/com/wix/detox/20.0.0/detox-20.0.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/README.md +1 -1
- package/android/detox/src/full/java/com/wix/detox/Detox.java +2 -59
- package/android/detox/src/full/java/com/wix/detox/NotificationDataParser.kt +3 -3
- package/index.d.ts +354 -191
- package/index.js +1 -0
- package/internals.d.ts +298 -0
- package/internals.js +4 -0
- package/local-cli/build-framework-cache.js +2 -2
- package/local-cli/build.js +7 -8
- package/local-cli/build.test.js +46 -40
- package/local-cli/clean-framework-cache.js +3 -3
- package/local-cli/cli.js +8 -7
- package/local-cli/init.js +73 -68
- package/local-cli/rebuild-framework-cache.js +1 -1
- package/local-cli/reset-lock-file.js +16 -0
- package/local-cli/templates/jest.js +14 -36
- package/local-cli/test.js +24 -282
- package/local-cli/test.test.js +394 -648
- package/local-cli/testCommand/TestRunnerCommand.js +163 -0
- package/local-cli/{utils/testCommandArgs.js → testCommand/builder.js} +10 -36
- package/local-cli/testCommand/middlewares.js +66 -0
- package/local-cli/{utils → testCommand}/warnings.js +0 -13
- package/local-cli/utils/jestInternals.js +13 -2
- package/local-cli/utils/yargsUtils.js +67 -0
- package/package.json +32 -19
- package/runners/deprecation.js +45 -0
- package/runners/jest/JestCircusEnvironment.js +3 -38
- package/runners/jest/adapter.d.ts +4 -10
- package/runners/jest/adapter.js +3 -6
- package/runners/jest/assignReporter.d.ts +4 -1
- package/runners/jest/assignReporter.js +3 -6
- package/runners/jest/globalSetup.js +1 -0
- package/runners/jest/globalTeardown.js +1 -0
- package/runners/jest/index.d.ts +60 -0
- package/runners/jest/index.js +16 -0
- package/runners/jest/index.test.js +13 -0
- package/runners/jest/reporter.js +1 -0
- package/runners/jest/reporters/DetoxReporter.js +36 -0
- package/runners/jest/specReporter.d.ts +4 -9
- package/runners/jest/specReporter.js +3 -10
- package/runners/jest/streamlineReporter.js +3 -22
- package/runners/jest/testEnvironment/index.js +205 -0
- package/runners/jest/testEnvironment/listeners/DetoxCoreListener.js +166 -0
- package/runners/{jest-circus → jest/testEnvironment}/listeners/DetoxInitErrorListener.js +1 -1
- package/runners/jest/testEnvironment/listeners/DetoxPlatformFilterListener.js +27 -0
- package/runners/jest/{SpecReporterImpl.js → testEnvironment/listeners/SpecReporter.js} +61 -9
- package/runners/jest/testEnvironment/listeners/WorkerAssignReporter.js +30 -0
- package/runners/jest/testEnvironment/listeners/index.js +13 -0
- package/runners/{jest-circus → jest/testEnvironment}/utils/assertExistingContext.js +2 -2
- package/runners/jest/testEnvironment/utils/assertJestCircus27.js +70 -0
- package/runners/jest/testEnvironment/utils/assertJestCircus27.test.js +22 -0
- package/runners/jest/{utils → testEnvironment/utils}/getFullTestName.js +0 -0
- package/runners/jest/{utils → testEnvironment/utils}/hasTimedOut.js +0 -0
- package/runners/jest/{utils → testEnvironment/utils}/index.js +0 -0
- package/runners/jest/{utils → testEnvironment/utils}/stdout.js +0 -0
- package/runners/jest-circus/environment/index.js +6 -0
- package/runners/jest-circus/index.js +1 -10
- package/runners/jest-circus/reporter.js +1 -0
- package/runners/migration.js +37 -0
- package/runners/mocha/DetoxMochaAdapter.js +3 -35
- package/runners/mocha/adapter.d.ts +4 -7
- package/runners/mocha/adapter.js +3 -5
- package/src/DetoxWorker.js +327 -0
- package/src/android/interactions/native.js +2 -1
- package/src/artifacts/ArtifactsManager.js +51 -35
- package/src/artifacts/instruments/ios/SimulatorInstrumentsRecording.js +3 -3
- package/src/artifacts/log/ios/SimulatorLogRecording.js +1 -1
- package/src/artifacts/providers/index.js +0 -4
- 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/buildDefaultArtifactsRootDirpath.js +2 -4
- package/src/artifacts/utils/temporaryPath.js +18 -5
- package/src/artifacts/video/SimulatorRecordVideoPlugin.js +1 -1
- package/src/client/AsyncWebSocket.js +8 -17
- package/src/client/Client.js +1 -1
- package/src/client/actions/actions.js +2 -2
- package/src/configuration/collectCliConfig.js +3 -16
- package/src/configuration/composeAppsConfig.js +12 -66
- package/src/configuration/composeArtifactsConfig.js +6 -32
- package/src/configuration/composeBehaviorConfig.js +3 -13
- package/src/configuration/composeDeviceConfig.js +38 -63
- package/src/configuration/composeLoggerConfig.js +59 -0
- package/src/configuration/composeRunnerConfig.js +127 -14
- package/src/configuration/composeSessionConfig.js +1 -3
- package/src/configuration/index.js +36 -30
- package/src/configuration/loadExternalConfig.js +1 -1
- package/src/configuration/utils/deviceAppTypes.js +0 -1
- package/src/devices/allocation/DeviceAllocator.js +4 -2
- package/src/devices/allocation/drivers/android/emulator/AVDValidator.js +1 -1
- package/src/devices/allocation/drivers/android/emulator/EmulatorAllocDriver.js +5 -3
- package/src/devices/allocation/drivers/android/emulator/EmulatorAllocationHelper.js +1 -1
- package/src/devices/allocation/drivers/android/emulator/EmulatorLauncher.js +3 -5
- 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/allocation/drivers/ios/SimulatorAllocDriver.js +1 -1
- package/src/devices/allocation/drivers/ios/SimulatorLauncher.js +3 -3
- package/src/devices/allocation/factories/index.js +0 -1
- package/src/devices/common/drivers/DeviceLauncher.js +2 -2
- package/src/devices/common/drivers/android/emulator/exec/EmulatorExec.js +1 -1
- package/src/devices/common/drivers/android/genycloud/services/GenyInstanceNaming.js +4 -9
- 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 +35 -10
- package/src/devices/lifecycle/GenyGlobalLifecycleHandler.js +13 -15
- package/src/devices/runtime/RuntimeDevice.js +85 -86
- package/src/devices/runtime/drivers/DeviceDriverBase.js +1 -1
- package/src/devices/runtime/drivers/android/AndroidDriver.js +3 -3
- package/src/devices/runtime/drivers/index.js +0 -1
- package/src/devices/runtime/drivers/ios/SimulatorDriver.js +4 -3
- package/src/devices/runtime/factories/ios.js +1 -8
- package/src/devices/runtime/utils/LaunchArgsEditor.js +4 -59
- package/src/devices/runtime/utils/Storage.js +4 -0
- package/src/environmentFactory.js +0 -8
- package/src/errors/DetoxConfigErrorComposer.js +92 -30
- package/src/errors/DetoxError.js +4 -0
- package/src/errors/DetoxRuntimeError.js +5 -5
- package/src/errors/index.js +2 -0
- package/src/ios/expectTwo.js +2 -1
- package/src/ipc/IPCClient.js +117 -0
- package/src/ipc/IPCServer.js +98 -0
- package/src/ipc/SessionState.js +62 -0
- package/src/logger/DetoxLogger.js +348 -0
- 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/{utils → logger/utils}/customConsoleLogger.js +5 -4
- package/src/logger/utils/sanitizeBunyanContext.js +30 -0
- package/src/logger/utils/streamUtils.js +248 -0
- package/src/logger/utils/tracerLegacy.js +37 -0
- package/src/realms/DetoxConstants.js +13 -0
- package/src/realms/DetoxContext.js +183 -0
- package/src/realms/DetoxInternalsFacade.js +31 -0
- package/src/realms/DetoxPrimaryContext.js +261 -0
- package/src/realms/DetoxSecondaryContext.js +91 -0
- package/src/realms/index.js +10 -0
- package/src/realms/primary.js +3 -0
- package/src/realms/secondary.js +3 -0
- 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 +50 -0
- package/src/utils/Timer.js +58 -33
- package/src/utils/argparse.js +11 -0
- package/src/utils/childProcess/exec.js +1 -1
- package/src/utils/childProcess/spawn.js +1 -1
- package/{local-cli/utils/misc.js → src/utils/envUtils.js} +0 -9
- package/src/utils/errorUtils.js +20 -0
- package/src/utils/logger.js +2 -162
- package/src/utils/shellUtils.js +18 -0
- package/src/utils/traceInvocationCall.js +21 -0
- package/src/utils/traceMethods.js +15 -0
- package/Detox-android/com/wix/detox/19.13.0/detox-19.13.0-javadoc.jar.md5 +0 -1
- package/Detox-android/com/wix/detox/19.13.0/detox-19.13.0-javadoc.jar.sha1 +0 -1
- package/Detox-android/com/wix/detox/19.13.0/detox-19.13.0-javadoc.jar.sha256 +0 -1
- package/Detox-android/com/wix/detox/19.13.0/detox-19.13.0-javadoc.jar.sha512 +0 -1
- package/Detox-android/com/wix/detox/19.13.0/detox-19.13.0-sources.jar.md5 +0 -1
- package/Detox-android/com/wix/detox/19.13.0/detox-19.13.0-sources.jar.sha1 +0 -1
- package/Detox-android/com/wix/detox/19.13.0/detox-19.13.0-sources.jar.sha256 +0 -1
- package/Detox-android/com/wix/detox/19.13.0/detox-19.13.0-sources.jar.sha512 +0 -1
- package/Detox-android/com/wix/detox/19.13.0/detox-19.13.0.aar +0 -0
- package/Detox-android/com/wix/detox/19.13.0/detox-19.13.0.aar.md5 +0 -1
- package/Detox-android/com/wix/detox/19.13.0/detox-19.13.0.aar.sha1 +0 -1
- package/Detox-android/com/wix/detox/19.13.0/detox-19.13.0.aar.sha256 +0 -1
- package/Detox-android/com/wix/detox/19.13.0/detox-19.13.0.aar.sha512 +0 -1
- package/Detox-android/com/wix/detox/19.13.0/detox-19.13.0.pom.md5 +0 -1
- package/Detox-android/com/wix/detox/19.13.0/detox-19.13.0.pom.sha1 +0 -1
- package/Detox-android/com/wix/detox/19.13.0/detox-19.13.0.pom.sha256 +0 -1
- package/Detox-android/com/wix/detox/19.13.0/detox-19.13.0.pom.sha512 +0 -1
- package/local-cli/templates/mocha.js +0 -32
- package/local-cli/utils/splitArgv.js +0 -107
- package/runners/integration.js +0 -16
- package/runners/jest/DetoxAdapterCircus.js +0 -60
- package/runners/jest/DetoxAdapterImpl.js +0 -81
- package/runners/jest/DetoxAdapterJasmine.js +0 -67
- package/runners/jest/DetoxStreamlineJestReporter.js +0 -98
- package/runners/jest/FailingTestsReporter.js +0 -16
- package/runners/jest/SpecReporterCircus.js +0 -51
- package/runners/jest/SpecReporterJasmine.js +0 -39
- package/runners/jest/WorkerAssignReporterCircus.js +0 -17
- package/runners/jest/WorkerAssignReporterImpl.js +0 -21
- package/runners/jest/WorkerAssignReporterJasmine.js +0 -15
- package/runners/jest/runnerInfo.js +0 -9
- package/runners/jest-circus/environment.js +0 -206
- package/runners/jest-circus/listeners/DetoxCoreListener.js +0 -113
- package/runners/jest-circus/utils/assertJestCircus26.js +0 -39
- package/runners/jest-circus/utils/wrapErrorWithNoopLifecycle.js +0 -14
- package/src/Detox.js +0 -317
- package/src/DetoxConstants.js +0 -13
- package/src/DetoxExportWrapper.js +0 -140
- package/src/artifacts/timeline/TimelineArtifactPlugin.js +0 -92
- package/src/configuration/utils/warnings.js +0 -12
- package/src/devices/allocation/drivers/NoneAllocDriver.js +0 -10
- package/src/devices/allocation/factories/none.js +0 -11
- package/src/index.js +0 -6
- package/src/utils/ChromeTracingExporter.js +0 -54
- package/src/utils/MissingDetox.js +0 -78
- package/src/utils/fakeTimestampsProvider.js +0 -9
- package/src/utils/getWorkerId.js +0 -5
- package/src/utils/lastFailedTests.js +0 -38
- package/src/utils/sh.js +0 -18
- package/src/utils/trace.js +0 -96
@@ -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;
|
@@ -0,0 +1,248 @@
|
|
1
|
+
const { PassThrough, Transform } = require('stream');
|
2
|
+
|
3
|
+
const bunyanDebugStream = require('bunyan-debug-stream');
|
4
|
+
const duplexify = require('duplexify');
|
5
|
+
const fs = require('fs-extra');
|
6
|
+
const multiSort = require('multi-sort-stream');
|
7
|
+
const pipe = require('multipipe');
|
8
|
+
const JsonlParser = require('stream-json/jsonl/Parser');
|
9
|
+
const stripAnsi = require('strip-ansi');
|
10
|
+
const { AbstractEventBuilder } = require('trace-event-lib');
|
11
|
+
|
12
|
+
const log = require('../../utils/logger').child({ cat: 'logger' });
|
13
|
+
|
14
|
+
function compareTimestamps(a, b) {
|
15
|
+
return +(a.value.time > b.value.time) - +(a.value.time < b.value.time);
|
16
|
+
}
|
17
|
+
|
18
|
+
function mapTransform(fn) {
|
19
|
+
return new Transform({
|
20
|
+
objectMode: true,
|
21
|
+
transform(chunk, encoding, callback){
|
22
|
+
this.push(fn(chunk));
|
23
|
+
callback();
|
24
|
+
},
|
25
|
+
});
|
26
|
+
}
|
27
|
+
|
28
|
+
function flatMapTransform(fn) {
|
29
|
+
let index = 0;
|
30
|
+
|
31
|
+
return new Transform({
|
32
|
+
objectMode: true,
|
33
|
+
transform(chunk, encoding, callback){
|
34
|
+
const result = fn(chunk, index++);
|
35
|
+
if (Array.isArray(result)) {
|
36
|
+
// eslint-disable-next-line unicorn/no-array-method-this-argument
|
37
|
+
result.forEach(pushThis, this);
|
38
|
+
} else if (result) {
|
39
|
+
this.push(result);
|
40
|
+
}
|
41
|
+
|
42
|
+
callback();
|
43
|
+
},
|
44
|
+
});
|
45
|
+
}
|
46
|
+
|
47
|
+
function pushThis(x) {
|
48
|
+
return this.push(x);
|
49
|
+
}
|
50
|
+
|
51
|
+
function extractValue({ value }) {
|
52
|
+
value.msg = stripAnsi(value.msg);
|
53
|
+
|
54
|
+
if (typeof value.time === 'string') {
|
55
|
+
value.time = new Date(value.time);
|
56
|
+
}
|
57
|
+
|
58
|
+
return value;
|
59
|
+
}
|
60
|
+
|
61
|
+
function through() {
|
62
|
+
return new PassThrough({ objectMode: true });
|
63
|
+
}
|
64
|
+
|
65
|
+
function mergeSortedJSONL(jsonlStreams, comparator = compareTimestamps) {
|
66
|
+
const intermediate = mapTransform(extractValue);
|
67
|
+
const reemitError = (err) => intermediate.emit('error', err);
|
68
|
+
const addReemit = (stream) => stream.on('error', reemitError);
|
69
|
+
return pipe(multiSort(jsonlStreams.map(addReemit), comparator), intermediate, through());
|
70
|
+
}
|
71
|
+
|
72
|
+
function writeJSONL() {
|
73
|
+
return new JsonlStringer({
|
74
|
+
header: '',
|
75
|
+
delimiter: '\n',
|
76
|
+
footer: '',
|
77
|
+
});
|
78
|
+
}
|
79
|
+
|
80
|
+
function writeJSON() {
|
81
|
+
return new JsonlStringer({
|
82
|
+
header: '[\n\t',
|
83
|
+
delimiter: ',\n\t',
|
84
|
+
footer: '\n]\n',
|
85
|
+
});
|
86
|
+
}
|
87
|
+
|
88
|
+
function debugStream(options) {
|
89
|
+
const out = new PassThrough({ encoding: 'utf8' });
|
90
|
+
const writable = bunyanDebugStream.default({
|
91
|
+
...options,
|
92
|
+
colors: false,
|
93
|
+
out,
|
94
|
+
});
|
95
|
+
|
96
|
+
return duplexify(writable, out, {
|
97
|
+
readableObjectMode: false,
|
98
|
+
writableObjectMode: true
|
99
|
+
});
|
100
|
+
}
|
101
|
+
|
102
|
+
class JsonlStringer extends Transform {
|
103
|
+
constructor({ replacer = undefined, header = '', delimiter = '\n', footer = '' } = {}) {
|
104
|
+
super({ writableObjectMode: true, readableObjectMode: false });
|
105
|
+
|
106
|
+
this._replacer = replacer;
|
107
|
+
this._header = header;
|
108
|
+
this._delimiter = delimiter;
|
109
|
+
this._footer = footer;
|
110
|
+
}
|
111
|
+
|
112
|
+
_transform(chunk, _, callback) {
|
113
|
+
if (this._header) {
|
114
|
+
this.push(this._header);
|
115
|
+
}
|
116
|
+
|
117
|
+
this.push(JSON.stringify(chunk, this._replacer));
|
118
|
+
this._transform = this._nextTransform;
|
119
|
+
callback(null);
|
120
|
+
}
|
121
|
+
|
122
|
+
_nextTransform(chunk, _, callback) {
|
123
|
+
this.push(this._delimiter + JSON.stringify(chunk, this._replacer));
|
124
|
+
callback(null);
|
125
|
+
}
|
126
|
+
|
127
|
+
_flush(callback) {
|
128
|
+
if (this._footer) {
|
129
|
+
this.push(this._footer);
|
130
|
+
}
|
131
|
+
|
132
|
+
callback();
|
133
|
+
}
|
134
|
+
}
|
135
|
+
|
136
|
+
class SimpleEventBuilder extends AbstractEventBuilder {
|
137
|
+
events = [];
|
138
|
+
|
139
|
+
send(event) {
|
140
|
+
this.events.push(event);
|
141
|
+
}
|
142
|
+
}
|
143
|
+
|
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) {
|
164
|
+
const knownPids = new Set();
|
165
|
+
const knownTids = new Set();
|
166
|
+
const fixTID = tidHashMap ? getFixedTID.bind(null, tidHashMap) : (x) => x.tid;
|
167
|
+
|
168
|
+
return flatMapTransform((data) => {
|
169
|
+
// eslint-disable-next-line no-unused-vars, @typescript-eslint/no-unused-vars
|
170
|
+
const { cat: rawCat, msg: name, ph = 'i', pid, tid: _tid, time, name: _name, hostname: _hostname, ...args } = data;
|
171
|
+
const ts = new Date(time).getTime() * 1E3;
|
172
|
+
const cat = rawCat || 'undefined';
|
173
|
+
const tid = fixTID(data);
|
174
|
+
|
175
|
+
const builder = new SimpleEventBuilder();
|
176
|
+
if (!knownPids.has(pid)) {
|
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 } });
|
179
|
+
knownPids.add(pid);
|
180
|
+
}
|
181
|
+
|
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);
|
187
|
+
}
|
188
|
+
|
189
|
+
const event = { ph, name, pid, tid, cat, ts, args };
|
190
|
+
if (ph === 'E') {
|
191
|
+
delete event.name;
|
192
|
+
}
|
193
|
+
|
194
|
+
builder.events.push(event);
|
195
|
+
return builder.events;
|
196
|
+
});
|
197
|
+
}
|
198
|
+
|
199
|
+
// TODO: create PR to https://github.com/mafintosh/duplexify
|
200
|
+
// should be able to pass { error: false } to end-of-stream
|
201
|
+
function preventErrorSubscriptions(emitter) {
|
202
|
+
const originalOn = emitter.on.bind(emitter);
|
203
|
+
emitter.on = (event, ...args) => {
|
204
|
+
if (event === 'error') {
|
205
|
+
return emitter;
|
206
|
+
}
|
207
|
+
|
208
|
+
return originalOn(event, ...args);
|
209
|
+
};
|
210
|
+
|
211
|
+
return emitter;
|
212
|
+
}
|
213
|
+
|
214
|
+
function readJSONL() {
|
215
|
+
const readable = through();
|
216
|
+
const writable = JsonlParser.make({ checkErrors: true })
|
217
|
+
.on('error', (err) => {
|
218
|
+
if (err instanceof SyntaxError) {
|
219
|
+
log.debug({ err });
|
220
|
+
readable.end();
|
221
|
+
} else {
|
222
|
+
readable.emit('error', err);
|
223
|
+
}
|
224
|
+
});
|
225
|
+
|
226
|
+
return duplexify.obj(preventErrorSubscriptions(writable), writable.pipe(readable));
|
227
|
+
}
|
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
|
+
|
240
|
+
module.exports = {
|
241
|
+
readJSONL,
|
242
|
+
writeJSON,
|
243
|
+
writeJSONL,
|
244
|
+
mergeSortedJSONL,
|
245
|
+
debugStream,
|
246
|
+
chromeTraceStream,
|
247
|
+
uniteSessionLogs,
|
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 };
|
@@ -0,0 +1,13 @@
|
|
1
|
+
module.exports = Object.freeze({
|
2
|
+
userNotificationTriggers: {
|
3
|
+
push: 'push',
|
4
|
+
calendar: 'calendar',
|
5
|
+
timeInterval: 'timeInterval',
|
6
|
+
location: 'location'
|
7
|
+
},
|
8
|
+
userActivityTypes: {
|
9
|
+
searchableItem: 'com.apple.corespotlightitem',
|
10
|
+
browsingWeb: 'NSUserActivityTypeBrowsingWeb',
|
11
|
+
},
|
12
|
+
searchableItemActivityIdentifier: 'kCSSearchableItemActivityIdentifier'
|
13
|
+
});
|
@@ -0,0 +1,183 @@
|
|
1
|
+
const funpermaproxy = require('funpermaproxy');
|
2
|
+
|
3
|
+
const temporary = require('../artifacts/utils/temporaryPath');
|
4
|
+
const { DetoxRuntimeError } = require('../errors');
|
5
|
+
const { DetoxLogger, DetoxLogFinalizer, installLegacyTracerInterface } = require('../logger');
|
6
|
+
const symbols = require('../symbols');
|
7
|
+
|
8
|
+
const DetoxConstants = require('./DetoxConstants');
|
9
|
+
|
10
|
+
//#region Protected symbols
|
11
|
+
const $cleanup = Symbol('cleanup');
|
12
|
+
const $logFinalizer = Symbol('logFinalizer');
|
13
|
+
const $restoreSessionState = Symbol('restoreSessionState');
|
14
|
+
const $sessionState = Symbol('restoreSessionState');
|
15
|
+
const $status = Symbol('status');
|
16
|
+
const $worker = Symbol('worker');
|
17
|
+
//#endregion
|
18
|
+
|
19
|
+
class DetoxContext {
|
20
|
+
constructor() {
|
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);
|
43
|
+
this[symbols.resolveConfig] = this[symbols.resolveConfig].bind(this);
|
44
|
+
this[symbols.installWorker] = this[symbols.installWorker].bind(this);
|
45
|
+
this[symbols.uninstallWorker] = this[symbols.uninstallWorker].bind(this);
|
46
|
+
|
47
|
+
this[$sessionState] = this[$restoreSessionState]();
|
48
|
+
|
49
|
+
/**
|
50
|
+
* @type {DetoxLogger & Detox.Logger}
|
51
|
+
*/
|
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,
|
57
|
+
});
|
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
|
+
|
66
|
+
/** @type {import('../DetoxWorker') | null} */
|
67
|
+
this[$worker] = null;
|
68
|
+
}
|
69
|
+
|
70
|
+
//#region Public members
|
71
|
+
device = funpermaproxy(() => this[symbols.worker].device);
|
72
|
+
|
73
|
+
element = funpermaproxy.callable(() => this[symbols.worker].element);
|
74
|
+
|
75
|
+
waitFor = funpermaproxy.callable(() => this[symbols.worker].waitFor);
|
76
|
+
|
77
|
+
expect = funpermaproxy.callable(() => this[symbols.worker].expect);
|
78
|
+
|
79
|
+
by = funpermaproxy(() => this[symbols.worker].by);
|
80
|
+
|
81
|
+
web = funpermaproxy.callable(() => this[symbols.worker].web);
|
82
|
+
|
83
|
+
get DetoxConstants() {
|
84
|
+
return DetoxConstants;
|
85
|
+
}
|
86
|
+
|
87
|
+
//#endregion
|
88
|
+
|
89
|
+
//#region Internal members
|
90
|
+
[symbols.onRunDescribeStart] = (...args) => this[symbols.worker].onRunDescribeStart(...args);
|
91
|
+
[symbols.onTestStart] = (...args) => this[symbols.worker].onTestStart(...args);
|
92
|
+
[symbols.onHookFailure] = (...args) => this[symbols.worker].onHookFailure(...args);
|
93
|
+
[symbols.onTestFnFailure] = (...args) => this[symbols.worker].onTestFnFailure(...args);
|
94
|
+
[symbols.onTestDone] = (...args) => this[symbols.worker].onTestDone(...args);
|
95
|
+
[symbols.onRunDescribeFinish] = (...args) => this[symbols.worker].onRunDescribeFinish(...args);
|
96
|
+
[symbols.config] = funpermaproxy(() => this[symbols.session].detoxConfig);
|
97
|
+
[symbols.session] = funpermaproxy(() => this[$sessionState]);
|
98
|
+
[symbols.tracing] = Object.freeze({
|
99
|
+
createEventStream: () => this[$logFinalizer].createEventStream(),
|
100
|
+
});
|
101
|
+
/** @abstract */
|
102
|
+
[symbols.reportTestResults](_testResults) {}
|
103
|
+
/**
|
104
|
+
* @abstract
|
105
|
+
* @param {Partial<DetoxInternals.DetoxInitOptions>} _opts
|
106
|
+
* @returns {Promise<DetoxInternals.RuntimeConfig>}
|
107
|
+
*/
|
108
|
+
async [symbols.resolveConfig](_opts) { return null; }
|
109
|
+
|
110
|
+
[symbols.getStatus]() {
|
111
|
+
return this[$status];
|
112
|
+
}
|
113
|
+
|
114
|
+
get [symbols.worker]() {
|
115
|
+
if (!this[$worker]) {
|
116
|
+
throw new DetoxRuntimeError({
|
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.',
|
119
|
+
});
|
120
|
+
}
|
121
|
+
|
122
|
+
return this[$worker];
|
123
|
+
}
|
124
|
+
|
125
|
+
/**
|
126
|
+
* @abstract
|
127
|
+
* @param {Partial<DetoxInternals.DetoxInitOptions>} [_opts]
|
128
|
+
* @returns {Promise<void>}
|
129
|
+
*/
|
130
|
+
async [symbols.init](_opts = {}) {}
|
131
|
+
|
132
|
+
/**
|
133
|
+
* @param {Partial<DetoxInternals.DetoxInstallWorkerOptions>} [opts]
|
134
|
+
*/
|
135
|
+
async [symbols.installWorker](opts) {
|
136
|
+
if (opts.global) {
|
137
|
+
opts.global['__detox__'] = this;
|
138
|
+
this.log.overrideConsole(opts.global);
|
139
|
+
}
|
140
|
+
|
141
|
+
const DetoxWorker = require('../DetoxWorker');
|
142
|
+
DetoxWorker.global = opts.global || global;
|
143
|
+
this[$worker] = new DetoxWorker(this);
|
144
|
+
this[$worker].id = opts.workerId;
|
145
|
+
await this[$worker].init();
|
146
|
+
}
|
147
|
+
|
148
|
+
async [symbols.uninstallWorker]() {
|
149
|
+
try {
|
150
|
+
if (this[$worker]) {
|
151
|
+
await this[$worker].cleanup();
|
152
|
+
}
|
153
|
+
} finally {
|
154
|
+
this[$worker] = null;
|
155
|
+
}
|
156
|
+
}
|
157
|
+
|
158
|
+
/**
|
159
|
+
* @abstract
|
160
|
+
*/
|
161
|
+
async [symbols.cleanup]() {}
|
162
|
+
//#endregion
|
163
|
+
|
164
|
+
//#region Protected members
|
165
|
+
/**
|
166
|
+
* @abstract
|
167
|
+
* @protected
|
168
|
+
*/
|
169
|
+
[$restoreSessionState]() {
|
170
|
+
return null;
|
171
|
+
}
|
172
|
+
//#endregion
|
173
|
+
}
|
174
|
+
|
175
|
+
module.exports = DetoxContext;
|
176
|
+
module.exports.protected = {
|
177
|
+
$cleanup,
|
178
|
+
$logFinalizer,
|
179
|
+
$restoreSessionState,
|
180
|
+
$status,
|
181
|
+
$sessionState,
|
182
|
+
$worker,
|
183
|
+
};
|
@@ -0,0 +1,31 @@
|
|
1
|
+
const funpermaproxy = require('funpermaproxy');
|
2
|
+
|
3
|
+
const symbols = require('../symbols');
|
4
|
+
|
5
|
+
class DetoxInternalsFacade {
|
6
|
+
/**
|
7
|
+
* @param context
|
8
|
+
*/
|
9
|
+
constructor(context) {
|
10
|
+
this.config = context[symbols.config];
|
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];
|
17
|
+
this.onHookFailure = context[symbols.onHookFailure];
|
18
|
+
this.onRunDescribeFinish = context[symbols.onRunDescribeFinish];
|
19
|
+
this.onRunDescribeStart = context[symbols.onRunDescribeStart];
|
20
|
+
this.onTestDone = context[symbols.onTestDone];
|
21
|
+
this.onTestFnFailure = context[symbols.onTestFnFailure];
|
22
|
+
this.onTestStart = context[symbols.onTestStart];
|
23
|
+
this.reportTestResults = context[symbols.reportTestResults];
|
24
|
+
this.resolveConfig = context[symbols.resolveConfig];
|
25
|
+
this.session = context[symbols.session];
|
26
|
+
this.tracing = context[symbols.tracing];
|
27
|
+
this.worker = funpermaproxy(() => context[symbols.worker]);
|
28
|
+
}
|
29
|
+
}
|
30
|
+
|
31
|
+
module.exports = DetoxInternalsFacade;
|