CB-10628 Fix emulate android --target

Added a test case
This commit is contained in:
daserge 2016-02-18 21:27:40 +03:00
parent 7be9e880c2
commit ce2525d4d8
4 changed files with 58 additions and 8 deletions

View File

@ -23,7 +23,6 @@
var retry = require('./retry');
var build = require('./build');
var check_reqs = require('./check_reqs');
var path = require('path');
var Adb = require('./Adb');
var AndroidManifest = require('./AndroidManifest');
@ -105,7 +104,8 @@ module.exports.best_image = function() {
var closest = 9999;
var best = images[0];
var project_target = check_reqs.get_target().replace('android-', '');
// Loading check_reqs at run-time to avoid test-time vs run-time directory structure difference issue
var project_target = require('./check_reqs').get_target().replace('android-', '');
for (var i in images) {
var target = images[i].target;
if(target) {
@ -165,7 +165,8 @@ module.exports.start = function(emulator_ID, boot_timeout) {
return best.name;
}
var androidCmd = check_reqs.getAbsoluteAndroidCmd();
// Loading check_reqs at run-time to avoid test-time vs run-time directory structure difference issue
var androidCmd = require('./check_reqs').getAbsoluteAndroidCmd();
return Q.reject(new CordovaError('No emulator images (avds) found.\n' +
'1. Download desired System Image by running: ' + androidCmd + ' sdk\n' +
'2. Create an AVD by running: ' + androidCmd + ' avd\n' +

View File

@ -27,6 +27,19 @@ var path = require('path'),
device = require('./device'),
Q = require('q');
function getInstallTarget(runOptions) {
var install_target;
if (runOptions.target) {
install_target = runOptions.target;
} else if (runOptions.device) {
install_target = '--device';
} else if (runOptions.emulator) {
install_target = '--emulator';
}
return install_target;
}
/**
* Runs the application on a device if available. If no device is found, it will
* use a started emulator. If no started emulators are found it will attempt
@ -40,10 +53,7 @@ var path = require('path'),
module.exports.run = function(runOptions) {
var self = this;
var install_target = runOptions.device ? '--device' :
runOptions.emulator ? '--emulator' :
runOptions.target;
var install_target = getInstallTarget(runOptions);
return Q()
.then(function() {

View File

@ -41,6 +41,7 @@
"devDependencies": {
"jasmine-node": "^1.14.5",
"jshint": "^2.6.0",
"promise-matchers": "~0"
"promise-matchers": "~0",
"rewire": "^2.1.3"
}
}

38
spec/unit/run.spec.js Normal file
View File

@ -0,0 +1,38 @@
/**
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
*/
var rewire = require("rewire");
var run = rewire("../../bin/templates/cordova/lib/run");
var getInstallTarget = run.__get__("getInstallTarget");
describe("run", function () {
describe("getInstallTarget", function() {
var targetOpts = { target: "emu" };
var deviceOpts = { device: true };
var emulatorOpts = { emulator: true };
var emptyOpts = {};
it("should select correct target based on the run opts", function() {
expect(getInstallTarget(targetOpts)).toBe("emu");
expect(getInstallTarget(deviceOpts)).toBe("--device");
expect(getInstallTarget(emulatorOpts)).toBe("--emulator");
expect(getInstallTarget(emptyOpts)).toBeUndefined();
});
});
});