detox 20.28.0 → 20.31.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (102) hide show
  1. package/Detox-android/com/wix/detox/{20.28.0/detox-20.28.0-sources.jar → 20.30.0/detox-20.30.0-sources.jar} +0 -0
  2. package/Detox-android/com/wix/detox/20.30.0/detox-20.30.0-sources.jar.md5 +1 -0
  3. package/Detox-android/com/wix/detox/20.30.0/detox-20.30.0-sources.jar.sha1 +1 -0
  4. package/Detox-android/com/wix/detox/20.30.0/detox-20.30.0-sources.jar.sha256 +1 -0
  5. package/Detox-android/com/wix/detox/20.30.0/detox-20.30.0-sources.jar.sha512 +1 -0
  6. package/Detox-android/com/wix/detox/20.30.0/detox-20.30.0.aar +0 -0
  7. package/Detox-android/com/wix/detox/20.30.0/detox-20.30.0.aar.md5 +1 -0
  8. package/Detox-android/com/wix/detox/20.30.0/detox-20.30.0.aar.sha1 +1 -0
  9. package/Detox-android/com/wix/detox/20.30.0/detox-20.30.0.aar.sha256 +1 -0
  10. package/Detox-android/com/wix/detox/20.30.0/detox-20.30.0.aar.sha512 +1 -0
  11. package/Detox-android/com/wix/detox/{20.28.0/detox-20.28.0.pom → 20.30.0/detox-20.30.0.pom} +2 -2
  12. package/Detox-android/com/wix/detox/20.30.0/detox-20.30.0.pom.md5 +1 -0
  13. package/Detox-android/com/wix/detox/20.30.0/detox-20.30.0.pom.sha1 +1 -0
  14. package/Detox-android/com/wix/detox/20.30.0/detox-20.30.0.pom.sha256 +1 -0
  15. package/Detox-android/com/wix/detox/20.30.0/detox-20.30.0.pom.sha512 +1 -0
  16. package/Detox-android/com/wix/detox/maven-metadata.xml +4 -4
  17. package/Detox-android/com/wix/detox/maven-metadata.xml.md5 +1 -1
  18. package/Detox-android/com/wix/detox/maven-metadata.xml.sha1 +1 -1
  19. package/Detox-android/com/wix/detox/maven-metadata.xml.sha256 +1 -1
  20. package/Detox-android/com/wix/detox/maven-metadata.xml.sha512 +1 -1
  21. package/Detox-ios-framework.tbz +0 -0
  22. package/Detox-ios-src.tbz +0 -0
  23. package/Detox-ios-xcuitest.tbz +0 -0
  24. package/android/build.gradle +5 -5
  25. package/android/detox/proguard-rules-app.pro +3 -0
  26. package/android/detox/src/full/java/com/wix/detox/espresso/EspressoDetox.java +1 -1
  27. package/android/detox/src/full/java/com/wix/detox/espresso/web/DetoxWebAtomMatcher.java +3 -3
  28. package/android/detox/src/full/java/com/wix/detox/espresso/web/WebElement.java +0 -1
  29. package/android/detox/src/full/java/com/wix/detox/espresso/web/WebViewElement.java +33 -8
  30. package/android/detox/src/full/java/com/wix/detox/reactnative/ReactNativeExtension.kt +6 -11
  31. package/android/detox/src/full/java/com/wix/detox/reactnative/ReactNativeInfo.kt +4 -11
  32. package/android/detox/src/full/java/com/wix/detox/reactnative/idlingresources/DetoxIdlingResource.kt +42 -0
  33. package/android/detox/src/full/java/com/wix/detox/reactnative/idlingresources/ReactNativeIdlingResources.kt +145 -0
  34. package/android/detox/src/full/java/com/wix/detox/reactnative/idlingresources/animations/AnimatedModuleIdlingResource.kt +61 -0
  35. package/android/detox/src/full/java/com/wix/detox/reactnative/idlingresources/bridge/BridgeIdlingResource.kt +72 -0
  36. package/android/detox/src/full/java/com/wix/detox/reactnative/idlingresources/factory/DetoxIdlingResourceFactory.kt +32 -0
  37. package/android/detox/src/full/java/com/wix/detox/reactnative/idlingresources/factory/IdlingResourcesName.kt +10 -0
  38. package/android/detox/src/full/java/com/wix/detox/reactnative/idlingresources/factory/LooperName.kt +6 -0
  39. package/android/detox/src/full/java/com/wix/detox/reactnative/idlingresources/looper/MQThreadsReflector.kt +47 -0
  40. package/android/detox/src/full/java/com/wix/detox/reactnative/idlingresources/network/NetworkIdlingResource.kt +105 -0
  41. package/android/detox/src/full/java/com/wix/detox/reactnative/idlingresources/{NetworkingModuleReflected.kt → network/NetworkingModuleReflected.kt} +1 -1
  42. package/android/detox/src/full/java/com/wix/detox/reactnative/idlingresources/{AsyncStorageIdlingResource.kt → storage/AsyncStorageIdlingResource.kt} +33 -35
  43. package/android/detox/src/full/java/com/wix/detox/reactnative/idlingresources/{SerialExecutorReflected.kt → storage/SerialExecutorReflected.kt} +1 -1
  44. package/android/detox/src/full/java/com/wix/detox/reactnative/idlingresources/timers/TimersIdlingResource.kt +21 -19
  45. package/android/detox/src/full/java/com/wix/detox/reactnative/idlingresources/uimodule/UIManagerModuleReflected.kt +19 -27
  46. package/android/detox/src/full/java/com/wix/detox/reactnative/idlingresources/uimodule/UIModuleIdlingResource.kt +5 -17
  47. package/android/detox/src/testFull/java/com/wix/detox/reactnative/idlingresources/AsyncStorageIdlingResourceTest.kt +248 -0
  48. package/android/detox/src/testFull/java/com/wix/detox/reactnative/idlingresources/NetworkIdlingResourcesTest.kt +5 -1
  49. package/android/detox/src/testFull/java/com/wix/detox/reactnative/idlingresources/SerialExecutorReflectedSpec.kt +1 -0
  50. package/android/detox/src/testFull/java/com/wix/detox/reactnative/idlingresources/timers/TimersIdlingResourceTest.kt +212 -0
  51. package/android/gradle/wrapper/gradle-wrapper.properties +1 -1
  52. package/android/rninfo.gradle +31 -24
  53. package/android/settings.gradle +11 -6
  54. package/package.json +11 -8
  55. package/scripts/postinstall.js +2 -2
  56. package/scripts/updateGradle.js +41 -8
  57. package/src/DetoxWorker.js +11 -6
  58. package/src/copilot/DetoxCopilot.js +3 -15
  59. package/Detox-android/com/wix/detox/20.28.0/detox-20.28.0-sources.jar.md5 +0 -1
  60. package/Detox-android/com/wix/detox/20.28.0/detox-20.28.0-sources.jar.sha1 +0 -1
  61. package/Detox-android/com/wix/detox/20.28.0/detox-20.28.0-sources.jar.sha256 +0 -1
  62. package/Detox-android/com/wix/detox/20.28.0/detox-20.28.0-sources.jar.sha512 +0 -1
  63. package/Detox-android/com/wix/detox/20.28.0/detox-20.28.0.aar +0 -0
  64. package/Detox-android/com/wix/detox/20.28.0/detox-20.28.0.aar.md5 +0 -1
  65. package/Detox-android/com/wix/detox/20.28.0/detox-20.28.0.aar.sha1 +0 -1
  66. package/Detox-android/com/wix/detox/20.28.0/detox-20.28.0.aar.sha256 +0 -1
  67. package/Detox-android/com/wix/detox/20.28.0/detox-20.28.0.aar.sha512 +0 -1
  68. package/Detox-android/com/wix/detox/20.28.0/detox-20.28.0.pom.md5 +0 -1
  69. package/Detox-android/com/wix/detox/20.28.0/detox-20.28.0.pom.sha1 +0 -1
  70. package/Detox-android/com/wix/detox/20.28.0/detox-20.28.0.pom.sha256 +0 -1
  71. package/Detox-android/com/wix/detox/20.28.0/detox-20.28.0.pom.sha512 +0 -1
  72. package/Detox-android/com/wix/detox-legacy/20.28.0/detox-legacy-20.28.0-sources.jar +0 -0
  73. package/Detox-android/com/wix/detox-legacy/20.28.0/detox-legacy-20.28.0-sources.jar.md5 +0 -1
  74. package/Detox-android/com/wix/detox-legacy/20.28.0/detox-legacy-20.28.0-sources.jar.sha1 +0 -1
  75. package/Detox-android/com/wix/detox-legacy/20.28.0/detox-legacy-20.28.0-sources.jar.sha256 +0 -1
  76. package/Detox-android/com/wix/detox-legacy/20.28.0/detox-legacy-20.28.0-sources.jar.sha512 +0 -1
  77. package/Detox-android/com/wix/detox-legacy/20.28.0/detox-legacy-20.28.0.aar +0 -0
  78. package/Detox-android/com/wix/detox-legacy/20.28.0/detox-legacy-20.28.0.aar.md5 +0 -1
  79. package/Detox-android/com/wix/detox-legacy/20.28.0/detox-legacy-20.28.0.aar.sha1 +0 -1
  80. package/Detox-android/com/wix/detox-legacy/20.28.0/detox-legacy-20.28.0.aar.sha256 +0 -1
  81. package/Detox-android/com/wix/detox-legacy/20.28.0/detox-legacy-20.28.0.aar.sha512 +0 -1
  82. package/Detox-android/com/wix/detox-legacy/20.28.0/detox-legacy-20.28.0.pom +0 -100
  83. package/Detox-android/com/wix/detox-legacy/20.28.0/detox-legacy-20.28.0.pom.md5 +0 -1
  84. package/Detox-android/com/wix/detox-legacy/20.28.0/detox-legacy-20.28.0.pom.sha1 +0 -1
  85. package/Detox-android/com/wix/detox-legacy/20.28.0/detox-legacy-20.28.0.pom.sha256 +0 -1
  86. package/Detox-android/com/wix/detox-legacy/20.28.0/detox-legacy-20.28.0.pom.sha512 +0 -1
  87. package/Detox-android/com/wix/detox-legacy/maven-metadata.xml +0 -13
  88. package/Detox-android/com/wix/detox-legacy/maven-metadata.xml.md5 +0 -1
  89. package/Detox-android/com/wix/detox-legacy/maven-metadata.xml.sha1 +0 -1
  90. package/Detox-android/com/wix/detox-legacy/maven-metadata.xml.sha256 +0 -1
  91. package/Detox-android/com/wix/detox-legacy/maven-metadata.xml.sha512 +0 -1
  92. package/android/detox/src/full/java/com/wix/detox/reactnative/ReactNativeIdlingResources.kt +0 -229
  93. package/android/detox/src/full/java/com/wix/detox/reactnative/idlingresources/AnimatedModuleIdlingResource.java +0 -215
  94. package/android/detox/src/full/java/com/wix/detox/reactnative/idlingresources/BridgeIdlingResource.java +0 -94
  95. package/android/detox/src/full/java/com/wix/detox/reactnative/idlingresources/DetoxBaseIdlingResource.java +0 -29
  96. package/android/detox/src/full/java/com/wix/detox/reactnative/idlingresources/NetworkIdlingResource.java +0 -134
  97. package/android/detox/src/full/java/com/wix/detox/reactnative/idlingresources/timers/DelegatedIdleInterrogationStrategy.kt +0 -23
  98. package/android/detox/src/full/java/com/wix/detox/reactnative/idlingresources/timers/IdleInterrogationStrategy.kt +0 -16
  99. package/android/detox/src/full/java/com/wix/detox/reactnative/idlingresources/uimodule/RN66Workaround.kt +0 -71
  100. package/android/detox/src/testFull/java/com/wix/detox/reactnative/idlingresources/AsyncStorageIdlingResourceSpec.kt +0 -227
  101. package/android/detox/src/testFull/java/com/wix/detox/reactnative/idlingresources/timers/DelegatedIdleInterrogationStrategySpec.kt +0 -47
  102. 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,10 @@
