detox 20.28.0 → 20.32.0
Sign up to get free protection for your applications and to get access to all the features.
- package/Detox-android/com/wix/detox/{20.28.0/detox-20.28.0-sources.jar → 20.32.0/detox-20.32.0-sources.jar} +0 -0
- package/Detox-android/com/wix/detox/20.32.0/detox-20.32.0-sources.jar.md5 +1 -0
- package/Detox-android/com/wix/detox/20.32.0/detox-20.32.0-sources.jar.sha1 +1 -0
- package/Detox-android/com/wix/detox/20.32.0/detox-20.32.0-sources.jar.sha256 +1 -0
- package/Detox-android/com/wix/detox/20.32.0/detox-20.32.0-sources.jar.sha512 +1 -0
- package/Detox-android/com/wix/detox/20.32.0/detox-20.32.0.aar +0 -0
- package/Detox-android/com/wix/detox/20.32.0/detox-20.32.0.aar.md5 +1 -0
- package/Detox-android/com/wix/detox/20.32.0/detox-20.32.0.aar.sha1 +1 -0
- package/Detox-android/com/wix/detox/20.32.0/detox-20.32.0.aar.sha256 +1 -0
- package/Detox-android/com/wix/detox/20.32.0/detox-20.32.0.aar.sha512 +1 -0
- package/Detox-android/com/wix/detox/{20.28.0/detox-20.28.0.pom → 20.32.0/detox-20.32.0.pom} +2 -2
- package/Detox-android/com/wix/detox/20.32.0/detox-20.32.0.pom.md5 +1 -0
- package/Detox-android/com/wix/detox/20.32.0/detox-20.32.0.pom.sha1 +1 -0
- package/Detox-android/com/wix/detox/20.32.0/detox-20.32.0.pom.sha256 +1 -0
- package/Detox-android/com/wix/detox/20.32.0/detox-20.32.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-framework.tbz +0 -0
- package/Detox-ios-src.tbz +0 -0
- package/Detox-ios-xcuitest.tbz +0 -0
- package/android/build.gradle +5 -5
- package/android/detox/proguard-rules-app.pro +3 -0
- package/android/detox/src/full/java/com/wix/detox/espresso/EspressoDetox.java +1 -1
- package/android/detox/src/full/java/com/wix/detox/espresso/web/DetoxWebAtomMatcher.java +3 -3
- package/android/detox/src/full/java/com/wix/detox/espresso/web/WebElement.java +0 -1
- package/android/detox/src/full/java/com/wix/detox/espresso/web/WebViewElement.java +33 -8
- package/android/detox/src/full/java/com/wix/detox/reactnative/ReactNativeExtension.kt +6 -11
- package/android/detox/src/full/java/com/wix/detox/reactnative/ReactNativeInfo.kt +4 -11
- package/android/detox/src/full/java/com/wix/detox/reactnative/idlingresources/DetoxIdlingResource.kt +42 -0
- package/android/detox/src/full/java/com/wix/detox/reactnative/idlingresources/ReactNativeIdlingResources.kt +145 -0
- package/android/detox/src/full/java/com/wix/detox/reactnative/idlingresources/animations/AnimatedModuleIdlingResource.kt +61 -0
- package/android/detox/src/full/java/com/wix/detox/reactnative/idlingresources/bridge/BridgeIdlingResource.kt +72 -0
- package/android/detox/src/full/java/com/wix/detox/reactnative/idlingresources/factory/DetoxIdlingResourceFactory.kt +32 -0
- package/android/detox/src/full/java/com/wix/detox/reactnative/idlingresources/factory/IdlingResourcesName.kt +10 -0
- package/android/detox/src/full/java/com/wix/detox/reactnative/idlingresources/factory/LooperName.kt +6 -0
- package/android/detox/src/full/java/com/wix/detox/reactnative/idlingresources/looper/MQThreadsReflector.kt +47 -0
- package/android/detox/src/full/java/com/wix/detox/reactnative/idlingresources/network/NetworkIdlingResource.kt +105 -0
- package/android/detox/src/full/java/com/wix/detox/reactnative/idlingresources/{NetworkingModuleReflected.kt → network/NetworkingModuleReflected.kt} +1 -1
- package/android/detox/src/full/java/com/wix/detox/reactnative/idlingresources/{AsyncStorageIdlingResource.kt → storage/AsyncStorageIdlingResource.kt} +33 -35
- package/android/detox/src/full/java/com/wix/detox/reactnative/idlingresources/{SerialExecutorReflected.kt → storage/SerialExecutorReflected.kt} +1 -1
- package/android/detox/src/full/java/com/wix/detox/reactnative/idlingresources/timers/TimersIdlingResource.kt +21 -19
- package/android/detox/src/full/java/com/wix/detox/reactnative/idlingresources/uimodule/UIManagerModuleReflected.kt +19 -27
- package/android/detox/src/full/java/com/wix/detox/reactnative/idlingresources/uimodule/UIModuleIdlingResource.kt +5 -17
- package/android/detox/src/testFull/java/com/wix/detox/reactnative/idlingresources/AsyncStorageIdlingResourceTest.kt +248 -0
- package/android/detox/src/testFull/java/com/wix/detox/reactnative/idlingresources/NetworkIdlingResourcesTest.kt +5 -1
- package/android/detox/src/testFull/java/com/wix/detox/reactnative/idlingresources/SerialExecutorReflectedSpec.kt +1 -0
- package/android/detox/src/testFull/java/com/wix/detox/reactnative/idlingresources/timers/TimersIdlingResourceTest.kt +212 -0
- package/android/gradle/wrapper/gradle-wrapper.properties +1 -1
- package/android/rninfo.gradle +31 -24
- package/android/settings.gradle +11 -6
- package/package.json +11 -8
- package/scripts/postinstall.js +2 -2
- package/scripts/updateGradle.js +41 -8
- package/src/DetoxWorker.js +11 -6
- package/src/copilot/DetoxCopilot.js +3 -15
- package/src/devices/allocation/drivers/android/genycloud/exec/GenyCloudExec.js +14 -8
- package/src/devices/validation/android/GenycloudEnvValidator.js +20 -3
- package/Detox-android/com/wix/detox/20.28.0/detox-20.28.0-sources.jar.md5 +0 -1
- package/Detox-android/com/wix/detox/20.28.0/detox-20.28.0-sources.jar.sha1 +0 -1
- package/Detox-android/com/wix/detox/20.28.0/detox-20.28.0-sources.jar.sha256 +0 -1
- package/Detox-android/com/wix/detox/20.28.0/detox-20.28.0-sources.jar.sha512 +0 -1
- package/Detox-android/com/wix/detox/20.28.0/detox-20.28.0.aar +0 -0
- package/Detox-android/com/wix/detox/20.28.0/detox-20.28.0.aar.md5 +0 -1
- package/Detox-android/com/wix/detox/20.28.0/detox-20.28.0.aar.sha1 +0 -1
- package/Detox-android/com/wix/detox/20.28.0/detox-20.28.0.aar.sha256 +0 -1
- package/Detox-android/com/wix/detox/20.28.0/detox-20.28.0.aar.sha512 +0 -1
- package/Detox-android/com/wix/detox/20.28.0/detox-20.28.0.pom.md5 +0 -1
- package/Detox-android/com/wix/detox/20.28.0/detox-20.28.0.pom.sha1 +0 -1
- package/Detox-android/com/wix/detox/20.28.0/detox-20.28.0.pom.sha256 +0 -1
- package/Detox-android/com/wix/detox/20.28.0/detox-20.28.0.pom.sha512 +0 -1
- package/Detox-android/com/wix/detox-legacy/20.28.0/detox-legacy-20.28.0-sources.jar +0 -0
- package/Detox-android/com/wix/detox-legacy/20.28.0/detox-legacy-20.28.0-sources.jar.md5 +0 -1
- package/Detox-android/com/wix/detox-legacy/20.28.0/detox-legacy-20.28.0-sources.jar.sha1 +0 -1
- package/Detox-android/com/wix/detox-legacy/20.28.0/detox-legacy-20.28.0-sources.jar.sha256 +0 -1
- package/Detox-android/com/wix/detox-legacy/20.28.0/detox-legacy-20.28.0-sources.jar.sha512 +0 -1
- package/Detox-android/com/wix/detox-legacy/20.28.0/detox-legacy-20.28.0.aar +0 -0
- package/Detox-android/com/wix/detox-legacy/20.28.0/detox-legacy-20.28.0.aar.md5 +0 -1
- package/Detox-android/com/wix/detox-legacy/20.28.0/detox-legacy-20.28.0.aar.sha1 +0 -1
- package/Detox-android/com/wix/detox-legacy/20.28.0/detox-legacy-20.28.0.aar.sha256 +0 -1
- package/Detox-android/com/wix/detox-legacy/20.28.0/detox-legacy-20.28.0.aar.sha512 +0 -1
- package/Detox-android/com/wix/detox-legacy/20.28.0/detox-legacy-20.28.0.pom +0 -100
- package/Detox-android/com/wix/detox-legacy/20.28.0/detox-legacy-20.28.0.pom.md5 +0 -1
- package/Detox-android/com/wix/detox-legacy/20.28.0/detox-legacy-20.28.0.pom.sha1 +0 -1
- package/Detox-android/com/wix/detox-legacy/20.28.0/detox-legacy-20.28.0.pom.sha256 +0 -1
- package/Detox-android/com/wix/detox-legacy/20.28.0/detox-legacy-20.28.0.pom.sha512 +0 -1
- package/Detox-android/com/wix/detox-legacy/maven-metadata.xml +0 -13
- package/Detox-android/com/wix/detox-legacy/maven-metadata.xml.md5 +0 -1
- package/Detox-android/com/wix/detox-legacy/maven-metadata.xml.sha1 +0 -1
- package/Detox-android/com/wix/detox-legacy/maven-metadata.xml.sha256 +0 -1
- package/Detox-android/com/wix/detox-legacy/maven-metadata.xml.sha512 +0 -1
- package/android/detox/src/full/java/com/wix/detox/reactnative/ReactNativeIdlingResources.kt +0 -229
- package/android/detox/src/full/java/com/wix/detox/reactnative/idlingresources/AnimatedModuleIdlingResource.java +0 -215
- package/android/detox/src/full/java/com/wix/detox/reactnative/idlingresources/BridgeIdlingResource.java +0 -94
- package/android/detox/src/full/java/com/wix/detox/reactnative/idlingresources/DetoxBaseIdlingResource.java +0 -29
- package/android/detox/src/full/java/com/wix/detox/reactnative/idlingresources/NetworkIdlingResource.java +0 -134
- package/android/detox/src/full/java/com/wix/detox/reactnative/idlingresources/timers/DelegatedIdleInterrogationStrategy.kt +0 -23
- package/android/detox/src/full/java/com/wix/detox/reactnative/idlingresources/timers/IdleInterrogationStrategy.kt +0 -16
- package/android/detox/src/full/java/com/wix/detox/reactnative/idlingresources/uimodule/RN66Workaround.kt +0 -71
- package/android/detox/src/testFull/java/com/wix/detox/reactnative/idlingresources/AsyncStorageIdlingResourceSpec.kt +0 -227
- package/android/detox/src/testFull/java/com/wix/detox/reactnative/idlingresources/timers/DelegatedIdleInterrogationStrategySpec.kt +0 -47
- package/android/detox/src/testFull/java/com/wix/detox/reactnative/idlingresources/timers/TimersIdlingResourceSpec.kt +0 -189
@@ -0,0 +1,32 @@
|
|
1
|
+
package com.wix.detox.reactnative.idlingresources.factory
|
2
|
+
|
3
|
+
import com.facebook.react.bridge.ReactContext
|
4
|
+
import com.wix.detox.reactnative.idlingresources.DetoxIdlingResource
|
5
|
+
import com.wix.detox.reactnative.idlingresources.animations.AnimatedModuleIdlingResource
|
6
|
+
import com.wix.detox.reactnative.idlingresources.bridge.BridgeIdlingResource
|
7
|
+
import com.wix.detox.reactnative.idlingresources.network.NetworkIdlingResource
|
8
|
+
import com.wix.detox.reactnative.idlingresources.storage.AsyncStorageIdlingResource
|
9
|
+
import com.wix.detox.reactnative.idlingresources.timers.TimersIdlingResource
|
10
|
+
import com.wix.detox.reactnative.idlingresources.uimodule.UIModuleIdlingResource
|
11
|
+
import kotlinx.coroutines.Dispatchers
|
12
|
+
import kotlinx.coroutines.withContext
|
13
|
+
|
14
|
+
class DetoxIdlingResourceFactory(private val reactContext: ReactContext) {
|
15
|
+
suspend fun create(): Map<IdlingResourcesName, DetoxIdlingResource> = withContext(Dispatchers.Main) {
|
16
|
+
val result = mutableMapOf(
|
17
|
+
IdlingResourcesName.Timers to TimersIdlingResource(reactContext),
|
18
|
+
IdlingResourcesName.RNBridge to BridgeIdlingResource(reactContext),
|
19
|
+
IdlingResourcesName.UIModule to UIModuleIdlingResource(reactContext),
|
20
|
+
IdlingResourcesName.Animations to AnimatedModuleIdlingResource(reactContext),
|
21
|
+
IdlingResourcesName.Network to NetworkIdlingResource(reactContext)
|
22
|
+
)
|
23
|
+
|
24
|
+
val asyncStorageIdlingResource = AsyncStorageIdlingResource.createIfNeeded(reactContext)
|
25
|
+
if (asyncStorageIdlingResource != null) {
|
26
|
+
result[IdlingResourcesName.AsyncStorage] = asyncStorageIdlingResource
|
27
|
+
}
|
28
|
+
|
29
|
+
return@withContext result
|
30
|
+
}
|
31
|
+
}
|
32
|
+
|
@@ -0,0 +1,47 @@
|
|
1
|
+
package com.wix.detox.reactnative.idlingresources.looper
|
2
|
+
|
3
|
+
import android.os.Looper
|
4
|
+
import android.util.Log
|
5
|
+
import com.facebook.react.bridge.ReactContext
|
6
|
+
import org.joor.Reflect
|
7
|
+
import org.joor.ReflectException
|
8
|
+
|
9
|
+
|
10
|
+
private const val LOG_TAG = "DetoxRNIdleRes"
|
11
|
+
private const val METHOD_GET_LOOPER = "getLooper"
|
12
|
+
private const val FIELD_NATIVE_MODULES_MSG_QUEUE = "mNativeModulesMessageQueueThread"
|
13
|
+
private const val FIELD_JS_MSG_QUEUE = "mJSMessageQueueThread"
|
14
|
+
|
15
|
+
internal class MQThreadsReflector(private val reactContext: ReactContext) {
|
16
|
+
|
17
|
+
fun getJSMQueue(): MQThreadReflected? {
|
18
|
+
return getQueue(FIELD_JS_MSG_QUEUE)
|
19
|
+
}
|
20
|
+
|
21
|
+
fun getNativeModulesQueue(): MQThreadReflected? {
|
22
|
+
return getQueue(FIELD_NATIVE_MODULES_MSG_QUEUE)
|
23
|
+
}
|
24
|
+
|
25
|
+
private fun getQueue(queueName: String): MQThreadReflected? {
|
26
|
+
try {
|
27
|
+
val queue = Reflect.on(reactContext).field(queueName).get() as Any?
|
28
|
+
return MQThreadReflected(queue, queueName)
|
29
|
+
} catch (e: ReflectException) {
|
30
|
+
Log.e(LOG_TAG, "Could not find queue: $queueName", e)
|
31
|
+
}
|
32
|
+
return null
|
33
|
+
}
|
34
|
+
}
|
35
|
+
|
36
|
+
internal class MQThreadReflected(private val queue: Any?, private val queueName: String) {
|
37
|
+
fun getLooper(): Looper? {
|
38
|
+
try {
|
39
|
+
if (queue != null) {
|
40
|
+
return Reflect.on(queue).call(METHOD_GET_LOOPER).get()
|
41
|
+
}
|
42
|
+
} catch (e: ReflectException) {
|
43
|
+
Log.e(LOG_TAG, "Could not find looper for queue: $queueName", e)
|
44
|
+
}
|
45
|
+
return null
|
46
|
+
}
|
47
|
+
}
|
@@ -0,0 +1,105 @@
|
|
1
|
+
package com.wix.detox.reactnative.idlingresources.network
|
2
|
+
|
3
|
+
import android.util.Log
|
4
|
+
import android.view.Choreographer
|
5
|
+
import androidx.test.espresso.IdlingResource.ResourceCallback
|
6
|
+
import com.facebook.react.bridge.ReactContext
|
7
|
+
import com.wix.detox.reactnative.idlingresources.DetoxIdlingResource
|
8
|
+
import okhttp3.Dispatcher
|
9
|
+
import java.util.regex.Pattern
|
10
|
+
import java.util.regex.PatternSyntaxException
|
11
|
+
|
12
|
+
/**
|
13
|
+
* Created by simonracz on 09/10/2017.
|
14
|
+
*
|
15
|
+
* Idling Resource which monitors React Native's OkHttpClient.
|
16
|
+
*
|
17
|
+
*
|
18
|
+
* Must call stop() on it, before removing it from Espresso.
|
19
|
+
*/
|
20
|
+
class NetworkIdlingResource(private val dispatcher: Dispatcher) : DetoxIdlingResource(),
|
21
|
+
Choreographer.FrameCallback {
|
22
|
+
private val busyResources: MutableSet<String> = HashSet()
|
23
|
+
|
24
|
+
constructor(reactContext: ReactContext) : this(NetworkingModuleReflected(reactContext).getHttpClient()!!.dispatcher)
|
25
|
+
|
26
|
+
override fun getName(): String {
|
27
|
+
return NetworkIdlingResource::class.java.name
|
28
|
+
}
|
29
|
+
|
30
|
+
override fun getDebugName(): String {
|
31
|
+
return "network"
|
32
|
+
}
|
33
|
+
|
34
|
+
@Synchronized
|
35
|
+
override fun getBusyHint(): Map<String, Any> = mapOf("urls" to ArrayList(busyResources))
|
36
|
+
|
37
|
+
override fun registerIdleTransitionCallback(callback: ResourceCallback?) {
|
38
|
+
super.registerIdleTransitionCallback(callback)
|
39
|
+
Choreographer.getInstance().postFrameCallback(this)
|
40
|
+
}
|
41
|
+
|
42
|
+
override fun doFrame(frameTimeNanos: Long) {
|
43
|
+
isIdleNow
|
44
|
+
}
|
45
|
+
|
46
|
+
@Synchronized
|
47
|
+
override fun checkIdle(): Boolean {
|
48
|
+
busyResources.clear()
|
49
|
+
|
50
|
+
val calls = dispatcher.runningCalls()
|
51
|
+
for (call in calls) {
|
52
|
+
val url = call.request().url.toString()
|
53
|
+
|
54
|
+
if (!isUrlBlacklisted(url)) {
|
55
|
+
busyResources.add(url)
|
56
|
+
}
|
57
|
+
}
|
58
|
+
|
59
|
+
if (busyResources.isNotEmpty()) {
|
60
|
+
Log.i(LOG_TAG, "Network is busy, with " + busyResources.size + " in-flight calls")
|
61
|
+
Choreographer.getInstance().postFrameCallback(this)
|
62
|
+
return false
|
63
|
+
}
|
64
|
+
|
65
|
+
notifyIdle()
|
66
|
+
return true
|
67
|
+
}
|
68
|
+
|
69
|
+
private fun isUrlBlacklisted(url: String): Boolean {
|
70
|
+
for (pattern in blacklist) {
|
71
|
+
if (pattern.matcher(url).matches()) {
|
72
|
+
return true
|
73
|
+
}
|
74
|
+
}
|
75
|
+
return false
|
76
|
+
}
|
77
|
+
|
78
|
+
companion object {
|
79
|
+
private const val LOG_TAG = "Detox"
|
80
|
+
|
81
|
+
private val blacklist = ArrayList<Pattern>()
|
82
|
+
|
83
|
+
/**
|
84
|
+
* Must be called on the UI thread.
|
85
|
+
*
|
86
|
+
* @param urls list of regexes of blacklisted urls
|
87
|
+
*/
|
88
|
+
@JvmStatic
|
89
|
+
fun setURLBlacklist(urls: List<String>?) {
|
90
|
+
blacklist.clear()
|
91
|
+
if (urls == null) return
|
92
|
+
|
93
|
+
for (url in urls) {
|
94
|
+
try {
|
95
|
+
blacklist.add(Pattern.compile(url))
|
96
|
+
} catch (e: PatternSyntaxException) {
|
97
|
+
Log.e(
|
98
|
+
LOG_TAG,
|
99
|
+
"Couldn't parse regular expression for Black list url: $url", e
|
100
|
+
)
|
101
|
+
}
|
102
|
+
}
|
103
|
+
}
|
104
|
+
}
|
105
|
+
}
|
@@ -1,16 +1,18 @@
|
|
1
|
-
package com.wix.detox.reactnative.idlingresources
|
1
|
+
package com.wix.detox.reactnative.idlingresources.storage
|
2
2
|
|
3
3
|
import android.util.Log
|
4
4
|
import androidx.test.espresso.IdlingResource
|
5
5
|
import com.facebook.react.bridge.NativeModule
|
6
6
|
import com.facebook.react.bridge.ReactContext
|
7
|
-
import com.wix.detox.espresso.idlingresources.DescriptiveIdlingResource
|
8
7
|
import com.wix.detox.reactnative.helpers.RNHelpers
|
8
|
+
import com.wix.detox.reactnative.idlingresources.DetoxIdlingResource
|
9
9
|
import org.joor.Reflect
|
10
10
|
import java.util.concurrent.Executor
|
11
11
|
|
12
12
|
private typealias SExecutorReflectedGenFnType = (executor: Executor) -> SerialExecutorReflected
|
13
|
-
|
13
|
+
|
14
|
+
private val defaultSExecutorReflectedGenFn: SExecutorReflectedGenFnType =
|
15
|
+
{ executor: Executor -> SerialExecutorReflected(executor) }
|
14
16
|
|
15
17
|
private class ModuleReflected(module: NativeModule, sexecutorReflectedGen: SExecutorReflectedGenFnType) {
|
16
18
|
private val executorReflected: SerialExecutorReflected
|
@@ -25,17 +27,16 @@ private class ModuleReflected(module: NativeModule, sexecutorReflectedGen: SExec
|
|
25
27
|
get() = executorReflected
|
26
28
|
}
|
27
29
|
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
30
|
+
class AsyncStorageIdlingResource
|
31
|
+
@JvmOverloads constructor(
|
32
|
+
module: NativeModule,
|
33
|
+
sexecutorReflectedGenFn: SExecutorReflectedGenFnType = defaultSExecutorReflectedGenFn
|
34
|
+
) : DetoxIdlingResource() {
|
33
35
|
|
34
|
-
|
36
|
+
val logTag: String
|
35
37
|
get() = LOG_TAG
|
36
38
|
|
37
39
|
private val moduleReflected = ModuleReflected(module, sexecutorReflectedGenFn)
|
38
|
-
private var callback: IdlingResource.ResourceCallback? = null
|
39
40
|
private var idleCheckTask: Runnable? = null
|
40
41
|
private val idleCheckTaskImpl = Runnable {
|
41
42
|
with(moduleReflected.sexecutor) {
|
@@ -44,7 +45,7 @@ open class AsyncStorageIdlingResource
|
|
44
45
|
executeTask(idleCheckTask!!)
|
45
46
|
} else {
|
46
47
|
clearIdleCheckTask()
|
47
|
-
|
48
|
+
notifyIdle()
|
48
49
|
}
|
49
50
|
}
|
50
51
|
}
|
@@ -54,22 +55,24 @@ open class AsyncStorageIdlingResource
|
|
54
55
|
override fun getDebugName() = "io"
|
55
56
|
override fun getBusyHint(): Map<String, Any>? = null
|
56
57
|
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
58
|
+
|
59
|
+
private fun checkIdleInternal(): Boolean =
|
60
|
+
with(moduleReflected.sexecutor) {
|
61
|
+
synchronized(executor()) {
|
62
|
+
!hasActiveTask() && !hasPendingTasks()
|
62
63
|
}
|
63
64
|
}
|
65
|
+
|
64
66
|
override fun registerIdleTransitionCallback(callback: IdlingResource.ResourceCallback?) {
|
65
|
-
|
67
|
+
super.registerIdleTransitionCallback(callback)
|
66
68
|
enqueueIdleCheckTask()
|
67
69
|
}
|
68
70
|
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
71
|
+
override fun checkIdle(): Boolean =
|
72
|
+
checkIdleInternal().also { idle ->
|
73
|
+
if (!idle) {
|
74
|
+
Log.d(logTag, "Async-storage is busy!")
|
75
|
+
enqueueIdleCheckTask()
|
73
76
|
}
|
74
77
|
}
|
75
78
|
|
@@ -94,26 +97,21 @@ open class AsyncStorageIdlingResource
|
|
94
97
|
companion object {
|
95
98
|
private const val LOG_TAG = "AsyncStorageIR"
|
96
99
|
|
97
|
-
fun createIfNeeded(reactContext: ReactContext
|
98
|
-
Log.d(LOG_TAG, "Checking whether a custom IR for Async-Storage is required...
|
100
|
+
fun createIfNeeded(reactContext: ReactContext): AsyncStorageIdlingResource? {
|
101
|
+
Log.d(LOG_TAG, "Checking whether a custom IR for Async-Storage is required...")
|
99
102
|
|
100
|
-
return RNHelpers.getNativeModule(reactContext, className(
|
101
|
-
Log.d(LOG_TAG, "IR for Async-Storage is required!
|
102
|
-
createInstance(module
|
103
|
+
return RNHelpers.getNativeModule(reactContext, className())?.let { module ->
|
104
|
+
Log.d(LOG_TAG, "IR for Async-Storage is required!")
|
105
|
+
createInstance(module)
|
103
106
|
}
|
104
107
|
}
|
105
108
|
|
106
|
-
private fun className(
|
107
|
-
val packageName =
|
109
|
+
private fun className(): String {
|
110
|
+
val packageName = "com.reactnativecommunity.asyncstorage"
|
108
111
|
return "$packageName.AsyncStorageModule"
|
109
112
|
}
|
110
113
|
|
111
|
-
private fun createInstance(module: NativeModule
|
112
|
-
|
114
|
+
private fun createInstance(module: NativeModule) =
|
115
|
+
AsyncStorageIdlingResource(module)
|
113
116
|
}
|
114
117
|
}
|
115
|
-
|
116
|
-
class AsyncStorageIdlingResourceLegacy(module: NativeModule): AsyncStorageIdlingResource(module) {
|
117
|
-
override val logTag: String
|
118
|
-
get() = super.logTag + "Legacy"
|
119
|
-
}
|
@@ -1,43 +1,45 @@
|
|
1
1
|
package com.wix.detox.reactnative.idlingresources.timers
|
2
2
|
|
3
|
+
import android.annotation.SuppressLint
|
3
4
|
import android.view.Choreographer
|
4
5
|
import androidx.test.espresso.IdlingResource
|
5
|
-
import com.
|
6
|
+
import com.facebook.react.bridge.ReactContext
|
7
|
+
import com.facebook.react.modules.core.TimingModule
|
8
|
+
import com.wix.detox.reactnative.idlingresources.DetoxIdlingResource
|
9
|
+
|
10
|
+
private const val BUSY_WINDOW_THRESHOLD = 1500L
|
6
11
|
|
7
12
|
class TimersIdlingResource @JvmOverloads constructor(
|
8
|
-
|
9
|
-
|
10
|
-
|
13
|
+
reactContext: ReactContext,
|
14
|
+
private val getChoreographer: () -> Choreographer = { Choreographer.getInstance() }
|
15
|
+
) : DetoxIdlingResource(), Choreographer.FrameCallback {
|
11
16
|
|
12
|
-
private
|
17
|
+
private val timingModule: TimingModule = reactContext.getNativeModule(TimingModule::class.java)!!
|
13
18
|
|
14
19
|
override fun getName(): String = this.javaClass.name
|
15
20
|
override fun getDebugName(): String = "timers"
|
16
21
|
override fun getBusyHint(): Map<String, Any>? = null
|
17
22
|
|
18
23
|
override fun registerIdleTransitionCallback(callback: IdlingResource.ResourceCallback?) {
|
19
|
-
|
24
|
+
super.registerIdleTransitionCallback(callback)
|
20
25
|
getChoreographer().postFrameCallback(this)
|
21
26
|
}
|
22
27
|
|
28
|
+
@SuppressLint("VisibleForTests")
|
23
29
|
override fun checkIdle(): Boolean {
|
24
|
-
|
25
|
-
if (result) {
|
26
|
-
notifyIdle()
|
27
|
-
} else {
|
28
|
-
getChoreographer().postFrameCallback(this@TimersIdlingResource)
|
29
|
-
}
|
30
|
-
}
|
31
|
-
}
|
30
|
+
val isIdle = !timingModule.hasActiveTimersInRange(BUSY_WINDOW_THRESHOLD)
|
32
31
|
|
33
|
-
|
34
|
-
|
35
|
-
|
32
|
+
if (isIdle) {
|
33
|
+
notifyIdle()
|
34
|
+
} else {
|
35
|
+
getChoreographer().postFrameCallback(this)
|
36
36
|
}
|
37
|
+
|
38
|
+
return isIdle
|
37
39
|
}
|
38
40
|
|
39
|
-
override fun
|
40
|
-
|
41
|
+
override fun doFrame(frameTimeNanos: Long) {
|
42
|
+
isIdleNow
|
41
43
|
}
|
42
44
|
|
43
45
|
companion object {
|
@@ -18,20 +18,12 @@ private const val FIELD_NON_BATCHED_OPS_LOCK = "mNonBatchedOperationsLock"
|
|
18
18
|
|
19
19
|
class UIManagerModuleReflected(private val reactContext: ReactContext) {
|
20
20
|
|
21
|
-
fun getUIOpsCount(): Int = (viewCommandOperations()?.size ?: 0)
|
22
|
-
fun getNextUIOpReflected() = viewCommandOperations()?.firstCommandReflected()
|
23
|
-
|
24
|
-
fun nativeViewHierarchyManager(): NativeHierarchyManagerReflected? =
|
25
|
-
getUIOperationQueue()?.let {
|
26
|
-
NativeHierarchyManagerReflected(it)
|
27
|
-
}
|
28
|
-
|
29
21
|
fun isRunnablesListEmpty(): Boolean =
|
30
22
|
getUIOperationQueue()?.let {
|
31
|
-
synchronized(Reflect.on(it).field(FIELD_DISPATCH_RUNNABLES_LOCK).get())
|
23
|
+
synchronized(Reflect.on(it).field(FIELD_DISPATCH_RUNNABLES_LOCK).get()) {
|
32
24
|
Reflect.on(it)
|
33
25
|
.field(FIELD_DISPATCH_RUNNABLES)
|
34
|
-
.call(METHOD_IS_EMPTY).get
|
26
|
+
.call(METHOD_IS_EMPTY).get()
|
35
27
|
}
|
36
28
|
} ?: true
|
37
29
|
|
@@ -39,32 +31,32 @@ class UIManagerModuleReflected(private val reactContext: ReactContext) {
|
|
39
31
|
getUIOperationQueue()?.let {
|
40
32
|
synchronized(Reflect.on(it).field(FIELD_NON_BATCHED_OPS_LOCK).get()) {
|
41
33
|
Reflect.on(it)
|
42
|
-
|
43
|
-
|
34
|
+
.field(FIELD_NON_BATCHED_OPS)
|
35
|
+
.call(METHOD_IS_EMPTY).get()
|
44
36
|
}
|
45
37
|
} ?: true
|
46
38
|
|
47
39
|
fun isOperationQueueEmpty(): Boolean =
|
48
40
|
getUIOperationQueue()?.let {
|
49
|
-
Reflect.on(it).call(METHOD_IS_EMPTY).get
|
41
|
+
Reflect.on(it).call(METHOD_IS_EMPTY).get()
|
50
42
|
} ?: true
|
51
43
|
|
52
44
|
private fun viewCommandOperations(): ViewCommandOpsQueueReflected? =
|
53
|
-
|
54
|
-
|
55
|
-
|
45
|
+
getUIOperationQueue()?.let {
|
46
|
+
ViewCommandOpsQueueReflected(it)
|
47
|
+
}
|
56
48
|
|
57
49
|
|
58
50
|
private fun getUIOperationQueue(): UIViewOperationQueue? =
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
51
|
+
try {
|
52
|
+
val uiModuleClass = Class.forName(CLASS_UI_MANAGER_MODULE)
|
53
|
+
Reflect.on(reactContext)
|
54
|
+
.call(METHOD_GET_NATIVE_MODULE, uiModuleClass)
|
55
|
+
.call(METHOD_GET_UI_IMPLEMENTATION)
|
56
|
+
.field(FIELD_UI_OPERATION_QUEUE)
|
57
|
+
.get()
|
58
|
+
} catch (e: Exception) {
|
59
|
+
Log.e(LOG_TAG, "failed to get $CLASS_UI_MANAGER_MODULE instance ", e)
|
60
|
+
null
|
61
|
+
}
|
70
62
|
}
|
@@ -5,7 +5,7 @@ import android.view.Choreographer
|
|
5
5
|
import androidx.test.espresso.IdlingResource.ResourceCallback
|
6
6
|
import com.facebook.react.bridge.ReactContext
|
7
7
|
import com.wix.detox.reactnative.helpers.RNHelpers
|
8
|
-
import com.wix.detox.reactnative.idlingresources.
|
8
|
+
import com.wix.detox.reactnative.idlingresources.DetoxIdlingResource
|
9
9
|
import org.joor.ReflectException
|
10
10
|
|
11
11
|
/**
|
@@ -13,11 +13,9 @@ import org.joor.ReflectException
|
|
13
13
|
* Hooks up to React Native internals to grab the pending ui operations from it.
|
14
14
|
*/
|
15
15
|
class UIModuleIdlingResource(private val reactContext: ReactContext)
|
16
|
-
:
|
16
|
+
: DetoxIdlingResource(), Choreographer.FrameCallback {
|
17
17
|
|
18
|
-
private val rn66workaround = RN66Workaround()
|
19
18
|
private val uiManagerModuleReflected = UIManagerModuleReflected(reactContext)
|
20
|
-
private var callback: ResourceCallback? = null
|
21
19
|
|
22
20
|
override fun getName(): String = UIModuleIdlingResource::class.java.name
|
23
21
|
override fun getDebugName(): String = " ui"
|
@@ -39,11 +37,7 @@ class UIModuleIdlingResource(private val reactContext: ReactContext)
|
|
39
37
|
|
40
38
|
val runnablesAreEmpty = uiManagerModuleReflected.isRunnablesListEmpty()
|
41
39
|
val nonBatchesOpsEmpty = uiManagerModuleReflected.isNonBatchOpsEmpty()
|
42
|
-
|
43
|
-
|
44
|
-
if (!operationQueueEmpty) {
|
45
|
-
operationQueueEmpty = rn66workaround.isScarceUISwitchCommandStuckInQueue(uiManagerModuleReflected)
|
46
|
-
}
|
40
|
+
val operationQueueEmpty = uiManagerModuleReflected.isOperationQueueEmpty()
|
47
41
|
|
48
42
|
if (runnablesAreEmpty && nonBatchesOpsEmpty && operationQueueEmpty) {
|
49
43
|
notifyIdle()
|
@@ -60,8 +54,8 @@ class UIModuleIdlingResource(private val reactContext: ReactContext)
|
|
60
54
|
return true
|
61
55
|
}
|
62
56
|
|
63
|
-
override fun registerIdleTransitionCallback(callback: ResourceCallback) {
|
64
|
-
|
57
|
+
override fun registerIdleTransitionCallback(callback: ResourceCallback?) {
|
58
|
+
super.registerIdleTransitionCallback(callback)
|
65
59
|
Choreographer.getInstance().postFrameCallback(this)
|
66
60
|
}
|
67
61
|
|
@@ -69,12 +63,6 @@ class UIModuleIdlingResource(private val reactContext: ReactContext)
|
|
69
63
|
isIdleNow
|
70
64
|
}
|
71
65
|
|
72
|
-
override fun notifyIdle() {
|
73
|
-
callback?.run {
|
74
|
-
onTransitionToIdle()
|
75
|
-
}
|
76
|
-
}
|
77
|
-
|
78
66
|
companion object {
|
79
67
|
private const val LOG_TAG = "Detox"
|
80
68
|
}
|