cordova-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From fil...@apache.org
Subject git commit: build specs.
Date Thu, 13 Jun 2013 05:28:14 GMT
Updated Branches:
  refs/heads/lazy faeef4f2d -> 4e3dc3210


build specs.


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

Branch: refs/heads/lazy
Commit: 4e3dc321073f53dd8e01c7216877402a8187c4d2
Parents: faeef4f
Author: Fil Maj <maj.fil@gmail.com>
Authored: Wed Jun 12 22:27:21 2013 -0700
Committer: Fil Maj <maj.fil@gmail.com>
Committed: Wed Jun 12 22:27:21 2013 -0700

----------------------------------------------------------------------
 spec/build.spec.js   | 87 +++++++++++++++--------------------------------
 spec/prepare.spec.js |  2 --
 src/build.js         |  2 --
 3 files changed, 28 insertions(+), 63 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-cli/blob/4e3dc321/spec/build.spec.js
----------------------------------------------------------------------
diff --git a/spec/build.spec.js b/spec/build.spec.js
index 7b30414..0a48293 100644
--- a/spec/build.spec.js
+++ b/spec/build.spec.js
@@ -16,59 +16,50 @@
     specific language governing permissions and limitations
     under the License.
 */
-var cordova = require('../../cordova'),
+var cordova = require('../cordova'),
+    platforms = require('../platforms'),
     shell = require('shelljs'),
     path = require('path'),
     fs = require('fs'),
-    events = require('../../src/events'),
-    hooker = require('../../src/hooker'),
-    tempDir = path.join(__dirname, '..', '..', 'temp');
+    hooker = require('../src/hooker'),
+    util = require('../src/util');
 
