cordova-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From fil...@apache.org
Subject [10/10] git commit: sped up emulate tests
Date Thu, 31 Jan 2013 22:03:45 GMT
Updated Branches:
  refs/heads/master ff34f5dbf -> 8296edaca


sped up emulate tests


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

Branch: refs/heads/master
Commit: 8296edacade0e4f77f9cb5234ff6e3a84d90cc8a
Parents: 2cfdf55
Author: Fil Maj <maj.fil@gmail.com>
Authored: Thu Jan 31 14:05:23 2013 -0800
Committer: Fil Maj <maj.fil@gmail.com>
Committed: Thu Jan 31 14:05:23 2013 -0800

----------------------------------------------------------------------
 bootstrap.js         |   26 ++---
 spec/emulate.spec.js |  244 ++++++++++++---------------------------------
 src/emulate.js       |   31 +++---
 3 files changed, 90 insertions(+), 211 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-cli/blob/8296edac/bootstrap.js
----------------------------------------------------------------------
diff --git a/bootstrap.js b/bootstrap.js
index c4f403b..4df2089 100644
--- a/bootstrap.js
+++ b/bootstrap.js
@@ -67,24 +67,20 @@ platforms.forEach(function(platform) {
                     console.error('ERROR! Could not create a native ' + platform + ' project
test fixture. See below for error output.');
                     console.error(output);
                 } else {
-                    // set permissions on executables
-                    switch (platform) {
-                        case 'android':
-                            break;
-                        case 'ios':
-                            var scripts_path = path.join(fix_path, 'cordova');
-                            var scripts = fs.readdirSync(scripts_path);
-                            scripts.forEach(function(script) {
-                                var script_path = path.join(scripts_path, script);
-                                shell.chmod('+x', script_path);
-                            });
-                            break;
-                        case 'blackberry':
-                            break;
-                    };
+                    // copy over to full cordova project test fixture
                     var platformDir = path.join(platformsDir, platform);
                     shell.mkdir('-p', platformDir);
                     shell.cp('-rf', path.join(fix_path, '*'), platformDir); 
+                    // set permissions on executables
+                    var scripts_path = path.join(fix_path, 'cordova');
+                    var other_path = path.join(platformDir, 'cordova');
+                    var scripts = fs.readdirSync(scripts_path);
+                    scripts.forEach(function(script) {
+                        var script_path = path.join(scripts_path, script);
+                        var other_script_path = path.join(other_path, script);
+                        shell.chmod('+x', script_path);
+                        shell.chmod('+x', other_script_path);
+                    });
                     console.log('SUCCESS: ' + platform + ' ready to rock!');
                 }
             });

http://git-wip-us.apache.org/repos/asf/cordova-cli/blob/8296edac/spec/emulate.spec.js
----------------------------------------------------------------------
diff --git a/spec/emulate.spec.js b/spec/emulate.spec.js
index a936e1e..ac6d115 100644
--- a/spec/emulate.spec.js
+++ b/spec/emulate.spec.js
@@ -26,13 +26,15 @@ var cordova = require('../cordova'),
     ios_parser = require('../src/metadata/ios_parser'),
     blackberry_parser = require('../src/metadata/blackberry_parser'),
     hooker = require('../src/hooker'),
-    tempDir = path.join(__dirname, '..', 'temp');
+    fixtures = path.join(__dirname, 'fixtures'),
+    hooks = path.join(fixtures, 'hooks'),
+    tempDir = path.join(__dirname, '..', 'temp'),
+    cordova_project = path.join(fixtures, 'projects', 'cordova');
 
 var cwd = process.cwd();
 
