Skip to content

Commit 3bf0d6d

Browse files
committed
Reuse an already-booted iOS simulator instead of hanging
IOSEmulatorManager.getTargetEmulator always picked the most recent iPhone simulator from `simctl list`, regardless of whether a different simulator was already booted. When one was, the boot-ready check kept failing and the manager tried to boot a second simulator, which conflicted with the first and hung until the retry loop timed out. Now, unless IOS_EMU pins a specific simulator, the picker reuses whichever simulator is already booted. Rewritten with async/await, matching the style already used elsewhere in this file.
1 parent ad5bb01 commit 3bf0d6d

2 files changed

Lines changed: 19 additions & 29 deletions

File tree

CLAUDE.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@ React Native CodePush is a native module that enables over-the-air updates for R
5656
- For the fast local loop: run `test:setup:ios` once per template/dependency change, then re-run `test:fast:ios` repeatedly while iterating on test/scenario code — this skips `pod install` and re-provisioning on every iteration.
5757
- There's still no "just build, no tests" npm script — for a raw build only, lift the `xcodebuild` invocation out of `RNIOS.buildApp` in `test/test.ts` and run it by hand against the provisioned `TestCodePush.xcworkspace`.
5858
- When debugging a CI failure, don't trust the first plausible-looking theory from log noise — reproduce the exact failing command locally on matching hardware/toolchain before writing up a root cause. This is faster than iterating against multi-hour CI runs and catches wrong hypotheses early.
59-
- Before running `npm run test:setup:ios`, shut down all booted simulators (`xcrun simctl shutdown all`) — the test framework's simulator picker hangs silently (no error) if simulators are already booted outside it.
6059
- `npm run test:setup:ios` provisions a full test app outside the repo (under a system temp/`test-run` dir), not inside `test/` — expect to search for it rather than finding it checked into the repo tree.
6160
- The provisioned test app's `node_modules/@bitrise/code-push-sdk` is a real copy, not a symlink — editing `ios/` (or `android/`) native source in the repo has zero effect on `test:fast:ios` runs until you re-copy those files into that `node_modules` path (or rerun `test:setup:ios`).
6261

code-push-plugin-testing-framework/script/platform.js

Lines changed: 19 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -347,36 +347,27 @@ var IOSEmulatorManager = (function () {
347347
/**
348348
* Returns the target emulator, which is specified through the command line.
349349
*/
350-
IOSEmulatorManager.prototype.getTargetEmulator = function () {
351-
let _this = this;
352-
if (this.targetEmulator)
353-
return Q(this.targetEmulator);
354-
else {
355-
let deferred = Q.defer();
356-
let targetIOSEmulator = process.env.IOS_EMU;
357-
if (!targetIOSEmulator) {
358-
// If no iOS simulator is specified, get the most recent iOS simulator to run tests on.
359-
testUtil_1.TestUtil.getProcessOutput("xcrun simctl list", { noLogCommand: true, noLogStdOut: true, noLogStdErr: true })
360-
.then((listOfDevicesWithDevicePairs) => {
361-
let listOfDevices = listOfDevicesWithDevicePairs.slice(listOfDevicesWithDevicePairs.indexOf("-- iOS"), listOfDevicesWithDevicePairs.indexOf("-- tvOS"));
362-
let phoneDevice = /iPhone\ \S*\ ?.*?\(([0-9A-Z-]*)\)/g;
363-
let match = phoneDevice.exec(listOfDevices);
364-
deferred.resolve(match[1]);
365-
}, (error) => {
366-
deferred.reject(error);
367-
});
368-
}
369-
else {
370-
// Use the simulator specified on the command line.
371-
deferred.resolve(targetIOSEmulator);
350+
IOSEmulatorManager.prototype.getTargetEmulator = async function () {
351+
if (this.targetEmulator) {
352+
return this.targetEmulator;
353+
}
354+
let targetEmulator = process.env.IOS_EMU;
355+
if (!targetEmulator) {
356+
try {
357+
const bootedUdid = await testUtil_1.TestUtil.getProcessOutput("xcrun simctl getenv booted SIMULATOR_UDID", { noLogCommand: true, noLogStdOut: true, noLogStdErr: true });
358+
targetEmulator = bootedUdid.trim();
359+
} catch {
360+
// No simulator is currently booted - fall back to the most recent iOS simulator.
361+
const listOfDevicesWithDevicePairs = await testUtil_1.TestUtil.getProcessOutput("xcrun simctl list", { noLogCommand: true, noLogStdOut: true, noLogStdErr: true });
362+
const listOfDevices = listOfDevicesWithDevicePairs.slice(listOfDevicesWithDevicePairs.indexOf("-- iOS"), listOfDevicesWithDevicePairs.indexOf("-- tvOS"));
363+
const phoneDevice = /iPhone\ \S*\ ?.*?\(([0-9A-Z-]*)\)/g;
364+
const match = phoneDevice.exec(listOfDevices);
365+
targetEmulator = match[1];
372366
}
373-
return deferred.promise
374-
.then((targetEmulator) => {
375-
_this.targetEmulator = targetEmulator;
376-
console.log("Using iOS simulator named " + _this.targetEmulator);
377-
return _this.targetEmulator;
378-
});
379367
}
368+
this.targetEmulator = targetEmulator;
369+
console.log("Using iOS simulator named " + this.targetEmulator);
370+
return this.targetEmulator;
380371
};
381372
/**
382373
* Boots the target emulator.

0 commit comments

Comments
 (0)