Skip to content

Commit 59e0774

Browse files
authored
feat(tests): run e2e tests on mobile (#16075)
* feat(tests): add mobile e2e tests * fix pnpm usage * fix ios test * chore: bump automation deps * fix audit * remove silly tests
1 parent 7b95549 commit 59e0774

28 files changed

Lines changed: 2994 additions & 228 deletions
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"tauri-cli": patch:bug
3+
"@tauri-apps/cli": patch:bug
4+
---
5+
6+
`tauri ios build` for a simulator target no longer fails with "failed to rename app: Directory not empty" when the output `.app` from a previous build exists.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"tauri-runtime-wry": patch:bug
3+
---
4+
5+
Fix a crash on iOS when the monitor APIs (`Window::current_monitor`, `primary_monitor`, `available_monitors`, `monitor_from_point` and the `AppHandle` equivalents) are called off the main thread, e.g. from a command: the monitor is now read on the main thread, where iOS requires it.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"tauri-cli": patch:bug
3+
"@tauri-apps/cli": patch:bug
4+
---
5+
6+
Detect pnpm from `npm_config_user_agent` when generating the mobile projects. pnpm's native binary (pnpm 11+) runs package scripts without setting `PNPM_PACKAGE_NAME`, and when installed through corepack the binary is named `pnpm-native`, so `tauri android init` recorded `pnpm-native` as the command for Gradle to run and the Android build failed with "A problem occurred starting process 'command 'pnpm-native''".
Lines changed: 196 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,196 @@
1+
# Copyright 2019-2024 Tauri Programme within The Commons Conservancy
2+
# SPDX-License-Identifier: Apache-2.0
3+
# SPDX-License-Identifier: MIT
4+
5+
name: test `@tauri-apps/api` e2e (mobile)
6+
7+
on:
8+
workflow_dispatch:
9+
push:
10+
branches:
11+
- dev
12+
pull_request:
13+
paths:
14+
- '.github/workflows/test-api-e2e-mobile.yml'
15+
- 'packages/api/**'
16+
- 'packages/api-e2e/**'
17+
- 'examples/api/**'
18+
- 'crates/tauri/mobile/**'
19+
- 'crates/tauri-cli/templates/mobile/**'
20+
21+
env:
22+
RUST_BACKTRACE: 1
23+
CARGO_PROFILE_DEV_DEBUG: 0 # keeps the target folder small for better cache efficiency
24+
25+
concurrency:
26+
group: ${{ github.workflow }}-${{ github.ref }}
27+
cancel-in-progress: true
28+
29+
permissions:
30+
contents: read
31+
32+
jobs:
33+
android:
34+
runs-on: ubuntu-latest
35+
env:
36+
# The emulator runs the host architecture, so only that target is built.
37+
E2E_ANDROID_TARGET: x86_64
38+
39+
steps:
40+
- uses: actions/checkout@v7
41+
42+
- name: install Rust stable
43+
uses: dtolnay/rust-toolchain@stable
44+
with:
45+
targets: x86_64-linux-android
46+
47+
- run: npm i -g --force corepack
48+
- name: setup node
49+
uses: actions/setup-node@v7
50+
with:
51+
node-version: 'lts/*'
52+
cache: 'pnpm'
53+
54+
- uses: actions/setup-java@v5
55+
with:
56+
distribution: temurin
57+
java-version: 25
58+
cache: gradle
59+
60+
- name: Setup NDK
61+
uses: nttld/setup-ndk@v1
62+
id: setup-ndk
63+
with:
64+
ndk-version: r29
65+
local-cache: true
66+
67+
# TODO check after https://github.com/nttld/setup-ndk/issues/518 is fixed
68+
- name: Restore Android Symlinks
69+
run: |
70+
directory="${{ steps.setup-ndk.outputs.ndk-path }}/toolchains/llvm/prebuilt/linux-x86_64/bin"
71+
find "$directory" -type l | while read link; do
72+
current_target=$(readlink "$link")
73+
new_target="$directory/$(basename "$current_target")"
74+
ln -sf "$new_target" "$link"
75+
echo "Changed $(basename "$link") from $current_target to $new_target"
76+
done
77+
78+
# Hardware acceleration for the emulator.
79+
- name: enable KVM
80+
run: |
81+
echo 'KERNEL=="kvm", GROUP="kvm", MODE="0666", OPTIONS+="static_node=kvm"' | sudo tee /etc/udev/rules.d/99-kvm4all.rules
82+
sudo udevadm control --reload-rules
83+
sudo udevadm trigger --name-match=kvm
84+
85+
- uses: Swatinem/rust-cache@v2
86+
with:
87+
key: android
88+
89+
- name: install dependencies
90+
run: pnpm i --frozen-lockfile
91+
92+
- name: build @tauri-apps/api
93+
run: pnpm build:api
94+
95+
- name: build @tauri-apps/cli
96+
run: pnpm build:cli
97+
98+
# Built before the emulator is up so it does not sit idle (and time out)
99+
# during the Rust and Gradle builds; the suite then reuses the APK.
100+
- name: build the APK
101+
working-directory: ./examples/api
102+
env:
103+
NDK_HOME: ${{ steps.setup-ndk.outputs.ndk-path }}
104+
run: |
105+
pnpm tauri android init --ci --skip-targets-install
106+
pnpm tauri android build --debug --apk --target $E2E_ANDROID_TARGET
107+
108+
- name: run e2e tests
109+
uses: reactivecircus/android-emulator-runner@v2
110+
timeout-minutes: 60
111+
with:
112+
api-level: 35
113+
arch: x86_64
114+
# google_apis images ship an up-to-date Android System WebView.
115+
target: google_apis
116+
profile: pixel_6
117+
emulator-options: -no-window -gpu swiftshader_indirect -noaudio -no-boot-anim -camera-back none
118+
disable-animations: true
119+
script: E2E_SKIP_BUILD=1 E2E_SPEC_RETRIES=1 pnpm test:api-e2e:android
120+
121+
- name: upload appium logs
122+
if: failure()
123+
uses: actions/upload-artifact@v7
124+
with:
125+
name: android-appium-logs
126+
path: packages/api-e2e/logs
127+
if-no-files-found: ignore
128+
129+
ios:
130+
runs-on: macos-latest
131+
132+
steps:
133+
- uses: actions/checkout@v7
134+
135+
- name: install Rust stable
136+
uses: dtolnay/rust-toolchain@stable
137+
with:
138+
targets: aarch64-apple-ios-sim
139+
140+
- run: npm i -g --force corepack
141+
- name: setup node
142+
uses: actions/setup-node@v7
143+
with:
144+
node-version: 'lts/*'
145+
cache: 'pnpm'
146+
147+
- uses: Swatinem/rust-cache@v2
148+
with:
149+
key: ios
150+
151+
- name: install dependencies
152+
run: pnpm i --frozen-lockfile
153+
154+
- name: build @tauri-apps/api
155+
run: pnpm build:api
156+
157+
- name: build @tauri-apps/cli
158+
run: pnpm build:cli
159+
160+
# Simulator build (`aarch64-sim` on the Apple Silicon runners), unsigned.
161+
# Built ahead of the suite for symmetry with the Android job.
162+
- name: build the simulator app
163+
working-directory: ./examples/api
164+
run: |
165+
pnpm tauri ios init --ci --skip-targets-install
166+
pnpm tauri ios build --debug --target aarch64-sim --no-sign
167+
168+
# wdio.ios.conf picks the iPhone simulator on the newest installed runtime
169+
# (no device name is hardcoded) and Appium boots it; the XCUITest driver
170+
# compiles WebDriverAgent on the first session.
171+
- name: run e2e tests
172+
timeout-minutes: 60
173+
env:
174+
E2E_SKIP_BUILD: '1'
175+
E2E_SPEC_RETRIES: '1'
176+
run: pnpm test:api-e2e:ios
177+
178+
- name: upload appium logs
179+
if: failure()
180+
uses: actions/upload-artifact@v7
181+
with:
182+
name: ios-appium-logs
183+
path: packages/api-e2e/logs
184+
if-no-files-found: ignore
185+
186+
- name: collect app crash reports
187+
if: failure()
188+
run: .scripts/ci/collect-macos-crash-reports.sh "$RUNNER_TEMP/crash-reports"
189+
190+
- name: upload app crash reports
191+
if: failure()
192+
uses: actions/upload-artifact@v7
193+
with:
194+
name: ios-crash-reports
195+
path: ${{ runner.temp }}/crash-reports
196+
if-no-files-found: ignore

‎Cargo.lock‎

Lines changed: 3 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎crates/tauri-cli/src/mobile/init.rs‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,8 @@ fn exec(
8484
return ("pnpm".into(), build_args);
8585
} else if is_pnpm_dlx() {
8686
return ("pnpm".into(), vec!["dlx", "@tauri-apps/cli"]);
87+
} else if is_pnpm_run() {
88+
return ("pnpm".into(), build_args);
8789
} else if let Some(npm_execpath) = var_os("npm_execpath") {
8890
let manager_stem = PathBuf::from(&npm_execpath)
8991
.file_stem()
@@ -390,6 +392,13 @@ fn unprefix_path(
390392
.map_err(Into::into)
391393
}
392394

395+
/// pnpm's native binary (pnpm >= 11) runs package scripts without setting `PNPM_PACKAGE_NAME`,
396+
/// and `npm_execpath` points at the binary itself, which is not necessarily named `pnpm`
397+
/// (corepack downloads it as `pnpm-native`), so the user agent is what identifies it.
398+
fn is_pnpm_run() -> bool {
399+
std::env::var("npm_config_user_agent").is_ok_and(|user_agent| user_agent.starts_with("pnpm/"))
400+
}
401+
393402
fn is_pnpm_dlx() -> bool {
394403
var_os("NODE_PATH")
395404
.map(PathBuf::from)

‎crates/tauri-cli/src/mobile/ios/build.rs‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -489,6 +489,10 @@ fn run_build(
489489
.with_extension("app");
490490

491491
let path = out_dir.join(app_path.file_name().unwrap());
492+
// `rename` does not replace a non-empty directory, such as the previous build
493+
if path.exists() {
494+
fs::remove_dir_all(&path).fs_context("failed to remove previous app", path.clone())?;
495+
}
492496
fs::rename(&app_path, &path).fs_context("failed to rename app", app_path)?;
493497
out_files.push(path);
494498
} else if options.no_sign {

0 commit comments

Comments
 (0)