Skip to content

Commit 878e04e

Browse files
committed
put tests in common test module
1 parent 39da466 commit 878e04e

File tree

12 files changed

+54
-94
lines changed

12 files changed

+54
-94
lines changed

build.gradle.kts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -131,22 +131,22 @@ subprojects {
131131

132132
dependencies {
133133
"commonMainImplementation"(kotlin("stdlib-common"))
134-
"commonMainImplementation"("org.jetbrains.kotlinx:kotlinx-coroutines-core-common:1.3.5-native-mt")
134+
"commonMainImplementation"("org.jetbrains.kotlinx:kotlinx-coroutines-core-common:1.3.5")
135135
"jsMainImplementation"(kotlin("stdlib-js"))
136-
"jsMainImplementation"("org.jetbrains.kotlinx:kotlinx-coroutines-core-js:1.3.4")
137-
"androidMainImplementation"("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.3.4")
138-
"androidMainImplementation"("org.jetbrains.kotlinx:kotlinx-coroutines-play-services:1.3.4")
139-
"iosMainImplementation"("org.jetbrains.kotlinx:kotlinx-coroutines-core-common:1.3.5-native-mt")
140-
"iosMainImplementation"("org.jetbrains.kotlinx:kotlinx-coroutines-core-native:1.3.5-native-mt")
136+
"jsMainImplementation"("org.jetbrains.kotlinx:kotlinx-coroutines-core-js:1.3.5")
137+
"androidMainImplementation"("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.3.5")
138+
"androidMainImplementation"("org.jetbrains.kotlinx:kotlinx-coroutines-play-services:1.3.5")
139+
"iosMainImplementation"("org.jetbrains.kotlinx:kotlinx-coroutines-core-common:1.3.5")
140+
"iosMainImplementation"("org.jetbrains.kotlinx:kotlinx-coroutines-core-native:1.3.5")
141141
"commonTestImplementation"(kotlin("test-common"))
142142
"commonTestImplementation"(kotlin("test-annotations-common"))
143-
"commonTestImplementation"("org.jetbrains.kotlinx:kotlinx-coroutines-core-common:1.3.5-native-mt")
144-
"commonTestImplementation"("org.jetbrains.kotlinx:kotlinx-coroutines-test:1.3.5-native-mt")
143+
"commonTestImplementation"("org.jetbrains.kotlinx:kotlinx-coroutines-core-common:1.3.5")
144+
"commonTestImplementation"("org.jetbrains.kotlinx:kotlinx-coroutines-test:1.3.5")
145145
"jsTestImplementation"(kotlin("test-js"))
146146
"androidAndroidTestImplementation"(kotlin("test-junit"))
147147
"androidAndroidTestImplementation"("junit:junit:4.12")
148148
"androidAndroidTestImplementation"("androidx.test:core:1.2.0")
149-
"androidAndroidTestImplementation"("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.3.4")
149+
"androidAndroidTestImplementation"("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.3.5")
150150
"androidAndroidTestImplementation"("androidx.test.ext:junit:1.1.1")
151151
"androidAndroidTestImplementation"("androidx.test:runner:1.1.0")
152152
}

firebase-app/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
"@gitlive/firebase-common": "0.1.0",
2727
"firebase": "7.14.0",
2828
"kotlin": "1.3.72",
29-
"kotlinx-coroutines-core": "1.3.4"
29+
"kotlinx-coroutines-core": "1.3.5"
3030
}
3131
}
3232

firebase-auth/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
"@gitlive/firebase-app": "0.1.0",
2727
"firebase": "7.14.0",
2828
"kotlin": "1.3.72",
29-
"kotlinx-coroutines-core": "1.3.4"
29+
"kotlinx-coroutines-core": "1.3.5"
3030
}
3131
}
3232

firebase-auth/src/androidAndroidTest/kotlin/dev/gitlive/firebase/auth/auth.kt

Lines changed: 2 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -5,38 +5,9 @@
55
@file:JvmName("tests")
66
package dev.gitlive.firebase.auth
77

