detox 20.0.3-breaking.new-global-lifecycle.0 → 20.0.3
Sign up to get free protection for your applications and to get access to all the features.
- package/Detox-android/com/wix/detox/{20.0.3-breaking.new-global-lifecycle.0/detox-20.0.3-breaking.new-global-lifecycle.0-javadoc.jar → 20.0.3/detox-20.0.3-javadoc.jar} +0 -0
- package/Detox-android/com/wix/detox/20.0.3/detox-20.0.3-javadoc.jar.md5 +1 -0
- package/Detox-android/com/wix/detox/20.0.3/detox-20.0.3-javadoc.jar.sha1 +1 -0
- package/Detox-android/com/wix/detox/20.0.3/detox-20.0.3-javadoc.jar.sha256 +1 -0
- package/Detox-android/com/wix/detox/20.0.3/detox-20.0.3-javadoc.jar.sha512 +1 -0
- package/Detox-android/com/wix/detox/{20.0.3-breaking.new-global-lifecycle.0/detox-20.0.3-breaking.new-global-lifecycle.0-sources.jar → 20.0.3/detox-20.0.3-sources.jar} +0 -0
- package/Detox-android/com/wix/detox/20.0.3/detox-20.0.3-sources.jar.md5 +1 -0
- package/Detox-android/com/wix/detox/20.0.3/detox-20.0.3-sources.jar.sha1 +1 -0
- package/Detox-android/com/wix/detox/20.0.3/detox-20.0.3-sources.jar.sha256 +1 -0
- package/Detox-android/com/wix/detox/20.0.3/detox-20.0.3-sources.jar.sha512 +1 -0
- package/Detox-android/com/wix/detox/20.0.3/detox-20.0.3.aar +0 -0
- package/Detox-android/com/wix/detox/20.0.3/detox-20.0.3.aar.md5 +1 -0
- package/Detox-android/com/wix/detox/20.0.3/detox-20.0.3.aar.sha1 +1 -0
- package/Detox-android/com/wix/detox/20.0.3/detox-20.0.3.aar.sha256 +1 -0
- package/Detox-android/com/wix/detox/20.0.3/detox-20.0.3.aar.sha512 +1 -0
- package/Detox-android/com/wix/detox/{20.0.3-breaking.new-global-lifecycle.0/detox-20.0.3-breaking.new-global-lifecycle.0.pom → 20.0.3/detox-20.0.3.pom} +1 -7
- package/Detox-android/com/wix/detox/20.0.3/detox-20.0.3.pom.md5 +1 -0
- package/Detox-android/com/wix/detox/20.0.3/detox-20.0.3.pom.sha1 +1 -0
- package/Detox-android/com/wix/detox/20.0.3/detox-20.0.3.pom.sha256 +1 -0
- package/Detox-android/com/wix/detox/20.0.3/detox-20.0.3.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 +195 -59
- package/internals.d.ts +205 -43
- package/local-cli/build.js +1 -1
- package/local-cli/cli.js +11 -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 +142 -61
- package/local-cli/testCommand/TestRunnerCommand.js +97 -77
- package/local-cli/testCommand/TestRunnerError.js +17 -0
- package/local-cli/testCommand/TestRunnerError.test.js +25 -0
- package/local-cli/testCommand/builder.js +0 -1
- package/local-cli/testCommand/middlewares.js +4 -13
- package/local-cli/testCommand/warnings.js +0 -3
- package/local-cli/utils/jestInternals.js +4 -1
- package/package.json +23 -18
- 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 +93 -46
- package/runners/jest/testEnvironment/listeners/DetoxPlatformFilterListener.js +1 -1
- package/runners/jest/testEnvironment/listeners/SpecReporter.js +13 -15
- package/runners/jest/testEnvironment/listeners/WorkerAssignReporter.js +1 -5
- package/runners/jest/testEnvironment/utils/assertJestCircus27.js +17 -3
- package/runners/jest/testEnvironment/utils/assertJestCircus27.test.js +0 -1
- package/src/DetoxWorker.js +99 -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 +49 -8
- 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 +14 -9
- package/src/configuration/index.js +5 -1
- package/src/configuration/loadExternalConfig.js +1 -1
- package/src/devices/allocation/DeviceAllocator.js +3 -2
- package/src/devices/allocation/drivers/android/emulator/AVDValidator.js +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 +6 -5
- package/src/devices/allocation/drivers/android/emulator/EmulatorVersionResolver.js +4 -6
- package/src/devices/allocation/drivers/android/emulator/launchEmulatorProcess.js +4 -17
- package/src/devices/allocation/drivers/android/genycloud/GenyInstanceAllocationHelper.js +1 -1
- package/src/devices/common/drivers/android/exec/ADB.js +4 -0
- 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 +14 -1
- package/src/errors/DetoxError.js +5 -1
- package/src/ios/expectTwo.js +153 -67
- package/src/ipc/IPCClient.js +12 -13
- package/src/ipc/IPCServer.js +28 -24
- package/src/ipc/{state.js → SessionState.js} +26 -53
- package/src/logger/DetoxLogger.js +287 -154
- package/src/logger/index.js +5 -0
- package/src/logger/utils/BunyanLogger.js +115 -0
- package/src/logger/utils/CategoryThreadDispatcher.js +37 -0
- package/src/logger/utils/DetoxLogFinalizer.js +162 -0
- package/src/logger/utils/MessageStack.js +35 -0
- package/src/logger/utils/ThreadDispatcher.js +61 -0
- package/src/logger/{customConsoleLogger.js → utils/customConsoleLogger.js} +23 -6
- package/src/logger/utils/getMainCategory.js +5 -0
- package/src/logger/utils/sanitizeBunyanContext.js +30 -0
- package/src/logger/utils/streams/BunyanTransformer.js +72 -0
- package/src/logger/utils/streams/ChromeTraceTransformer.js +127 -0
- package/src/logger/utils/streams/DetoxJSONLParser.js +31 -0
- package/src/logger/utils/streams/JSONLStringer.js +55 -0
- package/src/logger/utils/streams/index.js +7 -0
- package/src/logger/utils/streams/transformers.js +39 -0
- package/src/logger/utils/tracerLegacy.js +37 -0
- package/src/realms/DetoxContext.js +79 -65
- package/src/realms/DetoxInternalsFacade.js +8 -12
- package/src/realms/DetoxPrimaryContext.js +104 -70
- 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/pathUtils.js +11 -0
- package/src/utils/shellUtils.js +17 -0
- package/src/utils/traceInvocationCall.js +21 -0
- package/src/utils/traceMethods.js +15 -0
- package/Detox-android/com/wix/detox/20.0.3-breaking.new-global-lifecycle.0/detox-20.0.3-breaking.new-global-lifecycle.0-javadoc.jar.md5 +0 -1
- package/Detox-android/com/wix/detox/20.0.3-breaking.new-global-lifecycle.0/detox-20.0.3-breaking.new-global-lifecycle.0-javadoc.jar.sha1 +0 -1
- package/Detox-android/com/wix/detox/20.0.3-breaking.new-global-lifecycle.0/detox-20.0.3-breaking.new-global-lifecycle.0-javadoc.jar.sha256 +0 -1
- package/Detox-android/com/wix/detox/20.0.3-breaking.new-global-lifecycle.0/detox-20.0.3-breaking.new-global-lifecycle.0-javadoc.jar.sha512 +0 -1
- package/Detox-android/com/wix/detox/20.0.3-breaking.new-global-lifecycle.0/detox-20.0.3-breaking.new-global-lifecycle.0-sources.jar.md5 +0 -1
- package/Detox-android/com/wix/detox/20.0.3-breaking.new-global-lifecycle.0/detox-20.0.3-breaking.new-global-lifecycle.0-sources.jar.sha1 +0 -1
- package/Detox-android/com/wix/detox/20.0.3-breaking.new-global-lifecycle.0/detox-20.0.3-breaking.new-global-lifecycle.0-sources.jar.sha256 +0 -1
- package/Detox-android/com/wix/detox/20.0.3-breaking.new-global-lifecycle.0/detox-20.0.3-breaking.new-global-lifecycle.0-sources.jar.sha512 +0 -1
- package/Detox-android/com/wix/detox/20.0.3-breaking.new-global-lifecycle.0/detox-20.0.3-breaking.new-global-lifecycle.0.aar +0 -0
- package/Detox-android/com/wix/detox/20.0.3-breaking.new-global-lifecycle.0/detox-20.0.3-breaking.new-global-lifecycle.0.aar.md5 +0 -1
- package/Detox-android/com/wix/detox/20.0.3-breaking.new-global-lifecycle.0/detox-20.0.3-breaking.new-global-lifecycle.0.aar.sha1 +0 -1
- package/Detox-android/com/wix/detox/20.0.3-breaking.new-global-lifecycle.0/detox-20.0.3-breaking.new-global-lifecycle.0.aar.sha256 +0 -1
- package/Detox-android/com/wix/detox/20.0.3-breaking.new-global-lifecycle.0/detox-20.0.3-breaking.new-global-lifecycle.0.aar.sha512 +0 -1
- package/Detox-android/com/wix/detox/20.0.3-breaking.new-global-lifecycle.0/detox-20.0.3-breaking.new-global-lifecycle.0.pom.md5 +0 -1
- package/Detox-android/com/wix/detox/20.0.3-breaking.new-global-lifecycle.0/detox-20.0.3-breaking.new-global-lifecycle.0.pom.sha1 +0 -1
- package/Detox-android/com/wix/detox/20.0.3-breaking.new-global-lifecycle.0/detox-20.0.3-breaking.new-global-lifecycle.0.pom.sha256 +0 -1
- package/Detox-android/com/wix/detox/20.0.3-breaking.new-global-lifecycle.0/detox-20.0.3-breaking.new-global-lifecycle.0.pom.sha512 +0 -1
- package/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/streamUtils.js +0 -214
- package/src/utils/trace.js +0 -19
@@ -1,20 +1,26 @@
|
|
1
1
|
package com.wix.detox.reactnative.idlingresources
|
2
2
|
|
3
3
|
class IdlingResourceDescription private constructor(
|
4
|
-
|
5
|
-
|
6
|
-
fun json(): Map<String, Any> = mutableMapOf<String, Any>("name" to name)
|
7
|
-
.apply { if (description.isNotEmpty()) put("description", description) }
|
4
|
+
private val name: String,
|
5
|
+
private val description: Map<String, Any>) {
|
8
6
|
|
9
|
-
|
10
|
-
|
7
|
+
fun json() =
|
8
|
+
mutableMapOf<String, Any>("name" to name)
|
9
|
+
.apply {
|
10
|
+
if (description.isNotEmpty()) put("description", description)
|
11
|
+
}.toMap()
|
11
12
|
|
12
|
-
|
13
|
-
|
14
|
-
|
13
|
+
override fun equals(other: Any?) =
|
14
|
+
(other is IdlingResourceDescription && other.json() == this.json())
|
15
|
+
|
16
|
+
override fun hashCode(): Int =
|
17
|
+
(31 * name.hashCode() + description.hashCode())
|
15
18
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
19
|
+
data class Builder(
|
20
|
+
var name: String = "unknown",
|
21
|
+
var description: MutableMap<String, Any> = mutableMapOf()) {
|
22
|
+
fun name(value: String) = apply { name = value }
|
23
|
+
fun addDescription(key: String, value: Any) = apply { description[key] = value }
|
24
|
+
fun build() = IdlingResourceDescription(name, description)
|
25
|
+
}
|
20
26
|
}
|
@@ -69,42 +69,13 @@ public class NetworkIdlingResource extends DetoxBaseIdlingResource implements Ch
|
|
69
69
|
|
70
70
|
@NotNull
|
71
71
|
@Override
|
72
|
-
public IdlingResourceDescription getDescription() {
|
72
|
+
public synchronized IdlingResourceDescription getDescription() {
|
73
73
|
return new IdlingResourceDescription.Builder()
|
74
74
|
.name("network")
|
75
75
|
.addDescription("urls", new ArrayList<>(busyResources))
|
76
76
|
.build();
|
77
77
|
}
|
78
78
|
|
79
|
-
@Override
|
80
|
-
protected boolean checkIdle() {
|
81
|
-
boolean idle = true;
|
82
|
-
busyResources.clear();
|
83
|
-
List<Call> calls = dispatcher.runningCalls();
|
84
|
-
for (Call call : calls) {
|
85
|
-
idle = false;
|
86
|
-
String url = call.request().url().toString();
|
87
|
-
for (Pattern pattern : blacklist) {
|
88
|
-
if (pattern.matcher(url).matches()) {
|
89
|
-
idle = true;
|
90
|
-
break;
|
91
|
-
}
|
92
|
-
}
|
93
|
-
if (!idle) {
|
94
|
-
busyResources.add(call.request().url().toString());
|
95
|
-
}
|
96
|
-
}
|
97
|
-
if (!idle) {
|
98
|
-
Choreographer.getInstance().postFrameCallback(this);
|
99
|
-
Log.i(LOG_TAG, "Network is busy");
|
100
|
-
} else {
|
101
|
-
if (callback != null) {
|
102
|
-
callback.onTransitionToIdle();
|
103
|
-
}
|
104
|
-
}
|
105
|
-
return idle;
|
106
|
-
}
|
107
|
-
|
108
79
|
@Override
|
109
80
|
public void registerIdleTransitionCallback(ResourceCallback callback) {
|
110
81
|
this.callback = callback;
|
@@ -116,10 +87,42 @@ public class NetworkIdlingResource extends DetoxBaseIdlingResource implements Ch
|
|
116
87
|
isIdleNow();
|
117
88
|
}
|
118
89
|
|
90
|
+
@Override
|
91
|
+
protected synchronized boolean checkIdle() {
|
92
|
+
busyResources.clear();
|
93
|
+
|
94
|
+
List<Call> calls = dispatcher.runningCalls();
|
95
|
+
for (Call call: calls) {
|
96
|
+
final String url = call.request().url().toString();
|
97
|
+
|
98
|
+
if (!isUrlBlacklisted(url)) {
|
99
|
+
busyResources.add(url);
|
100
|
+
}
|
101
|
+
}
|
102
|
+
|
103
|
+
if (!busyResources.isEmpty()) {
|
104
|
+
Log.i(LOG_TAG, "Network is busy, with " + busyResources.size() + " in-flight calls");
|
105
|
+
Choreographer.getInstance().postFrameCallback(this);
|
106
|
+
return false;
|
107
|
+
}
|
108
|
+
|
109
|
+
notifyIdle();
|
110
|
+
return true;
|
111
|
+
}
|
112
|
+
|
119
113
|
@Override
|
120
114
|
protected void notifyIdle() {
|
121
115
|
if (callback != null) {
|
122
116
|
callback.onTransitionToIdle();
|
123
117
|
}
|
124
118
|
}
|
119
|
+
|
120
|
+
private boolean isUrlBlacklisted(String url) {
|
121
|
+
for (Pattern pattern: blacklist) {
|
122
|
+
if (pattern.matcher(url).matches()) {
|
123
|
+
return true;
|
124
|
+
}
|
125
|
+
}
|
126
|
+
return false;
|
127
|
+
}
|
125
128
|
}
|
@@ -1,43 +1,23 @@
|
|
1
|
+
|
1
2
|
package com.wix.detox.reactnative.idlingresources.timers
|
2
3
|
|
3
|
-
import com.facebook.react.bridge.NativeModule
|
4
4
|
import com.facebook.react.bridge.ReactContext
|
5
|
-
import com.
|
6
|
-
import com.wix.detox.reactnative.helpers.RNHelpers
|
7
|
-
import org.joor.Reflect
|
5
|
+
import com.facebook.react.modules.core.TimingModule
|
8
6
|
|
9
7
|
private const val BUSY_WINDOW_THRESHOLD = 1500L
|
10
8
|
|
11
|
-
private class RN62TimingModuleReflected(private val timingModule: NativeModule) {
|
12
|
-
fun hasActiveTimers(): Boolean = Reflect.on(timingModule).call("hasActiveTimersInRange", BUSY_WINDOW_THRESHOLD).get()
|
13
|
-
}
|
14
|
-
|
15
9
|
/**
|
16
10
|
* Delegates the interrogation to the native module itself, added
|
17
11
|
* [here](https://github.com/facebook/react-native/pull/27539) in the context
|
18
12
|
* of RN v0.62 (followed by a previous refactor and rename of the class).
|
19
13
|
*/
|
20
|
-
|
21
|
-
|
22
|
-
should) remove any usage of reflection here.
|
23
|
-
That includes the unit test's stub being used for that reason in particular.
|
24
|
-
""")
|
25
|
-
class DelegatedIdleInterrogationStrategy(timingModule: NativeModule): IdleInterrogationStrategy {
|
26
|
-
private val timingModuleReflected = RN62TimingModuleReflected(timingModule)
|
27
|
-
|
28
|
-
override fun isIdleNow(): Boolean = !timingModuleReflected.hasActiveTimers()
|
14
|
+
class DelegatedIdleInterrogationStrategy(private val timingModule: TimingModule): IdleInterrogationStrategy {
|
15
|
+
override fun isIdleNow(): Boolean = !timingModule.hasActiveTimersInRange(BUSY_WINDOW_THRESHOLD)
|
29
16
|
|
30
17
|
companion object {
|
31
|
-
fun
|
32
|
-
val
|
33
|
-
|
34
|
-
|
35
|
-
return try {
|
36
|
-
module.javaClass.getDeclaredMethod("hasActiveTimersInRange", Long::class.java)
|
37
|
-
DelegatedIdleInterrogationStrategy(module)
|
38
|
-
} catch (ex: Exception) {
|
39
|
-
null
|
40
|
-
}
|
18
|
+
fun create(reactContext: ReactContext): DelegatedIdleInterrogationStrategy {
|
19
|
+
val timingModule = reactContext.getNativeModule(TimingModule::class.java)!!
|
20
|
+
return DelegatedIdleInterrogationStrategy(timingModule)
|
41
21
|
}
|
42
22
|
}
|
43
23
|
}
|
@@ -1,6 +1,5 @@
|
|
1
1
|
package com.wix.detox.reactnative.idlingresources.timers
|
2
2
|
|
3
|
-
import android.util.Log
|
4
3
|
import com.facebook.react.bridge.ReactContext
|
5
4
|
import com.wix.detox.common.UIThread
|
6
5
|
import java.util.concurrent.Callable
|
@@ -13,14 +12,5 @@ fun getInterrogationStrategy(reactContext: ReactContext): IdleInterrogationStrat
|
|
13
12
|
// Getting a native-module (inside) also initializes it if needed. That has to run on a
|
14
13
|
// looper thread, and the easiest to make sure that happens is to use the main thread.
|
15
14
|
UIThread.runSync(Callable {
|
16
|
-
DelegatedIdleInterrogationStrategy.
|
17
|
-
return@Callable it
|
18
|
-
}
|
19
|
-
|
20
|
-
DefaultIdleInterrogationStrategy.createIfSupported(reactContext)?.let {
|
21
|
-
return@Callable it
|
22
|
-
}
|
23
|
-
|
24
|
-
Log.e(TimersIdlingResource.LOG_TAG, "Failed to determine proper implementation-strategy for timers idling resource")
|
25
|
-
null
|
15
|
+
return@Callable DelegatedIdleInterrogationStrategy.create(reactContext)
|
26
16
|
})
|
@@ -11,6 +11,7 @@ import org.assertj.core.api.Assertions.assertThat
|
|
11
11
|
import org.mockito.kotlin.*
|
12
12
|
import org.spekframework.spek2.Spek
|
13
13
|
import org.spekframework.spek2.style.specification.describe
|
14
|
+
import java.lang.NullPointerException
|
14
15
|
import kotlin.test.assertFailsWith
|
15
16
|
|
16
17
|
object DetoxMultiTapSpec: Spek({
|
@@ -136,17 +137,17 @@ object DetoxMultiTapSpec: Spek({
|
|
136
137
|
}
|
137
138
|
|
138
139
|
it("should throw if no UI-controller provided") {
|
139
|
-
assertFailsWith(
|
140
|
+
assertFailsWith(NullPointerException::class) {
|
140
141
|
uut(1).sendTap(null, coordinates, precision, -1, -1)
|
141
142
|
}
|
142
143
|
}
|
143
144
|
|
144
145
|
it("should throw if no coordinates / precision are provided") {
|
145
|
-
assertFailsWith(
|
146
|
+
assertFailsWith(NullPointerException::class) {
|
146
147
|
uut(1).sendTap(uiController, null, precision, -1, -1)
|
147
148
|
}
|
148
149
|
|
149
|
-
assertFailsWith(
|
150
|
+
assertFailsWith(NullPointerException::class) {
|
150
151
|
uut(1).sendTap(uiController, coordinates, null, -1, -1)
|
151
152
|
}
|
152
153
|
}
|
@@ -0,0 +1,61 @@
|
|
1
|
+
package com.wix.detox.reactnative.idlingresources
|
2
|
+
|
3
|
+
import com.wix.detox.UTHelpers.yieldToOtherThreads
|
4
|
+
import org.assertj.core.api.Assertions.assertThat
|
5
|
+
|
6
|
+
import okhttp3.Dispatcher
|
7
|
+
import org.junit.Before
|
8
|
+
import org.junit.Test
|
9
|
+
import org.junit.runner.RunWith
|
10
|
+
import org.robolectric.RobolectricTestRunner
|
11
|
+
import java.util.concurrent.Executors
|
12
|
+
|
13
|
+
@RunWith(RobolectricTestRunner::class)
|
14
|
+
class NetworkIdlingResourcesTest {
|
15
|
+
lateinit var dispatcher: Dispatcher
|
16
|
+
lateinit var uut: NetworkIdlingResource
|
17
|
+
|
18
|
+
@Before
|
19
|
+
fun setup() {
|
20
|
+
dispatcher = Dispatcher()
|
21
|
+
uut = NetworkIdlingResource(dispatcher)
|
22
|
+
}
|
23
|
+
|
24
|
+
// Note: Ideally, we should test that the list of busy resources is protected,
|
25
|
+
// rather than testing thread-safety as a whole.
|
26
|
+
@Test
|
27
|
+
fun `should return the description in a thread-safe way`() {
|
28
|
+
val localExecutor = Executors.newSingleThreadExecutor()
|
29
|
+
var description: IdlingResourceDescription? = null
|
30
|
+
|
31
|
+
synchronized(uut) {
|
32
|
+
localExecutor.submit {
|
33
|
+
description = uut.getDescription()
|
34
|
+
}
|
35
|
+
|
36
|
+
yieldToOtherThreads(localExecutor)
|
37
|
+
assertThat(description).isNull()
|
38
|
+
}
|
39
|
+
yieldToOtherThreads(localExecutor)
|
40
|
+
assertThat(description).isNotNull()
|
41
|
+
}
|
42
|
+
|
43
|
+
// Note: Ideally, we should test that the list of busy resources is protected,
|
44
|
+
// rather than testing thread-safety as a whole.
|
45
|
+
@Test
|
46
|
+
fun `should check for idle in a thread-safe way`() {
|
47
|
+
val localExecutor = Executors.newSingleThreadExecutor()
|
48
|
+
var idle = false
|
49
|
+
|
50
|
+
synchronized(uut) {
|
51
|
+
localExecutor.submit {
|
52
|
+
idle = uut.isIdleNow
|
53
|
+
}
|
54
|
+
|
55
|
+
yieldToOtherThreads(localExecutor)
|
56
|
+
assertThat(idle).isFalse
|
57
|
+
}
|
58
|
+
yieldToOtherThreads(localExecutor)
|
59
|
+
assertThat(idle).isTrue
|
60
|
+
}
|
61
|
+
}
|
@@ -5,22 +5,14 @@ import org.assertj.core.api.Assertions.assertThat
|
|
5
5
|
import org.mockito.kotlin.*
|
6
6
|
import org.spekframework.spek2.Spek
|
7
7
|
import org.spekframework.spek2.style.specification.describe
|
8
|
+
import com.facebook.react.modules.core.TimingModule
|
8
9
|
|
9
10
|
private const val BUSY_INTERVAL_MS = 1500L
|
10
11
|
|
11
|
-
abstract class TimingModuleStub: NativeModule {
|
12
|
-
abstract fun hasActiveTimersInRange(rangeMs: Long): Boolean
|
13
|
-
|
14
|
-
override fun onCatalystInstanceDestroy() {}
|
15
|
-
override fun getName(): String = "TimersNativeModuleStub"
|
16
|
-
override fun canOverrideExistingModule() = false
|
17
|
-
override fun initialize() {}
|
18
|
-
}
|
19
|
-
|
20
12
|
object DelegatedIdleInterrogationStrategySpec : Spek({
|
21
|
-
describe("
|
13
|
+
describe("Timers idle-interrogation strategy") {
|
22
14
|
|
23
|
-
lateinit var timingModule:
|
15
|
+
lateinit var timingModule: TimingModule
|
24
16
|
|
25
17
|
beforeEachTest {
|
26
18
|
timingModule = mock()
|