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/06/12 20:33:42 UTC

git commit: redid create specs. config_parser now available on util module, for easier spying/testing.

Updated Branches:
  refs/heads/lazy 56012d00b -> bd3cec50b


redid create specs. config_parser now available on util module, for easier spying/testing.


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

Branch: refs/heads/lazy
Commit: bd3cec50b814b4c749c34ad8697df80c8a2be29a
Parents: 56012d0
Author: Fil Maj <ma...@gmail.com>
Authored: Wed Jun 12 11:33:35 2013 -0700
Committer: Fil Maj <ma...@gmail.com>
Committed: Wed Jun 12 11:33:35 2013 -0700

----------------------------------------------------------------------
 package.json                    |   1 +
 spec/cordova-cli/create.spec.js | 154 ++++++++++++++++++++++-------------
 spec/cordova-cli/helper.js      |  59 --------------
 src/create.js                   |  10 +--
 src/help.js                     |   1 -
 src/util.js                     |   8 +-
 6 files changed, 107 insertions(+), 126 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-cli/blob/bd3cec50/package.json
----------------------------------------------------------------------
diff --git a/package.json b/package.json
index 7c9080b..4fc5581 100644
--- a/package.json
+++ b/package.json
@@ -7,6 +7,7 @@
   "engines":{
       "node":">=0.9.9"
   },
+  "engineStrict":true,
   "bin": {
     "cordova": "./bin/cordova"
   },

