cordova-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dase...@apache.org
Subject android commit: CB-10628 Fix emulate android --target
Date Thu, 18 Feb 2016 18:37:50 GMT
Repository: cordova-android
Updated Branches:
  refs/heads/master 7be9e880c -> ce2525d4d


CB-10628 Fix emulate android --target

Added a test case


Project: http://git-wip-us.apache.org/repos/asf/cordova-android/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-android/commit/ce2525d4
Tree: http://git-wip-us.apache.org/repos/asf/cordova-android/tree/ce2525d4
Diff: http://git-wip-us.apache.org/repos/asf/cordova-android/diff/ce2525d4

Branch: refs/heads/master
Commit: ce2525d4d8b2b7c2af0b467f99490529c14beb1d
Parents: 7be9e88
Author: daserge <v-seshak@microsoft.com>
Authored: Thu Feb 18 21:27:40 2016 +0300
Committer: daserge <v-seshak@microsoft.com>
Committed: Thu Feb 18 21:27:40 2016 +0300

----------------------------------------------------------------------
 bin/templates/cordova/lib/emulator.js |  7 +++---
 bin/templates/cordova/lib/run.js      | 18 ++++++++++----
 package.json                          |  3 ++-
 spec/unit/run.spec.js                 | 38 ++++++++++++++++++++++++++++++
 4 files changed, 58 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-android/blob/ce2525d4/bin/templates/cordova/lib/emulator.js
----------------------------------------------------------------------
diff --git a/bin/templates/cordova/lib/emulator.js b/bin/templates/cordova/lib/emulator.js
index e290897..96bb5c9 100644
--- a/bin/templates/cordova/lib/emulator.js
+++ b/bin/templates/cordova/lib/emulator.js
@@ -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' +

http://git-wip-us.apache.org/repos/asf/cordova-android/blob/ce2525d4/bin/templates/cordova/lib/run.js
----------------------------------------------------------------------
diff --git a/bin/templates/cordova/lib/run.js b/bin/templates/cordova/lib/run.js
index 48236dd..3cc5c0d 100644
--- a/bin/templates/cordova/lib/run.js
+++ b/bin/templates/cordova/lib/run.js
@@ -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() {

http://git-wip-us.apache.org/repos/asf/cordova-android/blob/ce2525d4/package.json
----------------------------------------------------------------------
diff --git a/package.json b/package.json
index d3c5942..5af1fc7 100644
--- a/package.json
+++ b/package.json
@@ -41,6 +41,7 @@
     "devDependencies": {
         "jasmine-node": "^1.14.5",
         "jshint": "^2.6.0",
-        "promise-matchers": "~0"
+        "promise-matchers": "~0",
+        "rewire": "^2.1.3"
     }
 }

http://git-wip-us.apache.org/repos/asf/cordova-android/blob/ce2525d4/spec/unit/run.spec.js
----------------------------------------------------------------------
diff --git a/spec/unit/run.spec.js b/spec/unit/run.spec.js
new file mode 100644
index 0000000..8c5ff99
--- /dev/null
+++ b/spec/unit/run.spec.js
@@ -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();
+    });
+  });
+});


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org
For additional commands, e-mail: commits-help@cordova.apache.org


Mime
View raw message