diff --git a/.github/workflows/screenshot-comparison.yml b/.github/workflows/screenshot-comparison.yml index ba7a21d60..9c930c233 100644 --- a/.github/workflows/screenshot-comparison.yml +++ b/.github/workflows/screenshot-comparison.yml @@ -13,7 +13,7 @@ permissions: { } jobs: screenshot-comparison: - runs-on: ubuntu-latest + runs-on: macos-latest timeout-minutes: 60 permissions: diff --git a/.github/workflows/unit-test.yml b/.github/workflows/unit-test.yml index 96d0cf513..a4b3d4cba 100644 --- a/.github/workflows/unit-test.yml +++ b/.github/workflows/unit-test.yml @@ -14,7 +14,7 @@ permissions: { } jobs: unit-test: - runs-on: ubuntu-latest + runs-on: macos-latest timeout-minutes: 60 permissions: @@ -33,7 +33,13 @@ jobs: name: event-payload path: ${{ github.event_path }} - - run: ./gradlew testDevDebugUnitTest testDebugUnitTest --stacktrace + - run: | + ./gradlew \ + testDevDebugUnitTest \ + testDebugUnitTest \ + :core:data:iosSimulatorArm64Test \ + :core:model:iosSimulatorArm64Test \ + --stacktrace # Saving cost # - run: ./gradlew koverHtmlReportDevDebug --stacktrace diff --git a/core/data/build.gradle.kts b/core/data/build.gradle.kts index 4fb0b13f7..2854c404b 100644 --- a/core/data/build.gradle.kts +++ b/core/data/build.gradle.kts @@ -54,6 +54,7 @@ kotlin { commonTest { dependencies { implementation(projects.core.model) + implementation(projects.core.testing) implementation(libs.kotlinTest) implementation(libs.okIo) implementation(libs.ktorKotlinxSerialization) diff --git a/core/data/src/commonTest/kotlin/io/github/droidkaigi/confsched/data/profilecard/ProfileCardJsonTest.kt b/core/data/src/commonTest/kotlin/io/github/droidkaigi/confsched/data/profilecard/ProfileCardJsonTest.kt index acde3bee6..8dd654670 100644 --- a/core/data/src/commonTest/kotlin/io/github/droidkaigi/confsched/data/profilecard/ProfileCardJsonTest.kt +++ b/core/data/src/commonTest/kotlin/io/github/droidkaigi/confsched/data/profilecard/ProfileCardJsonTest.kt @@ -2,12 +2,11 @@ package io.github.droidkaigi.confsched.data.profilecard import io.github.droidkaigi.confsched.model.ProfileCard import io.github.droidkaigi.confsched.model.ProfileCardType +import io.github.droidkaigi.confsched.testing.utils.readResourceFile import kotlinx.serialization.ExperimentalSerializationApi import kotlinx.serialization.encodeToString import kotlinx.serialization.json.Json -import okio.FileSystem import okio.Path.Companion.toPath -import okio.SYSTEM import kotlin.test.Test import kotlin.test.assertEquals import kotlin.test.assertFails @@ -77,10 +76,9 @@ class ProfileCardJsonTest { @Test fun `throw exception when both theme and card_type are not exist`() { - val jsonString = - FileSystem.SYSTEM.read("src/commonTest/resources/profilecard/invalid.json".toPath()) { - readUtf8() - } + val jsonString = readResourceFile("profilecard/invalid.json".toPath()) { + readUtf8() + } assertFails { Json.decodeFromString(jsonString).toModel() @@ -88,7 +86,7 @@ class ProfileCardJsonTest { } private fun readJsonString(version: Int): String { - return FileSystem.SYSTEM.read("src/commonTest/resources/profilecard/v$version.json".toPath()) { + return readResourceFile("profilecard/v$version.json".toPath()) { readUtf8() } } @@ -102,10 +100,9 @@ class ProfileCardJsonTest { } private fun assertSerializedJson(actual: String) { - val expected = - FileSystem.SYSTEM.read("src/commonTest/resources/profilecard/v2.json".toPath()) { - readUtf8() - } + val expected = readResourceFile("profilecard/v2.json".toPath()) { + readUtf8() + } assertEquals(expected.trim(), actual.trim()) } diff --git a/core/testing/build.gradle.kts b/core/testing/build.gradle.kts index a1a851932..b343d5670 100644 --- a/core/testing/build.gradle.kts +++ b/core/testing/build.gradle.kts @@ -1,40 +1,59 @@ plugins { - id("droidkaigi.primitive.android") - id("droidkaigi.primitive.android.kotlin") - id("droidkaigi.primitive.android.compose") - id("droidkaigi.primitive.android.hilt") + id("droidkaigi.primitive.kmp") + id("droidkaigi.primitive.kmp.android") + id("droidkaigi.primitive.kmp.android.hilt") + id("droidkaigi.primitive.kmp.compose") + id("droidkaigi.primitive.kmp.ios") id("droidkaigi.primitive.detekt") } android.namespace = "io.github.droidkaigi.confsched.core.testing" -dependencies { - implementation(projects.core.model) - implementation(projects.core.designsystem) - implementation(projects.core.data) - implementation(projects.core.droidkaigiui) - implementation(projects.feature.main) - implementation(projects.feature.sessions) - implementation(projects.feature.profilecard) - implementation(projects.feature.about) - implementation(projects.feature.staff) - implementation(projects.feature.sponsors) - implementation(projects.feature.settings) - implementation(projects.feature.favorites) - implementation(projects.feature.eventmap) - implementation(projects.feature.contributors) - implementation(libs.daggerHiltAndroidTesting) - implementation(libs.roborazzi) - implementation(libs.kermit) - implementation(libs.coilTest) - api(projects.core.testingManifest) - api(libs.composeNavigation) - api(libs.roborazziRule) - api(libs.roborazziCompose) - api(libs.robolectric) - api(libs.composeUiTestJunit4) - implementation(libs.composeMaterialWindowSize) - implementation(libs.composablePreviewScanner) - implementation(libs.composablePreviewScannerJvm) - implementation(libs.roborazziPreviewScannerSupport) +kotlin { + sourceSets { + androidMain { + dependencies { + implementation(projects.core.model) + implementation(projects.core.designsystem) + implementation(projects.core.data) + implementation(projects.core.droidkaigiui) + implementation(projects.feature.main) + implementation(projects.feature.sessions) + implementation(projects.feature.profilecard) + implementation(projects.feature.about) + implementation(projects.feature.staff) + implementation(projects.feature.sponsors) + implementation(projects.feature.settings) + implementation(projects.feature.favorites) + implementation(projects.feature.eventmap) + implementation(projects.feature.contributors) + implementation(libs.daggerHiltAndroidTesting) + implementation(libs.roborazzi) + implementation(libs.kermit) + implementation(libs.coilTest) + api(projects.core.testingManifest) + api(libs.composeNavigation) + api(libs.roborazziRule) + api(libs.roborazziCompose) + api(libs.robolectric) + api(libs.composeUiTestJunit4) + implementation(libs.composeMaterialWindowSize) + implementation(libs.composablePreviewScanner) + implementation(libs.composablePreviewScannerJvm) + implementation(libs.roborazziPreviewScannerSupport) + } + } + + commonMain { + dependencies { + implementation(libs.okIo) + } + } + + iosMain { + dependencies { + implementation(libs.okIo) + } + } + } } diff --git a/core/testing/src/commonMain/kotlin/io/github/droidkaigi/confsched/testing/utils/ReadResourceFile.kt b/core/testing/src/commonMain/kotlin/io/github/droidkaigi/confsched/testing/utils/ReadResourceFile.kt new file mode 100644 index 000000000..ecf23cdcb --- /dev/null +++ b/core/testing/src/commonMain/kotlin/io/github/droidkaigi/confsched/testing/utils/ReadResourceFile.kt @@ -0,0 +1,3 @@ +package io.github.droidkaigi.confsched.testing.utils + +expect inline fun readResourceFile(filePath: okio.Path, block: okio.BufferedSource.() -> T): T diff --git a/core/testing/src/iosMain/kotlin/io/github/droidkaigi/confsched/testing/utils/ReadResourceFile.ios.kt b/core/testing/src/iosMain/kotlin/io/github/droidkaigi/confsched/testing/utils/ReadResourceFile.ios.kt new file mode 100644 index 000000000..5a88909d4 --- /dev/null +++ b/core/testing/src/iosMain/kotlin/io/github/droidkaigi/confsched/testing/utils/ReadResourceFile.ios.kt @@ -0,0 +1,16 @@ +package io.github.droidkaigi.confsched.testing.utils + +import okio.BufferedSource +import okio.FileSystem +import okio.Path +import okio.Path.Companion.toPath +import platform.Foundation.NSBundle + +actual inline fun readResourceFile(filePath: Path, block: BufferedSource.() -> T): T { + return FileSystem.SYSTEM.read( + NSBundle.mainBundle.bundlePath.toPath().parent!!.parent!!.parent!!.parent!! + .div("src").div("commonTest").div("resources").div(filePath), + ) { + block() + } +} diff --git a/core/testing/src/main/java/io/github/droidkaigi/confsched/testing/utils/ReadResourceFile.android.kt b/core/testing/src/main/java/io/github/droidkaigi/confsched/testing/utils/ReadResourceFile.android.kt new file mode 100644 index 000000000..d97f22ff3 --- /dev/null +++ b/core/testing/src/main/java/io/github/droidkaigi/confsched/testing/utils/ReadResourceFile.android.kt @@ -0,0 +1,12 @@ +package io.github.droidkaigi.confsched.testing.utils + +import okio.FileSystem +import okio.Path.Companion.toPath + +actual inline fun readResourceFile(filePath: okio.Path, block: okio.BufferedSource.() -> T): T { + return FileSystem.SYSTEM.read( + "src".toPath().div("commonTest").div("resources").div(filePath), + ) { + block() + } +}