http://git-wip-us.apache.org/repos/asf/cordova-cli/blob/bd3cec50/spec/cordova-cli/create.spec.js
----------------------------------------------------------------------
diff --git a/spec/cordova-cli/create.spec.js b/spec/cordova-cli/create.spec.js
index c3cad3e..c8f6969 100644
--- a/spec/cordova-cli/create.spec.js
+++ b/spec/cordova-cli/create.spec.js
@@ -8,7 +8,7 @@ var cordova = require('../../cordova'),
     tempDir = path.join(__dirname, '..', '..', 'temp');
 
 describe('create command', function () {
-    var mkdir, cp, config_spy, load_cordova, load_custom, exists, config_read, parser;
+    var mkdir, cp, config_spy, load_cordova, load_custom, exists, config_read, parser, package, name;
     beforeEach(function() {
         shell.rm('-rf', tempDir);
         mkdir = spyOn(shell, 'mkdir');
@@ -22,68 +22,106 @@ describe('create command', function () {
         load_custom = spyOn(lazy_load, 'custom').andCallFake(function(url, id, platform, version, cb) {
             cb();
         });
-    });
-
-    it('should do something', function(done) {
-        cordova.create(tempDir, function() {
-            expect(true).toBe(true);
-            done();
+        package = jasmine.createSpy('config.packageName');
+        name = jasmine.createSpy('config.name');
+        parser = spyOn(util, 'config_parser').andReturn({
+            packageName:package,
+            name:name
         });
     });
 
-    /*
-    it('should print out help txt if no parameters are provided', function() {
-        expect(cordova.create()).toMatch(/synopsis/i);
-    });
-    it('should create a cordova project in the specified directory, and default id and name', function(done) {
-        cordova.create(tempDir, function(err) {
-            expect(err).not.toBeDefined();
-            var dotc = path.join(tempDir, '.cordova', 'config.json');
-            expect(fs.lstatSync(dotc).isFile()).toBe(true);
-            expect(JSON.parse(fs.readFileSync(dotc, 'utf8')).name).toBe("HelloCordova");
-            var hooks = path.join(tempDir, '.cordova', 'hooks');
-            expect(fs.existsSync(hooks)).toBe(true);
-            expect(fs.existsSync(path.join(hooks, 'before_platform_add'))).toBe(true);
-            expect(fs.existsSync(path.join(hooks, 'before_prepare'))).toBe(true);
-            expect(fs.existsSync(path.join(hooks, 'before_compile'))).toBe(true);
-            expect(fs.existsSync(path.join(hooks, 'after_platform_add'))).toBe(true);
-            expect(fs.existsSync(path.join(hooks, 'before_platform_rm'))).toBe(true);
-            expect(fs.existsSync(path.join(hooks, 'after_platform_rm'))).toBe(true);
-            expect(fs.existsSync(path.join(hooks, 'before_platform_ls'))).toBe(true);
-            expect(fs.existsSync(path.join(hooks, 'after_platform_ls'))).toBe(true);
-            expect(fs.existsSync(path.join(hooks, 'before_plugin_add'))).toBe(true);
-            expect(fs.existsSync(path.join(hooks, 'after_plugin_add'))).toBe(true);
-            expect(fs.existsSync(path.join(hooks, 'before_plugin_rm'))).toBe(true);
-            expect(fs.existsSync(path.join(hooks, 'after_plugin_rm'))).toBe(true);
-            expect(fs.existsSync(path.join(hooks, 'before_plugin_ls'))).toBe(true);
-            expect(fs.existsSync(path.join(hooks, 'after_plugin_ls'))).toBe(true);
-            expect(fs.existsSync(path.join(hooks, 'after_prepare'))).toBe(true);
-            expect(fs.existsSync(path.join(hooks, 'after_compile'))).toBe(true);
-            expect(fs.existsSync(path.join(hooks, 'before_build'))).toBe(true);
-            expect(fs.existsSync(path.join(hooks, 'after_build'))).toBe(true);
-            expect(fs.existsSync(path.join(hooks, 'before_emulate'))).toBe(true);
-            expect(fs.existsSync(path.join(hooks, 'after_emulate'))).toBe(true);
-            expect(fs.existsSync(path.join(hooks, 'before_docs'))).toBe(true);
-            expect(fs.existsSync(path.join(hooks, 'after_docs'))).toBe(true);
-            expect(fs.existsSync(path.join(hooks, 'before_run'))).toBe(true);
-            expect(fs.existsSync(path.join(hooks, 'after_run'))).toBe(true);
+    describe('failure', function() {
+        it('should return a help message if incorrect number of parameters is used', function() {
+            expect(cordova.create()).toMatch(/synopsis/gi);
         });
     });
-    it('should create a cordova project in the specified dir with specified name if provided', function() {
-        cordova.create(tempDir, "balls");
-
-        expect(fs.lstatSync(path.join(tempDir, '.cordova', 'config.json')).isFile()).toBe(true);
-
-        expect(fs.readFileSync(util.projectConfig(tempDir)).toString('utf8')).toMatch(/<name>balls<\/name>/);
-    });
-    it('should create a cordova project in the specified dir with specified name and id if provided', function() {
-        cordova.create(tempDir, "birdy.nam.nam", "numnum");
-
-        expect(fs.lstatSync(path.join(tempDir, '.cordova', 'config.json')).isFile()).toBe(true);
 
-        var config = fs.readFileSync(util.projectConfig(tempDir)).toString('utf8');
-        expect(config).toMatch(/<name>numnum<\/name>/);
-        expect(config).toMatch(/id="birdy\.nam\.nam"/);
+    describe('success', function() {
+        it('should create a default project if only directory is specified', function(done) {
+            cordova.create(tempDir, function() {
+                expect(mkdir).toHaveBeenCalledWith('-p', path.join(tempDir, '.cordova'));
+                expect(package).toHaveBeenCalledWith('io.cordova.hellocordova');
+                expect(name).toHaveBeenCalledWith('HelloCordova');
+                done();
+            });
+        });
+        it('should create a default project if only directory and id is specified', function(done) {
+            cordova.create(tempDir, 'ca.filmaj.canucks', function() {
+                expect(mkdir).toHaveBeenCalledWith('-p', path.join(tempDir, '.cordova'));
+                expect(package).toHaveBeenCalledWith('ca.filmaj.canucks');
+                expect(name).toHaveBeenCalledWith('HelloCordova');
+                done();
+            });
+        });
+        it('should create a project in specified directory with specified name and id', function(done) {
+            cordova.create(tempDir, 'ca.filmaj.canucks', 'IHateTheBruins', function() {
+                expect(mkdir).toHaveBeenCalledWith('-p', path.join(tempDir, '.cordova'));
+                expect(package).toHaveBeenCalledWith('ca.filmaj.canucks');
+                expect(name).toHaveBeenCalledWith('IHateTheBruins');
+                done();
+            });
+        });
+        it('should create top-level directory structure appropriate for a cordova-cli project', function(done) {
+            cordova.create(tempDir, function() {
+                expect(mkdir).toHaveBeenCalledWith('-p', path.join(tempDir, 'platforms'));
+                expect(mkdir).toHaveBeenCalledWith('-p', path.join(tempDir, 'merges'));
+                expect(mkdir).toHaveBeenCalledWith('-p', path.join(tempDir, 'plugins'));
+                expect(mkdir).toHaveBeenCalledWith('-p', path.join(tempDir, 'www'));
+                done();
+            });
+        });
+        it('should create appropriate directories for hooks', function(done) {
+            var hooks_dir = path.join(tempDir, '.cordova', 'hooks');
+            cordova.create(tempDir, function() {
+                expect(mkdir).toHaveBeenCalledWith('-p', hooks_dir);
+                expect(mkdir).toHaveBeenCalledWith( (path.join(hooks_dir, 'after_build')));
+                expect(mkdir).toHaveBeenCalledWith( (path.join(hooks_dir, 'after_compile')));
+                expect(mkdir).toHaveBeenCalledWith( (path.join(hooks_dir, 'after_docs')));
+                expect(mkdir).toHaveBeenCalledWith( (path.join(hooks_dir, 'after_emulate')));
+                expect(mkdir).toHaveBeenCalledWith( (path.join(hooks_dir, 'after_platform_add')));
+                expect(mkdir).toHaveBeenCalledWith( (path.join(hooks_dir, 'after_platform_rm')));
+                expect(mkdir).toHaveBeenCalledWith( (path.join(hooks_dir, 'after_platform_ls')));
+                expect(mkdir).toHaveBeenCalledWith( (path.join(hooks_dir, 'after_plugin_add')));
+                expect(mkdir).toHaveBeenCalledWith( (path.join(hooks_dir, 'after_plugin_ls')));
+                expect(mkdir).toHaveBeenCalledWith( (path.join(hooks_dir, 'after_plugin_rm')));
+                expect(mkdir).toHaveBeenCalledWith( (path.join(hooks_dir, 'after_prepare')));
+                expect(mkdir).toHaveBeenCalledWith( (path.join(hooks_dir, 'after_run')));
+                expect(mkdir).toHaveBeenCalledWith( (path.join(hooks_dir, 'before_build')));
+                expect(mkdir).toHaveBeenCalledWith( (path.join(hooks_dir, 'before_compile')));
+                expect(mkdir).toHaveBeenCalledWith( (path.join(hooks_dir, 'before_docs')));
+                expect(mkdir).toHaveBeenCalledWith( (path.join(hooks_dir, 'before_emulate')));
+                expect(mkdir).toHaveBeenCalledWith( (path.join(hooks_dir, 'before_platform_add')));
+                expect(mkdir).toHaveBeenCalledWith( (path.join(hooks_dir, 'before_platform_rm')));
+                expect(mkdir).toHaveBeenCalledWith( (path.join(hooks_dir, 'before_platform_ls')));
+                expect(mkdir).toHaveBeenCalledWith( (path.join(hooks_dir, 'before_plugin_add')));
+                expect(mkdir).toHaveBeenCalledWith( (path.join(hooks_dir, 'before_plugin_ls')));
+                expect(mkdir).toHaveBeenCalledWith( (path.join(hooks_dir, 'before_plugin_rm')));
+                expect(mkdir).toHaveBeenCalledWith( (path.join(hooks_dir, 'before_prepare')));
+                expect(mkdir).toHaveBeenCalledWith( (path.join(hooks_dir, 'before_run')));
+                done();
+            });
+        });
+        it('should by default use cordova-app-hello-world as www assets', function(done) {
+            cordova.create(tempDir, function() {
+                expect(load_cordova).toHaveBeenCalledWith('www', jasmine.any(Function));
+                done();
+            });
+        });
+        it('should try to lazy load custom www location if specified', function(done) {
+            var fake_config = {
+                lib:{
+                    www:{
+                        id:'supercordova',
+                        uri:'/supacordoba',
+                        version:'1337'
+                    }
+                }
+            };
+            config_read.andReturn(fake_config);
+            cordova.create(tempDir, function() {
+                expect(load_custom).toHaveBeenCalledWith(fake_config.lib.www.uri, fake_config.lib.www.id, 'www', fake_config.lib.www.version, jasmine.any(Function));
+                done();
+            });
+        });
     });
-    */
 });

http://git-wip-us.apache.org/repos/asf/cordova-cli/blob/bd3cec50/spec/cordova-cli/helper.js
----------------------------------------------------------------------
diff --git a/spec/cordova-cli/helper.js b/spec/cordova-cli/helper.js
index 5929677..351e6e4 100644
--- a/spec/cordova-cli/helper.js
+++ b/spec/cordova-cli/helper.js
@@ -17,62 +17,3 @@
     under the License.
 */
 jasmine.DEFAULT_TIMEOUT_INTERVAL = 10000;
-var root = this;
-var unfakes = [];
-var fake = function(owner, thingToFake, newThing) {
-        var originalThing;
-            originalThing = owner[thingToFake];
-                owner[thingToFake] = newThing;
-                    return unfakes.push(function() {
-                              return owner[thingToFake] = originalThing;
-                                  });
-                      };
-var _ = function(obj) {
-    return {
-        each: function(iterator) {
-            var item, _i, _len, _results;
-            _results = [];
-            for (_i = 0, _len = obj.length; _i < _len; _i++) {
-            item = obj[_i];
-            _results.push(iterator(item));
-            }
-            return _results;
-        },
-        isFunction: function() {
-            return Object.prototype.toString.call(obj) === "[object Function]";
-        },
-        isString: function() {
-            return Object.prototype.toString.call(obj) === "[object String]";
-        }
-    };
-};
-
-root.spyOnConstructor = function(owner, classToFake, methodsToSpy) {
-var fakeClass, spies;
-if (methodsToSpy == null) {
-methodsToSpy = [];
-}
-if (_(methodsToSpy).isString()) {
-methodsToSpy = [methodsToSpy];
-}
-spies = {
-constructor: jasmine.createSpy("" + classToFake + "'s constructor")
-};
-fakeClass = (function() {
-
-function _Class() {
-spies.constructor.apply(this, arguments);
-}
-
-return _Class;
-
-})();
-_(methodsToSpy).each(function(methodName) {
-spies[methodName] = jasmine.createSpy("" + classToFake + "#" + methodName);
-return fakeClass.prototype[methodName] = function() {
-return spies[methodName].apply(this, arguments);
-};
-});
-fake(owner, classToFake, fakeClass);
-return spies;
-};

http://git-wip-us.apache.org/repos/asf/cordova-cli/blob/bd3cec50/src/create.js
----------------------------------------------------------------------
diff --git a/src/create.js b/src/create.js
index b7f2e5d..5625d77 100644
--- a/src/create.js
+++ b/src/create.js
@@ -20,7 +20,6 @@ var path          = require('path'),
     fs            = require('fs'),
     shell         = require('shelljs'),
     help          = require('./help'),
-    config_parser = require('./config_parser'),
     events        = require('./events'),
     config        = require('./config'),
     lazy_load     = require('./lazy_load'),
@@ -62,12 +61,14 @@ module.exports = function create (dir, id, name, callback) {
     events.emit('log', 'Creating a new cordova project with name "' + name + '" and id "' + id + '" at location "' + dir + '"');
 
     var dotCordova = path.join(dir, '.cordova');
+    var www_dir = path.join(dir, 'www');
 
     // Create basic project structure.
     shell.mkdir('-p', dotCordova);
     shell.mkdir('-p', path.join(dir, 'platforms'));
     shell.mkdir('-p', path.join(dir, 'merges'));
     shell.mkdir('-p', path.join(dir, 'plugins'));
+    shell.mkdir('-p', www_dir);
     var hooks = path.join(dotCordova, 'hooks');
     shell.mkdir('-p', hooks);
 
@@ -103,10 +104,8 @@ module.exports = function create (dir, id, name, callback) {
         name:name
     });
 
-    // Copy in base www template
     var config_json = config.read(dir);
-    // Check if www assets to use was overridden.
-    var www_dir = path.join(dir, 'www');
+
     var finalize = function(www_lib) {
         while (!fs.existsSync(path.join(www_lib, 'index.html'))) {
             www_lib = path.join(www_lib, 'www');
@@ -122,12 +121,13 @@ module.exports = function create (dir, id, name, callback) {
         shell.cp(template_config_xml, www_dir);
         // Write out id and name to config.xml
         var configPath = util.projectConfig(dir);
-        var config = new config_parser(configPath);
+        var config = new util.config_parser(configPath);
         config.packageName(id);
         config.name(name);
         if (callback) callback();
     };
 
+    // Check if www assets to use was overridden.
     if (config_json.lib && config_json.lib.www) {
         events.emit('log', 'Using custom www assets ('+config_json.lib.www.id+').');
         lazy_load.custom(config_json.lib.www.uri, config_json.lib.www.id, 'www', config_json.lib.www.version, function(err) {

http://git-wip-us.apache.org/repos/asf/cordova-cli/blob/bd3cec50/src/help.js
----------------------------------------------------------------------
diff --git a/src/help.js b/src/help.js
index 0fa1c03..abd0f3e 100644
--- a/src/help.js
+++ b/src/help.js
@@ -1,4 +1,3 @@
-
 /**
     Licensed to the Apache Software Foundation (ASF) under one
     or more contributor license agreements.  See the NOTICE file

http://git-wip-us.apache.org/repos/asf/cordova-cli/blob/bd3cec50/src/util.js
----------------------------------------------------------------------
diff --git a/src/util.js b/src/util.js
index cd36377..6749c8f 100644
--- a/src/util.js
+++ b/src/util.js
@@ -16,9 +16,10 @@
     specific language governing permissions and limitations
     under the License.
 */
-var fs         = require('fs'),
-    path       = require('path'),
-    shell      = require('shelljs');
+var fs            = require('fs'),
+    path          = require('path'),
+    config_parser = require('./config_parser'),
+    shell         = require('shelljs');
 
 // Global configuration paths
 var HOME = process.env[(process.platform == 'win32') ? 'USERPROFILE' : 'HOME'];
@@ -52,6 +53,7 @@ module.exports = {
             }
         } else return false;
     },
+    config_parser:config_parser,
     // Recursively deletes .svn folders from a target path
     deleteSvnFolders:function(dir) {
         var contents = fs.readdirSync(dir);