You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by fi...@apache.org on 2013/05/10 23:22:34 UTC

git commit: added specs for fetch and clonePluginGitRepo w.r.t. subdirectory support

Updated Branches:
  refs/heads/dependencies 39d6f7937 -> 402bdf103


added specs for fetch and clonePluginGitRepo w.r.t. subdirectory support


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

Branch: refs/heads/dependencies
Commit: 402bdf1031352187af029cb9a5a142375fefb563
Parents: 39d6f79
Author: Fil Maj <ma...@gmail.com>
Authored: Fri May 10 14:22:26 2013 -0700
Committer: Fil Maj <ma...@gmail.com>
Committed: Fri May 10 14:22:26 2013 -0700

----------------------------------------------------------------------
 spec/fetch.spec.js        |    7 ++++++
 spec/util/plugins.spec.js |   42 ++++++++++++++++++++++++++++-----------
 src/util/plugins.js       |    5 ++-
 3 files changed, 40 insertions(+), 14 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-plugman/blob/402bdf10/spec/fetch.spec.js
----------------------------------------------------------------------
diff --git a/spec/fetch.spec.js b/spec/fetch.spec.js
index b36ceab..8f7c678 100644
--- a/spec/fetch.spec.js
+++ b/spec/fetch.spec.js
@@ -37,6 +37,13 @@ describe('fetch', function() {
             fetch("https://github.com/bobeast/GAPlugin.git", temp, false);
             expect(s).toHaveBeenCalled();
         });
+        it('should call clonePluginGitRepo with subdir if applicable', function() {
+            var s = spyOn(plugins, 'clonePluginGitRepo');
+            var url = "https://github.com/bobeast/GAPlugin.git";
+            var dir = 'fakeSubDir';
+            fetch(url, temp, false, dir);
+            expect(s).toHaveBeenCalledWith(url, temp, dir, undefined);
+        });
         it('should throw if used with url and `link` param', function() {
             expect(function() {
                 fetch("https://github.com/bobeast/GAPlugin.git", temp, true);

http://git-wip-us.apache.org/repos/asf/cordova-plugman/blob/402bdf10/spec/util/plugins.spec.js
----------------------------------------------------------------------
diff --git a/spec/util/plugins.spec.js b/spec/util/plugins.spec.js
index f0cb3e0..d2af311 100644
--- a/spec/util/plugins.spec.js
+++ b/spec/util/plugins.spec.js
@@ -23,22 +23,40 @@ var http   = require('http'),
     fs     = require('fs'),
     temp   = path.join(osenv.tmpdir(), 'plugman'),
     shell  = require('shelljs'),
-    plugins = require('../../src/util/plugins');
+    plugins = require('../../src/util/plugins'),
+    xml_helpers = require('../../src/util/xml-helpers');
 
-describe('plugins', function(){
-    describe('server', function(){
-        it('should be able to receive the correct git clone arguments', function(){
-            var mySpy = spyOn(plugins, 'clonePluginGitRepo');
+describe('plugins utility module', function(){
+    describe('clonePluginGitRepo', function(){
+        it('should shell out to git clone with correct arguments', function(){
+            var mySpy = spyOn(shell, 'exec');
             var plugin_git_url = 'https://github.com/imhotep/ChildBrowser'
-            var myFunction = function(){};
             
-            plugins.clonePluginGitRepo(plugin_git_url, temp, '.', myFunction);
+            plugins.clonePluginGitRepo(plugin_git_url, temp, '.');
             
-             expect(mySpy).toHaveBeenCalled();
-             expect(mySpy).toHaveBeenCalledWith(plugin_git_url, temp, '.', myFunction);
+            expect(mySpy).toHaveBeenCalled();
+            var git_clone_regex = new RegExp('^git clone "' + plugin_git_url + '" ".*"$', 'gi');
+            expect(mySpy.mostRecentCall.args[0]).toMatch(git_clone_regex);
+        });
+        it('should take into account subdirectory argument when copying over final repository into plugins+plugin_id directory', function() {
+            var exec_spy = spyOn(shell, 'exec');
+            var cp_spy = spyOn(shell, 'cp');
+            var fake_id = 'VillageDrunkard';
+            var xml_spy = spyOn(xml_helpers, 'parseElementtreeSync').andReturn({
+                getroot:function() {
+                    return {
+                        attrib:{id:fake_id}
+                    };
+                }
+            });
+            var plugin_git_url = 'https://github.com/imhotep/ChildBrowser'
+            
+            var fake_subdir = 'TheBrainRecoilsInHorror';
+            plugins.clonePluginGitRepo(plugin_git_url, temp, fake_subdir);
+            exec_spy.mostRecentCall.args[2](0); // fake out shell.exec finishing appropriately (so we dont ACTUALLY shell out to git-clone, assume it worked fine)
+            var expected_subdir_cp_path = new RegExp(fake_subdir + '[\\\\\\/]\\*$', 'gi');
+            expect(cp_spy.mostRecentCall.args[1]).toMatch(expected_subdir_cp_path);
+            expect(cp_spy.mostRecentCall.args[2]).toEqual(path.join(temp, fake_id));
         });
     });
 });
-
-
-

http://git-wip-us.apache.org/repos/asf/cordova-plugman/blob/402bdf10/src/util/plugins.js
----------------------------------------------------------------------
diff --git a/src/util/plugins.js b/src/util/plugins.js
index fddecfa..ff9cace 100644
--- a/src/util/plugins.js
+++ b/src/util/plugins.js
@@ -42,12 +42,13 @@ module.exports = {
         var cmd = util.format('git clone "%s" "%s"', plugin_git_url, tmp_dir);
         shell.exec(cmd, {silent: true, async:true}, function(code, output) {
             if (code > 0) {
-                var err = new Error('failed to get the plugin via git from URL '+ plugin_git_url);
+                var err = new Error('failed to get the plugin via git from URL '+ plugin_git_url + ', output: ' + output);
                 if (callback) callback(err)
                 else throw err;
             } else {
                 // Read the plugin.xml file and extract the plugin's ID.
                 tmp_dir = path.join(tmp_dir, subdir);
+                // TODO: what if plugin.xml does not exist?
                 var xml_file = path.join(tmp_dir, 'plugin.xml');
                 var xml = xml_helpers.parseElementtreeSync(xml_file);
                 var plugin_id = xml.getroot().attrib.id;
@@ -58,6 +59,6 @@ module.exports = {
                 if (callback) callback(null, plugin_dir);
             }
         });
-    },
+    }
 };