incubator-callback-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From fil...@apache.org
Subject git commit: test updates. omg was shooting myself in the foot with jasmine helpers.argh!
Date Tue, 04 Sep 2012 22:40:42 GMT
Updated Branches:
  refs/heads/cordova-client 89c3c133b -> 382e89fa2


test updates. omg was shooting myself in the foot with jasmine helpers.argh!


Project: http://git-wip-us.apache.org/repos/asf/incubator-cordova-labs/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-cordova-labs/commit/382e89fa
Tree: http://git-wip-us.apache.org/repos/asf/incubator-cordova-labs/tree/382e89fa
Diff: http://git-wip-us.apache.org/repos/asf/incubator-cordova-labs/diff/382e89fa

Branch: refs/heads/cordova-client
Commit: 382e89fa261cc37faf809d4d5a13b3ebdc0f88a6
Parents: 89c3c13
Author: Fil Maj <maj.fil@gmail.com>
Authored: Tue Sep 4 15:40:34 2012 -0700
Committer: Fil Maj <maj.fil@gmail.com>
Committed: Tue Sep 4 15:40:34 2012 -0700

----------------------------------------------------------------------
 README.md             |    3 +-
 spec/build.spec.js    |   74 +++++++++++++++++++++++++++++++++++++++++++-
 spec/helper.js        |   28 +----------------
 spec/platform.spec.js |   35 +++++++++++++++++---
 src/build.js          |   18 ++++++----
 src/platform.js       |    9 ++---
 6 files changed, 120 insertions(+), 47 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-cordova-labs/blob/382e89fa/README.md
