From ea20c38f7a520de7b977a8b9adbefaa9de9e2f68 Mon Sep 17 00:00:00 2001 From: Jonathan Lipps Date: Fri, 10 Jan 2014 09:08:20 -0800 Subject: [PATCH] cleanup app state before a test too (rewrite of #1732) cc @dandoveralba @bootstraponline --- lib/devices/ios/ios.js | 54 ++++++++++++++++++++++++++++-------------- 1 file changed, 36 insertions(+), 18 deletions(-) diff --git a/lib/devices/ios/ios.js b/lib/devices/ios/ios.js index f3a4cbfc5..b865d1575 100644 --- a/lib/devices/ios/ios.js +++ b/lib/devices/ios/ios.js @@ -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); + }); } } };