You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by gt...@apache.org on 2013/03/22 23:49:51 UTC

[06/14] git commit: added merges tests

added merges tests

- added tests for merges to buid.spec to watch for the update_overrides
method to be called.

- added tests to individual parses to ensure that the copys process
correctly

- added merges directory to bootstape for use in fixtures


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

Branch: refs/heads/next
Commit: 51f1cc353f1b5b45a4f5bd0767420f8aa98a3275
Parents: 293ec62
Author: michael.wolf <mi...@MWolf-MBP.local>
Authored: Sun Feb 17 18:42:08 2013 -0500
Committer: Fil Maj <ma...@gmail.com>
Committed: Mon Mar 4 10:47:31 2013 -0800

----------------------------------------------------------------------
 bootstrap.js                            |    5 +-
 spec/build.spec.js                      |   62 +++++++++++-
 spec/metadata/android_parser.spec.js    |   41 +++++++
 spec/metadata/blackberry_parser.spec.js |   41 +++++++
 spec/metadata/ios_parser.spec.js        |  150 ++++++++++++++++----------
 5 files changed, 242 insertions(+), 57 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-cli/blob/51f1cc35/bootstrap.js
----------------------------------------------------------------------
diff --git a/bootstrap.js b/bootstrap.js
index 7152a6b..e45a5f9 100644
--- a/bootstrap.js
+++ b/bootstrap.js
@@ -90,7 +90,9 @@ platforms.forEach(function(platform) {
                     shell.rm('-rf', path.join(dub, 'spec'));
                     // copy over to full cordova project test fixture
                     shell.mkdir('-p', platformDir);
-                    shell.cp('-rf', path.join(fix_path, '*'), platformDir); 
+                    shell.cp('-rf', path.join(fix_path, '*'), platformDir);
+                    shell.mkdir('-p',path.join(cordovaDir,'merges',platform));
+
                     // set permissions on executables
                     var scripts_path = path.join(fix_path, 'cordova');
                     var other_path = path.join(platformDir, 'cordova');
@@ -108,3 +110,4 @@ platforms.forEach(function(platform) {
         }
     });
 });
+

http://git-wip-us.apache.org/repos/asf/cordova-cli/blob/51f1cc35/spec/build.spec.js
----------------------------------------------------------------------
diff --git a/spec/build.spec.js b/spec/build.spec.js
index 2427a0b..9eeffb5 100644
--- a/spec/build.spec.js
+++ b/spec/build.spec.js
@@ -29,7 +29,12 @@ var cordova = require('../cordova'),
     fixtures = path.join(__dirname, 'fixtures'),
     hooks = path.join(fixtures, 'hooks'),
     tempDir = path.join(__dirname, '..', 'temp'),
-    cordova_project = path.join(fixtures, 'projects', 'cordova');
+    cordova_project = path.join(fixtures, 'projects', 'cordova'),
+    ios_project_path = path.join(cordova_project, 'platforms', 'ios'),
+    blackberry_project_path = path.join(cordova_project, 'platforms', 'blackberry'),
+    www_config = path.join(cordova_project, 'www', 'config.xml');
+
+
 
 var cwd = process.cwd();
 
@@ -135,5 +140,60 @@ describe('build command', function() {
                 expect(s).not.toHaveBeenCalledWith('after_build');
             });
         });
+
+    });
+
+    describe('merges', function() {
+        describe('per platform', function() {
+            beforeEach(function() {
+                process.chdir(cordova_project);
+            });
+
+            afterEach(function() {
+                process.chdir(cwd);
+            });
+
+            describe('Android', function() {
+                it('should call android_parser\'s update_overrides', function() {
+                    spyOn(require('shelljs'), 'exec').andReturn({code:0});
+                    var s = spyOn(android_parser.prototype, 'update_overrides');
+
+                    cordova.build('android');
+                    expect(s).toHaveBeenCalled();
+                });
+
+            });
+
+            describe('iOS', function() {
+                it('should call ios_parser\'s update_overrides', function(done) {
+                    var parser = new ios_parser(ios_project_path);
+                    var config = new config_parser(www_config);
+
+                    var s = spyOn(parser, 'update_overrides');
+                    parser.update_project(config, function() {
+                        expect(s).toHaveBeenCalled();
+                        done();
+                    });
+                });
+
+            });
+
+            describe('BlackBerry', function() {
+                it('should call blackberry_parser\'s update_overrides', function(done) {
+                    var parser = new blackberry_parser(blackberry_project_path);
+                    var config = new config_parser(www_config);
+
+                    var s = spyOn(parser, 'update_overrides');
+                    parser.update_project(config, function() {
+                        expect(s).toHaveBeenCalled();
+                        done();
+                    });
+                });
+
+            });
+
+
+        });
     });
