expo-modules-test-core 0.17.2 → 0.18.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/android/build.gradle
CHANGED
|
@@ -1,113 +1,24 @@
|
|
|
1
1
|
apply plugin: 'com.android.library'
|
|
2
|
-
apply plugin: 'kotlin-android'
|
|
3
|
-
apply plugin: 'maven-publish'
|
|
4
2
|
|
|
5
3
|
group = 'org.unimodules'
|
|
6
|
-
version = '0.
|
|
4
|
+
version = '0.18.0'
|
|
7
5
|
|
|
8
6
|
def expoModulesCorePlugin = new File(project(":expo-modules-core").projectDir.absolutePath, "ExpoModulesCorePlugin.gradle")
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
useExpoPublishing()
|
|
15
|
-
useCoreDependencies()
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
buildscript {
|
|
20
|
-
// Simple helper that allows the root project to override versions declared by this library.
|
|
21
|
-
ext.safeExtGet = { prop, fallback ->
|
|
22
|
-
rootProject.ext.has(prop) ? rootProject.ext.get(prop) : fallback
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
// Ensures backward compatibility
|
|
26
|
-
ext.getKotlinVersion = {
|
|
27
|
-
if (ext.has("kotlinVersion")) {
|
|
28
|
-
ext.kotlinVersion()
|
|
29
|
-
} else {
|
|
30
|
-
ext.safeExtGet("kotlinVersion", "1.8.10")
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
repositories {
|
|
35
|
-
mavenCentral()
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
dependencies {
|
|
39
|
-
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:${getKotlinVersion()}")
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
// Remove this if and it's contents, when support for SDK49 is dropped
|
|
44
|
-
if (!safeExtGet("expoProvidesDefaultConfig", false)) {
|
|
45
|
-
afterEvaluate {
|
|
46
|
-
publishing {
|
|
47
|
-
publications {
|
|
48
|
-
release(MavenPublication) {
|
|
49
|
-
from components.release
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
repositories {
|
|
53
|
-
maven {
|
|
54
|
-
url = mavenLocal().url
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
}
|
|
7
|
+
apply from: expoModulesCorePlugin
|
|
8
|
+
applyKotlinExpoModulesCorePlugin()
|
|
9
|
+
useCoreDependencies()
|
|
10
|
+
useDefaultAndroidSdkVersions()
|
|
11
|
+
useExpoPublishing()
|
|
60
12
|
|
|
61
13
|
android {
|
|
62
|
-
// Remove this if and it's contents, when support for SDK49 is dropped
|
|
63
|
-
if (!safeExtGet("expoProvidesDefaultConfig", false)) {
|
|
64
|
-
compileSdkVersion safeExtGet("compileSdkVersion", 34)
|
|
65
|
-
|
|
66
|
-
defaultConfig {
|
|
67
|
-
minSdkVersion safeExtGet("minSdkVersion", 23)
|
|
68
|
-
targetSdkVersion safeExtGet("targetSdkVersion", 34)
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
publishing {
|
|
72
|
-
singleVariant("release") {
|
|
73
|
-
withSourcesJar()
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
lintOptions {
|
|
78
|
-
abortOnError false
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
def agpVersion = com.android.Version.ANDROID_GRADLE_PLUGIN_VERSION
|
|
83
|
-
if (agpVersion.tokenize('.')[0].toInteger() < 8) {
|
|
84
|
-
compileOptions {
|
|
85
|
-
sourceCompatibility JavaVersion.VERSION_11
|
|
86
|
-
targetCompatibility JavaVersion.VERSION_11
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
kotlinOptions {
|
|
90
|
-
jvmTarget = JavaVersion.VERSION_11.majorVersion
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
|
|
94
14
|
namespace "org.unimodules.test.core"
|
|
95
15
|
defaultConfig {
|
|
96
16
|
versionCode 3
|
|
97
|
-
versionName '0.
|
|
17
|
+
versionName '0.18.0'
|
|
98
18
|
}
|
|
99
19
|
}
|
|
100
20
|
|
|
101
|
-
repositories {
|
|
102
|
-
mavenCentral()
|
|
103
|
-
}
|
|
104
|
-
|
|
105
21
|
dependencies {
|
|
106
|
-
// Remove this if and it's contents, when support for SDK49 is dropped
|
|
107
|
-
if (!safeExtGet("expoProvidesDefaultConfig", false)) {
|
|
108
|
-
implementation project(':expo-modules-core')
|
|
109
|
-
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:${getKotlinVersion()}"
|
|
110
|
-
}
|
|
111
22
|
api 'androidx.test:core:1.5.0'
|
|
112
23
|
api 'junit:junit:4.13.2'
|
|
113
24
|
api 'io.mockk:mockk:1.13.5'
|
|
@@ -115,5 +26,5 @@ dependencies {
|
|
|
115
26
|
|
|
116
27
|
implementation 'com.facebook.react:react-android'
|
|
117
28
|
|
|
118
|
-
implementation "org.jetbrains.kotlin:kotlin-reflect:${
|
|
29
|
+
implementation "org.jetbrains.kotlin:kotlin-reflect:${kotlinVersion()}"
|
|
119
30
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "expo-modules-test-core",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.18.0",
|
|
4
4
|
"main": "./app.plugin.js",
|
|
5
5
|
"description": "Module providing native testing utilities for testing Expo modules",
|
|
6
6
|
"keywords": [
|
|
@@ -34,5 +34,5 @@
|
|
|
34
34
|
"xml-js": "^1.6.11",
|
|
35
35
|
"yaml": "^2.3.2"
|
|
36
36
|
},
|
|
37
|
-
"gitHead": "
|
|
37
|
+
"gitHead": "4165b8d72e1b9a1889c2767534cc619e21468110"
|
|
38
38
|
}
|
|
@@ -1,88 +0,0 @@
|
|
|
1
|
-
package org.unimodules.test.core
|
|
2
|
-
|
|
3
|
-
import expo.modules.core.Promise
|
|
4
|
-
|
|
5
|
-
enum class PromiseState {
|
|
6
|
-
NONE,
|
|
7
|
-
REJECTED,
|
|
8
|
-
RESOLVED,
|
|
9
|
-
ILLEGAL
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
class PromiseMock : Promise {
|
|
13
|
-
|
|
14
|
-
var state = PromiseState.NONE
|
|
15
|
-
|
|
16
|
-
var resolveValueSet: Boolean = false
|
|
17
|
-
var resolveValue: Any? = null
|
|
18
|
-
set(value) {
|
|
19
|
-
this.resolveValueSet = true
|
|
20
|
-
field = value
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
var rejectCodeSet: Boolean = false
|
|
24
|
-
var rejectCode: String? = null
|
|
25
|
-
set(value) {
|
|
26
|
-
this.rejectCodeSet = true
|
|
27
|
-
field = value
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
var rejectMessageSet: Boolean = false
|
|
31
|
-
var rejectMessage: String? = null
|
|
32
|
-
set(value) {
|
|
33
|
-
this.rejectMessageSet = true
|
|
34
|
-
field = value
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
var rejectThrowableSet: Boolean = false
|
|
38
|
-
var rejectThrowable: Throwable? = null
|
|
39
|
-
set(value) {
|
|
40
|
-
this.rejectThrowableSet = true
|
|
41
|
-
field = value
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
override fun resolve(value: Any?) {
|
|
45
|
-
assertNotResolvedNorRejected()
|
|
46
|
-
state = PromiseState.RESOLVED
|
|
47
|
-
resolveValue = value
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
override fun reject(code: String?, message: String?, e: Throwable?) {
|
|
51
|
-
assertNotResolvedNorRejected()
|
|
52
|
-
state = PromiseState.REJECTED
|
|
53
|
-
rejectCode = code
|
|
54
|
-
rejectMessage = message
|
|
55
|
-
rejectThrowable = e
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
override fun reject(e: Throwable?) {
|
|
59
|
-
assertNotResolvedNorRejected()
|
|
60
|
-
state = PromiseState.REJECTED
|
|
61
|
-
rejectThrowable = e
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
override fun reject(code: String?, message: String?) {
|
|
65
|
-
assertNotResolvedNorRejected()
|
|
66
|
-
state = PromiseState.REJECTED
|
|
67
|
-
rejectCode = code
|
|
68
|
-
rejectMessage = message
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
override fun reject(code: String?, e: Throwable?) {
|
|
72
|
-
assertNotResolvedNorRejected()
|
|
73
|
-
state = PromiseState.REJECTED
|
|
74
|
-
rejectCode = code
|
|
75
|
-
rejectThrowable = e
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
private fun assertNotResolvedNorRejected() {
|
|
79
|
-
when (state) {
|
|
80
|
-
PromiseState.RESOLVED, PromiseState.REJECTED, PromiseState.ILLEGAL -> {
|
|
81
|
-
state = PromiseState.ILLEGAL
|
|
82
|
-
throw IllegalStateException("Cannot resolve same promise twice!")
|
|
83
|
-
}
|
|
84
|
-
else -> {
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
}
|
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
package org.unimodules.test.core
|
|
2
|
-
|
|
3
|
-
import android.os.Bundle
|
|
4
|
-
import junit.framework.ComparisonFailure
|
|
5
|
-
import org.junit.Assert.assertEquals
|
|
6
|
-
import org.junit.Assert.assertTrue
|
|
7
|
-
import expo.modules.core.arguments.MapArguments
|
|
8
|
-
import expo.modules.core.arguments.ReadableArguments
|
|
9
|
-
|
|
10
|
-
fun assertSetsEqual(first: Set<*>, second: Set<*>, message: String = "") {
|
|
11
|
-
if (!first.all { second.contains(it) }) {
|
|
12
|
-
throw ComparisonFailure(message, first.toString(), second.toString())
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
fun assertListsEqual(first: List<*>?, second: List<*>?, message: String = "") {
|
|
17
|
-
if (first == second) return
|
|
18
|
-
|
|
19
|
-
if (first == null || second == null) {
|
|
20
|
-
throw throw ComparisonFailure(message, first.toString(), second.toString())
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
if (!first.toTypedArray().contentDeepEquals(second.toTypedArray())) {
|
|
24
|
-
throw ComparisonFailure(message, first.toString(), second.toString())
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
fun assertResolved(promise: PromiseMock) {
|
|
29
|
-
assertEquals(PromiseState.RESOLVED, promise.state)
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
fun assertRejected(promise: PromiseMock) {
|
|
33
|
-
assertEquals(PromiseState.REJECTED, promise.state)
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
fun promiseResolved(promise: PromiseMock, with: (Bundle) -> Unit) {
|
|
37
|
-
assertResolved(promise)
|
|
38
|
-
with(promise.resolveValue as Bundle)
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
inline fun <reified T> promiseResolvedWithType(promise: PromiseMock, with: (T) -> Unit) {
|
|
42
|
-
assertResolved(promise)
|
|
43
|
-
assertTrue("Promise resolved with incorrect type", promise.resolveValue is T)
|
|
44
|
-
with(promise.resolveValue as T)
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
fun promiseRejected(promise: PromiseMock, with: (PromiseMock) -> Unit) {
|
|
48
|
-
assertRejected(promise)
|
|
49
|
-
with(promise)
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
fun assertRejectedWithCode(promise: PromiseMock, rejectCode: String) {
|
|
53
|
-
promiseRejected(promise) {
|
|
54
|
-
assertTrue("Promise has no rejection code", it.rejectCodeSet)
|
|
55
|
-
assertEquals(it.rejectCode, rejectCode)
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
fun readableArgumentsOf(values: Map<String, Any>): ReadableArguments {
|
|
60
|
-
return MapArguments(values)
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
fun assertStringValueNull(bundle: Bundle, key: String) {
|
|
64
|
-
assertTrue(bundle.containsKey(key))
|
|
65
|
-
assertEquals(null, bundle.getString(key))
|
|
66
|
-
}
|
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
package org.unimodules.test.core
|
|
2
|
-
|
|
3
|
-
import io.mockk.MockKGateway
|
|
4
|
-
import io.mockk.every
|
|
5
|
-
import io.mockk.mockk
|
|
6
|
-
import io.mockk.spyk
|
|
7
|
-
import expo.modules.core.ExportedModule
|
|
8
|
-
import expo.modules.core.ModuleRegistry
|
|
9
|
-
import expo.modules.core.interfaces.InternalModule
|
|
10
|
-
import java.util.*
|
|
11
|
-
|
|
12
|
-
@JvmOverloads
|
|
13
|
-
fun moduleRegistryMock(
|
|
14
|
-
internalModules: List<InternalModule> = Collections.emptyList(),
|
|
15
|
-
exportedModules: List<ExportedModule> = Collections.emptyList()
|
|
16
|
-
): ModuleRegistry {
|
|
17
|
-
return mockk<ModuleRegistry>().also {
|
|
18
|
-
mockInternalModules(it, internalModules)
|
|
19
|
-
mockExternalModules(it, exportedModules)
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
inline fun <reified T : InternalModule> mockkInternalModule(relaxed: Boolean = false, asInterface: Class<*> = T::class.java): T {
|
|
24
|
-
val mock: T = mockk(relaxed = relaxed)
|
|
25
|
-
every { mock.exportedInterfaces } returns listOf(asInterface)
|
|
26
|
-
return mock
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
private fun mockInternalModules(mock: ModuleRegistry, internalModules: List<InternalModule>) {
|
|
30
|
-
internalModules.forEach {
|
|
31
|
-
mock.mockInternalModule(it)
|
|
32
|
-
}
|
|
33
|
-
every { mock.getModule<Any>(any()) } returns null
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
private fun mockExternalModules(mock: ModuleRegistry, exportedModules: List<ExportedModule>) {
|
|
37
|
-
exportedModules.forEach {
|
|
38
|
-
every { mock.getExportedModule(it.name) } returns it
|
|
39
|
-
}
|
|
40
|
-
every { mock.getExportedModule(any()) } returns null
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
fun ModuleRegistry.mockInternalModule(module: InternalModule) =
|
|
44
|
-
if (!this.isMock) {
|
|
45
|
-
throw IllegalStateException("Mocking modules available only for mocked module registry!")
|
|
46
|
-
} else {
|
|
47
|
-
module.exportedInterfaces.forEach {
|
|
48
|
-
every { this@mockInternalModule.getModule(it) } returns module
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
fun ModuleRegistry.mockExportedModule(module: ExportedModule) =
|
|
53
|
-
if (!this.isMock) {
|
|
54
|
-
throw IllegalStateException("Mocking modules available only for mocked module registry!")
|
|
55
|
-
} else {
|
|
56
|
-
every { this@mockExportedModule.getExportedModule(module.name) } returns module
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
fun mockPromise(): PromiseMock {
|
|
60
|
-
return spyk()
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
private val <T : Any> T.isMock: Boolean
|
|
64
|
-
get() {
|
|
65
|
-
return try {
|
|
66
|
-
MockKGateway.implementation().mockFactory.isMock(this)
|
|
67
|
-
} catch (e: UninitializedPropertyAccessException) {
|
|
68
|
-
false
|
|
69
|
-
}
|
|
70
|
-
}
|