Skip to content

Commit 1b4d997

Browse files
authored
Gl 861 add ability to skip ios tests for firebase (#230)
* Added properties to skip iostarget and skip ios tests. * Adjusted tests to not use skip variable. Added granular ios test skip * Added missing property. Added skip for ios tests in auth target. * added logging * Added different approach to cancel ios tests * Disable test tasks in gradle to skip ios tests * Disable test tasks in gradle to skip ios tests * Moved skip test to the outer scope of a project. * Added ignore case for task check * fixed typo * Added fix for android tests
1 parent 6ac7a83 commit 1b4d997

File tree

12 files changed

+359
-295
lines changed

12 files changed

+359
-295
lines changed

firebase-app/build.gradle.kts

+48-36
Original file line numberDiff line numberDiff line change
@@ -57,42 +57,46 @@ kotlin {
5757
publishAllLibraryVariants()
5858
}
5959

60-
fun nativeTargetConfig(): KotlinNativeTarget.() -> Unit = {
61-
val nativeFrameworkPaths = listOf(
62-
projectDir.resolve("src/nativeInterop/cinterop/Carthage/Build/iOS")
63-
).plus(
64-
listOf(
65-
"FirebaseAnalytics",
66-
"FirebaseCore",
67-
"FirebaseCoreDiagnostics",
68-
"FirebaseInstallations",
69-
"GoogleAppMeasurement",
70-
"GoogleDataTransport",
71-
"GoogleUtilities",
72-
"nanopb",
73-
"PromisesObjC"
74-
).map {
75-
projectDir.resolve("src/nativeInterop/cinterop/Carthage/Build/$it.xcframework/${konanTarget.archVariant}")
76-
}
77-
)
60+
val supportIosTarget = project.property("skipIosTarget") != "true"
61+
if (supportIosTarget) {
62+
63+
fun nativeTargetConfig(): KotlinNativeTarget.() -> Unit = {
64+
val nativeFrameworkPaths = listOf(
65+
projectDir.resolve("src/nativeInterop/cinterop/Carthage/Build/iOS")
66+
).plus(
67+
listOf(
68+
"FirebaseAnalytics",
69+
"FirebaseCore",
70+
"FirebaseCoreDiagnostics",
71+
"FirebaseInstallations",
72+
"GoogleAppMeasurement",
73+
"GoogleDataTransport",
74+
"GoogleUtilities",
75+
"nanopb",
76+
"PromisesObjC"
77+
).map {
78+
projectDir.resolve("src/nativeInterop/cinterop/Carthage/Build/$it.xcframework/${konanTarget.archVariant}")
79+
}
80+
)
7881

79-
binaries {
80-
getTest("DEBUG").apply {
81-
linkerOpts(nativeFrameworkPaths.map { "-F$it" })
82-
linkerOpts("-ObjC")
82+
binaries {
83+
getTest("DEBUG").apply {
84+
linkerOpts(nativeFrameworkPaths.map { "-F$it" })
85+
linkerOpts("-ObjC")
86+
}
8387
}
84-
}
8588

86-
compilations.getByName("main") {
87-
cinterops.create("FirebaseCore") {
88-
compilerOpts(nativeFrameworkPaths.map { "-F$it" })
89-
extraOpts("-verbose")
89+
compilations.getByName("main") {
90+
cinterops.create("FirebaseCore") {
91+
compilerOpts(nativeFrameworkPaths.map { "-F$it" })
92+
extraOpts("-verbose")
93+
}
9094
}
9195
}
92-
}
9396

94-
ios(configure = nativeTargetConfig())
95-
iosSimulatorArm64(configure = nativeTargetConfig())
97+
ios(configure = nativeTargetConfig())
98+
iosSimulatorArm64(configure = nativeTargetConfig())
99+
}
96100

97101
js {
98102
useCommonJs()
@@ -133,18 +137,26 @@ kotlin {
133137
}
134138
}
135139

136-
val iosMain by getting
137-
val iosSimulatorArm64Main by getting
138-
iosSimulatorArm64Main.dependsOn(iosMain)
140+
if (supportIosTarget) {
141+
val iosMain by getting
142+
val iosSimulatorArm64Main by getting
143+
iosSimulatorArm64Main.dependsOn(iosMain)
139144

140-
val iosTest by sourceSets.getting
141-
val iosSimulatorArm64Test by sourceSets.getting
142-
iosSimulatorArm64Test.dependsOn(iosTest)
145+
val iosTest by sourceSets.getting
146+
val iosSimulatorArm64Test by sourceSets.getting
147+
iosSimulatorArm64Test.dependsOn(iosTest)
148+
}
143149

144150
val jsMain by getting
145151
}
146152
}
147153

154+
if (project.property("firebase-app.skipIosTests") == "true") {
155+
tasks.forEach {
156+
if (it.name.contains("ios", true) && it.name.contains("test", true)) { it.enabled = false }
157+
}
158+
}
159+
148160
signing {
149161
val signingKey: String? by project
150162
val signingPassword: String? by project

firebase-auth/build.gradle.kts

+54-43
Original file line numberDiff line numberDiff line change
@@ -80,50 +80,53 @@ kotlin {
8080
publishAllLibraryVariants()
8181
}
8282

83-
fun nativeTargetConfig(): KotlinNativeTarget.() -> Unit = {
84-
val nativeFrameworkPaths = listOf(
85-
rootProject.project("firebase-app").projectDir.resolve("src/nativeInterop/cinterop/Carthage/Build/iOS")
86-
).plus(
87-
listOf(
88-
"FirebaseAnalytics",
89-
"FirebaseCore",
90-
"FirebaseCoreDiagnostics",
91-
"FirebaseInstallations",
92-
"GoogleAppMeasurement",
93-
"GoogleDataTransport",
94-
"GoogleUtilities",
95-
"nanopb",
96-
"PromisesObjC"
97-
).map {
98-
rootProject.project("firebase-app").projectDir.resolve("src/nativeInterop/cinterop/Carthage/Build/$it.xcframework/${konanTarget.archVariant}")
99-
}
100-
).plus(
101-
listOf(
102-
"FirebaseAuth",
103-
"GTMSessionFetcher"
104-
).map {
105-
projectDir.resolve("src/nativeInterop/cinterop/Carthage/Build/$it.xcframework/${konanTarget.archVariant}")
83+
val supportIosTarget = project.property("skipIosTarget") != "true"
84+
if (supportIosTarget) {
85+
86+
fun nativeTargetConfig(): KotlinNativeTarget.() -> Unit = {
87+
val nativeFrameworkPaths = listOf(
88+
rootProject.project("firebase-app").projectDir.resolve("src/nativeInterop/cinterop/Carthage/Build/iOS")
89+
).plus(
90+
listOf(
91+
"FirebaseAnalytics",
92+
"FirebaseCore",
93+
"FirebaseCoreDiagnostics",
94+
"FirebaseInstallations",
95+
"GoogleAppMeasurement",
96+
"GoogleDataTransport",
97+
"GoogleUtilities",
98+
"nanopb",
99+
"PromisesObjC"
100+
).map {
101+
rootProject.project("firebase-app").projectDir.resolve("src/nativeInterop/cinterop/Carthage/Build/$it.xcframework/${konanTarget.archVariant}")
102+
}
103+
).plus(
104+
listOf(
105+
"FirebaseAuth",
106+
"GTMSessionFetcher"
107+
).map {
108+
projectDir.resolve("src/nativeInterop/cinterop/Carthage/Build/$it.xcframework/${konanTarget.archVariant}")
109+
}
110+
)
111+
binaries {
112+
getTest("DEBUG").apply {
113+
linkerOpts(nativeFrameworkPaths.map { "-F$it" })
114+
linkerOpts("-ObjC")
115+
}
106116
}
107-
)
108117

109-
binaries {
110-
getTest("DEBUG").apply {
111-
linkerOpts(nativeFrameworkPaths.map { "-F$it" })
112-
linkerOpts("-ObjC")
118+
compilations.getByName("main") {
119+
cinterops.create("FirebaseAuth") {
120+
compilerOpts(nativeFrameworkPaths.map { "-F$it" })
121+
extraOpts("-verbose")
122+
}
113123
}
114124
}
115125

116-
compilations.getByName("main") {
117-
cinterops.create("FirebaseAuth") {
118-
compilerOpts(nativeFrameworkPaths.map { "-F$it" })
119-
extraOpts("-verbose")
120-
}
121-
}
126+
ios(configure = nativeTargetConfig())
127+
iosSimulatorArm64(configure = nativeTargetConfig())
122128
}
123129

124-
ios(configure = nativeTargetConfig())
125-
iosSimulatorArm64(configure = nativeTargetConfig())
126-
127130
js {
128131
useCommonJs()
129132
nodejs {
@@ -165,18 +168,26 @@ kotlin {
165168
}
166169
}
167170

168-
val iosMain by getting
169-
val iosSimulatorArm64Main by getting
170-
iosSimulatorArm64Main.dependsOn(iosMain)
171+
if (supportIosTarget) {
172+
val iosMain by getting
173+
val iosSimulatorArm64Main by getting
174+
iosSimulatorArm64Main.dependsOn(iosMain)
171175

172-
val iosTest by sourceSets.getting
173-
val iosSimulatorArm64Test by sourceSets.getting
174-
iosSimulatorArm64Test.dependsOn(iosTest)
176+
val iosTest by sourceSets.getting
177+
val iosSimulatorArm64Test by sourceSets.getting
178+
iosSimulatorArm64Test.dependsOn(iosTest)
179+
}
175180

176181
val jsMain by getting
177182
}
178183
}
179184

185+
if (project.property("firebase-auth.skipIosTests") == "true") {
186+
tasks.forEach {
187+
if (it.name.contains("ios", true) && it.name.contains("test", true)) { it.enabled = false }
188+
}
189+
}
190+
180191
signing {
181192
val signingKey: String? by project
182193
val signingPassword: String? by project

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

+1-8
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,7 @@ actual val emulatorHost: String = "10.0.2.2"
1313

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

16-
actual val currentPlatform: Platform = Platform.Android
17-
18-
actual fun runTest(skip: Boolean, test: suspend () -> Unit) = runBlocking {
19-
if (skip) {
20-
Log.w("Test", "Skip the test.")
21-
return@runBlocking
22-
}
23-
16+
actual fun runTest(test: suspend () -> Unit) = runBlocking {
2417
test()
2518
}
2619

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

+7-13
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,10 @@ import kotlin.test.*
1010

1111
expect val emulatorHost: String
1212
expect val context: Any
13-
expect fun runTest(skip: Boolean = false, test: suspend () -> Unit)
14-
expect val currentPlatform: Platform
15-
16-
enum class Platform { Android, IOS, JS }
13+
expect fun runTest(test: suspend () -> Unit)
1714

1815
class FirebaseAuthTest {
1916

20-
// Skip the tests on iOS simulator due keychain exceptions
21-
private val skip = currentPlatform == Platform.IOS
22-
2317
@BeforeTest
2418
fun initializeFirebase() {
2519
Firebase
@@ -41,14 +35,14 @@ class FirebaseAuthTest {
4135
}
4236

4337
@Test
44-
fun testSignInWithUsernameAndPassword() = runTest(skip) {
38+
fun testSignInWithUsernameAndPassword() = runTest {
4539
val uid = getTestUid("[email protected]", "test123")
4640
val result = Firebase.auth.signInWithEmailAndPassword("[email protected]", "test123")
4741
assertEquals(uid, result.user!!.uid)
4842
}
4943

5044
@Test
51-
fun testCreateUserWithEmailAndPassword() = runTest(skip) {
45+
fun testCreateUserWithEmailAndPassword() = runTest {
5246
val email = "test+${Random.nextInt(100000)}@test.com"
5347
val createResult = Firebase.auth.createUserWithEmailAndPassword(email, "test123")
5448
assertNotEquals(null, createResult.user?.uid)
@@ -63,7 +57,7 @@ class FirebaseAuthTest {
6357
}
6458

6559
@Test
66-
fun testFetchSignInMethods() = runTest(skip) {
60+
fun testFetchSignInMethods() = runTest {
6761
val email = "test+${Random.nextInt(100000)}@test.com"
6862
var signInMethodResult = Firebase.auth.fetchSignInMethodsForEmail(email)
6963
assertEquals(emptyList(), signInMethodResult)
@@ -75,7 +69,7 @@ class FirebaseAuthTest {
7569
}
7670

7771
@Test
78-
fun testSendEmailVerification() = runTest(skip) {
72+
fun testSendEmailVerification() = runTest {
7973
val email = "test+${Random.nextInt(100000)}@test.com"
8074
val createResult = Firebase.auth.createUserWithEmailAndPassword(email, "test123")
8175
assertNotEquals(null, createResult.user?.uid)
@@ -85,7 +79,7 @@ class FirebaseAuthTest {
8579
}
8680

8781
@Test
88-
fun sendPasswordResetEmail() = runTest(skip) {
82+
fun sendPasswordResetEmail() = runTest {
8983
val email = "test+${Random.nextInt(100000)}@test.com"
9084
val createResult = Firebase.auth.createUserWithEmailAndPassword(email, "test123")
9185
assertNotEquals(null, createResult.user?.uid)
@@ -96,7 +90,7 @@ class FirebaseAuthTest {
9690
}
9791

9892
@Test
99-
fun testSignInWithCredential() = runTest(skip) {
93+
fun testSignInWithCredential() = runTest {
10094
val uid = getTestUid("[email protected]", "test123")
10195
val credential = EmailAuthProvider.credential("[email protected]", "test123")
10296
val result = Firebase.auth.signInWithCredential(credential)

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

+1-8
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,7 @@ actual val emulatorHost: String = "localhost"
1111

1212
actual val context: Any = Unit
1313

14-
actual val currentPlatform: Platform = Platform.IOS
15-
16-
actual fun runTest(skip: Boolean, test: suspend () -> Unit) = runBlocking {
17-
if (skip) {
18-
NSLog("Skip the test.")
19-
return@runBlocking
20-
}
21-
14+
actual fun runTest(test: suspend () -> Unit) = runBlocking {
2215
val testRun = MainScope().async { test() }
2316
while (testRun.isActive) {
2417
NSRunLoop.mainRunLoop.runMode(

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

+1-8
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,8 @@ actual val emulatorHost: String = "localhost"
1111

1212
actual val context: Any = Unit
1313

14-
actual val currentPlatform: Platform = Platform.JS
15-
16-
actual fun runTest(skip: Boolean, test: suspend () -> Unit) = GlobalScope
14+
actual fun runTest(test: suspend () -> Unit) = GlobalScope
1715
.promise {
18-
if (skip) {
19-
console.log("Skip the test.")
20-
return@promise
21-
}
22-
2316
try {
2417
test()
2518
} catch (e: dynamic) {

0 commit comments

Comments
 (0)