-var cwd = process.cwd();
+var supported_platforms = Object.keys(platforms).filter(function(p) { return p != 'www';
});
 
 describe('build command', function() {
+    var is_cordova, list_platforms, fire;
+    var project_dir = '/some/path';
+    var prepare_spy, compile_spy;
     beforeEach(function() {
-        shell.rm('-rf', tempDir);
-        shell.mkdir('-p', tempDir);
+        is_cordova = spyOn(util, 'isCordova').andReturn(project_dir);
+        list_platforms = spyOn(util, 'listPlatforms').andReturn(supported_platforms);
+        fire = spyOn(hooker.prototype, 'fire').andCallFake(function(e, opts, cb) {
+            cb(false);
+        });
+        prepare_spy = spyOn(cordova, 'prepare').andCallFake(function(platforms, cb) {
+            cb();
+        });
+        compile_spy = spyOn(cordova, 'compile').andCallFake(function(platforms, cb) {
+            cb();
+        });
     });
-
     describe('failure', function() {
-        afterEach(function() {
-            process.chdir(cwd);
-            spyOn(shell, 'exec');
-        });
-        it('should not run inside a Cordova-based project with no added platforms', function()
{
-            cordova.create(tempDir);
-            process.chdir(tempDir);
+        it('should not run inside a Cordova-based project with no added platforms by calling
util.listPlatforms', function() {
+            list_platforms.andReturn([]);
             expect(function() {
                 cordova.build();
-            }).toThrow();
+            }).toThrow('No platforms added! `cordova platform add <platform>` to add
a platform.');
         });
         it('should not run outside of a Cordova-based project', function() {
-            shell.mkdir('-p', tempDir);
-            process.chdir(tempDir);
+            is_cordova.andReturn(false);
             expect(function() {
                 cordova.build();
-            }).toThrow();
+            }).toThrow('Current working directory is not a Cordova-based project.');
         });
     });
 
     describe('success', function() {
-        beforeEach(function() {
-            cordova.create(tempDir);
-            process.chdir(tempDir);
-        });
-        afterEach(function() {
-            process.chdir(cwd);
-        });
         it('should run inside a Cordova-based project with at least one added platform and
call both prepare and compile', function(done) {
-            var prepare_spy = spyOn(cordova, 'prepare').andCallFake(function(platforms, cb)
{
-                cb();
-            });
-            var compile_spy = spyOn(cordova, 'compile').andCallFake(function(platforms, cb)
{
-                cb();
-            });
-
             cordova.build(['android','ios'], function(err) {
                 expect(prepare_spy).toHaveBeenCalledWith(['android', 'ios'], jasmine.any(Function));
                 expect(compile_spy).toHaveBeenCalledWith(['android', 'ios'], jasmine.any(Function));
@@ -78,37 +69,14 @@ describe('build command', function() {
     });
 
     describe('hooks', function() {
-        var hook_spy;
-        var prepare_spy;
-        var compile_spy;
-        beforeEach(function() {
-            hook_spy = spyOn(hooker.prototype, 'fire').andCallFake(function(hook, opts, cb)
{
-                cb();
-            });
-            prepare_spy = spyOn(cordova, 'prepare').andCallFake(function(platforms, cb) {
-                cb(); 
-            });
-            compile_spy = spyOn(cordova, 'compile').andCallFake(function(platforms, cb) {
-                cb(); 
-            });
-            cordova.create(tempDir);
-            process.chdir(tempDir);
-        });
-        afterEach(function() {
-            hook_spy.reset();
-            prepare_spy.reset();
-            compile_spy.reset();
-            process.chdir(cwd);
-        });
-
         describe('when platforms are added', function() {
             it('should fire before hooks through the hooker module', function() {
                 cordova.build(['android', 'ios']);
-                expect(hook_spy).toHaveBeenCalledWith('before_build', {platforms:['android',
'ios']}, jasmine.any(Function));
+                expect(fire).toHaveBeenCalledWith('before_build', {platforms:['android',
'ios']}, jasmine.any(Function));
             });
             it('should fire after hooks through the hooker module', function(done) {
                 cordova.build('android', function() {
-                     expect(hook_spy).toHaveBeenCalledWith('after_build', {platforms:['android']},
jasmine.any(Function));
+                     expect(fire).toHaveBeenCalledWith('after_build', {platforms:['android']},
jasmine.any(Function));
                      done();
                 });
             });
@@ -116,10 +84,11 @@ describe('build command', function() {
 
         describe('with no platforms added', function() {
             it('should not fire the hooker', function() {
+                list_platforms.andReturn([]);
                 expect(function() {
                     cordova.build();
                 }).toThrow();
-                expect(hook_spy).not.toHaveBeenCalled();
+                expect(fire).not.toHaveBeenCalled();
             });
         });
     });

http://git-wip-us.apache.org/repos/asf/cordova-cli/blob/4e3dc321/spec/prepare.spec.js
----------------------------------------------------------------------
diff --git a/spec/prepare.spec.js b/spec/prepare.spec.js
index bc49246..671213c 100644
--- a/spec/prepare.spec.js
+++ b/spec/prepare.spec.js
@@ -27,8 +27,6 @@ var cordova = require('../cordova'),
     fixtures = path.join(__dirname, 'fixtures'),
     hooks = path.join(fixtures, 'hooks');
 
-var cwd = process.cwd();
-
 var supported_platforms = Object.keys(platforms).filter(function(p) { return p != 'www';
});
 
 describe('prepare command', function() {

http://git-wip-us.apache.org/repos/asf/cordova-cli/blob/4e3dc321/src/build.js
----------------------------------------------------------------------
diff --git a/src/build.js b/src/build.js
index adc6749..28874bb 100644
--- a/src/build.js
+++ b/src/build.js
@@ -18,10 +18,8 @@
 */
 var util              = require('./util'),
     path              = require('path'),
-    config_parser     = require('./config_parser'),
     fs                = require('fs'),
     shell             = require('shelljs'),
-    et                = require('elementtree'),
     hooker            = require('./hooker'),
     events            = require('./events'),
     n                 = require('ncallbacks');


Mime
View raw message