Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Fix Maestro iOS tests #24

Merged
merged 1 commit into from
Jun 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 20 additions & 3 deletions .github/workflows/lightsaber-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ jobs:
- uses: ./.github/actions/setup-lightsaber-ci

- name: Build Shared
# TODO Understand why compileIosMainKotlinMetadata fails every time
run: ./gradlew shared:assemble -x compileIosMainKotlinMetadata
run: ./gradlew shared:assemble

build-androidApp:
runs-on: macos-14
Expand Down Expand Up @@ -74,6 +73,13 @@ jobs:
mkdir -p ~/Library/MobileDevice/Provisioning\ Profiles
cp $PP_PATH ~/Library/MobileDevice/Provisioning\ Profiles

# Generate dummy framework to ensure that compose-resources are copied.
# See https://github.com/JetBrains/compose-multiplatform/issues/5011
- name: Generate dummy framework
run: |
mkdir -p ./shared/build/compose/cocoapods/compose-resources
./gradlew generateDummyFramework

- name: Shared Pod Install
run: ./gradlew podInstall

Expand Down Expand Up @@ -188,4 +194,15 @@ jobs:
- name: Run Maestro tests
run: |
export MAESTRO_DRIVER_STARTUP_TIMEOUT=60000
maestro test .maestro
maestro test .maestro

- name: Collect logs
if: failure()
run: xcrun simctl spawn "${{ steps.ios-simulator.outputs.udid }}" log collect --output ${{ github.workspace }}/${{ steps.ios-simulator.outputs.udid }}.logarchive

- name: Archive the device logs
if: always()
uses: actions/upload-artifact@v4
with:
name: device-logs
path: ${{ github.workspace }}/*.logarchive
2 changes: 2 additions & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ androidx-appcompat = "1.7.0"
androidx-core-ktx = "1.13.1"
datastore-version = "1.1.1"
compose-ui-test = "1.6.7"
kermit = "2.0.4"

[libraries]
androidx-core-splashscreen = { module = "androidx.core:core-splashscreen", version.ref = "core-splashscreen" }
Expand All @@ -26,6 +27,7 @@ androidx-datastore-core-okio = { group = "androidx.datastore", name = "datastore
androidx-datastore-preferences-core = { group = "androidx.datastore", name = "datastore-preferences-core", version.ref = "datastore-version" }
androidx-compose-ui-test-junit4-android = { group = "androidx.compose.ui" , name = "ui-test-junit4-android", version.ref = "compose-ui-test" }
androidx-compose-ui-test-manifest = { group = "androidx.compose.ui" , name = "ui-test-manifest", version.ref = "compose-ui-test" }
kermit = { group = "co.touchlab" , name = "kermit", version.ref = "kermit" }

[plugins]
kotlin-jvm = { id = "org.jetbrains.kotlin.jvm", version.ref = "kotlin" }
Expand Down
3 changes: 0 additions & 3 deletions iosApp/iosApp/ContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,3 @@ struct ContentView: View {
.ignoresSafeArea(.all, edges: .bottom) // Compose has own keyboard handler
}
}



1 change: 1 addition & 0 deletions shared/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ kotlin {
implementation(libs.circuitx.gesture.navigation)
implementation(libs.androidx.datastore.preferences.core)
implementation(libs.androidx.datastore.core.okio)
api(libs.kermit)
}
}
commonTest {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ package xyz.alaniz.aaron.lightsaber
import androidx.compose.runtime.ExperimentalComposeApi
import androidx.compose.ui.platform.AccessibilitySyncOptions
import androidx.compose.ui.window.ComposeUIViewController
import co.touchlab.kermit.DefaultFormatter
import co.touchlab.kermit.Logger
import co.touchlab.kermit.NSLogWriter
import co.touchlab.kermit.OSLogWriter
import kotlinx.cinterop.ExperimentalForeignApi
import platform.Foundation.NSDocumentDirectory
import platform.Foundation.NSFileManager
Expand All @@ -12,8 +16,9 @@ import xyz.alaniz.aaron.lightsaber.di.IosApplicationComponent
import xyz.alaniz.aaron.lightsaber.di.create
import xyz.alaniz.aaron.lightsaber.di.dataStoreFileName
import xyz.alaniz.aaron.lightsaber.ui.lightsaber.IosLightsaberScreen
import kotlin.experimental.ExperimentalNativeApi

@OptIn(ExperimentalForeignApi::class, ExperimentalComposeApi::class)
@OptIn(ExperimentalForeignApi::class, ExperimentalComposeApi::class, ExperimentalNativeApi::class)
fun MainViewController() = ComposeUIViewController(configure = {
/**
* TODO Update this to only sync the accessibility tree for debug builds
Expand All @@ -36,6 +41,20 @@ fun MainViewController() = ComposeUIViewController(configure = {
error = null,
)
val dataStorePath = requireNotNull(documentDirectory).path + "/$dataStoreFileName"

/**
* Use NSLogWriter so that logs are available to pull off the simulator in CI.
*
* TODO Inject log writers based on debug or release builds.
*/
Logger.setLogWriters(listOf(NSLogWriter(messageStringFormatter = DefaultFormatter)))

/**
* Log unhandled exceptions.
*/
setUnhandledExceptionHook {
Logger.e(throwable = it) { "Unhandled exception: cause = ${it.cause} message = ${it.message}" }
}
App(initialScreen = IosLightsaberScreen) { scope, navigator ->
IosApplicationComponent.create(
navigator = navigator,
Expand Down
Loading