Skip to content

Commit 101aa55

Browse files
committed
Run tests on native platforms
1 parent 2ef0791 commit 101aa55

File tree

4 files changed

+33
-3
lines changed

4 files changed

+33
-3
lines changed

integrations/sqldelight/build.gradle.kts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ plugins {
66
alias(libs.plugins.kotlinter)
77
alias(libs.plugins.kotlin.atomicfu)
88
id("com.powersync.plugins.sonatype")
9+
id("com.powersync.plugins.sharedbuild")
910
id("dokka-convention")
1011
}
1112

@@ -21,17 +22,29 @@ kotlin {
2122
implementation(libs.kotlinx.coroutines.core)
2223
}
2324

24-
jvmTest.dependencies {
25+
commonTest.dependencies {
2526
// Separate project because SQLDelight can't generate code in test source sets.
2627
implementation(projects.integrations.sqldelightTestDatabase)
2728

2829
implementation(libs.kotlin.test)
30+
implementation(libs.kotlinx.io)
2931
implementation(libs.test.turbine)
3032
implementation(libs.test.coroutines)
3133
implementation(libs.test.kotest.assertions)
3234

3335
implementation(libs.sqldelight.coroutines)
3436
}
37+
38+
val commonIntegrationTest by creating {
39+
dependsOn(commonTest.get())
40+
}
41+
42+
// The PowerSync SDK links the core extension, so we can just run tests as-is.
43+
jvmTest.get().dependsOn(commonIntegrationTest)
44+
45+
// We have special setup in this build configuration to make these tests link the PowerSync extension, so they
46+
// can run integration tests along with the executable for unit testing.
47+
nativeTest.orNull?.dependsOn(commonIntegrationTest)
3548
}
3649
}
3750

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package com.powersync.integrations.sqldelight
2+
3+
import com.powersync.DatabaseDriverFactory
4+
5+
actual fun databaseDriverFactory(): DatabaseDriverFactory {
6+
return DatabaseDriverFactory()
7+
}

integrations/sqldelight/src/jvmTest/kotlin/com/powersync/integrations/sqldelight/SqlDelightTest.kt renamed to integrations/sqldelight/src/commonIntegrationTest/kotlin/com/powersync/integrations/sqldelight/SqlDelightTest.kt

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import io.kotest.matchers.shouldBe
1616
import kotlinx.coroutines.currentCoroutineContext
1717
import kotlinx.coroutines.test.TestScope
1818
import kotlinx.coroutines.test.runTest
19+
import kotlinx.io.files.SystemTemporaryDirectory
1920
import kotlin.test.Test
2021

2122
class SqlDelightTest {
@@ -125,7 +126,7 @@ private fun databaseTest(body: suspend TestScope.(PowerSyncDatabase) -> Unit) {
125126

126127
val db =
127128
PowerSyncDatabase(
128-
DatabaseDriverFactory(),
129+
databaseDriverFactory(),
129130
schema =
130131
Schema(
131132
Table(
@@ -137,10 +138,12 @@ private fun databaseTest(body: suspend TestScope.(PowerSyncDatabase) -> Unit) {
137138
),
138139
),
139140
dbFilename = "db-$suffix",
140-
dbDirectory = System.getProperty("java.io.tmpdir"),
141+
dbDirectory = SystemTemporaryDirectory.toString(),
141142
)
142143

143144
body(db)
144145
db.close()
145146
}
146147
}
148+
149+
expect fun databaseDriverFactory(): DatabaseDriverFactory
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package com.powersync.integrations.sqldelight
2+
3+
import com.powersync.DatabaseDriverFactory
4+
5+
actual fun databaseDriverFactory(): DatabaseDriverFactory {
6+
return DatabaseDriverFactory()
7+
}

0 commit comments

Comments
 (0)