8-
import androidx.test.ext.junit.runners.AndroidJUnit4
9-
import androidx.test.filters.SmallTest
108
import androidx.test.platform.app.InstrumentationRegistry
11-
import dev.gitlive.firebase.Firebase
12-
import dev.gitlive.firebase.FirebaseOptions
13-
import dev.gitlive.firebase.initialize
149
import kotlinx.coroutines.runBlocking
15-
import org.junit.Before
16-
import org.junit.runner.RunWith
17-
import kotlin.test.assertEquals
1810

19-
val context: Any = InstrumentationRegistry.getInstrumentation().targetContext
11+
actual val context: Any = InstrumentationRegistry.getInstrumentation().targetContext
2012

21-
@RunWith(AndroidJUnit4::class)
22-
@SmallTest
23-
class FirebaseAuthTest {
24-
25-
@Before
26-
fun initializeFirebase() {
27-
Firebase.initialize(context, FirebaseOptions(
28-
applicationId ="fir-kotlin-sdk",
29-
apiKey = "AIzaSyDft_DSsVA7KPJj_GItUvMLjk6wbOdGBOs",
30-
databaseUrl = "https://fir-kotlin-sdk.firebaseio.com",
31-
storageBucket = "fir-kotlin-sdk.appspot.com",
32-
projectId ="fir-kotlin-sdk"
33-
))
34-
35-
}
36-
37-
@org.junit.Test
38-
fun testSignInWithUsernameAndPassword() = runBlocking {
39-
val result = Firebase.auth.signInWithEmailAndPassword("[email protected]", "test123")
40-
assertEquals("mn8kgIFnxLO7il8GpTa5g0ObP6I2", result.user!!.uid)
41-
}
42-
}
13+
actual fun runTest(test: suspend () -> Unit) = runBlocking { test() }

