Skip to content

Commit 0a73592

Browse files
committed
fix: make libimobiledevice optional when native crash detection is off
1 parent 4c93648 commit 0a73592

2 files changed

Lines changed: 62 additions & 6 deletions

File tree

packages/platform-ios/src/__tests__/instance.test.ts

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@ const harnessConfig = {
1515
metroPort: DEFAULT_METRO_PORT,
1616
} as HarnessConfig;
1717

18+
const harnessConfigWithoutNativeCrashDetection = {
19+
metroPort: DEFAULT_METRO_PORT,
20+
detectNativeCrashes: false,
21+
} as HarnessConfig;
22+
1823
describe('iOS platform instance dependency validation', () => {
1924
beforeEach(() => {
2025
vi.restoreAllMocks();
@@ -43,7 +48,7 @@ describe('iOS platform instance dependency validation', () => {
4348
expect(assertInstalled).not.toHaveBeenCalled();
4449
});
4550

46-
it('validates libimobiledevice before creating a physical device instance', async () => {
51+
it('validates libimobiledevice before creating a physical device instance when native crash detection is enabled', async () => {
4752
const assertInstalled = vi
4853
.spyOn(libimobiledevice, 'assertLibimobiledeviceInstalled')
4954
.mockRejectedValue(new Error('missing'));
@@ -85,7 +90,7 @@ describe('iOS platform instance dependency validation', () => {
8590
expect(getSimulatorId).toHaveBeenCalled();
8691
});
8792

88-
it('does not try to discover the physical device when the dependency is missing', async () => {
93+
it('does not try to discover the physical device when the dependency is missing and native crash detection is enabled', async () => {
8994
vi.spyOn(libimobiledevice, 'assertLibimobiledeviceInstalled').mockRejectedValue(
9095
new Error('missing')
9196
);
@@ -102,4 +107,37 @@ describe('iOS platform instance dependency validation', () => {
102107
).rejects.toThrow('missing');
103108
expect(getDeviceId).not.toHaveBeenCalled();
104109
});
110+
111+
it('skips libimobiledevice validation when native crash detection is disabled', async () => {
112+
const assertInstalled = vi
113+
.spyOn(libimobiledevice, 'assertLibimobiledeviceInstalled')
114+
.mockRejectedValue(new Error('missing'));
115+
vi.spyOn(devicectl, 'getDevice').mockResolvedValue({
116+
identifier: 'physical-device-id',
117+
deviceProperties: {
118+
name: 'My iPhone',
119+
osVersionNumber: '18.0',
120+
},
121+
hardwareProperties: {
122+
marketingName: 'iPhone',
123+
productType: 'iPhone17,1',
124+
udid: '00008140-001600222422201C',
125+
},
126+
});
127+
vi.spyOn(devicectl, 'isAppInstalled').mockResolvedValue(true);
128+
129+
const config = {
130+
name: 'ios-device',
131+
device: { type: 'physical' as const, name: 'My iPhone' },
132+
bundleId: 'com.harnessplayground',
133+
};
134+
135+
await expect(
136+
getApplePhysicalDevicePlatformInstance(
137+
config,
138+
harnessConfigWithoutNativeCrashDetection
139+
)
140+
).resolves.toBeDefined();
141+
expect(assertInstalled).not.toHaveBeenCalled();
142+
});
105143
});

packages/platform-ios/src/instance.ts

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import {
2+
AppMonitor,
23
AppNotInstalledError,
34
CreateAppMonitorOptions,
45
DeviceNotFoundError,
@@ -22,6 +23,14 @@ import {
2223
} from './app-monitor.js';
2324
import { assertLibimobiledeviceInstalled } from './libimobiledevice.js';
2425

26+
const createNoopAppMonitor = (): AppMonitor => ({
27+
start: async () => {},
28+
stop: async () => {},
29+
dispose: async () => {},
30+
addListener: () => {},
31+
removeListener: () => {},
32+
});
33+
2534
export const getAppleSimulatorPlatformInstance = async (
2635
config: ApplePlatformConfig,
2736
harnessConfig: HarnessConfig
@@ -100,7 +109,11 @@ export const getApplePhysicalDevicePlatformInstance = async (
100109
harnessConfig: HarnessConfig
101110
): Promise<HarnessPlatformRunner> => {
102111
assertAppleDevicePhysical(config.device);
103-
await assertLibimobiledeviceInstalled();
112+
const detectNativeCrashes = harnessConfig.detectNativeCrashes;
113+
114+
if (detectNativeCrashes) {
115+
await assertLibimobiledeviceInstalled();
116+
}
104117

105118
if (harnessConfig.metroPort !== DEFAULT_METRO_PORT) {
106119
throw new Error(
@@ -153,12 +166,17 @@ export const getApplePhysicalDevicePlatformInstance = async (
153166
isAppRunning: async () => {
154167
return await devicectl.isAppRunning(deviceId, config.bundleId);
155168
},
156-
createAppMonitor: (options?: CreateAppMonitorOptions) =>
157-
createIosDeviceAppMonitor({
169+
createAppMonitor: (options?: CreateAppMonitorOptions) => {
170+
if (!detectNativeCrashes) {
171+
return createNoopAppMonitor();
172+
}
173+
174+
return createIosDeviceAppMonitor({
158175
deviceId,
159176
libimobiledeviceUdid: hardwareUdid,
160177
bundleId: config.bundleId,
161178
crashArtifactWriter: options?.crashArtifactWriter,
162-
}),
179+
});
180+
},
163181
};
164182
};

0 commit comments

Comments
 (0)