Skip to content

Commit

Permalink
cleanup app state before a test too (rewrite of #1732)
Browse files Browse the repository at this point in the history
cc @dandoveralba @bootstraponline
  • Loading branch information
jlipps committed Jan 10, 2014
1 parent 44b8ed8 commit ea20c38
Showing 1 changed file with 36 additions and 18 deletions.
54 changes: 36 additions & 18 deletions lib/devices/ios/ios.js
Expand Up @@ -619,27 +619,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);
});
}
}
};
Expand Down

0 comments on commit ea20c38

Please sign in to comment.