diff --git a/desktop/app/src/server/devices/IOSDevice.tsx b/desktop/app/src/server/devices/IOSDevice.tsx index 9ed7a0542..751e62617 100644 --- a/desktop/app/src/server/devices/IOSDevice.tsx +++ b/desktop/app/src/server/devices/IOSDevice.tsx @@ -69,8 +69,10 @@ export default class IOSDevice extends BaseDevice { } navigateToLocation(location: string) { - const command = `xcrun simctl openurl ${this.serial} "${location}"`; - exec(command); + return this.iOSBridge.navigate(this.serial, location).catch((err) => { + console.warn(`Failed to navigate to location ${location}:`, err); + return err; + }); } startLogging() { diff --git a/desktop/app/src/server/utils/IOSBridge.tsx b/desktop/app/src/server/utils/IOSBridge.tsx index 74915e13d..8a37389dd 100644 --- a/desktop/app/src/server/utils/IOSBridge.tsx +++ b/desktop/app/src/server/utils/IOSBridge.tsx @@ -27,6 +27,7 @@ export interface IOSBridge { deviceType: DeviceType, ) => child_process.ChildProcessWithoutNullStreams; screenshot: (serial: string) => Promise; + navigate: (serial: string, location: string) => Promise; } async function isAvailable(idbPath: string): Promise { @@ -119,6 +120,20 @@ export async function idbScreenshot(serial: string): Promise { return runScreenshotCommand(command, imagePath); } +export async function xcrunNavigate( + serial: string, + location: string, +): Promise { + exec(`xcrun simctl io ${serial} launch url "${location}"`); +} + +export async function idbNavigate( + serial: string, + location: string, +): Promise { + exec(`idb open --udid ${serial} "${location}"`); +} + export async function makeIOSBridge( idbPath: string, isXcodeDetected: boolean, @@ -129,6 +144,7 @@ export async function makeIOSBridge( return { startLogListener: idbStartLogListener.bind(null, idbPath), screenshot: idbScreenshot, + navigate: idbNavigate, }; } @@ -137,6 +153,7 @@ export async function makeIOSBridge( return { startLogListener: xcrunStartLogListener, screenshot: xcrunScreenshot, + navigate: xcrunNavigate, }; } diff --git a/desktop/app/src/server/utils/__tests__/IOSBridge.node.tsx b/desktop/app/src/server/utils/__tests__/IOSBridge.node.tsx index c4812e194..f055fc671 100644 --- a/desktop/app/src/server/utils/__tests__/IOSBridge.node.tsx +++ b/desktop/app/src/server/utils/__tests__/IOSBridge.node.tsx @@ -116,3 +116,21 @@ test.unix('uses idb to take screenshots when available', async () => { 'idb screenshot --udid deadbeef /temp/00000000-0000-0000-0000-000000000000.png', ); }); + +test('uses xcrun to navigate with no idb when xcode is detected', async () => { + const ib = await makeIOSBridge('', true); + + ib.navigate('deadbeef', 'fb://dummy'); + + expect(exec).toHaveBeenCalledWith( + 'xcrun simctl io deadbeef launch url "fb://dummy"', + ); +}); + +test('uses idb to navigate when available', async () => { + const ib = await makeIOSBridge('/usr/local/bin/idb', true, async (_) => true); + + ib.navigate('deadbeef', 'fb://dummy'); + + expect(exec).toHaveBeenCalledWith('idb open --udid deadbeef "fb://dummy"'); +});