Skip to content

Commit 44370bb

Browse files
ofalvaiclaude
andcommitted
Fail loudly when preparing the emulator for a test fails
The beforeEach hook in testBuilder swallowed every error from prepareEmulatorForTest, so an emulator in a bad state surfaced later as an unrelated assertion failure somewhere else in the scenario. It now logs and rethrows. Rethrowing on its own would have broken every scenario, because iOS "simctl terminate" exits non-zero when the app is not running, and the app is not running before the first test of a scenario. Verified on Xcode 26.6 / iOS 26.5: terminate reports "found nothing to terminate" identically whether the app was never installed or is merely idle, so the error text and the exit code cannot tell a missing app apart from a broken simulator. simctl appinfo, get_app_container and listapps do not help either, as they only report whether the app is installed, and their output is unchanged by the app running or not. So IOSEmulatorManager.endRunningApplication now establishes the running state up front with "simctl spawn booted launchctl list", where a running app appears as UIKitApplication:<bundle id> with a live pid, and skips terminate when the app is not running. Everything else propagates. Android needs no equivalent guard: "am force-stop" exits 0 whether or not the app is installed or running (verified against an emulator), and "pm clear" is already guarded by an existence check. Adding one there would only add an adb round-trip per test. Verified end to end against a live simulator and emulator for the installed-but-idle, never-installed and actually-running cases. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
1 parent ad5bb01 commit 44370bb

2 files changed

Lines changed: 23 additions & 3 deletions

File tree

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

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -409,8 +409,13 @@ var IOSEmulatorManager = (function () {
409409
/**
410410
* Ends a running application given its app id.
411411
*/
412-
IOSEmulatorManager.prototype.endRunningApplication = function (appId) {
413-
return testUtil_1.TestUtil.getProcessOutput("xcrun simctl terminate booted " + appId, undefined).then(function () { return null; })
412+
IOSEmulatorManager.prototype.endRunningApplication = async function (appId) {
413+
const isAppRunning = await isAppRunningOnIOS(appId);
414+
if (!isAppRunning) {
415+
return null;
416+
}
417+
await testUtil_1.TestUtil.getProcessOutput("xcrun simctl terminate booted " + appId, undefined);
418+
return null;
414419
};
415420
/**
416421
* Restarts an already installed application by app id.
@@ -461,6 +466,18 @@ var IOSEmulatorManager = (function () {
461466
}());
462467
exports.IOSEmulatorManager = IOSEmulatorManager;
463468

469+
/**
470+
* Returns whether the app is currently running on the booted simulator.
471+
*
472+
* "xcrun simctl terminate" fails when the app is not running, and it reports that the same way it reports
473+
* a genuinely broken simulator, so the running state has to be established up front instead. Running apps
474+
* appear in launchctl's job list as "UIKitApplication:<bundle id>[...]" with a live pid.
475+
*/
476+
async function isAppRunningOnIOS(appId) {
477+
const output = await testUtil_1.TestUtil.getProcessOutput("xcrun simctl spawn booted launchctl list", { noLogCommand: true, noLogStdOut: true, noLogStdErr: true });
478+
return output.includes(appId);
479+
}
480+
464481
function commandWithCheckAppExistence(command, appId) {
465482
return testUtil_1.TestUtil.getProcessOutput("adb shell pm list packages", { noLogCommand: true, noLogStdOut: true, noLogStdErr: true })
466483
.then((output) => {

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,10 @@ function describeInternal(func, description, spec, scenarioPath) {
3535
});
3636
beforeEach(function () {
3737
return TestContext.targetPlatform.getEmulatorManager().prepareEmulatorForTest(TestConfig.TestNamespace)
38-
.catch(function () { });
38+
.catch(function (error) {
39+
console.error("Failed to prepare emulator/simulator for the test.");
40+
throw error;
41+
});
3942
});
4043
if (scenarioPath) {
4144
before(function () {

0 commit comments

Comments
 (0)