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/01/31 23:03:46 UTC
[2/10] git commit: speeding up parser specs. refactoring a bit for
tighter/clearner/faster tests.
speeding up parser specs. refactoring a bit for tighter/clearner/faster 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/47c4528b
Tree: http://git-wip-us.apache.org/repos/asf/cordova-cli/tree/47c4528b
Diff: http://git-wip-us.apache.org/repos/asf/cordova-cli/diff/47c4528b
Branch: refs/heads/master
Commit: 47c4528bd0619fb16ab29ab4cae9c9fed99d4fa7
Parents: 5ef109b
Author: Fil Maj <ma...@gmail.com>
Authored: Wed Jan 30 12:20:49 2013 -0800
Committer: Fil Maj <ma...@gmail.com>
Committed: Wed Jan 30 12:20:49 2013 -0800
----------------------------------------------------------------------
spec/config_parser.spec.js | 5 +-
spec/metadata/ios_parser.spec.js | 224 ++++++++++++---------------------
src/metadata/ios_parser.js | 4 +-
3 files changed, 83 insertions(+), 150 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cordova-cli/blob/47c4528b/spec/config_parser.spec.js
----------------------------------------------------------------------
diff --git a/spec/config_parser.spec.js b/spec/config_parser.spec.js
index 0963ed5..99bc717 100644
--- a/spec/config_parser.spec.js
+++ b/spec/config_parser.spec.js
@@ -26,12 +26,11 @@ var cordova = require('../cordova'),
et = require('elementtree'),
xml = path.join(tempDir, 'www', 'config.xml');
+
describe('config.xml parser', function () {
beforeEach(function() {
- cordova.create(tempDir);
- });
- afterEach(function() {
shell.rm('-rf', tempDir);
+ cordova.create(tempDir);
});
it('should create an instance based on an xml file', function() {
http://git-wip-us.apache.org/repos/asf/cordova-cli/blob/47c4528b/spec/metadata/ios_parser.spec.js
----------------------------------------------------------------------
diff --git a/spec/metadata/ios_parser.spec.js b/spec/metadata/ios_parser.spec.js
index ff08a27..0a1e252 100644
--- a/spec/metadata/ios_parser.spec.js
+++ b/spec/metadata/ios_parser.spec.js
@@ -1,4 +1,3 @@
-
/**
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
@@ -17,6 +16,7 @@
specific language governing permissions and limitations
under the License.
*/
+
var ios_parser = require('../../src/metadata/ios_parser'),
config_parser = require('../../src/config_parser'),
cordova = require('../../cordova'),
@@ -25,24 +25,19 @@ var ios_parser = require('../../src/metadata/ios_parser'),
shell = require('shelljs'),
fs = require('fs'),
et = require('elementtree'),
- cfg_path = path.join(__dirname, '..', 'fixtures', 'projects', 'test', 'www', 'config.xml'),
- ios_path = path.join(__dirname, '..', 'fixtures', 'projects', 'native', 'ios_fixture'),
tempDir = path.join(__dirname, '..', '..', 'temp'),
- ios_plist = path.join(ios_path, 'cordovaExample', 'cordovaExample-Info.plist'),
- ios_pbx = path.join(ios_path, 'cordovaExample.xcodeproj', 'project.pbxproj'),
- ios_config_xml = path.join(ios_path, 'cordovaExample', 'config.xml');
-
-var cwd = process.cwd();
+ projects_path = path.join(__dirname, '..', 'fixtures', 'projects')
+ 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 original_pbx = fs.readFileSync(ios_pbx, 'utf-8');
-var original_plist = fs.readFileSync(ios_plist, 'utf-8');
-var original_config = fs.readFileSync(cfg_path, 'utf-8');
-var orig_cordova = fs.readFileSync(ios_config_xml, 'utf-8');
+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() {
- var project = new ios_parser(cwd);
+ var project = new ios_parser(process.cwd());
}).toThrow();
});
it('should accept a proper native ios project path as construction parameter', function() {
@@ -56,192 +51,131 @@ describe('ios project parser', function() {
describe('update_from_config method', function() {
var project, config;
+ var ios_plist = path.join(ios_path, 'cordovaExample', 'cordovaExample-Info.plist'),
+ ios_pbx = path.join(ios_path, 'cordovaExample.xcodeproj', 'project.pbxproj'),
+ ios_config_xml = path.join(ios_path, 'cordovaExample', 'config.xml');
+
+ var original_pbx = fs.readFileSync(ios_pbx, 'utf-8');
+ var original_plist = fs.readFileSync(ios_plist, 'utf-8');
+ var original_ios_config = fs.readFileSync(ios_config_xml, 'utf-8');
+
beforeEach(function() {
project = new ios_parser(ios_path);
- config = new config_parser(cfg_path);
+ config = new config_parser(www_config);
});
afterEach(function() {
fs.writeFileSync(ios_pbx, original_pbx, 'utf-8');
- fs.writeFileSync(ios_config_xml, orig_cordova, 'utf-8');
+ fs.writeFileSync(ios_config_xml, original_ios_config, 'utf-8');
fs.writeFileSync(ios_plist, original_plist, 'utf-8');
- fs.writeFileSync(cfg_path, original_config, '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() {
project.update_from_config({});
}).toThrow();
});
- it('should update the application name properly', function() {
- var cb = jasmine.createSpy();
-
- runs(function() {
- config.name('bond. james bond.');
- project.update_from_config(config, cb);
- });
-
- waitsFor(function() { return cb.wasCalled; }, "update_from_config callback");
-
- runs(function() {
+ it('should update the application name properly', function(done) {
+ config.name('bond. james bond.');
+ 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() {
- var cb = jasmine.createSpy();
-
- runs(function() {
- config.packageName('ca.filmaj.dewd');
- project.update_from_config(config, cb);
- });
-
- waitsFor(function() { return cb.wasCalled; }, "update_from_config callback");
-
- runs(function() {
+ it('should update the application package name (bundle identifier) properly', function(done) {
+ config.packageName('ca.filmaj.dewd');
+ 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() {
- var cb = jasmine.createSpy();
-
- runs(function() {
- project.update_from_config(config, cb);
- });
-
- waitsFor(function() { return cb.wasCalled; }, "update_from_config callback");
-
- runs(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() {
- var cb = jasmine.createSpy();
-
- runs(function() {
- config.preference.add({name:'henrik',value:'sedin'});
- project.update_from_config(config, cb);
- });
-
- waitsFor(function() { return cb.wasCalled; }, "update_from_config callback");
-
- runs(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(13);
+ expect(ps.length).toEqual(17);
expect(ps[0].attrib.name).toEqual('KeyboardDisplayRequiresUserAction');
expect(ps[0].attrib.value).toEqual('true');
- expect(ps[12].attrib.name).toEqual('henrik');
- expect(ps[12].attrib.value).toEqual('sedin');
+ expect(ps[16].attrib.name).toEqual('henrik');
+ expect(ps[16].attrib.value).toEqual('sedin');
+ done();
});
});
- it('should override a default project preference if applicable', function() {
- var cb = jasmine.createSpy();
- runs(function() {
- config.preference.add({name:'UIWebViewBounce',value:'false'});
- project.update_from_config(config, cb);
- });
-
- waitsFor(function() { return cb.wasCalled; }, "update_from_config callback");
-
- runs(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(12);
+ expect(ps.length).toEqual(16);
expect(ps[2].attrib.name).toEqual('UIWebViewBounce');
expect(ps[2].attrib.value).toEqual('false');
+ done();
});
});
});
});
- describe('update_www method', function() {
- var parser, ios_platform = path.join(tempDir, 'platforms', 'ios');
+ 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'),
+ ios_config_xml = path.join(ios_project_path, 'cordovaExample', 'config.xml');
+
+ var original_pbx = fs.readFileSync(ios_pbx, 'utf-8');
+ var original_plist = fs.readFileSync(ios_plist, 'utf-8');
+ var original_ios_config = fs.readFileSync(ios_config_xml, 'utf-8');
beforeEach(function() {
- shell.rm('-rf', tempDir);
- cordova.create(tempDir);
- process.chdir(tempDir);
+ parser = new ios_parser(ios_project_path);
+ config = new config_parser(www_config);
});
afterEach(function() {
- process.chdir(cwd);
+ 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 update all www assets', function() {
- var cb = jasmine.createSpy();
- runs(function() {
- cordova.platform('add', 'ios', cb);
- });
- waitsFor(function() { return cb.wasCalled; }, 'platform add ios');
- runs(function() {
- parser = new ios_parser(ios_platform);
- var newFile = path.join(tempDir, 'www', 'somescript.js');
+ describe('update_www method', function() {
+ it('should update all www assets', function() {
+ var newFile = path.join(project_path, 'www', 'somescript.js');
+ this.after(function() {
+ shell.rm('-f', newFile);
+ });
fs.writeFileSync(newFile, 'alert("sup");', 'utf-8');
parser.update_www();
- expect(fs.existsSync(path.join(ios_platform, 'www', 'somescript.js'))).toBe(true);
- });
- });
- it('should write out ios js to cordova.js', function() {
- var cb = jasmine.createSpy();
- runs(function() {
- cordova.platform('add', 'ios', cb);
+ expect(fs.existsSync(path.join(ios_project_path, 'www', 'somescript.js'))).toBe(true);
});
- waitsFor(function() { return cb.wasCalled; }, 'platform add ios');
- runs(function() {
- parser = new ios_parser(ios_platform);
+ it('should write out ios js to cordova.js', function() {
parser.update_www();
- expect(fs.readFileSync(path.join(ios_platform, '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'));
});
});
- });
-
- describe('update_project method', function() {
- var parser, ios_platform, cfg;
- beforeEach(function() {
- shell.rm('-rf', tempDir);
- cordova.create(tempDir);
- process.chdir(tempDir);
- });
- afterEach(function() {
- process.chdir(cwd);
- });
- it('should invoke update_www', function() {
- var cb = jasmine.createSpy();
- var updatecb = jasmine.createSpy();
- var spyWww;
- runs(function() {
- cordova.platform('add', 'ios', cb);
- });
- waitsFor(function() { return cb.wasCalled; }, 'platform add ios');
- runs(function() {
- ios_platform = path.join(tempDir, 'platforms', 'ios');
- parser = new ios_parser(ios_platform);
- cfg = new config_parser(cfg_path);
- spyWww = spyOn(parser, 'update_www');
- parser.update_project(cfg, updatecb);
- });
- waitsFor(function() { return updatecb.wasCalled; }, 'update project callback');
- runs(function() {
- expect(spyWww).toHaveBeenCalled();
- });
- });
- it('should invoke update_from_config', function() {
- var cb = jasmine.createSpy();
- var updatecb = jasmine.createSpy();
- var spyConfig;
- ios_platform = path.join(tempDir, 'platforms', 'ios');
- runs(function() {
- cordova.platform('add', 'ios', cb);
+ describe('update_project method', function() {
+ it('should invoke update_www', function(done) {
+ var spyWww = spyOn(parser, 'update_www');
+ parser.update_project(config, function() {
+ expect(spyWww).toHaveBeenCalled();
+ done();
+ });
});
- waitsFor(function() { return cb.wasCalled; }, 'platform add ios');
- runs(function() {
- parser = new ios_parser(ios_platform);
- cfg = new config_parser(cfg_path);
- spyConfig = spyOn(parser, 'update_from_config');
- parser.update_project(cfg, updatecb);
- expect(spyConfig).toHaveBeenCalled();
+ it('should invoke update_from_config', function(done) {
+ var spyConfig = spyOn(parser, 'update_from_config').andCallThrough();
+ parser.update_project(config, function() {
+ expect(spyConfig).toHaveBeenCalled();
+ done();
+ });
});
});
});
http://git-wip-us.apache.org/repos/asf/cordova-cli/blob/47c4528b/src/metadata/ios_parser.js
----------------------------------------------------------------------
diff --git a/src/metadata/ios_parser.js b/src/metadata/ios_parser.js
index dda982a..e9e665a 100644
--- a/src/metadata/ios_parser.js
+++ b/src/metadata/ios_parser.js
@@ -138,7 +138,7 @@ module.exports.prototype = {
},
update_www:function() {
- var projectRoot = util.isCordova(process.cwd());
+ var projectRoot = util.isCordova(this.path);
var www = path.join(projectRoot, 'www');
var project_www = path.join(this.path, 'www');
@@ -149,7 +149,7 @@ module.exports.prototype = {
shell.cp('-rf', www, this.path);
// write out proper cordova.js
- shell.mv('-f', path.join(project_www, 'cordova-*.js'), path.join(project_www, 'cordova.js'));
+ shell.cp('-f', path.join(util.libDirectory, 'cordova-ios', 'CordovaLib', 'cordova.ios.js'), path.join(project_www, 'cordova.js'));
util.deleteSvnFolders(project_www);
},