detox 19.9.0 → 20.0.1-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/{19.9.0/detox-19.9.0-javadoc.jar → 20.0.1-breaking.new-global-lifecycle.0/detox-20.0.1-breaking.new-global-lifecycle.0-javadoc.jar} +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-javadoc.jar.md5 +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-javadoc.jar.sha1 +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-javadoc.jar.sha256 +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-javadoc.jar.sha512 +1 -0
- package/Detox-android/com/wix/detox/{19.9.0/detox-19.9.0-sources.jar → 20.0.1-breaking.new-global-lifecycle.0/detox-20.0.1-breaking.new-global-lifecycle.0-sources.jar} +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-sources.jar.md5 +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.sha1 +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.sha256 +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.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.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 +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.aar.sha1 +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.aar.sha256 +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.aar.sha512 +1 -0
- package/Detox-android/com/wix/detox/{19.9.0/detox-19.9.0.pom → 20.0.1-breaking.new-global-lifecycle.0/detox-20.0.1-breaking.new-global-lifecycle.0.pom} +1 -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 +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.sha1 +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.sha256 +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.sha512 +1 -0
- package/Detox-android/com/wix/detox/maven-metadata.xml +4 -4
- package/Detox-android/com/wix/detox/maven-metadata.xml.md5 +1 -1
- package/Detox-android/com/wix/detox/maven-metadata.xml.sha1 +1 -1
- package/Detox-android/com/wix/detox/maven-metadata.xml.sha256 +1 -1
- package/Detox-android/com/wix/detox/maven-metadata.xml.sha512 +1 -1
- package/Detox-ios-src.tbz +0 -0
- package/Detox-ios.tbz +0 -0
- package/android/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/android/detox/src/full/java/com/wix/detox/reactnative/idlingresources/uimodule/RN66Workaround.kt +13 -4
- package/index.d.ts +208 -186
- package/index.js +1 -0
- package/internals.d.ts +124 -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 +0 -1
- package/local-cli/init.js +20 -55
- package/local-cli/templates/jest.js +9 -34
- package/local-cli/test.js +18 -282
- package/local-cli/test.test.js +332 -673
- package/local-cli/testCommand/TestRunnerCommand.js +157 -0
- package/local-cli/{utils/testCommandArgs.js → testCommand/builder.js} +10 -35
- package/local-cli/testCommand/middlewares.js +75 -0
- package/local-cli/{utils → testCommand}/warnings.js +0 -10
- package/local-cli/utils/jestInternals.js +13 -2
- package/local-cli/utils/yargsUtils.js +67 -0
- package/package.json +26 -20
- package/runners/deprecation.js +47 -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/deprecation.js +25 -0
- package/runners/jest/globalSetup.js +1 -0
- package/runners/jest/globalTeardown.js +1 -0
- package/runners/jest/index.js +21 -0
- package/runners/jest/reporter.js +1 -0
- package/runners/jest/reporters/DetoxReporter.js +5 -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 +155 -0
- package/runners/{jest-circus → jest/testEnvironment}/listeners/DetoxCoreListener.js +35 -17
- 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 -7
- package/runners/jest/testEnvironment/listeners/WorkerAssignReporter.js +34 -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 +56 -0
- package/runners/jest/testEnvironment/utils/assertJestCircus27.test.js +23 -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/{Detox.js → DetoxWorker.js} +131 -164
- package/src/artifacts/ArtifactsManager.js +51 -2
- package/src/artifacts/providers/index.js +0 -4
- package/src/artifacts/utils/buildDefaultArtifactsRootDirpath.js +2 -4
- package/src/artifacts/utils/temporaryPath.js +2 -0
- package/src/client/AsyncWebSocket.js +1 -1
- package/src/client/actions/actions.js +2 -2
- package/src/configuration/collectCliConfig.js +2 -4
- package/src/configuration/composeAppsConfig.js +8 -66
- package/src/configuration/composeArtifactsConfig.js +6 -32
- package/src/configuration/composeBehaviorConfig.js +3 -13
- package/src/configuration/composeDeviceConfig.js +37 -62
- package/src/configuration/composeLoggerConfig.js +50 -0
- package/src/configuration/composeRunnerConfig.js +74 -14
- package/src/configuration/composeSessionConfig.js +1 -3
- package/src/configuration/index.js +24 -23
- package/src/configuration/utils/deviceAppTypes.js +0 -1
- package/src/devices/allocation/DeviceAllocator.js +3 -3
- package/src/devices/allocation/drivers/android/emulator/EmulatorAllocDriver.js +4 -3
- package/src/devices/allocation/drivers/android/emulator/EmulatorLauncher.js +2 -6
- 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/ios/tools/AppleSimUtils.js +34 -9
- package/src/devices/lifecycle/GenyGlobalLifecycleHandler.js +1 -1
- package/src/devices/runtime/RuntimeDevice.js +69 -81
- package/src/devices/runtime/drivers/index.js +0 -1
- package/src/devices/runtime/drivers/ios/SimulatorDriver.js +3 -2
- 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 +77 -30
- package/src/errors/DetoxError.js +4 -0
- package/src/errors/DetoxRuntimeError.js +5 -5
- package/src/errors/index.js +2 -0
- package/src/ipc/IPCClient.js +117 -0
- package/src/ipc/IPCServer.js +87 -0
- package/src/ipc/state.js +76 -0
- package/src/logger/DetoxLogger.js +244 -0
- package/src/logger/DetoxTraceEventBuilder.js +21 -0
- package/src/logger/DetoxTracer.js +133 -0
- package/src/logger/TraceThreadDispatcher.js +52 -0
- package/src/{utils → logger}/customConsoleLogger.js +1 -1
- package/src/realms/DetoxConstants.js +13 -0
- package/src/realms/DetoxContext.js +170 -0
- package/src/realms/DetoxInternalsFacade.js +35 -0
- package/src/realms/DetoxPrimaryContext.js +229 -0
- package/src/realms/DetoxSecondaryContext.js +94 -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 +1 -1
- package/src/symbols.js +56 -0
- package/src/utils/Timer.js +14 -6
- package/{local-cli/utils/misc.js → src/utils/envUtils.js} +0 -9
- package/src/utils/environment.js +30 -15
- package/src/utils/logger.js +2 -162
- package/src/utils/shellUtils.js +18 -0
- package/src/utils/streamUtils.js +214 -0
- package/src/utils/trace.js +9 -44
- package/Detox-android/com/wix/detox/19.9.0/detox-19.9.0-javadoc.jar.md5 +0 -1
- package/Detox-android/com/wix/detox/19.9.0/detox-19.9.0-javadoc.jar.sha1 +0 -1
- package/Detox-android/com/wix/detox/19.9.0/detox-19.9.0-javadoc.jar.sha256 +0 -1
- package/Detox-android/com/wix/detox/19.9.0/detox-19.9.0-javadoc.jar.sha512 +0 -1
- package/Detox-android/com/wix/detox/19.9.0/detox-19.9.0-sources.jar.md5 +0 -1
- package/Detox-android/com/wix/detox/19.9.0/detox-19.9.0-sources.jar.sha1 +0 -1
- package/Detox-android/com/wix/detox/19.9.0/detox-19.9.0-sources.jar.sha256 +0 -1
- package/Detox-android/com/wix/detox/19.9.0/detox-19.9.0-sources.jar.sha512 +0 -1
- package/Detox-android/com/wix/detox/19.9.0/detox-19.9.0.aar +0 -0
- package/Detox-android/com/wix/detox/19.9.0/detox-19.9.0.aar.md5 +0 -1
- package/Detox-android/com/wix/detox/19.9.0/detox-19.9.0.aar.sha1 +0 -1
- package/Detox-android/com/wix/detox/19.9.0/detox-19.9.0.aar.sha256 +0 -1
- package/Detox-android/com/wix/detox/19.9.0/detox-19.9.0.aar.sha512 +0 -1
- package/Detox-android/com/wix/detox/19.9.0/detox-19.9.0.pom.md5 +0 -1
- package/Detox-android/com/wix/detox/19.9.0/detox-19.9.0.pom.sha1 +0 -1
- package/Detox-android/com/wix/detox/19.9.0/detox-19.9.0.pom.sha256 +0 -1
- package/Detox-android/com/wix/detox/19.9.0/detox-19.9.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/utils/assertJestCircus26.js +0 -39
- package/runners/jest-circus/utils/wrapErrorWithNoopLifecycle.js +0 -14
- package/src/DetoxConstants.js +0 -13
- package/src/DetoxExportWrapper.js +0 -140
- package/src/artifacts/timeline/TimelineArtifactPlugin.js +0 -95
- 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/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
@@ -0,0 +1,229 @@
|
|
1
|
+
const path = require('path');
|
2
|
+
const { URL } = require('url');
|
3
|
+
|
4
|
+
const fs = require('fs-extra');
|
5
|
+
const pipe = require('multipipe');
|
6
|
+
|
7
|
+
const temporary = require('../artifacts/utils/temporaryPath');
|
8
|
+
const { DetoxRuntimeError } = require('../errors');
|
9
|
+
const { PrimarySessionState } = require('../ipc/state');
|
10
|
+
const symbols = require('../symbols');
|
11
|
+
|
12
|
+
const DetoxContext = require('./DetoxContext');
|
13
|
+
|
14
|
+
const { $logger, $restoreSessionState, $sessionState } = DetoxContext.protected;
|
15
|
+
|
16
|
+
const _finalizeLogs = Symbol('finalizeLogs');
|
17
|
+
const _globalLifecycleHandler = Symbol('globalLifecycleHandler');
|
18
|
+
const _ipcServer = Symbol('ipcServer');
|
19
|
+
const _resetLockFile = Symbol('resetLockFile');
|
20
|
+
const _wss = Symbol('wss');
|
21
|
+
const _dirty = Symbol('dirty');
|
22
|
+
|
23
|
+
class DetoxPrimaryContext extends DetoxContext {
|
24
|
+
constructor() {
|
25
|
+
super();
|
26
|
+
|
27
|
+
this[_dirty] = false;
|
28
|
+
this[_wss] = null;
|
29
|
+
this[_globalLifecycleHandler] = null;
|
30
|
+
/**
|
31
|
+
* @type {import('../ipc/IPCServer') | null}
|
32
|
+
*/
|
33
|
+
this[_ipcServer] = null;
|
34
|
+
}
|
35
|
+
|
36
|
+
//#region Internal members
|
37
|
+
async [symbols.reportFailedTests](testFilePaths) {
|
38
|
+
if (this[_ipcServer]) {
|
39
|
+
this[_ipcServer].onFailedTests({ testFilePaths });
|
40
|
+
}
|
41
|
+
}
|
42
|
+
|
43
|
+
async [symbols.resolveConfig](opts = {}) {
|
44
|
+
const session = this[symbols.session];
|
45
|
+
if (!session.detoxConfig) {
|
46
|
+
const configuration = require('../configuration');
|
47
|
+
session.detoxConfig = await configuration.composeDetoxConfig(opts);
|
48
|
+
}
|
49
|
+
|
50
|
+
return session.detoxConfig;
|
51
|
+
}
|
52
|
+
|
53
|
+
/**
|
54
|
+
* @override
|
55
|
+
* @param {Partial<DetoxInternals.DetoxGlobalSetupOptions>} [opts]
|
56
|
+
*/
|
57
|
+
async [symbols.globalSetup](opts) {
|
58
|
+
if (this[_dirty]) {
|
59
|
+
throw new DetoxRuntimeError({
|
60
|
+
message: 'Cannot initialize primary Detox context more than once.',
|
61
|
+
hint: DetoxRuntimeError.reportIssueIfJest,
|
62
|
+
});
|
63
|
+
}
|
64
|
+
|
65
|
+
this[_dirty] = true;
|
66
|
+
const detoxConfig = await this[symbols.resolveConfig](opts);
|
67
|
+
|
68
|
+
const { behaviorConfig, deviceConfig, loggerConfig, sessionConfig } = detoxConfig;
|
69
|
+
await this[$logger].setConfig(loggerConfig);
|
70
|
+
|
71
|
+
this.trace.begin({
|
72
|
+
cat: 'lifecycle',
|
73
|
+
args: this[$sessionState],
|
74
|
+
name: process.argv.slice(1).join(' '),
|
75
|
+
});
|
76
|
+
|
77
|
+
const IPCServer = require('../ipc/IPCServer');
|
78
|
+
this[_ipcServer] = new IPCServer({
|
79
|
+
sessionState: this[$sessionState],
|
80
|
+
logger: this[$logger],
|
81
|
+
});
|
82
|
+
|
83
|
+
await this[_ipcServer].init();
|
84
|
+
|
85
|
+
const environmentFactory = require('../environmentFactory');
|
86
|
+
this[_globalLifecycleHandler] = await environmentFactory.createGlobalLifecycleHandler(deviceConfig);
|
87
|
+
|
88
|
+
if (this[_globalLifecycleHandler]) {
|
89
|
+
await this[_globalLifecycleHandler].globalInit();
|
90
|
+
}
|
91
|
+
|
92
|
+
if (!behaviorConfig.init.keepLockFile) {
|
93
|
+
await this[_resetLockFile]();
|
94
|
+
}
|
95
|
+
|
96
|
+
const DetoxServer = require('../server/DetoxServer');
|
97
|
+
if (sessionConfig.autoStart) {
|
98
|
+
this[_wss] = new DetoxServer({
|
99
|
+
port: sessionConfig.server
|
100
|
+
? new URL(sessionConfig.server).port
|
101
|
+
: 0,
|
102
|
+
standalone: false,
|
103
|
+
});
|
104
|
+
|
105
|
+
await this[_wss].open();
|
106
|
+
}
|
107
|
+
|
108
|
+
if (!sessionConfig.server && this[_wss]) {
|
109
|
+
sessionConfig.server = `ws://localhost:${this[_wss].port}`;
|
110
|
+
}
|
111
|
+
|
112
|
+
await fs.writeFile(this[$sessionState].detoxConfigSnapshotPath, this[$sessionState].stringify());
|
113
|
+
process.env.DETOX_CONFIG_SNAPSHOT_PATH = this[$sessionState].detoxConfigSnapshotPath;
|
114
|
+
|
115
|
+
// TODO: think about signal-exit and cleaning up the logs
|
116
|
+
}
|
117
|
+
|
118
|
+
/**
|
119
|
+
* @override
|
120
|
+
* @param {Partial<DetoxInternals.DetoxConfigurationSetupOptions>} [opts]
|
121
|
+
*/
|
122
|
+
async [symbols.setup](opts) {
|
123
|
+
const workerId = opts.workerId || 1;
|
124
|
+
this[$sessionState].workerId = workerId;
|
125
|
+
this[_ipcServer].onRegisterWorker({ workerId });
|
126
|
+
await super[symbols.setup](opts);
|
127
|
+
}
|
128
|
+
|
129
|
+
/** @override */
|
130
|
+
async [symbols.globalTeardown]() {
|
131
|
+
if (this[_globalLifecycleHandler]) {
|
132
|
+
await this[_globalLifecycleHandler].globalCleanup();
|
133
|
+
this[_globalLifecycleHandler] = null;
|
134
|
+
}
|
135
|
+
|
136
|
+
if (this[_wss]) {
|
137
|
+
await this[_wss].close();
|
138
|
+
this[_wss] = null;
|
139
|
+
}
|
140
|
+
|
141
|
+
if (this[_ipcServer]) {
|
142
|
+
await this[_ipcServer].dispose();
|
143
|
+
this[_ipcServer] = null;
|
144
|
+
}
|
145
|
+
|
146
|
+
await fs.remove(this[$sessionState].detoxConfigSnapshotPath);
|
147
|
+
delete process.env.DETOX_CONFIG_SNAPSHOT_PATH;
|
148
|
+
|
149
|
+
try {
|
150
|
+
this.trace.end({ cat: 'lifecycle' });
|
151
|
+
await this[_finalizeLogs]();
|
152
|
+
} catch (err) {
|
153
|
+
this[$logger].error({ err }, 'Encountered an error while merging the process logs:');
|
154
|
+
}
|
155
|
+
}
|
156
|
+
//#endregion
|
157
|
+
|
158
|
+
//#region Protected members
|
159
|
+
/**
|
160
|
+
* @protected
|
161
|
+
* @override
|
162
|
+
* @return {PrimarySessionState}
|
163
|
+
*/
|
164
|
+
[$restoreSessionState]() {
|
165
|
+
return new PrimarySessionState({
|
166
|
+
detoxConfigSnapshotPath: temporary.for.json(),
|
167
|
+
detoxIPCServer: `primary-${process.pid}`,
|
168
|
+
});
|
169
|
+
}
|
170
|
+
//#endregion
|
171
|
+
|
172
|
+
//#region Private members
|
173
|
+
async[_finalizeLogs]() {
|
174
|
+
const logs = [this[$logger].file, ...this[$sessionState].logFiles].filter(f => f && fs.existsSync(f));
|
175
|
+
if (logs.length === 0) {
|
176
|
+
return;
|
177
|
+
}
|
178
|
+
|
179
|
+
const streamUtils = require('../utils/streamUtils');
|
180
|
+
const { rootDir, plugins } = this[symbols.config].artifactsConfig || {};
|
181
|
+
const logConfig = plugins && plugins.log || 'none';
|
182
|
+
const enabled = rootDir && (typeof logConfig === 'string' ? logConfig !== 'none' : logConfig.enabled);
|
183
|
+
|
184
|
+
if (enabled) {
|
185
|
+
await fs.mkdirp(rootDir);
|
186
|
+
const [out1Stream, out2Stream, out3Stream] = ['detox.log.jsonl', 'detox.log', 'detox.trace.json']
|
187
|
+
.map((filename) => fs.createWriteStream(path.join(rootDir, filename)));
|
188
|
+
|
189
|
+
const mergedStream = streamUtils
|
190
|
+
.mergeSortedJSONL(
|
191
|
+
logs.map(filePath => fs.createReadStream(filePath).pipe(streamUtils.readJSONL()))
|
192
|
+
);
|
193
|
+
|
194
|
+
await Promise.all([
|
195
|
+
pipe(mergedStream, streamUtils.writeJSONL(), out1Stream),
|
196
|
+
pipe(mergedStream, streamUtils.debugStream(this[$logger].config.options), out2Stream),
|
197
|
+
pipe(mergedStream, streamUtils.chromeTraceStream(), streamUtils.writeJSON(), out3Stream),
|
198
|
+
]);
|
199
|
+
}
|
200
|
+
|
201
|
+
await Promise.all(logs.map(filepath => fs.remove(filepath)));
|
202
|
+
}
|
203
|
+
|
204
|
+
async[_resetLockFile]() {
|
205
|
+
const DeviceRegistry = require('../devices/DeviceRegistry');
|
206
|
+
|
207
|
+
const deviceType = this[symbols.config].deviceConfig.type;
|
208
|
+
|
209
|
+
switch (deviceType) {
|
210
|
+
case 'ios.none':
|
211
|
+
case 'ios.simulator':
|
212
|
+
await DeviceRegistry.forIOS().reset();
|
213
|
+
break;
|
214
|
+
case 'android.attached':
|
215
|
+
case 'android.emulator':
|
216
|
+
case 'android.genycloud':
|
217
|
+
await DeviceRegistry.forAndroid().reset();
|
218
|
+
break;
|
219
|
+
}
|
220
|
+
|
221
|
+
if (deviceType === 'android.genycloud') {
|
222
|
+
const GenyDeviceRegistryFactory = require('../devices/allocation/drivers/android/genycloud/GenyDeviceRegistryFactory');
|
223
|
+
await GenyDeviceRegistryFactory.forGlobalShutdown().reset();
|
224
|
+
}
|
225
|
+
}
|
226
|
+
//#endregion
|
227
|
+
}
|
228
|
+
|
229
|
+
module.exports = DetoxPrimaryContext;
|
@@ -0,0 +1,94 @@
|
|
1
|
+
const fs = require('fs');
|
2
|
+
|
3
|
+
const { DetoxInternalError } = require('../errors');
|
4
|
+
const { SecondarySessionState } = require('../ipc/state');
|
5
|
+
const symbols = require('../symbols');
|
6
|
+
|
7
|
+
const DetoxContext = require('./DetoxContext');
|
8
|
+
|
9
|
+
const { $logger, $restoreSessionState, $sessionState } = DetoxContext.protected;
|
10
|
+
const _ipcClient = Symbol('ipcClient');
|
11
|
+
|
12
|
+
class DetoxSecondaryContext extends DetoxContext {
|
13
|
+
constructor() {
|
14
|
+
super();
|
15
|
+
|
16
|
+
/**
|
17
|
+
* @protected
|
18
|
+
* @type {*}
|
19
|
+
*/
|
20
|
+
this[_ipcClient] = null;
|
21
|
+
}
|
22
|
+
|
23
|
+
//#region Internal members
|
24
|
+
async [symbols.reportFailedTests](testFilePaths) {
|
25
|
+
if (this[_ipcClient]) {
|
26
|
+
await this[_ipcClient].reportFailedTests(testFilePaths);
|
27
|
+
} else {
|
28
|
+
throw new DetoxInternalError('Detected an attempt to report failed tests using a non-initialized context.');
|
29
|
+
}
|
30
|
+
}
|
31
|
+
|
32
|
+
async [symbols.resolveConfig]() {
|
33
|
+
return this[symbols.config];
|
34
|
+
}
|
35
|
+
|
36
|
+
/** @override */
|
37
|
+
async [symbols.globalSetup](_opts = {}) {
|
38
|
+
// This is a no-op function.
|
39
|
+
// It is forbidden to add any logic to `globalSetup` of the secondary context.
|
40
|
+
// Violating this principle will almost definitely break some flows, where it is
|
41
|
+
// not guaranteed that `globalSetup` will ever get called. See UML diagrams.
|
42
|
+
}
|
43
|
+
|
44
|
+
/** @override */
|
45
|
+
async [symbols.globalTeardown]() {
|
46
|
+
// This is a no-op function.
|
47
|
+
// It is forbidden to add any logic to `globalTeardown` of the secondary context.
|
48
|
+
// Violating this principle will almost definitely break some flows, where it is
|
49
|
+
// not guaranteed that `globalTeardown` will ever get called. See UML diagrams.
|
50
|
+
}
|
51
|
+
|
52
|
+
/** @override */
|
53
|
+
async [symbols.setup](opts) {
|
54
|
+
const IPCClient = require('../ipc/IPCClient');
|
55
|
+
|
56
|
+
this[_ipcClient] = new IPCClient({
|
57
|
+
id: `secondary-${process.pid}`,
|
58
|
+
state: this[$sessionState],
|
59
|
+
logger: this[$logger],
|
60
|
+
});
|
61
|
+
|
62
|
+
const workerId = opts.workerId || 1;
|
63
|
+
await this[_ipcClient].init();
|
64
|
+
await this[_ipcClient].registerWorker(workerId);
|
65
|
+
await super[symbols.setup](opts);
|
66
|
+
}
|
67
|
+
|
68
|
+
/** @override */
|
69
|
+
async [symbols.teardown]() {
|
70
|
+
try {
|
71
|
+
await super[symbols.teardown]();
|
72
|
+
} finally {
|
73
|
+
if (this[_ipcClient]) {
|
74
|
+
await this[_ipcClient].dispose();
|
75
|
+
this[_ipcClient] = null;
|
76
|
+
}
|
77
|
+
}
|
78
|
+
}
|
79
|
+
//#endregion
|
80
|
+
|
81
|
+
//#region Protected members
|
82
|
+
|
83
|
+
/**
|
84
|
+
* @protected
|
85
|
+
* @override
|
86
|
+
* @return {SecondarySessionState}
|
87
|
+
*/
|
88
|
+
[$restoreSessionState]() {
|
89
|
+
return SecondarySessionState.parse(fs.readFileSync(process.env.DETOX_CONFIG_SNAPSHOT_PATH));
|
90
|
+
}
|
91
|
+
//#endregion
|
92
|
+
}
|
93
|
+
|
94
|
+
module.exports = DetoxSecondaryContext;
|
@@ -3,7 +3,7 @@ const _ = require('lodash');
|
|
3
3
|
const { WebSocket } = require('ws'); // eslint-disable-line @typescript-eslint/no-unused-vars, no-unused-vars
|
4
4
|
|
5
5
|
const DetoxRuntimeError = require('../errors/DetoxRuntimeError');
|
6
|
-
const logger = require('../utils/logger').child({ __filename });
|
6
|
+
const logger = require('../utils/logger').child({ __filename, cat: 'ws-server,ws' });
|
7
7
|
|
8
8
|
const AnonymousConnectionHandler = require('./handlers/AnonymousConnectionHandler');
|
9
9
|
|
package/src/symbols.js
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
/**
|
2
|
+
* @type {{
|
3
|
+
* readonly config: unique symbol;
|
4
|
+
* readonly globalSetup: unique symbol;
|
5
|
+
* readonly globalTeardown: unique symbol;
|
6
|
+
* readonly onHookFailure: unique symbol;
|
7
|
+
* readonly onHookStart: unique symbol;
|
8
|
+
* readonly onHookSuccess: unique symbol;
|
9
|
+
* readonly onRunDescribeFinish: unique symbol;
|
10
|
+
* readonly onRunDescribeStart: unique symbol;
|
11
|
+
* readonly onRunFinish: unique symbol;
|
12
|
+
* readonly onRunStart: unique symbol;
|
13
|
+
* readonly onTestDone: unique symbol;
|
14
|
+
* readonly onTestFnFailure: unique symbol;
|
15
|
+
* readonly onTestFnStart: unique symbol;
|
16
|
+
* readonly onTestFnSuccess: unique symbol;
|
17
|
+
* readonly onTestStart: unique symbol;
|
18
|
+
* readonly reportFailedTests: unique symbol;
|
19
|
+
* readonly resolveConfig: unique symbol;
|
20
|
+
* readonly session: unique symbol;
|
21
|
+
* readonly setup: unique symbol;
|
22
|
+
* readonly teardown: unique symbol;
|
23
|
+
* readonly worker: unique symbol;
|
24
|
+
* }}
|
25
|
+
*/
|
26
|
+
module.exports = {
|
27
|
+
//#region Lifecycle
|
28
|
+
onRunStart: Symbol('run_start'),
|
29
|
+
onRunDescribeStart: Symbol('run_describe_start'),
|
30
|
+
onTestStart: Symbol('test_start'),
|
31
|
+
onHookStart: Symbol('hook_start'),
|
32
|
+
onHookFailure: Symbol('hook_failure'),
|
33
|
+
onHookSuccess: Symbol('hook_success'),
|
34
|
+
onTestFnStart: Symbol('test_fn_start'),
|
35
|
+
onTestFnFailure: Symbol('test_fn_failure'),
|
36
|
+
onTestFnSuccess: Symbol('test_fn_success'),
|
37
|
+
onTestDone: Symbol('test_done'),
|
38
|
+
onRunDescribeFinish: Symbol('run_describe_finish'),
|
39
|
+
onRunFinish: Symbol('run_finish'),
|
40
|
+
//#endregion
|
41
|
+
|
42
|
+
//#region IPC
|
43
|
+
reportFailedTests: Symbol('reportFailedTests'),
|
44
|
+
//#endregion
|
45
|
+
|
46
|
+
//#region Main
|
47
|
+
config: Symbol('config'),
|
48
|
+
globalSetup: Symbol('globalSetup'),
|
49
|
+
globalTeardown: Symbol('globalTeardown'),
|
50
|
+
resolveConfig: Symbol('resolveConfig'),
|
51
|
+
session: Symbol('session'),
|
52
|
+
setup: Symbol('setup'),
|
53
|
+
teardown: Symbol('teardown'),
|
54
|
+
worker: Symbol('worker'),
|
55
|
+
//#endregion
|
56
|
+
};
|
package/src/utils/Timer.js
CHANGED
@@ -26,14 +26,13 @@ class Timer {
|
|
26
26
|
}
|
27
27
|
|
28
28
|
async run(action) {
|
29
|
-
const error = new DetoxRuntimeError(
|
30
|
-
|
29
|
+
const error = new DetoxRuntimeError({
|
30
|
+
message: `Exceeded timeout of ${this._timeout}ms while ${this.description}`,
|
31
|
+
noStack: true,
|
32
|
+
});
|
31
33
|
|
32
34
|
return Promise.race([
|
33
|
-
this._timeoutDeferred.promise.then(() => {
|
34
|
-
error.message = `Exceeded timeout of ${this._timeout}ms while ${this.description}`;
|
35
|
-
throw error;
|
36
|
-
}),
|
35
|
+
this._timeoutDeferred.promise.then(() => { throw error; }),
|
37
36
|
Promise.resolve().then(action),
|
38
37
|
]);
|
39
38
|
}
|
@@ -52,6 +51,15 @@ class Timer {
|
|
52
51
|
this._timeoutHandle = setTimeout(() => this._timeoutDeferred.resolve(), extraDelayMs);
|
53
52
|
}
|
54
53
|
}
|
54
|
+
|
55
|
+
static async run({ description, timeout, fn }) {
|
56
|
+
const timer = new Timer({ description, timeout });
|
57
|
+
try {
|
58
|
+
await timer.run(fn);
|
59
|
+
} finally {
|
60
|
+
timer.dispose();
|
61
|
+
}
|
62
|
+
}
|
55
63
|
}
|
56
64
|
|
57
65
|
module.exports = Timer;
|
@@ -1,13 +1,5 @@
|
|
1
1
|
const path = require('path');
|
2
2
|
|
3
|
-
function getPlatformSpecificString(platform) {
|
4
|
-
switch (platform) {
|
5
|
-
case 'ios': return ':android:';
|
6
|
-
case 'android': return ':ios:';
|
7
|
-
default: return undefined;
|
8
|
-
}
|
9
|
-
}
|
10
|
-
|
11
3
|
function printEnvironmentVariables(envObject) {
|
12
4
|
return Object.entries(envObject).reduce((cli, [key, value]) => {
|
13
5
|
if (value == null || value === '') {
|
@@ -33,7 +25,6 @@ function prependNodeModulesBinToPATH(env) {
|
|
33
25
|
}
|
34
26
|
|
35
27
|
module.exports = {
|
36
|
-
getPlatformSpecificString,
|
37
28
|
printEnvironmentVariables,
|
38
29
|
prependNodeModulesBinToPATH,
|
39
30
|
};
|
package/src/utils/environment.js
CHANGED
@@ -78,7 +78,7 @@ function getAndroidEmulatorPath() {
|
|
78
78
|
return legacyPath;
|
79
79
|
}
|
80
80
|
|
81
|
-
|
81
|
+
throwSdkBinIntegrityError(sdkRoot, 'emulator/emulator');
|
82
82
|
}
|
83
83
|
|
84
84
|
async function getAaptPath() {
|
@@ -88,23 +88,33 @@ async function getAaptPath() {
|
|
88
88
|
}
|
89
89
|
|
90
90
|
const latestBuildTools = await getLatestBuildToolsPath(sdkRoot);
|
91
|
-
|
91
|
+
if (!latestBuildTools) {
|
92
|
+
throwSdkIntegrityError('Failed to find the "aapt" tool under the Android SDK: No build-tools are installed!');
|
93
|
+
}
|
94
|
+
|
95
|
+
const defaultPath = which('aapt', latestBuildTools);
|
92
96
|
if (defaultPath) {
|
93
97
|
return defaultPath;
|
94
98
|
}
|
95
99
|
|
96
|
-
|
100
|
+
throwSdkToolPathError(`${latestBuildTools}/aapt`);
|
97
101
|
}
|
98
102
|
|
99
103
|
async function getLatestBuildToolsPath(sdkRoot) {
|
100
|
-
if (!sdkRoot)
|
104
|
+
if (!sdkRoot) {
|
105
|
+
return '';
|
106
|
+
}
|
101
107
|
|
102
108
|
const buildToolsDir = path.join(sdkRoot, 'build-tools');
|
103
|
-
if (!fs.existsSync(buildToolsDir))
|
109
|
+
if (!fs.existsSync(buildToolsDir)) {
|
110
|
+
return '';
|
111
|
+
}
|
104
112
|
|
105
113
|
const buildToolsVersions = await fsext.getDirectories(buildToolsDir);
|
106
114
|
const latestBuildToolsVersion = _.last(buildToolsVersions);
|
107
|
-
if (!latestBuildToolsVersion)
|
115
|
+
if (!latestBuildToolsVersion) {
|
116
|
+
return '';
|
117
|
+
}
|
108
118
|
|
109
119
|
return path.join(buildToolsDir, latestBuildToolsVersion);
|
110
120
|
}
|
@@ -120,7 +130,7 @@ function getAdbPath() {
|
|
120
130
|
return defaultPath;
|
121
131
|
}
|
122
132
|
|
123
|
-
|
133
|
+
throwSdkBinIntegrityError(sdkRoot, 'platform-tools/adb');
|
124
134
|
}
|
125
135
|
|
126
136
|
function getGmsaasPath() {
|
@@ -142,15 +152,20 @@ function throwMissingAvdError(avdName, avdPath, avdIniPath) {
|
|
142
152
|
);
|
143
153
|
}
|
144
154
|
|
145
|
-
function
|
146
|
-
const executablePath = path.join(sdkRoot,
|
147
|
-
|
148
|
-
|
155
|
+
function throwSdkBinIntegrityError(sdkRoot, relativeBinPath) {
|
156
|
+
const executablePath = path.join(sdkRoot, relativeBinPath);
|
157
|
+
throwSdkToolPathError(executablePath);
|
158
|
+
}
|
149
159
|
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
160
|
+
function throwSdkToolPathError(sdkToolPath) {
|
161
|
+
const name = path.basename(sdkToolPath);
|
162
|
+
const dir = path.dirname(sdkToolPath);
|
163
|
+
|
164
|
+
throwSdkIntegrityError(`There was no "${name}" executable file in directory: ${dir}`);
|
165
|
+
}
|
166
|
+
|
167
|
+
function throwSdkIntegrityError(errMessage) {
|
168
|
+
throw new DetoxRuntimeError(`${errMessage}\nCheck the integrity of your Android SDK.`);
|
154
169
|
}
|
155
170
|
|
156
171
|
function throwMissingGmsaasError() {
|