Skip to content
TypeScript

fix(mobile): e2e landscape poses rotate for real on tablets and folds

Julius Marminge3e47c1cabc46
diff --git a/scripts/mobile-e2e.ts b/scripts/mobile-e2e.ts
index dc9af4a5e3b..9b3466dd2a7 100644
--- a/scripts/mobile-e2e.ts
+++ b/scripts/mobile-e2e.ts
@@ -139,7 +139,10 @@ async function runPose(
async function main() {
const args = NodeProcess.argv.slice(2);
if (args.includes("--list")) {
- for (const pose of POSES) NodeProcess.stdout.write(`${pose.id}\t${pose.device}\n`);
+ for (const pose of POSES)
+ NodeProcess.stdout.write(
+ `${pose.id}\t${pose.device}${pose.pending ? `\t(pending: ${pose.pending})` : ""}\n`,
+ );
return;
}
const values = (flag: string) =>
@@ -150,7 +153,7 @@ async function main() {
const platforms = values("--platform");
const poses = POSES.filter(
(pose) =>
- (selected.length === 0 || selected.includes(pose.id)) &&
+ (selected.length === 0 ? !pose.pending : selected.includes(pose.id)) &&
(platforms.length === 0 || platforms.includes(pose.platform)),
);
const concurrencyFlag = values("--concurrency")[0];
@@ -221,8 +224,15 @@ async function main() {
},
);
await waitForPort(metroPort, "Metro", 120_000);
- // Warm each platform's bundle once, instead of on every device at once.
+ // Warm each platform's bundle once, instead of on every device at once, and have its dev
+ // client cached before any lease: a cache miss builds, which can outlast a lease.
for (const platform of new Set(poses.map((pose) => pose.platform))) {
+ log("e2e", `preparing the ${platform} dev client`);
+ await run(
+ NodeProcess.execPath,
+ ["scripts/mobile-native-client.ts", "ensure", platform, "--prepare"],
+ { cwd: REPO_ROOT, timeoutMs: 1_800_000 },
+ );
log("e2e", `bundling for ${platform}`);
await run("curl", [
"-sf",
diff --git a/scripts/mobile-e2e/device.ts b/scripts/mobile-e2e/device.ts
index a2638b10d9a..5a8175eab22 100644
--- a/scripts/mobile-e2e/device.ts
+++ b/scripts/mobile-e2e/device.ts
@@ -105,9 +105,9 @@ export class Device {
try {
return await this.agentOnce(args, options);
} catch (error) {
- if (attempt >= 3 || !(error instanceof AgentDeviceError) || !TRANSIENT.test(error.message))
+ if (attempt >= 5 || !(error instanceof AgentDeviceError) || !TRANSIENT.test(error.message))
throw error;
- await delay(3_000 * attempt);
+ await delay(5_000 * attempt);
}
}
}
@@ -174,6 +174,22 @@ export class Device {
await this.acceptOpenPrompt();
}
+ /**
+ * agent-device names rotations relative to the device's natural orientation, which is
+ * landscape on tablets and unfolded folds, so try each name until the screen has the shape.
+ */
+ async orient(shape: "landscape" | "portrait"): Promise<Snapshot> {
+ let snapshot = await this.snapshot();
+ for (const name of ["landscape-left", "portrait", "landscape-right"]) {
+ const { width, height } = snapshot.viewport;
+ if (width > height === (shape === "landscape")) return snapshot;
+ await this.agent(["orientation", name]);
+ await delay(2_000);
+ snapshot = await this.snapshot();
+ }
+ return snapshot;
+ }
+
async openUrl(url: string) {
await this.agent(["open", BUNDLE_ID, url]);
await this.acceptOpenPrompt();
diff --git a/scripts/mobile-e2e/journey.ts b/scripts/mobile-e2e/journey.ts
index 49e6dfb90fd..f3442d0a8c9 100644
--- a/scripts/mobile-e2e/journey.ts
+++ b/scripts/mobile-e2e/journey.ts
@@ -137,9 +137,8 @@ export async function runJourney(
}
if (!threads) throw new Error("the app did not show the fixture threads after pairing");
// Rotated only once the app is up: a rotation during launch is lost.
- if (device.pose.landscape) await device.agent(["orientation", "landscape-left"]);
- await delay(device.pose.landscape ? 2_000 : 1_000);
- threads = await device.snapshot();
+ await delay(1_000);
+ threads = await device.orient(device.pose.landscape ? "landscape" : "portrait");
const tabs = tabBarRect(threads);
const wide = threads.viewport.width > threads.viewport.height;
await capture("threads", threads, [
@@ -270,9 +269,7 @@ export async function runJourney(
await capture("settings", await device.snapshot());
if (device.pose.form === "tablet" && !device.pose.fold) {
- await device.agent(["orientation", device.pose.landscape ? "portrait" : "landscape-left"]);
- await delay(2_000);
- await capture("rotated", await device.snapshot());
+ await capture("rotated", await device.orient(device.pose.landscape ? "portrait" : "landscape"));
}
if (device.pose.fold) {
await device.agent(["fold", device.pose.fold === "open" ? "closed" : "open"]);
diff --git a/scripts/mobile-e2e/poses.ts b/scripts/mobile-e2e/poses.ts
index 0586d08e9ee..9cc42b40a26 100644
--- a/scripts/mobile-e2e/poses.ts
+++ b/scripts/mobile-e2e/poses.ts
@@ -9,6 +9,8 @@ export interface Pose {
readonly landscape?: boolean;
readonly fold?: "closed" | "open";
readonly textSize?: "accessibility-large";
+ /** Why the pose is skipped unless named with --pose. */
+ readonly pending?: string;
}
const pose = (value: Pose) => value;
@@ -35,6 +37,8 @@ export const POSES: ReadonlyArray<Pose> = [
form: "phone",
appearance: "light",
fold: "closed",
+ pending:
+ "agent-device fold refuses simulators outside the default device set, which Simlock uses",
}),
pose({
id: "iphone-duo-unfolded",
@@ -43,6 +47,8 @@ export const POSES: ReadonlyArray<Pose> = [
form: "tablet",
appearance: "dark",
fold: "open",
+ pending:
+ "agent-device fold refuses simulators outside the default device set, which Simlock uses",
}),
pose({
id: "ipad-13-portrait",