Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 19 additions & 2 deletions code-push-plugin-testing-framework/script/platform.js
Original file line number Diff line number Diff line change
Expand Up @@ -409,8 +409,13 @@ var IOSEmulatorManager = (function () {
/**
* Ends a running application given its app id.
*/
IOSEmulatorManager.prototype.endRunningApplication = function (appId) {
return testUtil_1.TestUtil.getProcessOutput("xcrun simctl terminate booted " + appId, undefined).then(function () { return null; })
IOSEmulatorManager.prototype.endRunningApplication = async function (appId) {
const isAppRunning = await isAppRunningOnIOS(appId);
if (!isAppRunning) {
return null;
}
await testUtil_1.TestUtil.getProcessOutput("xcrun simctl terminate booted " + appId, undefined);
return null;
};
/**
* Restarts an already installed application by app id.
Expand Down Expand Up @@ -461,6 +466,18 @@ var IOSEmulatorManager = (function () {
}());
exports.IOSEmulatorManager = IOSEmulatorManager;

/**
* Returns whether the app is currently running on the booted simulator.
*
* "xcrun simctl terminate" fails when the app is not running, and it reports that the same way it reports
* a genuinely broken simulator, so the running state has to be established up front instead. Running apps
* appear in launchctl's job list as "UIKitApplication:<bundle id>[...]" with a live pid.
*/
async function isAppRunningOnIOS(appId) {
const output = await testUtil_1.TestUtil.getProcessOutput("xcrun simctl spawn booted launchctl list", { noLogCommand: true, noLogStdOut: true, noLogStdErr: true });
return output.includes(appId);
}

function commandWithCheckAppExistence(command, appId) {
return testUtil_1.TestUtil.getProcessOutput("adb shell pm list packages", { noLogCommand: true, noLogStdOut: true, noLogStdErr: true })
.then((output) => {
Expand Down
5 changes: 4 additions & 1 deletion code-push-plugin-testing-framework/script/testBuilder.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,10 @@ function describeInternal(func, description, spec, scenarioPath) {
});
beforeEach(function () {
return TestContext.targetPlatform.getEmulatorManager().prepareEmulatorForTest(TestConfig.TestNamespace)
.catch(function () { });
.catch(function (error) {
console.error("Failed to prepare emulator/simulator for the test.");
throw error;
});
});
if (scenarioPath) {
before(function () {
Expand Down