Skip to content

Commit 9aab987

Browse files
committed
Add integration tests
1 parent 119be6f commit 9aab987

File tree

7 files changed

+40
-41
lines changed

7 files changed

+40
-41
lines changed

.github/workflows/test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ jobs:
1616
matrix:
1717
include:
1818
- os: macos-latest
19-
targets: iosSimulatorArm64Test jvmTest
19+
targets: iosSimulatorArm64Test jvmTest lintKotlin
2020
- os: ubuntu-latest
2121
targets: testDebugUnitTest testReleaseUnitTest jvmTest
2222
- os: windows-latest

core/build.gradle.kts

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ kotlin {
145145
}
146146
}
147147

148-
// iosX64()
148+
iosX64()
149149
iosArm64()
150150
iosSimulatorArm64()
151151

@@ -166,39 +166,42 @@ kotlin {
166166
cinterops.create("powersync-sqlite-core")
167167
}
168168

169-
if (konanTarget.family == Family.IOS) {
169+
if (konanTarget.family == Family.IOS && konanTarget.name.contains("simulator")) {
170170
binaries.withType<TestExecutable>().configureEach {
171171
linkTaskProvider.dependsOn(unzipPowersyncFramework)
172172
linkerOpts("-framework", "powersync-sqlite-core")
173-
174-
val framework = if (konanTarget.name.contains("simulator")) {
175-
"ios-arm64_x86_64-simulator"
176-
} else {
177-
"ios-arm64"
178-
}
179-
val frameworkRoot = binariesFolder.map { it.dir("framework/powersync-sqlite-core.xcframework/$framework") }.get().asFile.path
173+
val frameworkRoot = binariesFolder.map { it.dir("framework/powersync-sqlite-core.xcframework/ios-arm64_x86_64-simulator") }.get().asFile.path
180174

181175
linkerOpts("-F", frameworkRoot)
182176
linkerOpts("-rpath", frameworkRoot)
183177
}
184-
} else {
178+
}
179+
/*
180+
If we ever need macOS support:
181+
{
185182
binaries.withType<TestExecutable>().configureEach {
186183
linkTaskProvider.dependsOn(downloadPowersyncDesktopBinaries)
187184
linkerOpts("-lpowersync")
188185
linkerOpts("-L", binariesFolder.map { it.dir("powersync") }.get().asFile.path)
189186
}
190187
}
188+
*/
191189
}
192190

193191
explicitApi()
194192

193+
applyDefaultHierarchyTemplate()
195194
sourceSets {
196195
all {
197196
languageSettings {
198197
optIn("kotlinx.cinterop.ExperimentalForeignApi")
199198
}
200199
}
201200

201+
val commonIntegrationTest by creating {
202+
dependsOn(commonTest.get())
203+
}
204+
202205
commonMain.dependencies {
203206
implementation(libs.uuid)
204207
implementation(libs.kotlin.stdlib)
@@ -233,6 +236,13 @@ kotlin {
233236
implementation(libs.test.turbine)
234237
implementation(libs.kermit.test)
235238
}
239+
240+
// We're putting the native libraries into our JAR, so integration tests for the JVM can run as part of the unit
241+
// tests.
242+
jvmTest.get().dependsOn(commonIntegrationTest)
243+
244+
// We're linking the xcframework for the simulator tests, so they can use integration tests too
245+
iosSimulatorArm64Test.orNull?.dependsOn(commonIntegrationTest)
236246
}
237247
}
238248

core/src/androidUnitTest/kotlin/com/powersync/testutils/TestUtils.android.kt

Lines changed: 0 additions & 13 deletions
This file was deleted.

core/src/commonTest/kotlin/com/powersync/DatabaseTest.kt renamed to core/src/commonIntegrationTest/kotlin/com/powersync/DatabaseTest.kt

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,25 +6,21 @@ import com.powersync.db.getString
66
import com.powersync.db.schema.Column
77
import com.powersync.db.schema.Schema
88
import com.powersync.db.schema.Table
9-
import com.powersync.testutils.IgnoreOnAndroid
10-
import com.powersync.testutils.cleanup
11-
import com.powersync.testutils.factory
129
import kotlinx.coroutines.runBlocking
1310
import kotlinx.coroutines.test.runTest
1411
import kotlin.test.AfterTest
1512
import kotlin.test.BeforeTest
1613
import kotlin.test.Test
1714
import kotlin.test.assertEquals
1815