firebase-auth/src/androidMain/kotlin/dev/gitlive/firebase/auth/auth.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ actual class FirebaseAuth internal constructor(val android: com.google.firebase.
2222
get() = android.currentUser?.let { FirebaseUser(it) }
2323

2424
actual suspend fun signInWithEmailAndPassword(email: String, password: String) =
25-
AuthResult(android.signInWithCustomToken(email).await())
25+
AuthResult(android.signInWithEmailAndPassword(email, password).await())
2626
//AuthResult(android.signInWithEmailAndPassword(email, password).await())
2727

2828
actual suspend fun signInWithCustomToken(token: String) =

firebase-auth/src/jsTest/kotlin/auth/auth.kt renamed to firebase-auth/src/commonTest/kotlin/dev/gitlive/firebase/auth/auth.kt

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,29 +8,31 @@ import dev.gitlive.firebase.Firebase
88
import dev.gitlive.firebase.FirebaseOptions
99
import dev.gitlive.firebase.initialize
1010
import kotlinx.coroutines.GlobalScope
11-
import kotlinx.coroutines.promise
1211
import kotlin.test.BeforeTest
1312
import kotlin.test.Test
1413
import kotlin.test.assertEquals
1514

16-
//expect val context: Any
15+
expect val context: Any
16+
expect fun runTest(test: suspend () -> Unit)
1717

1818
class FirebaseAuthTest {
1919

2020
@BeforeTest
2121
fun initializeFirebase() {
22-
Firebase.initialize(null, FirebaseOptions(
23-
applicationId ="fir-kotlin-sdk",
24-
apiKey = "AIzaSyDft_DSsVA7KPJj_GItUvMLjk6wbOdGBOs",
25-
databaseUrl = "https://fir-kotlin-sdk.firebaseio.com",
26-
storageBucket = "fir-kotlin-sdk.appspot.com",
27-
projectId ="fir-kotlin-sdk"
28-
))
29-
22+
Firebase.initialize(
23+
context,
24+
FirebaseOptions(
25+
applicationId = "1:846484016111:ios:dd1f6688bad7af768c841a",
26+
apiKey = "AIzaSyCK87dcMFhzCz_kJVs2cT2AVlqOTLuyWV0",
27+
databaseUrl = "https://fir-kotlin-sdk.firebaseio.com",
28+
storageBucket = "fir-kotlin-sdk.appspot.com",
29+
projectId = "fir-kotlin-sdk"
30+
)
31+
)
3032
}
3133

3234
@Test
33-
fun testSignInWithUsernameAndPassword() = GlobalScope.promise {
35+
fun testSignInWithUsernameAndPassword() = runTest {
3436
val result = Firebase.auth.signInWithEmailAndPassword("[email protected]", "test123")
3537
assertEquals("mn8kgIFnxLO7il8GpTa5g0ObP6I2", result.user!!.uid)
3638
}

firebase-auth/src/iosTest/kotlin/dev/gitlive/firebase/auth/auth.kt

Lines changed: 11 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -4,44 +4,19 @@
44

55
package dev.gitlive.firebase.auth
66

7-
import dev.gitlive.firebase.Firebase
8-
import dev.gitlive.firebase.FirebaseOptions
9-
import dev.gitlive.firebase.initialize
107
import kotlinx.coroutines.*
118
import platform.Foundation.*
12-
import kotlin.test.BeforeTest
13-
import kotlin.test.Test
14-
import kotlin.test.assertEquals
159

16-
class FirebaseAuthTest {
10+
actual val context: Any = Unit
1711

18-
@BeforeTest
19-
fun initializeFirebase() {
20-
Firebase.initialize(null, FirebaseOptions(
21-
applicationId = "1:846484016111:ios:dd1f6688bad7af768c841a",
22-
apiKey = "AIzaSyCK87dcMFhzCz_kJVs2cT2AVlqOTLuyWV0",
23-
databaseUrl = "https://fir- kotlin-sdk.firebaseio.com",
24-
storageBucket = "fir-kotlin-sdk.appspot.com",
25-
projectId = "fir-kotlin-sdk"
26-
))
12+
actual fun runTest(test: suspend () -> Unit) = runBlocking {
13+
val testRun = MainScope().async { test() }
14+
while (testRun.isActive) {
15+
NSRunLoop.mainRunLoop.runMode(
16+
NSDefaultRunLoopMode,
17+
beforeDate = NSDate.create(timeInterval = 1.0, sinceDate = NSDate())
18+
)
19+
yield()
2720
}
28-
29-
@Test
30-
fun testSignInWithUsernameAndPassword() {
31-
val auth = Firebase.auth
32-
var done = false
33-
lateinit var result: AuthResult
34-
//GlobalScope.launch(Dispatchers.Unconfined) {
35-
MainScope().launch {
36-
result = auth.signInWithEmailAndPassword("[email protected]", "test123")
37-
println("Stop the run, cant stop the run")
38-
done = true
39-
}
40-
while (!done) {
41-
println("LoopStart")
42-
NSRunLoop.mainRunLoop.runMode(NSDefaultRunLoopMode, beforeDate = NSDate.create(timeInterval = 1.0, sinceDate = NSDate()))
43-
println("LoopEnd")
44-
}
45-
assertEquals("mn8kgIFnxLO7il8GpTa5g0ObP6I2", result.user!!.uid)
46-
}
47-
}
21+
testRun.await()
22+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
/*
2+
* Copyright (c) 2020 GitLive Ltd. Use of this source code is governed by the Apache 2.0 license.
3+
*/
4+
5+
package dev.gitlive.firebase.auth
6+
7+
import kotlinx.coroutines.GlobalScope
8+
import kotlinx.coroutines.promise
9+
10+
actual val context: Any = Unit
11+
12+
actual fun runTest(test: suspend () -> Unit) = GlobalScope.promise { test() }.unsafeCast<Unit>()

firebase-common/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
"dependencies": {
2626
"firebase": "7.14.0",
2727
"kotlin": "1.3.72",
28-
"kotlinx-coroutines-core": "1.3.4",
28+
"kotlinx-coroutines-core": "1.3.5",
2929
"kotlinx-serialization-kotlinx-serialization-runtime": "0.20.0"
3030
}
3131
}

firebase-database/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
"@gitlive/firebase-app": "0.1.0",
2727
"firebase": "7.14.0",
2828
"kotlin": "1.3.72",
29-
"kotlinx-coroutines-core": "1.3.4"
29+
"kotlinx-coroutines-core": "1.3.5"
3030
}
3131
}
3232

0 commit comments

Comments
 (0)