Repository: cordova-lib
Updated Branches:
  refs/heads/master 7e91d03fa -> c33416b88


CB-10592 Don't quote platform specific args values

Also add tests to cover the argiments compatibility logic. This closes #386


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

Branch: refs/heads/master
Commit: c33416b88c34b652f3a7208870950f0617197f99
Parents: 7e91d03
Author: Vladimir Kotikov <[email protected]>
Authored: Thu Feb 11 15:28:03 2016 +0300
Committer: Vladimir Kotikov <[email protected]>
Committed: Mon Feb 15 14:37:59 2016 +0300

----------------------------------------------------------------------
 cordova-lib/spec-cordova/build.spec.js |   2 +-
 cordova-lib/spec-cordova/run.spec.js   |   4 +-
 cordova-lib/spec-cordova/util.spec.js  | 112 ++++++++++++++++++++++++++++
 cordova-lib/src/cordova/util.js        |   2 +-
 4 files changed, 116 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-lib/blob/c33416b8/cordova-lib/spec-cordova/build.spec.js
----------------------------------------------------------------------
diff --git a/cordova-lib/spec-cordova/build.spec.js 
b/cordova-lib/spec-cordova/build.spec.js
index b521156..f5f1b2b 100644
--- a/cordova-lib/spec-cordova/build.spec.js
+++ b/cordova-lib/spec-cordova/build.spec.js
@@ -87,7 +87,7 @@ describe('build command', function() {
 
             cordova.on('warn', warnSpy);
             cordova.raw.build({platforms:['android'], options:['--release', 
'--cdvBuildOpt=opt']}).then(function () {
-                var opts = {platforms: ['android'], options: 
jasmine.objectContaining({release: true, argv: ['--cdvBuildOpt="opt"']}), 
verbose: false};
+                var opts = {platforms: ['android'], options: 
jasmine.objectContaining({release: true, argv: ['--cdvBuildOpt=opt']}), 
verbose: false};
                 expect(prepare_spy).toHaveBeenCalledWith(opts);
                 expect(compile_spy).toHaveBeenCalledWith(opts);
                 cordova.off('warn', warnSpy);

http://git-wip-us.apache.org/repos/asf/cordova-lib/blob/c33416b8/cordova-lib/spec-cordova/run.spec.js
----------------------------------------------------------------------
diff --git a/cordova-lib/spec-cordova/run.spec.js 
b/cordova-lib/spec-cordova/run.spec.js
index bf260e9..13e6e13 100644
--- a/cordova-lib/spec-cordova/run.spec.js
+++ b/cordova-lib/spec-cordova/run.spec.js
@@ -92,8 +92,8 @@ describe('run command', function() {
             cordova.on('warn', warnSpy);
             cordova.raw.run({platforms: ['blackberry10'], 
options:['--password=1q1q']}).then(function() {
                 expect(prepare_spy).toHaveBeenCalledWith({ platforms: [ 
'blackberry10' ],
-                    options: 
jasmine.objectContaining({argv:['--password="1q1q"']}), verbose: false });
-                
expect(platformApi.run).toHaveBeenCalledWith(jasmine.objectContaining({argv:['--password="1q1q"']}));
+                    options: 
jasmine.objectContaining({argv:['--password=1q1q']}), verbose: false });
+                
expect(platformApi.run).toHaveBeenCalledWith(jasmine.objectContaining({argv:['--password=1q1q']}));
             }, function(err) {
                 expect(err).toBeUndefined();
             })

http://git-wip-us.apache.org/repos/asf/cordova-lib/blob/c33416b8/cordova-lib/spec-cordova/util.spec.js
----------------------------------------------------------------------
diff --git a/cordova-lib/spec-cordova/util.spec.js 
b/cordova-lib/spec-cordova/util.spec.js
index 1e234e6..8a678c8 100644
--- a/cordova-lib/spec-cordova/util.spec.js
+++ b/cordova-lib/spec-cordova/util.spec.js
@@ -23,6 +23,7 @@ var shell = require('shelljs'),
     path = require('path'),
     fs = require('fs'),
     util = require('../src/cordova/util'),
+    events = require('../cordova-lib').events,
     temp = path.join(__dirname, '..', 'temp');
 
 var cwd = process.cwd();
@@ -184,4 +185,115 @@ describe('util module', function() {
             expect(res.indexOf('CVS')).toEqual(-1);
         });
     });
+    describe('preprocessOptions method', function() {
+
+        var isCordova, listPlatforms;
+        var DEFAULT_OPTIONS = {
+            // 'android' is here because we create a spy
+            // for listPlatforms below that returns 'android'
+            platforms: ['android'],
+            verbose: false
+        };
+
+        beforeEach(function() {
+            isCordova = spyOn(util, 'isCordova').andReturn('/fake/path');
+            listPlatforms = spyOn(util, 
'listPlatforms').andReturn(['android']);
+        });
+
+        it('should throw if called outside of cordova project', function() {
+            isCordova.andReturn(false);
+            expect(function() { util.preProcessOptions(); }).toThrow();
+        });
+
+        it('should throw when no platforms added to project', function() {
+            listPlatforms.andReturn([]);
+            expect(function () { util.preProcessOptions(); }).toThrow();
+        });
+
+        it('should return default options when no arguments passed', 
function() {
+            
expect(util.preProcessOptions()).toEqual(jasmine.objectContaining(DEFAULT_OPTIONS));
+        });
+
+        it('should accept single string argument as platform name', function() 
{
+            
expect(util.preProcessOptions('ios')).toEqual(jasmine.objectContaining({platforms:
 ['ios']}));
+        });
+
+        it('should accept array of strings as platform names', function() {
+            expect(util.preProcessOptions(['ios', 
'windows'])).toEqual(jasmine.objectContaining({platforms: ['ios', 'windows']}));
+        });
+
+        it('should fall back to installed platform if input doesn\'t contain 
platforms list', function() {
+            expect(util.preProcessOptions({verbose: true}))
+                .toEqual(jasmine.objectContaining({platforms: ['android'], 
verbose: true}));
+        });
+
+        it('should pick buildConfig if no option is provided, but 
buildConfig.json exists', function() {
+            spyOn(fs, 'existsSync').andReturn(true);
+            // Using path.join below to normalize path separators
+            expect(util.preProcessOptions())
+                .toEqual(jasmine.objectContaining({options: {buildConfig: 
path.join('/fake/path/build.json')}}));
+        });
+
+        describe('ensurePlatformOptionsCompatible', function() {
+
+            var unknownOptions = ['--foo', '--appx=uap', 
'--gradleArg=--no-daemon'];
+            var validOptions = ['--debug', '--release', '--device', 
'--emulator', '--nobuild', '--list',
+                    '--buildConfig=/fake/path/build.json', '--target=foo', 
'--archs="x86 x64"'];
+
+            it('should return \'options\' unchanged if they are not an array', 
function() {
+                ['foo', true, {bar: true}].forEach(function (optionValue) {
+                    expect(util.preProcessOptions({options: optionValue}))
+                        .toEqual(jasmine.objectContaining({options: 
optionValue}));
+                });
+            });
+
+            it('should emit \'warn\' event if \'options\' is an Array', 
function() {
+                var warnSpy = jasmine.createSpy('warnSpy');
+                events.on('warn', warnSpy);
+                util.preProcessOptions({options: ['foo']});
+                expect(warnSpy).toHaveBeenCalled();
+                expect(warnSpy.calls[0].args[0]).toMatch('consider updating 
your cordova.raw.* method calls');
+                events.removeListener('warn', warnSpy);
+            });
+
+            it('should convert options Array into object with \'argv\' field', 
function() {
+                expect(util.preProcessOptions({options: []}))
+                    .toEqual(jasmine.objectContaining({options: {argv: []}}));
+            });
+
+            it('should convert known options (platform-agnostic) into 
resultant object\'s fields', function () {
+                var expectedResult = {
+                    'debug': true, 'release': true,
+                    'device': true, 'emulator': true,
+                    'nobuild': true, 'list': true,
+                    'buildConfig': '/fake/path/build.json',
+                    'target': 'foo',
+                    'archs': '\"x86 x64\"'
+                };
+
+                expect(util.preProcessOptions({options: validOptions}).options)
+                    .toEqual(jasmine.objectContaining(expectedResult));
+
+                validOptions.forEach(function (validOption) {
+                    expect(util.preProcessOptions({options: 
validOptions}).options.argv)
+                        .not.toContain(validOption);
+                });
+            });
+
+            it('should try to convert unknown options (platform-specific) into 
resultant object\'s fields', function () {
+                var expectedResult = {
+                    'foo': true, 'appx': 'uap', 'gradleArg': '--no-daemon'
+                };
+
+                expect(util.preProcessOptions({options: 
unknownOptions}).options)
+                    .toEqual(jasmine.objectContaining(expectedResult));
+            });
+
+            it('should copy unknown options (platform-specific) into resultant 
object\'s argv field', function () {
+                unknownOptions.forEach(function (validOption) {
+                    expect(util.preProcessOptions({options: 
unknownOptions}).options.argv).toContain(validOption);
+                });
+            });
+        });
+    });
 });

http://git-wip-us.apache.org/repos/asf/cordova-lib/blob/c33416b8/cordova-lib/src/cordova/util.js
----------------------------------------------------------------------
diff --git a/cordova-lib/src/cordova/util.js b/cordova-lib/src/cordova/util.js
index ed3a91c..2cba201 100644
--- a/cordova-lib/src/cordova/util.js
+++ b/cordova-lib/src/cordova/util.js
@@ -297,7 +297,7 @@ function ensurePlatformOptionsCompatible (platformOptions) {
     }).map(function (arg) {
         return opts[arg] === true ?
             '--' + arg :
-            '--' + arg + '="' + opts[arg].toString() + '"';
+            '--' + arg + '=' + opts[arg].toString();
     });
 
     return opts;


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to