Merge pull request #1726 from jlipps/master

cleanup app state before a test too (rewrite of #1732)
This commit is contained in:
bootstraponline
2014-01-10 09:44:46 -08:00
+36 -18
View File
@@ -622,27 +622,45 @@ IOS.prototype.setDeviceAndLaunchSimulator = function(cb) {
cb(new Error(msg));
} else {
this.endSimulator(function(err) {
if (err) return cb(err);
var cleanup = function(cb) {
if (this.reset) {
this.cleanupAppState(cb);
} else {
cb();
}
}.bind(this);
var setDeviceInfo = function(cb) {
var iosDeviceString = this.getDeviceString();
var isiPhone = iosDeviceString.toLowerCase().indexOf("ipad") === -1;
var iosSimArgs = ["-SimulateDevice", iosDeviceString];
logger.debug("Launching device: " + iosDeviceString);
this.setDeviceTypeInInfoPlist(isiPhone ? 1 : 2, function() {
this.iosSimProcess = spawn(iosSimPath, iosSimArgs);
var waitForSimulatorLogs = function(countdown) {
if (countdown <= 0 || this.logs.syslog.getAllLogs().length > 0 || this.logs.crashlog.getAllLogs().length > 0) {
logger.info(countdown > 0 ? "Simulator is now ready." : "Waited 10 seconds for simulator to start.");
cb();
} else {
setTimeout(function() {
waitForSimulatorLogs(countdown-1);
} ,1000);
}
}.bind(this);
waitForSimulatorLogs(10);
}.bind(this));
}.bind(this));
this.setDeviceTypeInInfoPlist(isiPhone ? 1 : 2, cb);
}.bind(this);
var startSim = function(cb) {
var iosSimArgs = ["-SimulateDevice", this.getDeviceString()];
this.iosSimProcess = spawn(iosSimPath, iosSimArgs);
var waitForSimulatorLogs = function(countdown) {
if (countdown <= 0 || this.logs.syslog.getAllLogs().length > 0 || this.logs.crashlog.getAllLogs().length > 0) {
logger.info(countdown > 0 ? "Simulator is now ready." : "Waited 10 seconds for simulator to start.");
cb();
} else {
setTimeout(function() {
waitForSimulatorLogs(countdown-1);
} ,1000);
}
}.bind(this);
waitForSimulatorLogs(10);
}.bind(this);
async.series([
this.endSimulator.bind(this),
cleanup,
setDeviceInfo,
startSim
], function(err) {
cb(err);
});
}
}
};