-xdescribe('emulate command', function() {
+describe('emulate command', function() {
     beforeEach(function() {
-        // Make a temp directory
         shell.rm('-rf', tempDir);
         shell.mkdir('-p', tempDir);
     });
@@ -50,237 +52,109 @@ xdescribe('emulate command', function() {
     });
     
     it('should run inside a Cordova-based project with at least one added platform', function()
{
+        shell.mv('-f', path.join(cordova_project, 'platforms', 'blackberry'), path.join(tempDir));
+        shell.mv('-f', path.join(cordova_project, 'platforms', 'ios'), path.join(tempDir));
         this.after(function() {
             process.chdir(cwd);
+            shell.mv('-f', path.join(tempDir, 'blackberry'), path.join(cordova_project, 'platforms',
'blackberry'));
+            shell.mv('-f', path.join(tempDir, 'ios'), path.join(cordova_project, 'platforms',
'ios'));
         });
 
-        var cb = jasmine.createSpy();
-        var cbem = jasmine.createSpy();
-        var s;
+        process.chdir(cordova_project);
 
-        runs(function() {
-            cordova.create(tempDir);
-            process.chdir(tempDir);
-            cordova.platform('add', 'ios', cb);
-        });
-        waitsFor(function() { return cb.wasCalled; }, 'platform add ios');
-
-        runs(function() {
-            s = spyOn(shell, 'exec').andReturn({code:0});
-            expect(function() {
-                cordova.emulate(cbem);
-            }).not.toThrow();
-        });
-        waitsFor(function() { return cbem.wasCalled; }, 'ios emulate');
-
-        runs(function() {
+        var s = spyOn(shell, 'exec');
+        spyOn(android_parser.prototype, 'update_project');
+        expect(function() {
+            cordova.emulate();
             expect(s).toHaveBeenCalled();
-        });
+        }).not.toThrow();
     });
-    
     it('should not run outside of a Cordova-based project', function() {
         this.after(function() {
             process.chdir(cwd);
         });
 
+        shell.mkdir('-p', tempDir);
         process.chdir(tempDir);
 
         expect(function() {
             cordova.emulate();
         }).toThrow();
     });
-    
     describe('per platform', function() {
         beforeEach(function() {
-            cordova.create(tempDir);
-            process.chdir(tempDir);
+            process.chdir(cordova_project);
         });
 
         afterEach(function() {
             process.chdir(cwd);
         });
-        
+       
         describe('Android', function() {
+            var s;
             beforeEach(function() {
-                cordova.platform('add', 'android');
+                s = spyOn(require('shelljs'), 'exec');
             });
-
             it('should shell out to run command on Android', function() {
-                var s = spyOn(require('shelljs'), 'exec').andReturn({code:0});
-                cordova.emulate();
-                expect(s.mostRecentCall.args[0].match(/android\/cordova\/run/)).not.toBeNull();
+                cordova.emulate('android');
+                expect(s.mostRecentCall.args[0].match(/\/cordova\/run/)).not.toBeNull();
             });
             it('should call android_parser\'s update_project', function() {
-                spyOn(require('shelljs'), 'exec').andReturn({code:0});
-                var s = spyOn(android_parser.prototype, 'update_project');
-                cordova.emulate();
-                expect(s).toHaveBeenCalled();
+                var spy = spyOn(android_parser.prototype, 'update_project');
+                cordova.emulate('android');
+                expect(spy).toHaveBeenCalled();
             });
         });
         describe('iOS', function() {
             it('should shell out to emulate command on iOS', function() {
-                var cb = jasmine.createSpy();
-                var buildcb = jasmine.createSpy();
-                var s;
-
-                runs(function() {
-                    cordova.platform('add', 'ios', cb);
-                });
-                waitsFor(function() { return cb.wasCalled; }, 'platform add ios callback');
-                runs(function() {
-                    s = spyOn(require('shelljs'), 'exec').andReturn({code:0});
-                    cordova.emulate(buildcb);
-                });
-                waitsFor(function() { return buildcb.wasCalled; }, 'emulate ios');
-                runs(function() {
-                    expect(s).toHaveBeenCalled();
-                    expect(s.mostRecentCall.args[0].match(/ios\/cordova\/emulate/)).not.toBeNull();
-                });
+                var s = spyOn(require('shelljs'), 'exec');
+                var proj_spy = spyOn(ios_parser.prototype, 'update_project');
+                cordova.emulate('ios');
+                proj_spy.mostRecentCall.args[1]();
+                expect(s).toHaveBeenCalled();
+                expect(s.mostRecentCall.args[0].match(/\/cordova\/emulate/)).not.toBeNull();
             });
             it('should call ios_parser\'s update_project', function() {
-                var cb = jasmine.createSpy();
-                var buildcb = jasmine.createSpy();
-                var s;
-
-                runs(function() {
-                    cordova.platform('add', 'ios', cb);
-                });
-                waitsFor(function() { return cb.wasCalled; }, 'platform add ios callback');
-                runs(function() {
-                    s = spyOn(ios_parser.prototype, 'update_project');
-                    cordova.emulate(buildcb);
-                    expect(s).toHaveBeenCalled();
-                });
+                var s = spyOn(ios_parser.prototype, 'update_project');
+                cordova.emulate('ios');
+                expect(s).toHaveBeenCalled();
             });
         });
         describe('BlackBerry', function() {
             it('should shell out to ant command on blackberry', function() {
-                var buildcb = jasmine.createSpy();
-                var cb = jasmine.createSpy();
-                var s, t = spyOn(require('prompt'), 'get').andReturn(true);
-
-                runs(function() {
-                    cordova.platform('add', 'blackberry', cb);
-                    // Fake prompt invoking its callback
-                    t.mostRecentCall.args[1](null, {});
-                });
-                waitsFor(function() { return cb.wasCalled; }, 'platform add blackberry');
-                runs(function() {
-                    s = spyOn(require('shelljs'), 'exec').andReturn({code:0});
-                    cordova.emulate(buildcb);
-                });
-                waitsFor(function() { return buildcb.wasCalled; }, 'build call', 20000);
-                runs(function() {
-                    expect(s).toHaveBeenCalled();
-                    expect(s.mostRecentCall.args[0].match(/ant -f .*build\.xml qnx load-simulator/)).not.toBeNull();
-                });
+                var proj_spy = spyOn(blackberry_parser.prototype, 'update_project');
+                var s = spyOn(require('shelljs'), 'exec');
+                cordova.emulate('blackberry');
+                proj_spy.mostRecentCall.args[1](); // update_project fake
+                expect(s).toHaveBeenCalled();
+                expect(s.mostRecentCall.args[0]).toMatch(/ant -f .*build\.xml" qnx load-simulator/);
             });
             it('should call blackberry_parser\'s update_project', function() {
-                var cb = jasmine.createSpy();
-                var buildcb = jasmine.createSpy();
-                var s;
-
-                runs(function() {
-                    var p = spyOn(require('prompt'), 'get');
-                    cordova.platform('add', 'blackberry', cb);
-                    p.mostRecentCall.args[1](null, {});
-                });
-                waitsFor(function() { return cb.wasCalled; }, 'platform add bb');
-                runs(function() {
-                    s = spyOn(blackberry_parser.prototype, 'update_project');
-                    cordova.emulate(buildcb);
-                    expect(s).toHaveBeenCalled();
-                });
-            });
-        });
-    });
-    describe('specifying platforms to emulate', function() {
-        beforeEach(function() {
-            cordova.create(tempDir);
-            process.chdir(tempDir);
-            cordova.platform('add', 'android');
-        });
-
-        afterEach(function() {
-            process.chdir(cwd);
-            shell.rm('-rf', tempDir);
-        });
-        it('should only emulate the specified platform (array notation)', function() {
-            var cb = jasmine.createSpy();
-            var buildcb = jasmine.createSpy();
-            var s;
-            runs(function() {
-                cordova.platform('add', 'ios', cb);
-            });
-            waitsFor(function() { return cb.wasCalled; }, 'platform add ios');
-            runs(function() {
-                s = spyOn(shell, 'exec').andReturn({code:0});
-                cordova.build(['android'], buildcb);
-            });
-            waitsFor(function() { return buildcb.wasCalled; }, 'emulate android');
-            runs(function() {
-                expect(s.callCount).toEqual(1);
-            });
-        });
-        it('should only emulate the specified platform (string notation)', function() {
-            var cb = jasmine.createSpy();
-            var buildcb = jasmine.createSpy();
-            var s;
-            runs(function() {
-                cordova.platform('add', 'ios', cb);
-            });
-            waitsFor(function() { return cb.wasCalled; }, 'platform add ios');
-            runs(function() {
-                s = spyOn(shell, 'exec').andReturn({code:0});
-                cordova.build('android', buildcb);
-            });
-            waitsFor(function() { return buildcb.wasCalled; }, 'emulate android');
-            runs(function() {
-                expect(s.callCount).toEqual(1);
-            });
-        });
-        it('should handle multiple platforms to be emulated', function() {
-            var cb = jasmine.createSpy();
-            var bbcb = jasmine.createSpy();
-            var buildcb = jasmine.createSpy();
-            var s;
-            runs(function() {
-                cordova.platform('add', 'ios', cb);
-            });
-            waitsFor(function() { return cb.wasCalled; }, 'platform add ios');
-            runs(function() {
-                var g = spyOn(require('prompt'), 'get');
-                cordova.platform('add', 'blackberry', bbcb);
-                g.mostRecentCall.args[1](null, {}); // fake out prompt io
-            });
-            waitsFor(function() { return bbcb.wasCalled; }, 'platform add bb');
-            runs(function() {
-                s = spyOn(shell, 'exec').andReturn({code:0});
-                cordova.build(['android','ios'], buildcb);
-            });
-            waitsFor(function() { return buildcb.wasCalled; }, 'emulate android+ios');
-            runs(function() {
-                expect(s.callCount).toEqual(2);
+                var s = spyOn(blackberry_parser.prototype, 'update_project');
+                cordova.emulate('blackberry');
+                expect(s).toHaveBeenCalled();
             });
         });
     });
 
     describe('hooks', function() {
-        var s;
+        var s, sh, ap;
         beforeEach(function() {
-            cordova.create(tempDir);
-            process.chdir(tempDir);
             s = spyOn(hooker.prototype, 'fire').andReturn(true);
         });
-        afterEach(function() {
-            process.chdir(cwd);
-            shell.rm('-rf', tempDir);
-        });
 
         describe('when platforms are added', function() {
             beforeEach(function() {
-                cordova.platform('add', 'android');
-                spyOn(shell, 'exec').andReturn({code:0});
+                shell.mv('-f', path.join(cordova_project, 'platforms', 'blackberry'), path.join(tempDir));
+                shell.mv('-f', path.join(cordova_project, 'platforms', 'ios'), path.join(tempDir));
+                sh = spyOn(shell, 'exec');
+                ap = spyOn(android_parser.prototype, 'update_project');
+                process.chdir(cordova_project);
+            });
+            afterEach(function() {
+                shell.mv('-f', path.join(tempDir, 'blackberry'), path.join(cordova_project,
'platforms', 'blackberry'));
+                shell.mv('-f', path.join(tempDir, 'ios'), path.join(cordova_project, 'platforms',
'ios'));
+                process.chdir(cwd);
             });
 
             it('should fire before hooks through the hooker module', function() {
@@ -289,13 +163,21 @@ xdescribe('emulate command', function() {
             });
             it('should fire after hooks through the hooker module', function() {
                 cordova.emulate();
+                sh.mostRecentCall.args[2](0); //fake shell call
                 expect(s).toHaveBeenCalledWith('after_emulate');
             });
         });
 
         describe('with no platforms added', function() {
+            beforeEach(function() {
+                cordova.create(tempDir);
+                process.chdir(tempDir);
+            });
+            afterEach(function() {
+                process.chdir(cwd);
+            });
             it('should not fire the hooker', function() {
-                spyOn(shell, 'exec').andReturn({code:0});
+                spyOn(shell, 'exec');
                 expect(function() {
                     cordova.emulate();
                 }).toThrow();

http://git-wip-us.apache.org/repos/asf/cordova-cli/blob/8296edac/src/emulate.js
----------------------------------------------------------------------
diff --git a/src/emulate.js b/src/emulate.js
index 3e8f08c..39cbb22 100644
--- a/src/emulate.js
+++ b/src/emulate.js
@@ -1,4 +1,3 @@
-
 /**
     Licensed to the Apache Software Foundation (ASF) under one
     or more contributor license agreements.  See the NOTICE file
@@ -31,16 +30,21 @@ var cordova_util = require('./util'),
     hooker = require('../src/hooker'),
     util = require('util');
 
-function shell_out_to_emulate(root, platform) {
+function shell_out_to_emulate(root, platform, callback) {
     var cmd = path.join(root, 'platforms', platform, 'cordova', 'emulate');
     // TODO: PLATFORM LIBRARY INCONSISTENCY 
     if (platform == 'blackberry') {
-        cmd = 'ant -f ' + path.join(root, 'platforms', platform, 'build.xml') + ' qnx load-simulator';
+        cmd = 'ant -f "' + path.join(root, 'platforms', platform, 'build.xml') + '" qnx load-simulator';
     } else if (platform.indexOf('android') > -1) {
         cmd = path.join(root, 'platforms', platform, 'cordova', 'run');
     }
-    var em = shell.exec(cmd, {silent:true});
-    if (em.code > 0) throw 'An error occurred while emulating/deploying the ' + platform
+ ' project.' + em.output;
+    shell.exec(cmd, {silent:true, async:true}, function(code, output) {
+        if (code > 0) {
+            throw new Error('An error occurred while emulating/deploying the ' + platform
+ ' project.' + output);
+        } else {
+            callback();
+        }
+    });
 }
 
 module.exports = function emulate (platforms, callback) {
@@ -55,22 +59,22 @@ module.exports = function emulate (platforms, callback) {
 
     if (arguments.length === 0 || (platforms instanceof Array && platforms.length
=== 0)) {
         platforms = ls(path.join(projectRoot, 'platforms'));
-    } else if (platforms instanceof String) platforms = [platforms];
+    } else if (typeof platforms == 'string') platforms = [platforms];
     else if (platforms instanceof Function && callback === undefined) {
         callback = platforms;
         platforms = ls(path.join(projectRoot, 'platforms'));
     }
 
-    if (platforms.length === 0) throw 'No platforms added to this project. Please use `cordova
platform add <platform>`.';
+    if (platforms.length === 0) throw new Error('No platforms added to this project. Please
use `cordova platform add <platform>`.');
 
     var hooks = new hooker(projectRoot);
     if (!(hooks.fire('before_emulate'))) {
-        throw 'before_emulate hooks exited with non-zero code. Aborting build.';
+        throw new Error('before_emulate hooks exited with non-zero code. Aborting build.');
     }
 
     var end = n(platforms.length, function() {
         if (!(hooks.fire('after_emulate'))) {
-            throw 'after_emulate hooks exited with non-zero code. Aborting.';
+            throw new Error('after_emulate hooks exited with non-zero code. Aborting.');
         }
         if (callback) callback();
     });
@@ -85,8 +89,7 @@ module.exports = function emulate (platforms, callback) {
 
                 // Update the related platform project from the config
                 parser.update_project(cfg);
-                shell_out_to_emulate(projectRoot, 'android');
-                end();
+                shell_out_to_emulate(projectRoot, 'android', end);
                 break;
             case 'blackberry':
                 platformPath = path.join(projectRoot, 'platforms', 'blackberry');
@@ -95,8 +98,7 @@ module.exports = function emulate (platforms, callback) {
                 // Update the related platform project from the config
                 parser.update_project(cfg, function() {
                     // Shell it
-                    shell_out_to_emulate(projectRoot, 'blackberry');
-                    end();
+                    shell_out_to_emulate(projectRoot, 'blackberry', end);
                 });
                 break;
             case 'ios':
@@ -104,8 +106,7 @@ module.exports = function emulate (platforms, callback) {
                 parser = new ios_parser(platformPath);
                 // Update the related platform project from the config
                 parser.update_project(cfg, function() {
-                    shell_out_to_emulate(projectRoot, 'ios');
-                    end();
+                    shell_out_to_emulate(projectRoot, 'ios', end);
                 });
                 break;
         }


Mime
View raw message