----------------------------------------------------------------------
diff --git a/README.md b/README.md
index fa3390c..5a01776 100644
--- a/README.md
+++ b/README.md
@@ -15,7 +15,8 @@ For every platform that Cordova supports and you want to use with
 cordova-client, you will need to install the SDK for that platform. See:
 
 - [iOS SDK](http://developer.apple.com)
-- [Android SDK](http://developer.android.com)
+- [Android SDK](http://developer.android.com) - **NOTE** MAKE SURE YOU
+  HAVE THE LATEST _EVERYTHING_ !!!!!
 
 cordova-client has been tested on Mas OS X _only_. Sorry.
 

http://git-wip-us.apache.org/repos/asf/incubator-cordova-labs/blob/382e89fa/spec/build.spec.js
----------------------------------------------------------------------
diff --git a/spec/build.spec.js b/spec/build.spec.js
index c6e20de..d41e29e 100644
--- a/spec/build.spec.js
+++ b/spec/build.spec.js
@@ -1,4 +1,76 @@
+var cordova = require('../cordova'),
+    wrench = require('wrench'),
+    mkdirp = wrench.mkdirSyncRecursive,
+    path = require('path'),
+    rmrf = wrench.rmdirSyncRecursive,
+    fs = require('fs'),
+    tempDir = path.join(__dirname, '..', 'temp');
+
 describe('build command', function() {
-    describe('(android builds)', function() {
+    beforeEach(function() {
+        // Make a temp directory
+        try { rmrf(tempDir); } catch(e) {}
+        mkdirp(tempDir);
     });
+
+    it('should not run inside a Cordova-based project with no added platforms', function()
{
+        var cwd = process.cwd();
+        this.after(function() {
+            process.chdir(cwd);
+        });
+
+        cordova.create(tempDir);
+        process.chdir(tempDir);
+        expect(function() {
+            cordova.build();
+        }).toThrow();
+    });
+    /*
+    it('should run inside a Cordova-based project with at least one added platform', function()
{
+        var cwd = process.cwd();
+        this.after(function() {
+            process.chdir(cwd);
+        });
+
+        var buildcb = jasmine.createSpy();
+        var cb = jasmine.createSpy().andCallFake(function() {
+            runs(function() {
+                expect(function() {
+                    console.log('running build');
+                    cordova.build(buildcb);
+                }).not.toThrow();
+            });
+            waitsFor(function() { return buildcb.wasCalled; });
+        });
+
+        runs(function() {
+            cordova.create(tempDir);
+            process.chdir(tempDir);
+            cordova.platform('add', 'android', cb);
+        });
+        waitsFor(function() { return cb.wasCalled; }, 'platform add android callback');
+    });
+    
+    it('should not run outside of a Cordova-based project', function() {
+        var cwd = process.cwd();
+        this.after(function() {
+            process.chdir(cwd);
+        });
+
+        process.chdir(tempDir);
+
+        expect(function() {
+            cordova.build();
+        }).toThrow();
+    });
+    it('should shell out to the debug command for each platform', function() {
+        // TODO how to test this?
+    });
+
+    describe('should interpolate config.xml', function() {
+        describe('into Android builds', function() {
+        });
+        describe('into iOS builds', function() {
+        });
+    }); */
 });

http://git-wip-us.apache.org/repos/asf/incubator-cordova-labs/blob/382e89fa/spec/helper.js
----------------------------------------------------------------------
diff --git a/spec/helper.js b/spec/helper.js
index 82170af..ce6a952 100644
--- a/spec/helper.js
+++ b/spec/helper.js
@@ -1,27 +1 @@
-// Override exec for certain commands, to speed execution of tests.
-var _exec = require('child_process').exec,
-    fs = require('fs'),
-    wrench = require('wrench'),
-    mkdirp = wrench.mkdirSyncRecursive,
-    cpr = wrench.copyDirSyncRecursive,
-    path = require('path'),
-    templates = path.join(__dirname, '..', 'templates'),
-    www = path.join(templates, 'www');
-
-require('child_process').exec = function(cmd, cb){
-    var create_android = new RegExp('android' + path.sep + 'bin' + path.sep + 'create');
-    if (create_android.test(cmd)) {
-        // It's a create-android-project call. Fake as much of an
-        // android project as possible.
-        var dir = cmd.substr(cmd.indexOf('"') + 1);
-        dir = dir.substr(0, dir.length -1);
-        var android = path.join(dir, 'platforms', 'android');
-        mkdirp(android);
-        var assets = path.join(android, 'assets', 'www');
-        mkdirp(assets);
-        cpr(www, assets);
-        cb();
-    } else {
-        _exec(cmd, cb);
-    }
-};
+jasmine.DEFAULT_TIMEOUT_INTERVAL = 10000;

http://git-wip-us.apache.org/repos/asf/incubator-cordova-labs/blob/382e89fa/spec/platform.spec.js
----------------------------------------------------------------------
diff --git a/spec/platform.spec.js b/spec/platform.spec.js
index 2e3f2eb..c055e7d 100644
--- a/spec/platform.spec.js
+++ b/spec/platform.spec.js
@@ -6,6 +6,8 @@ var cordova = require('../cordova'),
     fs = require('fs'),
     tempDir = path.join(__dirname, '..', 'temp');
 
+var cwd = process.cwd();
+
 describe('platform command', function() {
     beforeEach(function() {
         // Make a temp directory
@@ -14,7 +16,6 @@ describe('platform command', function() {
     });
 
     it('should run inside a Cordova-based project', function() {
-        var cwd = process.cwd();
         this.after(function() {
             process.chdir(cwd);
         });
@@ -28,7 +29,6 @@ describe('platform command', function() {
         }).not.toThrow();
     });
     it('should not run outside of a Cordova-based project', function() {
-        var cwd = process.cwd();
         this.after(function() {
             process.chdir(cwd);
         });
@@ -41,8 +41,6 @@ describe('platform command', function() {
     });
 
     describe('`ls`', function() {
-        var cwd = process.cwd();
-
         beforeEach(function() {
             cordova.create(tempDir);
         });
@@ -77,9 +75,34 @@ describe('platform command', function() {
         });
     });
 
-    describe('remove', function() {
-        var cwd = process.cwd();
+    describe('`add`', function() {
+        beforeEach(function() {
+            cordova.create(tempDir);
+        });
 
+        afterEach(function() {
+            process.chdir(cwd);
+        });
+
+        describe('android', function() {
+            it('should add a basic android project', function() {
+                var cb = jasmine.createSpy().andCallFake(function() {
+                    expect(fs.existsSync(path.join(tempDir, 'platforms', 'android', 'AndroidManifest.xml'))).toBe(true);
+                });
+
+                process.chdir(tempDir);
+                runs(function() {
+                    cordova.platform('add', 'android', cb);
+                });
+                waitsFor(function() { return cb.wasCalled; }, "platform add android callback");
+            });
+        });
+
+        describe('ios', function() {
+        });
+    });
+
+    describe('remove', function() {
         beforeEach(function() {
             cordova.create(tempDir);
         });

http://git-wip-us.apache.org/repos/asf/incubator-cordova-labs/blob/382e89fa/src/build.js
----------------------------------------------------------------------
diff --git a/src/build.js b/src/build.js
index 7873f2a..d2e0d88 100644
--- a/src/build.js
+++ b/src/build.js
@@ -10,20 +10,23 @@ var cordova_util  = require('./util'),
     et            = require('elementtree'),
     util          = require('util');
 
-module.exports = function build () {
+module.exports = function build (callback) {
     var projectRoot = cordova_util.isCordova(process.cwd());
 
     if (!projectRoot) {
         throw 'Current working directory is not a Cordova-based project.';
     }
 
+    var xml = path.join(projectRoot, 'www', 'config.xml');
+    var assets = path.join(projectRoot, 'www');
+    var cfg = new config_parser(xml);
+    var name = cfg.name();
+    var id = cfg.packageName();
+    var platforms = cfg.ls_platforms();
+
+    if (platforms.length === 0) throw 'No platforms added to this project. Please use `cordova
platform add <platform>`.';
+
     asyncblock(function(flow) {
-        var xml = path.join(projectRoot, 'www', 'config.xml');
-        var assets = path.join(projectRoot, 'www');
-        var cfg = new config_parser(xml);
-        var name = cfg.name();
-        var id = cfg.packageName();
-        var platforms = cfg.ls_platforms();
 
         // Iterate over each added platform 
         platforms.map(function(platform) {
@@ -67,6 +70,7 @@ module.exports = function build () {
             }));
             var buffers = flow.get('debug');
             if (buffers.err) throw 'An error occurred while building the ' + platform + '
project. ' + buffers.err;
+            if (callback) callback();
         });
     });
 };

http://git-wip-us.apache.org/repos/asf/incubator-cordova-labs/blob/382e89fa/src/platform.js
----------------------------------------------------------------------
diff --git a/src/platform.js b/src/platform.js
index f746ad0..9ad4503 100644
--- a/src/platform.js
+++ b/src/platform.js
@@ -13,7 +13,6 @@ var repos = {
     android:'https://git-wip-us.apache.org/repos/asf/incubator-cordova-android.git'
 };
 
-
 module.exports = function platform(command, target, callback) {
     var projectRoot = cordova_util.isCordova(process.cwd());
 
@@ -81,20 +80,20 @@ module.exports = function platform(command, target, callback) {
                     var bin = path.join(__dirname, '..', 'lib', target, 'bin', 'create');
                     var pkg = cfg.packageName().replace(/[^\w.]/g,'_');
                     var name = cfg.name().replace(/\W/g,'_');
-                    var command = util.format('%s "%s" "%s" "%s"', bin, output, pkg, name);
-                    exec(command, flow.set({
+                    var command = util.format('"%s" "%s" "%s" "%s"', bin, output, pkg, name);
+                    child = exec(command, flow.set({
                         key:'create',
                         firstArgIsError:false,
                         responseFormat:['err', 'stdout', 'stderr']
                     }));
-
                     var bfrs = flow.get('create');
                     if (bfrs.err) {
                         cfg.remove_platform(target);
                         throw ('An error occured during creation of ' + target + ' sub-project.
' + bfrs.err);
+                    } else {
+                        if (callback) callback();
                     }
                 }
-                if (callback) callback();
             });
             break;
         case 'remove':


Mime
View raw message