Skip to content

Commit

Permalink
make sure we check available devices when --default-device is used as…
Browse files Browse the repository at this point in the history
… well
  • Loading branch information
jlipps committed Apr 4, 2014
1 parent 341c15b commit cd0e4aa
Showing 1 changed file with 24 additions and 20 deletions.
44 changes: 24 additions & 20 deletions lib/devices/ios/ios.js
Original file line number Diff line number Diff line change
Expand Up @@ -835,6 +835,23 @@ IOS.prototype.setDeviceTypeInInfoPlist = function (deviceTypeCode, cb) {
});
};

IOS.prototype.checkDeviceAvailable = function (cb) {
logger.debug("Checking whether instruments supports our device string");
this.instruments.getAvailableDevices(function (err, availDevices) {
var dString = this.getDeviceString();
if (err) return cb(err);
if (!_.contains(availDevices, dString)) {
var msg = "Could not find a device to launch. You requested '" +
dString + "', but the available devices were: " +
JSON.stringify(availDevices);
logger.error(msg);
return cb(new Error(msg));
}
cb();
}.bind(this));
};


IOS.prototype.setDeviceAndLaunchSimulator = function (cb) {
var msg;
if (this.args.udid) {
Expand All @@ -849,9 +866,12 @@ IOS.prototype.setDeviceAndLaunchSimulator = function (cb) {
cb(null);
} else if (this.args.defaultDevice) {
logger.info("User specified default device, letting instruments launch it");
var iosDeviceString = this.getDeviceString();
var isiPhone = iosDeviceString.toLowerCase().indexOf("ipad") === -1;
this.setDeviceTypeInInfoPlist(isiPhone ? 1 : 2, cb);
this.checkDeviceAvailable(function (err) {
if (err) return cb(err);
var iosDeviceString = this.getDeviceString();
var isiPhone = iosDeviceString.toLowerCase().indexOf("ipad") === -1;
this.setDeviceTypeInInfoPlist(isiPhone ? 1 : 2, cb);
}.bind(this));
} else {
var iosSimPath = path.resolve(this.xcodeFolder, "Platforms/iPhoneSimulator.platform/Developer/Applications" +
"/iPhone Simulator.app/Contents/MacOS/iPhone Simulator");
Expand Down Expand Up @@ -881,22 +901,6 @@ IOS.prototype.setDeviceAndLaunchSimulator = function (cb) {
this.setDeviceTypeInInfoPlist(isiPhone ? 1 : 2, cb);
}.bind(this);

var checkDeviceAvailable = function (cb) {
logger.debug("Checking whether instruments supports our device string");
this.instruments.getAvailableDevices(function (err, availDevices) {
var dString = this.getDeviceString();
if (err) return cb(err);
if (!_.contains(availDevices, dString)) {
var msg = "Could not find a device to launch. You requested '" +
dString + "', but the available devices were: " +
JSON.stringify(availDevices);
logger.error(msg);
return cb(new Error(msg));
}
cb();
}.bind(this));
}.bind(this);

var startSim = function (cb) {
logger.debug("Launching device: " + this.getDeviceString());
var iosSimArgs = ["-SimulateDevice", this.getDeviceString()];
Expand Down Expand Up @@ -927,7 +931,7 @@ IOS.prototype.setDeviceAndLaunchSimulator = function (cb) {
} else {
async.series([
this.endSimulator.bind(this),
checkDeviceAvailable,
this.checkDeviceAvailable.bind(this),
cleanup,
], function (err) {
cb(err);
Expand Down

0 comments on commit cd0e4aa

Please sign in to comment.