Skip to content

Commit 72a817c

Browse files
committed
fix: bound iOS simulator app termination
1 parent be5081d commit 72a817c

3 files changed

Lines changed: 27 additions & 1 deletion

File tree

src/platforms/ios/__tests__/index.test.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ import { ensureBootedSimulator, openIosSimulatorApp } from '../simulator.ts';
7171
import { prepareSimulatorStatusBarForScreenshot as prepareStatusBarForScreenshot } from '../screenshot-status-bar.ts';
7272
import { runIosRunnerCommand } from '../runner-client.ts';
7373
import { iosRunnerOverrides } from '../interactions.ts';
74+
import { IOS_SIMULATOR_TERMINATE_TIMEOUT_MS } from '../config.ts';
7475
import type { DeviceInfo } from '../../../utils/device.ts';
7576
import { withDiagnosticsScope } from '../../../utils/diagnostics.ts';
7677
import { AppError } from '../../../utils/errors.ts';
@@ -1136,6 +1137,24 @@ test('closeIosApp on macOS uses helper quit for bundle identifiers', async () =>
11361137
);
11371138
});
11381139

1140+
test('closeIosApp on iOS simulator bounds simctl terminate', async () => {
1141+
mockEnsureBootedSimulator.mockResolvedValue(undefined);
1142+
mockRunCmd.mockResolvedValue({ stdout: '', stderr: '', exitCode: 0 });
1143+
1144+
await closeIosApp(IOS_TEST_SIMULATOR, 'com.example.foobar');
1145+
1146+
assert.equal(mockRunCmd.mock.calls.length, 1);
1147+
assert.equal(mockRunCmd.mock.calls[0]?.[0], 'xcrun');
1148+
assert.deepEqual(mockRunCmd.mock.calls[0]?.[1], [
1149+
'simctl',
1150+
'terminate',
1151+
'sim-1',
1152+
'com.example.foobar',
1153+
]);
1154+
assert.equal(mockRunCmd.mock.calls[0]?.[2]?.allowFailure, true);
1155+
assert.equal(mockRunCmd.mock.calls[0]?.[2]?.timeoutMs, IOS_SIMULATOR_TERMINATE_TIMEOUT_MS);
1156+
});
1157+
11391158
test('quitMacOsApp rejects invalid bundle identifiers before invoking helper', async () => {
11401159
await assert.rejects(() => quitMacOsApp('not a bundle id'), /reverse-DNS form/i);
11411160
});

src/platforms/ios/apps.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,11 @@ import {
2828
type CommandAttemptFailure,
2929
} from '../command-attempts.ts';
3030

31-
import { IOS_APP_LAUNCH_TIMEOUT_MS, IOS_DEVICECTL_TIMEOUT_MS } from './config.ts';
31+
import {
32+
IOS_APP_LAUNCH_TIMEOUT_MS,
33+
IOS_DEVICECTL_TIMEOUT_MS,
34+
IOS_SIMULATOR_TERMINATE_TIMEOUT_MS,
35+
} from './config.ts';
3236
import {
3337
IOS_DEVICECTL_DEFAULT_HINT,
3438
listIosDeviceApps,
@@ -277,6 +281,7 @@ export async function closeIosApp(device: DeviceInfo, app: string): Promise<void
277281
const terminateArgs = simctlArgs(device, ['terminate', device.id, bundleId]);
278282
const result = await runXcrun(terminateArgs, {
279283
allowFailure: true,
284+
timeoutMs: IOS_SIMULATOR_TERMINATE_TIMEOUT_MS,
280285
});
281286
if (result.exitCode !== 0) {
282287
const stderr = result.stderr.toLowerCase();

src/platforms/ios/config.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ export const IOS_DEVICECTL_TIMEOUT_MS = 20_000;
88

99
export const IOS_SIMULATOR_FOCUS_TIMEOUT_MS = 10_000;
1010

11+
export const IOS_SIMULATOR_TERMINATE_TIMEOUT_MS = 15_000;
12+
1113
export const IOS_SIMULATOR_SCREENSHOT_TIMEOUT_MS = 20_000;
1214

1315
export const IOS_RUNNER_SCREENSHOT_COPY_TIMEOUT_MS = 20_000;

0 commit comments

Comments
 (0)