+
 });

http://git-wip-us.apache.org/repos/asf/cordova-cli/blob/51f1cc35/spec/metadata/android_parser.spec.js
----------------------------------------------------------------------
diff --git a/spec/metadata/android_parser.spec.js b/spec/metadata/android_parser.spec.js
index 5429dec..0f965e7 100644
--- a/spec/metadata/android_parser.spec.js
+++ b/spec/metadata/android_parser.spec.js
@@ -177,6 +177,47 @@ describe('android project parser', function() {
             });
         });
 
+        describe('update_overrides method',function() {
+
+            it('should copy a new file from merges into www', function() {
+
+                var newFile = path.join(project_path, 'merges','android', 'merge.js');
+
+                this.after(function() {
+                    shell.rm('-rf', path.join(project_path, 'merges','android','merge.js'));
+                });
+
+                fs.writeFileSync(newFile, 'alert("sup");', 'utf-8');
+                parser.update_overrides();
+                expect(fs.existsSync(path.join(android_project_path, 'assets', 'www', 'merge.js'))).toBe(true);
+            });
+
+            it('should copy a file from merges over a file in www', function() {
+
+                var newFile = path.join(project_path, 'merges','android', 'merge.js');
+                var newFileWWW = path.join(project_path, 'www','merge.js');
+
+                this.after(function() {
+                    shell.rm('-rf', path.join(project_path, 'merges','android','merge.js'));
+                    shell.rm('-rf',path.join(project_path,'www','merge.js'));
+                });
+
+                fs.writeFileSync(newFile, 'var foo=2;', 'utf-8');
+                fs.writeFileSync(newFileWWW, 'var foo=1;', 'utf-8');
+                parser.update_overrides();
+                expect(fs.existsSync(path.join(android_project_path, 'assets', 'www', 'merge.js'))).toBe(true);
+                console.log(fs.readFileSync(path.join(android_project_path, 'assets', 'www', 'merge.js')));
+                expect(fs.readFileSync(path.join(android_project_path, 'assets', 'www', 'merge.js'),'utf-8')).toEqual('var foo=2;');
+            });
+
+
+            it('should call out to util.deleteSvnFolders', function() {
+                var spy = spyOn(util, 'deleteSvnFolders');
+                parser.update_overrides();
+                expect(spy).toHaveBeenCalled();
+            });
+        });
+
         describe('update_project method', function() {
             it('should invoke update_www', function() {
                 var spyWww = spyOn(parser, 'update_www');

http://git-wip-us.apache.org/repos/asf/cordova-cli/blob/51f1cc35/spec/metadata/blackberry_parser.spec.js
----------------------------------------------------------------------
diff --git a/spec/metadata/blackberry_parser.spec.js b/spec/metadata/blackberry_parser.spec.js
index 17cb905..21eb826 100644
--- a/spec/metadata/blackberry_parser.spec.js
+++ b/spec/metadata/blackberry_parser.spec.js
@@ -145,6 +145,47 @@ describe('blackberry project parser', function() {
             });
         });
 
+        describe('update_overrides method',function() {
+
+            it('should copy a new file from merges into www', function() {
+
+                var newFile = path.join(project_path, 'merges','blackberry', 'merge.js');
+
+                this.after(function() {
+                    shell.rm('-rf', path.join(project_path, 'merges','blackberry','merge.js'));
+                });
+
+                fs.writeFileSync(newFile, 'alert("sup");', 'utf-8');
+                parser.update_overrides();
+                expect(fs.existsSync(path.join(blackberry_project_path, 'www', 'merge.js'))).toBe(true);
+            });
+
+            it('should copy a file from merges over a file in www', function() {
+
+                var newFile = path.join(project_path, 'merges','blackberry', 'merge.js');
+                var newFileWWW = path.join(project_path, 'www','merge.js');
+
+                this.after(function() {
+                    shell.rm('-rf', path.join(project_path, 'merges','blackberry','merge.js'));
+                    shell.rm('-rf',path.join(project_path,'www','merge.js'));
+                });
+
+                fs.writeFileSync(newFile, 'var foo=2;', 'utf-8');
+                fs.writeFileSync(newFileWWW, 'var foo=1;', 'utf-8');
+                parser.update_overrides();
+                expect(fs.existsSync(path.join(blackberry_project_path, 'www', 'merge.js'))).toBe(true);
+                expect(fs.readFileSync(path.join(blackberry_project_path, 'www', 'merge.js'),'utf-8')).toEqual('var foo=2;');
+            });
+
+
+            it('should call out to util.deleteSvnFolders', function() {
+                var spy = spyOn(util, 'deleteSvnFolders');
+                parser.update_overrides();
+                expect(spy).toHaveBeenCalled();
+            });
+        });
+
+
         describe('update_project method', function() {
             var cordova_config_path = path.join(project_path, '.cordova', 'config.json');
             var original_config_json = fs.readFileSync(cordova_config_path, 'utf-8');

http://git-wip-us.apache.org/repos/asf/cordova-cli/blob/51f1cc35/spec/metadata/ios_parser.spec.js
----------------------------------------------------------------------
diff --git a/spec/metadata/ios_parser.spec.js b/spec/metadata/ios_parser.spec.js
index b467fef..de62b1c 100644
--- a/spec/metadata/ios_parser.spec.js
+++ b/spec/metadata/ios_parser.spec.js
@@ -1,21 +1,21 @@
 /**
-    Licensed to the Apache Software Foundation (ASF) under one
-    or more contributor license agreements.  See the NOTICE file
-    distributed with this work for additional information
-    regarding copyright ownership.  The ASF licenses this file
-    to you under the Apache License, Version 2.0 (the
-    "License"); you may not use this file except in compliance
-    with the License.  You may obtain a copy of the License at
-
-    http://www.apache.org/licenses/LICENSE-2.0
-
-    Unless required by applicable law or agreed to in writing,
-    software distributed under the License is distributed on an
-    "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-    KIND, either express or implied.  See the License for the
-    specific language governing permissions and limitations
-    under the License.
-*/
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements.  See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership.  The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License.  You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied.  See the License for the
+ specific language governing permissions and limitations
+ under the License.
+ */
 
 var ios_parser = require('../../src/metadata/ios_parser'),
     config_parser = require('../../src/config_parser'),
@@ -26,28 +26,28 @@ var ios_parser = require('../../src/metadata/ios_parser'),
     fs = require('fs'),
     et = require('elementtree'),
     projects_path = path.join(__dirname, '..', 'fixtures', 'projects')
-    ios_path = path.join(projects_path, 'native', 'ios_fixture'),
+ios_path = path.join(projects_path, 'native', 'ios_fixture'),
     project_path = path.join(projects_path, 'cordova'),
     ios_project_path = path.join(project_path, 'platforms', 'ios');
 
 var www_config = path.join(project_path, 'www', 'config.xml');
 var original_www_config = fs.readFileSync(www_config, 'utf-8');
 
-describe('ios project parser', function() {
-    it('should throw an exception with a path that is not a native ios project', function() {
-        expect(function() {
+describe('ios project parser', function () {
+    it('should throw an exception with a path that is not a native ios project', function () {
+        expect(function () {
             var project = new ios_parser(process.cwd());
         }).toThrow();
     });
-    it('should accept a proper native ios project path as construction parameter', function() {
+    it('should accept a proper native ios project path as construction parameter', function () {
         var project;
-        expect(function() {
+        expect(function () {
             project = new ios_parser(ios_path);
         }).not.toThrow();
         expect(project).toBeDefined();
     });
 
-    describe('update_from_config method', function() {
+    describe('update_from_config method', function () {
         var project, config;
 
         var ios_plist = path.join(ios_path, 'cordovaExample', 'cordovaExample-Info.plist'),
@@ -58,48 +58,48 @@ describe('ios project parser', function() {
         var original_plist = fs.readFileSync(ios_plist, 'utf-8');
         var original_ios_config = fs.readFileSync(ios_config_xml, 'utf-8');
 
-        beforeEach(function() {
+        beforeEach(function () {
             project = new ios_parser(ios_path);
             config = new config_parser(www_config);
         });
-        afterEach(function() {
+        afterEach(function () {
             fs.writeFileSync(ios_pbx, original_pbx, 'utf-8');
             fs.writeFileSync(ios_config_xml, original_ios_config, 'utf-8');
             fs.writeFileSync(ios_plist, original_plist, 'utf-8');
             fs.writeFileSync(www_config, original_www_config, 'utf-8');
         });
-        it('should throw an exception if a non config_parser object is passed into it', function() {
-            expect(function() {
+        it('should throw an exception if a non config_parser object is passed into it', function () {
+            expect(function () {
                 project.update_from_config({});
             }).toThrow();
         });
-        it('should update the application name properly', function(done) {
+        it('should update the application name properly', function (done) {
             config.name('bond. james bond.');
-            project.update_from_config(config, function() {
+            project.update_from_config(config, function () {
                 var pbx_contents = fs.readFileSync(ios_pbx, 'utf-8');
                 expect(pbx_contents.match(/PRODUCT_NAME\s*=\s*"bond. james bond."/)[0]).toBe('PRODUCT_NAME = "bond. james bond."');
                 done();
             });
         });
-        it('should update the application package name (bundle identifier) properly', function(done) {
+        it('should update the application package name (bundle identifier) properly', function (done) {
             config.packageName('ca.filmaj.dewd');
-            project.update_from_config(config, function() {
+            project.update_from_config(config, function () {
                 var plist_contents = fs.readFileSync(ios_plist, 'utf-8');
                 expect(plist_contents).toMatch(/<string>ca.filmaj.dewd/);
                 done();
             });
         });
-        it('should update the whitelist in the project config.xml', function(done) {
-            project.update_from_config(config, function() {
+        it('should update the whitelist in the project config.xml', function (done) {
+            project.update_from_config(config, function () {
                 var config_contents = fs.readFileSync(ios_config_xml, 'utf-8');
                 expect(config_contents).toMatch(/<access origin="\*" \/>/);
                 done();
             });
         });
-        describe('preferences', function() {
-            it('should not change default project preferences and copy over additional project preferences to platform-level config.xml', function(done) {
-                config.preference.add({name:'henrik',value:'sedin'});
-                project.update_from_config(config, function() {
+        describe('preferences', function () {
+            it('should not change default project preferences and copy over additional project preferences to platform-level config.xml', function (done) {
+                config.preference.add({name:'henrik', value:'sedin'});
+                project.update_from_config(config, function () {
                     var native_config = new et.ElementTree(et.XML(fs.readFileSync(ios_config_xml, 'utf-8')));
                     var ps = native_config.findall('preference');
                     expect(ps.length).toEqual(17);
@@ -110,9 +110,9 @@ describe('ios project parser', function() {
                     done();
                 });
             });
-            it('should override a default project preference if applicable', function(done) {
-                config.preference.add({name:'UIWebViewBounce',value:'false'});
-                project.update_from_config(config, function() {
+            it('should override a default project preference if applicable', function (done) {
+                config.preference.add({name:'UIWebViewBounce', value:'false'});
+                project.update_from_config(config, function () {
                     var native_config = new et.ElementTree(et.XML(fs.readFileSync(ios_config_xml, 'utf-8')));
                     var ps = native_config.findall('preference');
                     expect(ps.length).toEqual(16);
@@ -124,7 +124,7 @@ describe('ios project parser', function() {
         });
     });
 
-    describe('cross-platform project level methods', function() {
+    describe('cross-platform project level methods', function () {
         var parser, config;
         var ios_plist = path.join(ios_project_path, 'cordovaExample', 'cordovaExample-Info.plist'),
             ios_pbx = path.join(ios_project_path, 'cordovaExample.xcodeproj', 'project.pbxproj'),
@@ -134,49 +134,89 @@ describe('ios project parser', function() {
         var original_plist = fs.readFileSync(ios_plist, 'utf-8');
         var original_ios_config = fs.readFileSync(ios_config_xml, 'utf-8');
 
-        beforeEach(function() {
+        beforeEach(function () {
             parser = new ios_parser(ios_project_path);
             config = new config_parser(www_config);
         });
-        afterEach(function() {
+        afterEach(function () {
             fs.writeFileSync(ios_pbx, original_pbx, 'utf-8');
             fs.writeFileSync(ios_config_xml, original_ios_config, 'utf-8');
             fs.writeFileSync(ios_plist, original_plist, 'utf-8');
             fs.writeFileSync(www_config, original_www_config, 'utf-8');
         });
 
-        describe('update_www method', function() {
-            it('should update all www assets', function() {
+        describe('update_www method', function () {
+            it('should update all www assets', function () {
                 var newFile = path.join(project_path, 'www', 'somescript.js');
-                this.after(function() {
+                this.after(function () {
                     shell.rm('-f', newFile);
                 });
                 fs.writeFileSync(newFile, 'alert("sup");', 'utf-8');
                 parser.update_www();
                 expect(fs.existsSync(path.join(ios_project_path, 'www', 'somescript.js'))).toBe(true);
             });
-            it('should write out ios js to cordova.js', function() {
+            it('should write out ios js to cordova.js', function () {
                 parser.update_www();
-                expect(fs.readFileSync(path.join(ios_project_path, 'www', 'cordova.js'),'utf-8')).toBe(fs.readFileSync(path.join(util.libDirectory, 'cordova-ios', 'CordovaLib', 'cordova.ios.js'), 'utf-8'));
+                expect(fs.readFileSync(path.join(ios_project_path, 'www', 'cordova.js'), 'utf-8')).toBe(fs.readFileSync(path.join(util.libDirectory, 'cordova-ios', 'CordovaLib', 'cordova.ios.js'), 'utf-8'));
             });
-            it('should call out to util.deleteSvnFolders', function() {
+            it('should call out to util.deleteSvnFolders', function () {
                 var spy = spyOn(util, 'deleteSvnFolders');
                 parser.update_www();
                 expect(spy).toHaveBeenCalled();
             });
         });
 
-        describe('update_project method', function() {
-            it('should invoke update_www', function(done) {
+        describe('update_overrides method', function () {
+
+            it('should copy a new file from merges into www', function () {
+
+                var newFile = path.join(project_path, 'merges', 'ios', 'merge.js');
+
+                this.after(function () {
+                    shell.rm('-rf', path.join(project_path, 'merges','ios','merge.js'));
+                });
+
+                fs.writeFileSync(newFile, 'alert("sup");', 'utf-8');
+                parser.update_overrides();
+                expect(fs.existsSync(path.join(ios_project_path, 'www', 'merge.js'))).toBe(true);
+            });
+
+            it('should copy a file from merges over a file in www', function () {
+
+                var newFile = path.join(project_path, 'merges', 'ios', 'merge.js');
+                var newFileWWW = path.join(project_path, 'www', 'merge.js');
+
+                this.after(function () {
+                    shell.rm('-rf', path.join(project_path, 'merges','ios','merge.js'));
+                    shell.rm('-rf', path.join(project_path, 'www', 'merge.js'));
+                });
+
+                fs.writeFileSync(newFile, 'var foo=2;', 'utf-8');
+                fs.writeFileSync(newFileWWW, 'var foo=1;', 'utf-8');
+                parser.update_overrides();
+                expect(fs.existsSync(path.join(ios_project_path, 'www', 'merge.js'))).toBe(true);
+                expect(fs.readFileSync(path.join(ios_project_path, 'www', 'merge.js'), 'utf-8')).toEqual('var foo=2;');
+            });
+
+            it('should call out to util.deleteSvnFolders', function() {
+                var spy = spyOn(util, 'deleteSvnFolders');
+                parser.update_overrides();
+                expect(spy).toHaveBeenCalled();
+            });
+
+        });
+
+        describe('update_project method', function () {
+            it('should invoke update_www', function (done) {
                 var spyWww = spyOn(parser, 'update_www');
-                parser.update_project(config, function() {
+                parser.update_project(config, function () {
                     expect(spyWww).toHaveBeenCalled();
                     done();
                 });
             });
-            it('should invoke update_from_config', function(done) {
+            it('should invoke update_from_config', function (done) {
                 var spyConfig = spyOn(parser, 'update_from_config').andCallThrough();
-                parser.update_project(config, function() {
+                parser.update_project(config, function () {
                     expect(spyConfig).toHaveBeenCalled();
                     done();
                 });