1
+ package com.wix.detox.reactnative.idlingresources.factory
2
+
3
+ enum class IdlingResourcesName {
4
+ Timers,
5
+ AsyncStorage,
6
+ RNBridge,
7
+ UIModule,
8
+ Animations,
9
+ Network
10
+ }
@@ -0,0 +1,6 @@
1
+ package com.wix.detox.reactnative.idlingresources.factory
2
+
3
+ enum class LooperName {
4
+ JS,
5
+ NativeModules
6
+ }
@@ -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,4 +1,4 @@
1
- package com.wix.detox.reactnative.idlingresources
1
+ package com.wix.detox.reactnative.idlingresources.network
2
2
 
3
3
  import android.util.Log
4
4
  import com.facebook.react.bridge.ReactContext
@@ -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
- private val defaultSExecutorReflectedGenFn: SExecutorReflectedGenFnType = { executor: Executor -> SerialExecutorReflected(executor) }
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
- open class AsyncStorageIdlingResource
29
- @JvmOverloads constructor(
30
- module: NativeModule,
31
- sexecutorReflectedGenFn: SExecutorReflectedGenFnType = defaultSExecutorReflectedGenFn)
32
- : DescriptiveIdlingResource {
30
+ class AsyncStorageIdlingResource
31
+ @JvmOverloads constructor(
32
+ module: NativeModule,
33
+ sexecutorReflectedGenFn: SExecutorReflectedGenFnType = defaultSExecutorReflectedGenFn
34
+ ) : DetoxIdlingResource() {
33
35
 
34
- open val logTag: String
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
- callback?.onTransitionToIdle()
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
- override fun isIdleNow(): Boolean =
58
- checkIdle().also { idle ->
59
- if (!idle) {
60
- Log.d(logTag, "Async-storage is busy!")
61
- enqueueIdleCheckTask()
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
- this.callback = callback
67
+ super.registerIdleTransitionCallback(callback)
66
68
  enqueueIdleCheckTask()
67
69
  }
68
70
 
69
- private fun checkIdle(): Boolean =
70
- with(moduleReflected.sexecutor) {
71
- synchronized(executor()) {
72
- !hasActiveTask() && !hasPendingTasks()
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, legacy: Boolean): AsyncStorageIdlingResource? {
98
- Log.d(LOG_TAG, "Checking whether a custom IR for Async-Storage is required... (legacy=$legacy)")
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(legacy))?.let { module ->
101
- Log.d(LOG_TAG, "IR for Async-Storage is required! (legacy=$legacy)")
102
- createInstance(module, legacy)
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(legacy: Boolean): String {
107
- val packageName = if (legacy) "com.facebook.react.modules.storage" else "com.reactnativecommunity.asyncstorage"
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, legacy: Boolean) =
112
- if (legacy) AsyncStorageIdlingResourceLegacy(module) else AsyncStorageIdlingResource(module)
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,4 +1,4 @@
1
- package com.wix.detox.reactnative.idlingresources
1
+ package com.wix.detox.reactnative.idlingresources.storage
2
2
 
3
3
  import org.joor.Reflect
4
4
  import java.util.concurrent.Executor
@@ -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.wix.detox.reactnative.idlingresources.DetoxBaseIdlingResource
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
- private val interrogationStrategy: IdleInterrogationStrategy,
9
- private val getChoreographer: () -> Choreographer = { Choreographer.getInstance() }
10
- ) : DetoxBaseIdlingResource(), Choreographer.FrameCallback {
13
+ reactContext: ReactContext,
14
+ private val getChoreographer: () -> Choreographer = { Choreographer.getInstance() }
15
+ ) : DetoxIdlingResource(), Choreographer.FrameCallback {
11
16
 
12
- private var callback: IdlingResource.ResourceCallback? = null
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
- this.callback = callback
24
+ super.registerIdleTransitionCallback(callback)
20
25
  getChoreographer().postFrameCallback(this)
21
26
  }
22
27
 
28
+ @SuppressLint("VisibleForTests")
23
29
  override fun checkIdle(): Boolean {
24
- return interrogationStrategy.isIdleNow().also { result ->
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
- override fun doFrame(frameTimeNanos: Long) {
34
- callback?.let {
35
- isIdleNow
32
+ if (isIdle) {
33
+ notifyIdle()
34
+ } else {
35
+ getChoreographer().postFrameCallback(this)
36
36
  }
37
+
38
+ return isIdle
37
39
  }
38
40
 
39
- override fun notifyIdle() {
40
- callback?.onTransitionToIdle()
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<Boolean>()
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
- .field(FIELD_NON_BATCHED_OPS)
43
- .call(METHOD_IS_EMPTY).get<Boolean>()
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<Boolean>()
41
+ Reflect.on(it).call(METHOD_IS_EMPTY).get()
50
42
  } ?: true
51
43
 
52
44
  private fun viewCommandOperations(): ViewCommandOpsQueueReflected? =
53
- getUIOperationQueue()?.let {
54
- ViewCommandOpsQueueReflected(it)
55
- }
45
+ getUIOperationQueue()?.let {
46
+ ViewCommandOpsQueueReflected(it)
47
+ }
56
48
 
57
49
 
58
50
  private fun getUIOperationQueue(): UIViewOperationQueue? =
59
- try {
60
- val uiModuleClass = Class.forName(CLASS_UI_MANAGER_MODULE)
61
- Reflect.on(reactContext)
62
- .call(METHOD_GET_NATIVE_MODULE, uiModuleClass)
63
- .call(METHOD_GET_UI_IMPLEMENTATION)
64
- .field(FIELD_UI_OPERATION_QUEUE)
65
- .get()
66
- } catch (e: Exception) {
67
- Log.e(LOG_TAG, "failed to get $CLASS_UI_MANAGER_MODULE instance ", e)
68
- null
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.DetoxBaseIdlingResource
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
- : DetoxBaseIdlingResource(), Choreographer.FrameCallback {
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
- var operationQueueEmpty = uiManagerModuleReflected.isOperationQueueEmpty()
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
- this.callback = callback
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
  }