Skip to content

Gl 861 add ability to skip ios tests for firebase #230

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Merged
merged 11 commits into from
Oct 5, 2021
84 changes: 48 additions & 36 deletions firebase-app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -57,42 +57,46 @@ kotlin {
publishAllLibraryVariants()
}

fun nativeTargetConfig(): KotlinNativeTarget.() -> Unit = {
val nativeFrameworkPaths = listOf(
projectDir.resolve("src/nativeInterop/cinterop/Carthage/Build/iOS")
).plus(
listOf(
"FirebaseAnalytics",
"FirebaseCore",
"FirebaseCoreDiagnostics",
"FirebaseInstallations",
"GoogleAppMeasurement",
"GoogleDataTransport",
"GoogleUtilities",
"nanopb",
"PromisesObjC"
).map {
projectDir.resolve("src/nativeInterop/cinterop/Carthage/Build/$it.xcframework/${konanTarget.archVariant}")
}
)
val supportIosTarget = project.property("skipIosTarget") != "true"
if (supportIosTarget) {

fun nativeTargetConfig(): KotlinNativeTarget.() -> Unit = {
val nativeFrameworkPaths = listOf(
projectDir.resolve("src/nativeInterop/cinterop/Carthage/Build/iOS")
).plus(
listOf(
"FirebaseAnalytics",
"FirebaseCore",
"FirebaseCoreDiagnostics",
"FirebaseInstallations",
"GoogleAppMeasurement",
"GoogleDataTransport",
"GoogleUtilities",
"nanopb",
"PromisesObjC"
).map {
projectDir.resolve("src/nativeInterop/cinterop/Carthage/Build/$it.xcframework/${konanTarget.archVariant}")
}
)

binaries {
getTest("DEBUG").apply {
linkerOpts(nativeFrameworkPaths.map { "-F$it" })
linkerOpts("-ObjC")
binaries {
getTest("DEBUG").apply {
linkerOpts(nativeFrameworkPaths.map { "-F$it" })
linkerOpts("-ObjC")
}
}
}

compilations.getByName("main") {
cinterops.create("FirebaseCore") {
compilerOpts(nativeFrameworkPaths.map { "-F$it" })
extraOpts("-verbose")
compilations.getByName("main") {
cinterops.create("FirebaseCore") {
compilerOpts(nativeFrameworkPaths.map { "-F$it" })
extraOpts("-verbose")
}
}
}
}

ios(configure = nativeTargetConfig())
iosSimulatorArm64(configure = nativeTargetConfig())
ios(configure = nativeTargetConfig())
iosSimulatorArm64(configure = nativeTargetConfig())
}

js {
useCommonJs()
Expand Down Expand Up @@ -133,18 +137,26 @@ kotlin {
}
}

val iosMain by getting
val iosSimulatorArm64Main by getting
iosSimulatorArm64Main.dependsOn(iosMain)
if (supportIosTarget) {
val iosMain by getting
val iosSimulatorArm64Main by getting
iosSimulatorArm64Main.dependsOn(iosMain)

val iosTest by sourceSets.getting
val iosSimulatorArm64Test by sourceSets.getting
iosSimulatorArm64Test.dependsOn(iosTest)
val iosTest by sourceSets.getting
val iosSimulatorArm64Test by sourceSets.getting
iosSimulatorArm64Test.dependsOn(iosTest)
}

val jsMain by getting
}
}

if (project.property("firebase-app.skipIosTests") == "true") {
tasks.forEach {
if (it.name.contains("ios", true) && it.name.contains("test", true)) { it.enabled = false }
}
}

signing {
val signingKey: String? by project
val signingPassword: String? by project
Expand Down
97 changes: 54 additions & 43 deletions firebase-auth/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -80,50 +80,53 @@ kotlin {
publishAllLibraryVariants()
}

fun nativeTargetConfig(): KotlinNativeTarget.() -> Unit = {
val nativeFrameworkPaths = listOf(
rootProject.project("firebase-app").projectDir.resolve("src/nativeInterop/cinterop/Carthage/Build/iOS")
).plus(
listOf(
"FirebaseAnalytics",
"FirebaseCore",
"FirebaseCoreDiagnostics",
"FirebaseInstallations",
"GoogleAppMeasurement",
"GoogleDataTransport",
"GoogleUtilities",
"nanopb",
"PromisesObjC"
).map {
rootProject.project("firebase-app").projectDir.resolve("src/nativeInterop/cinterop/Carthage/Build/$it.xcframework/${konanTarget.archVariant}")
}
).plus(
listOf(
"FirebaseAuth",
"GTMSessionFetcher"
).map {
projectDir.resolve("src/nativeInterop/cinterop/Carthage/Build/$it.xcframework/${konanTarget.archVariant}")
val supportIosTarget = project.property("skipIosTarget") != "true"
if (supportIosTarget) {

fun nativeTargetConfig(): KotlinNativeTarget.() -> Unit = {
val nativeFrameworkPaths = listOf(
rootProject.project("firebase-app").projectDir.resolve("src/nativeInterop/cinterop/Carthage/Build/iOS")
).plus(
listOf(
"FirebaseAnalytics",
"FirebaseCore",
"FirebaseCoreDiagnostics",
"FirebaseInstallations",
"GoogleAppMeasurement",
"GoogleDataTransport",
"GoogleUtilities",
"nanopb",
"PromisesObjC"
).map {
rootProject.project("firebase-app").projectDir.resolve("src/nativeInterop/cinterop/Carthage/Build/$it.xcframework/${konanTarget.archVariant}")
}
).plus(
listOf(
"FirebaseAuth",
"GTMSessionFetcher"
).map {
projectDir.resolve("src/nativeInterop/cinterop/Carthage/Build/$it.xcframework/${konanTarget.archVariant}")
}
)
binaries {
getTest("DEBUG").apply {
linkerOpts(nativeFrameworkPaths.map { "-F$it" })
linkerOpts("-ObjC")
}
}
)

binaries {
getTest("DEBUG").apply {
linkerOpts(nativeFrameworkPaths.map { "-F$it" })
linkerOpts("-ObjC")
compilations.getByName("main") {
cinterops.create("FirebaseAuth") {
compilerOpts(nativeFrameworkPaths.map { "-F$it" })
extraOpts("-verbose")
}
}
}

compilations.getByName("main") {
cinterops.create("FirebaseAuth") {
compilerOpts(nativeFrameworkPaths.map { "-F$it" })
extraOpts("-verbose")
}
}
ios(configure = nativeTargetConfig())
iosSimulatorArm64(configure = nativeTargetConfig())
}

ios(configure = nativeTargetConfig())
iosSimulatorArm64(configure = nativeTargetConfig())

js {
useCommonJs()
nodejs {
Expand Down Expand Up @@ -165,18 +168,26 @@ kotlin {
}
}

val iosMain by getting
val iosSimulatorArm64Main by getting
iosSimulatorArm64Main.dependsOn(iosMain)
if (supportIosTarget) {
val iosMain by getting
val iosSimulatorArm64Main by getting
iosSimulatorArm64Main.dependsOn(iosMain)

val iosTest by sourceSets.getting
val iosSimulatorArm64Test by sourceSets.getting
iosSimulatorArm64Test.dependsOn(iosTest)
val iosTest by sourceSets.getting
val iosSimulatorArm64Test by sourceSets.getting
iosSimulatorArm64Test.dependsOn(iosTest)
}

val jsMain by getting
}
}

if (project.property("firebase-auth.skipIosTests") == "true") {
tasks.forEach {
if (it.name.contains("ios", true) && it.name.contains("test", true)) { it.enabled = false }
}
}

signing {
val signingKey: String? by project
val signingPassword: String? by project
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,7 @@ actual val emulatorHost: String = "10.0.2.2"

actual val context: Any = InstrumentationRegistry.getInstrumentation().targetContext

actual val currentPlatform: Platform = Platform.Android

actual fun runTest(skip: Boolean, test: suspend () -> Unit) = runBlocking {
if (skip) {
Log.w("Test", "Skip the test.")
return@runBlocking
}

actual fun runTest(test: suspend () -> Unit) = runBlocking {
test()
}

Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,10 @@ import kotlin.test.*

expect val emulatorHost: String
expect val context: Any
expect fun runTest(skip: Boolean = false, test: suspend () -> Unit)
expect val currentPlatform: Platform

enum class Platform { Android, IOS, JS }
expect fun runTest(test: suspend () -> Unit)

class FirebaseAuthTest {

// Skip the tests on iOS simulator due keychain exceptions
private val skip = currentPlatform == Platform.IOS

@BeforeTest
fun initializeFirebase() {
Firebase
Expand All @@ -41,14 +35,14 @@ class FirebaseAuthTest {
}

@Test
fun testSignInWithUsernameAndPassword() = runTest(skip) {
fun testSignInWithUsernameAndPassword() = runTest {
val uid = getTestUid("test@test.com", "test123")
val result = Firebase.auth.signInWithEmailAndPassword("test@test.com", "test123")
assertEquals(uid, result.user!!.uid)
}

@Test
fun testCreateUserWithEmailAndPassword() = runTest(skip) {
fun testCreateUserWithEmailAndPassword() = runTest {
val email = "test+${Random.nextInt(100000)}@test.com"
val createResult = Firebase.auth.createUserWithEmailAndPassword(email, "test123")
assertNotEquals(null, createResult.user?.uid)
Expand All @@ -63,7 +57,7 @@ class FirebaseAuthTest {
}

@Test
fun testFetchSignInMethods() = runTest(skip) {
fun testFetchSignInMethods() = runTest {
val email = "test+${Random.nextInt(100000)}@test.com"
var signInMethodResult = Firebase.auth.fetchSignInMethodsForEmail(email)
assertEquals(emptyList(), signInMethodResult)
Expand All @@ -75,7 +69,7 @@ class FirebaseAuthTest {
}

@Test
fun testSendEmailVerification() = runTest(skip) {
fun testSendEmailVerification() = runTest {
val email = "test+${Random.nextInt(100000)}@test.com"
val createResult = Firebase.auth.createUserWithEmailAndPassword(email, "test123")
assertNotEquals(null, createResult.user?.uid)
Expand All @@ -85,7 +79,7 @@ class FirebaseAuthTest {
}

@Test
fun sendPasswordResetEmail() = runTest(skip) {
fun sendPasswordResetEmail() = runTest {
val email = "test+${Random.nextInt(100000)}@test.com"
val createResult = Firebase.auth.createUserWithEmailAndPassword(email, "test123")
assertNotEquals(null, createResult.user?.uid)
Expand All @@ -96,7 +90,7 @@ class FirebaseAuthTest {
}

@Test
fun testSignInWithCredential() = runTest(skip) {
fun testSignInWithCredential() = runTest {
val uid = getTestUid("test@test.com", "test123")
val credential = EmailAuthProvider.credential("test@test.com", "test123")
val result = Firebase.auth.signInWithCredential(credential)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,7 @@ actual val emulatorHost: String = "localhost"

actual val context: Any = Unit

actual val currentPlatform: Platform = Platform.IOS

actual fun runTest(skip: Boolean, test: suspend () -> Unit) = runBlocking {
if (skip) {
NSLog("Skip the test.")
return@runBlocking
}

actual fun runTest(test: suspend () -> Unit) = runBlocking {
val testRun = MainScope().async { test() }
while (testRun.isActive) {
NSRunLoop.mainRunLoop.runMode(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,8 @@ actual val emulatorHost: String = "localhost"

actual val context: Any = Unit

actual val currentPlatform: Platform = Platform.JS

actual fun runTest(skip: Boolean, test: suspend () -> Unit) = GlobalScope
actual fun runTest(test: suspend () -> Unit) = GlobalScope
.promise {
if (skip) {
console.log("Skip the test.")
return@promise
}

try {
test()
} catch (e: dynamic) {
Expand Down
Loading