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 19:16:12 UTC

[56/56] [abbrv] git commit: start of test refactor, lots of work left here still.

start of test refactor, lots of work left here still.


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

Branch: refs/heads/lazy
Commit: 74075fa1106af1b2bdfc6612c5f44ef8f7134913
Parents: 79d08a2
Author: Fil Maj <ma...@gmail.com>
Authored: Wed Jun 12 10:09:12 2013 -0700
Committer: Fil Maj <ma...@gmail.com>
Committed: Wed Jun 12 10:14:53 2013 -0700

----------------------------------------------------------------------
 package.json                    |  2 +-
 spec/cordova-cli/create.spec.js | 99 ++++++++++++++++++++++--------------
 spec/cordova-cli/helper.js      | 60 +++++++++++++++++++++-
 spec/cordova-cli/util.spec.js   | 29 ++---------
 src/create.js                   |  2 +-
 src/util.js                     |  7 ---
 test_runner.js                  | 43 ----------------
 7 files changed, 125 insertions(+), 117 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-cli/blob/74075fa1/package.json
----------------------------------------------------------------------
diff --git a/package.json b/package.json
index 5ed2492..1757a8a 100644
--- a/package.json
+++ b/package.json
@@ -11,7 +11,7 @@
     "cordova": "./bin/cordova"
   },
   "scripts": {
-    "test": "jasmine-node --color spec/cordova-cli"
+    "test": "jasmine-node --color spec"
   },
   "repository": {
     "type": "git",

http://git-wip-us.apache.org/repos/asf/cordova-cli/blob/74075fa1/spec/cordova-cli/create.spec.js
----------------------------------------------------------------------
diff --git a/spec/cordova-cli/create.spec.js b/spec/cordova-cli/create.spec.js
index 4dad502..3d5d0e0 100644
--- a/spec/cordova-cli/create.spec.js
+++ b/spec/cordova-cli/create.spec.js
@@ -3,54 +3,74 @@ var cordova = require('../../cordova'),
     shell   = require('shelljs'),
     fs      = require('fs'),
     util    = require('../../src/util'),
+    config    = require('../../src/config'),
+    lazy_load = require('../../src/lazy_load'),
     tempDir = path.join(__dirname, '..', '..', 'temp');
 
+config_parser    = require('../../src/config_parser');
+
 describe('create command', function () {
+    var mkdir, cp, config_spy, load_cordova, load_custom, exists, config_read, parser;
     beforeEach(function() {
         shell.rm('-rf', tempDir);
+        mkdir = spyOn(shell, 'mkdir');
+        cp = spyOn(shell, 'cp');
+        config_spy = spyOn(cordova, 'config');
+        config_read = spyOn(config, 'read').andReturn({});
+        exists = spyOn(fs, 'existsSync').andReturn(true);
+        load_cordova = spyOn(lazy_load, 'cordova').andCallFake(function(platform, cb) {
+            cb();
+        });
+        load_custom = spyOn(lazy_load, 'custom').andCallFake(function(url, id, platform, version, cb) {
+            cb();
+        });
+        parser = spyOnConstructor(global, 'config_parser', ['packageName', 'name']);
     });
 
-    it('should print out help txt if no directory is provided', function() {
-        expect(cordova.create()).toMatch(/synopsis/i);
+    it('should do something', function(done) {
+        cordova.create(tempDir, function() {
+            expect(true).toBe(true);
+            done();
+        });
     });
-    it('should create a cordova project in the specified directory if parameter is provided', function() {
-        cordova.create(tempDir);
-        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);
+
+    /*
+    it('should print out help txt if no parameters are provided', function() {
+        expect(cordova.create()).toMatch(/synopsis/i);
     });
-    it('should throw if the directory is already a cordova project', function() {
-        shell.mkdir('-p', path.join(tempDir, '.cordova'));
-        
-        expect(function() {
-            cordova.create(tempDir);
-        }).toThrow();
+    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);
+        });
     });
     it('should create a cordova project in the specified dir with specified name if provided', function() {
         cordova.create(tempDir, "balls");
@@ -68,4 +88,5 @@ describe('create command', function () {
         expect(config).toMatch(/<name>numnum<\/name>/);
         expect(config).toMatch(/id="birdy\.nam\.nam"/);
     });
+    */
 });

http://git-wip-us.apache.org/repos/asf/cordova-cli/blob/74075fa1/spec/cordova-cli/helper.js
----------------------------------------------------------------------
diff --git a/spec/cordova-cli/helper.js b/spec/cordova-cli/helper.js
index 2c4f331..5929677 100644
--- a/spec/cordova-cli/helper.js
+++ b/spec/cordova-cli/helper.js
@@ -1,4 +1,3 @@
-
 /**
     Licensed to the Apache Software Foundation (ASF) under one
     or more contributor license agreements.  See the NOTICE file
@@ -18,3 +17,62 @@
     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/74075fa1/spec/cordova-cli/util.spec.js
----------------------------------------------------------------------
diff --git a/spec/cordova-cli/util.spec.js b/spec/cordova-cli/util.spec.js
index 787b00f..a57d551 100644
--- a/spec/cordova-cli/util.spec.js
+++ b/spec/cordova-cli/util.spec.js
@@ -3,32 +3,11 @@ var cordova = require('../../cordova'),
     path = require('path'),
     fs = require('fs'),
     cordova_util = require('../../src/util'),
-    fixtures = path.join(__dirname, '..', 'fixtures'),
-    cordova_project = path.join(fixtures, 'projects', 'cordova');
-
+    fixtures = path.join(__dirname, '..', 'fixtures');
 
 var cwd = process.cwd();
 
-describe('util command', function() {
-    beforeEach(function() {
-        process.chdir(cordova_project);
-    });
-    afterEach(function() {
-        process.chdir(cwd);
-    });
-    describe('listPlatforms', function() {
-        it('should not treat a .gitignore file as a platform', function() {
-            var gitignore = path.join(cordova_project, 'platforms', '.gitignore');
-            fs.writeFileSync(gitignore, 'somethinghere', 'utf-8');
-            this.after(function() {
-                shell.rm('-f', gitignore);
-            });
-
-            var s = spyOn(shell, 'exec');
-            var platforms = cordova_util.listPlatforms(cordova_project);
-            platforms.forEach(function(platform) {
-                expect(platform).not.toMatch(/\.gitignore/);
-            }); 
-        });
+describe('util module', function() {
+    describe('isCordova method', function() {
     });
-});
\ No newline at end of file
+});

http://git-wip-us.apache.org/repos/asf/cordova-cli/blob/74075fa1/src/create.js
----------------------------------------------------------------------
diff --git a/src/create.js b/src/create.js
index 6665694..663fe9a 100644
--- a/src/create.js
+++ b/src/create.js
@@ -98,7 +98,7 @@ module.exports = function create (dir, id, name, callback) {
     shell.mkdir(path.join(hooks, 'before_run'));
 
     // Write out .cordova/config.json file with a simple json manifest
-    config(dir, {
+    require('../cordova').config(dir, {
         id:id,
         name:name
     });

http://git-wip-us.apache.org/repos/asf/cordova-cli/blob/74075fa1/src/util.js
----------------------------------------------------------------------
diff --git a/src/util.js b/src/util.js
index c689340..cd36377 100644
--- a/src/util.js
+++ b/src/util.js
@@ -28,17 +28,10 @@ shell.mkdir('-p', lib_path);
 // What tag of the cordova libs should be dl'ed
 var TAG = '2.8.0';
 
-function chmod(path) {
-    shell.exec('chmod +x "' + path + '"', {silent:true});
-}
-
 module.exports = {
     cordovaTag:TAG,
     globalConfig:global_config_path,
     libDirectory:lib_path,
-    has_platform_lib:function has_platform_lib(platform) {
-        return fs.existsSync(path.join(lib_path, platform, 'cordova', TAG, 'bin', 'create'));
-    },
     // Runs up the directory chain looking for a .cordova directory.
     // IF it is found we are in a Cordova project.
     // If not.. we're not. HOME directory doesnt count.

http://git-wip-us.apache.org/repos/asf/cordova-cli/blob/74075fa1/test_runner.js
----------------------------------------------------------------------
diff --git a/test_runner.js b/test_runner.js
deleted file mode 100644
index 5ad1f1c..0000000
--- a/test_runner.js
+++ /dev/null
@@ -1,43 +0,0 @@
-var platform = require('./src/platform'),
-    n = require('ncallbacks'),
-    path = require('path'),
-    shell = require('shelljs'),
-    platforms = require('./platforms');
-
-var specs = [];
-var supported = [];
-
-// stupid bs, jasmine-node cant accept multiple directories /facepalm
-process.chdir(__dirname);
-var tmp = 'spec_tmp';
-shell.rm('-rf', tmp);
-shell.mkdir('-p', path.join(tmp, 'platform-script'));
-shell.cp('-r', path.join(__dirname, 'spec', 'fixtures'), tmp);
-
-var end = n(Object.keys(platforms).length, function() {
-    console.log('Testing core cli and the following platforms: ' + supported.join(', '));
-    var cmd = 'node ' + path.join('node_modules', 'jasmine-node', 'bin', 'jasmine-node') + ' --color ' + tmp;
-    specs.forEach(function(s) { 
-        var p = path.join(__dirname, s);
-        shell.cp('-r', p, path.join(tmp, 'platform-script'));
-    });
-    shell.cp('-r', path.join(__dirname, 'spec', 'cordova-cli'), tmp);
-    shell.exec(cmd, {async:true, silent:false}, function(code, output) {
-        if(code > 0) {
-            console.log(output);
-        }
-    });
-});
-/*
-TODO: figure out how the test runner should work w.r.t. platform parsers / platform-specific stuff
-console.log('Determining which platforms to run tests for...');
-Object.keys(platforms).forEach(function(p) {
-    platform.supports(p, function(e) {
-        if (e) {
-        } else {
-            specs.push('spec/platform-script/' + p);
-            supported.push(p);
-        }
-        end();
-    });
-});