19-
@IgnoreOnAndroid
2016
class DatabaseTest {
2117
private lateinit var database: PowerSyncDatabase
2218

2319
@BeforeTest
2420
fun setupDatabase() {
2521
database =
2622
PowerSyncDatabase(
27-
factory = factory,
23+
factory = com.powersync.testutils.factory,
2824
schema =
2925
Schema(
3026
Table(name = "users", columns = listOf(Column.text("name"), Column.text("email"))),
@@ -40,7 +36,7 @@ class DatabaseTest {
4036
@AfterTest
4137
fun tearDown() {
4238
runBlocking { database.disconnectAndClear(true) }
43-
cleanup("testdb")
39+
com.powersync.testutils.cleanup("testdb")
4440
}
4541

4642
@Test
@@ -58,12 +54,21 @@ class DatabaseTest {
5854
// Wait for initial query
5955
assertEquals(0, query.awaitItem().size)
6056

61-
database.execute("INSERT INTO users (id, name, email) VALUES (uuid(), ?, ?)", listOf("Test", "[email protected]"))
57+
database.execute(
58+
"INSERT INTO users (id, name, email) VALUES (uuid(), ?, ?)",
59+
listOf("Test", "[email protected]"),
60+
)
6261
assertEquals(1, query.awaitItem().size)
6362

6463
database.writeTransaction {
65-
it.execute("INSERT INTO users (id, name, email) VALUES (uuid(), ?, ?)", listOf("Test2", "[email protected]"))
66-
it.execute("INSERT INTO users (id, name, email) VALUES (uuid(), ?, ?)", listOf("Test3", "[email protected]"))
64+
it.execute(
65+
"INSERT INTO users (id, name, email) VALUES (uuid(), ?, ?)",
66+
listOf("Test2", "[email protected]"),
67+
)
68+
it.execute(
69+
"INSERT INTO users (id, name, email) VALUES (uuid(), ?, ?)",
70+
listOf("Test3", "[email protected]"),
71+
)
6772
}
6873

6974
assertEquals(3, query.awaitItem().size)
@@ -77,7 +82,10 @@ class DatabaseTest {
7782
// Ignore
7883
}
7984

80-
database.execute("INSERT INTO users (id, name, email) VALUES (uuid(), ?, ?)", listOf("Test4", "[email protected]"))
85+
database.execute(
86+
"INSERT INTO users (id, name, email) VALUES (uuid(), ?, ?)",
87+
listOf("Test4", "[email protected]"),
88+
)
8189
assertEquals(4, query.awaitItem().size)
8290

8391
query.expectNoEvents()

core/src/commonTest/kotlin/com/powersync/testutils/TestUtils.kt renamed to core/src/commonIntegrationTest/kotlin/com/powersync/testutils/TestUtils.kt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@ package com.powersync.testutils
22

33
import com.powersync.DatabaseDriverFactory
44

5-
expect annotation class IgnoreOnAndroid()
6-
75
expect val factory: DatabaseDriverFactory
86

97
expect fun cleanup(path: String)

core/src/iosTest/kotlin/com/powersync/testutils/TestUtils.ios.kt renamed to core/src/iosSimulatorArm64Test/kotlin/com/powersync/testutils/TestUtils.iosSimulatorArm64.kt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@ import com.powersync.DatabaseDriverFactory
44
import kotlinx.io.files.Path
55
import kotlinx.io.files.SystemFileSystem
66

7-
actual annotation class IgnoreOnAndroid
8-
97
actual val factory: DatabaseDriverFactory
108
get() = DatabaseDriverFactory()
119

core/src/jvmTest/kotlin/com/powersync/testutils/TestUtils.jvm.kt

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,8 @@ package com.powersync.testutils
33
import com.powersync.DatabaseDriverFactory
44
import java.io.File
55

6-
actual annotation class IgnoreOnAndroid
7-
86
actual val factory: DatabaseDriverFactory
9-
get() = DatabaseDriverFactory()
7+
get() = DatabaseDriverFactory()
108

119
actual fun cleanup(path: String) {
1210
File(path).delete()

0 commit comments

Comments
 (0)