cordova-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From fil...@apache.org
Subject [12/14] cordova-lib git commit: pending tests for plugin specs. small refactor tweaks, mostly TODOs being dropped. remove old platform-add tests. fixes for jshint.
Date Thu, 22 Jun 2017 17:34:43 GMT
pending tests for plugin specs. small refactor tweaks, mostly TODOs
being dropped. remove old platform-add tests. fixes for jshint.


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

Branch: refs/heads/master
Commit: 2daef359c7a6e7f644d30ec688d7259f4371f731
Parents: e314d07
Author: filmaj <maj.fil@gmail.com>
Authored: Tue Jun 20 18:36:47 2017 -0500
Committer: filmaj <maj.fil@gmail.com>
Committed: Wed Jun 21 14:58:29 2017 -0500

----------------------------------------------------------------------
 spec-cordova/platform/addHelper.spec.js | 466 ---------------------------
 spec-cordova/platform/index.spec.js     |   2 +
 spec-cordova/plugin/add.spec.js         |  78 +++++
 spec-cordova/plugin/search.spec.js      |  28 ++
 spec-cordova/plugin/util.spec.js        |  31 ++
 src/cordova/platform/addHelper.js       |   3 +-
 src/cordova/plugin/add.js               |  15 +-
 src/cordova/plugin/index.js             |   2 +-
 8 files changed, 151 insertions(+), 474 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-lib/blob/2daef359/spec-cordova/platform/addHelper.spec.js
----------------------------------------------------------------------
diff --git a/spec-cordova/platform/addHelper.spec.js b/spec-cordova/platform/addHelper.spec.js
index 0617fb0..8218d91 100644
--- a/spec-cordova/platform/addHelper.spec.js
+++ b/spec-cordova/platform/addHelper.spec.js
@@ -16,15 +16,6 @@
 */
 /* eslint-env jasmine */
 
-var path = require('path');
-var fs = require('fs');
-var shell = require('shelljs');
-var rewire = require('rewire');
-var platform_addHelper = rewire('../../src/cordova/platform/addHelper');
-var cordova_util = require('../../src/cordova/util');
-
-var config_xml_path = 'spec-cordova/fixtures/config.xml';
-
 describe('cordova/platform/addHelper', function () {
     describe('error/warning conditions', function () {
         it('should require specifying at least one platform');
@@ -55,461 +46,4 @@ describe('cordova/platform/addHelper', function () {
          * - fire after_platform_add/update hook
          */
     });
-    /*
-    var projectRoot = path.join('some', 'path'),
-        windowsPath = path.join(projectRoot,'cordova-windows'),
-        configParserRevert,
-        fetchRevert,
-        downloadPlatformRevert,
-        pkgJson = {},
-        configEngines = [],
-        fetchArgs = [];
-
-    // Mock HooksRunner
-    var hooksRunnerMock = {
-        fire: function () {
-            return Q();
-        }
-    };
-
-    // Mock Platform Api
-    function PlatformApiMock() {}
-    PlatformApiMock.createPlatform = function() {
-        return Q();
-    };
-    PlatformApiMock.updatePlatform = function() {
-        return Q();
-    };
-
-    // Mock cordova-fetch
-    var fetchMock = function(target) {
-        fetchArgs.push(target);
-        //return the basename of either the target, url or local path 
-        return Q(path.basename(target));
-    };
-
-    // Mock ConfigParser
-    function ConfigParserMock() {}
-    ConfigParserMock.prototype = {
-        write: function() {
-            //do nothing
-        },
-        addEngine: function(plat, spec) {
-            //add engine to configEngines
-            configEngines.push({'name': plat, 'spec': spec});
-        },
-        removeEngine: function(plat) {
-            //delete engine from configEngines
-            configEngines.forEach(function(item, index) {
-                if(item.name === plat){
-                    delete configEngines[index]; 
-                }
-            });
-        },
-        getEngines: function() {
-            return configEngines;
-        }
-    };
-
-    function getPlatformDetailsFromDirMock(dir, platform) {
-        var ver;
-        var parts = dir.split('@');
-        //attempt to derive version from dir/target
-        //eg dir = android@~6.1.1 || atari@1.0.0
-        if(parts.length > 1) {
-            ver = parts[1] || parts[0];
-            //remove ~ or ^ since the real function version wouldn't have that
-            if(ver[0] === '~' || ver[0] === '^') {
-                ver = ver.slice(1);
-            }
-        }
-        // not a perfect representation of the real function, but good for testing
-		return Q({
-            'libDir':'Api.js',
-            'platform':platform || path.basename(dir),
-            'version':ver || 'n/a'
-        });
-    }
-
-    beforeEach(function () {
-        spyOn(cordova_util, 'projectConfig').and.returnValue(config_xml_path);
-        spyOn(shell, 'mkdir').and.returnValue(true);
-
-        configParserRevert = platform_addHelper.__set__('ConfigParser', ConfigParserMock);
-        fetchRevert = platform_addHelper.__set__('fetch', fetchMock);
-        spyOn(platform, 'getPlatformDetailsFromDir').and.callFake(getPlatformDetailsFromDirMock);
-        spyOn(prepare, 'preparePlatforms').and.returnValue(Q());
-        spyOn(cordova, 'prepare').and.returnValue(Q());
-        spyOn(platformMetadata, 'save').and.returnValue(true);
-        spyOn(cordova_util, 'getPlatformApiFunction').and.returnValue(PlatformApiMock);
-        // writes to package.json
-        spyOn(fs, 'writeFileSync').and.callFake(function (dest, pkgJ) {
-            pkgJson = JSON.parse(pkgJ);
-            return true;
-        });
-
-        // return true for windows local path target
-        spyOn(cordova_util, 'isDirectory').and.callFake(function (filePath) {
-            if (filePath.indexOf(windowsPath) !== -1) {
-                return true;
-            } else {
-                return false;
-            }
-        });
-
-        spyOn(lazy_load, 'git_clone').and.callFake(function (git_url, branch) {
-            return Q(path.basename(git_url));
-        });
-        spyOn(lazy_load, 'based_on_config').and.callFake(function (projRoot, target) {
-            return Q(target);
-        });
-    });
-
-    afterEach(function () {
-        configParserRevert();
-        fetchRevert();
-        if (downloadPlatformRevert) {
-            downloadPlatformRevert();
-            downloadPlatformRevert = undefined;
-        }
-        pkgJson = {};
-        configEngines = [];
-        fetchArgs = [];
-    });
-    */
-
-    xdescribe('old add tests', function () {
-        it('should succeed with fetch, save and package.json. Tests npm package, gitURL,
local path and non core platforms with spec as targets', function(done) {
-            //spy for package.json to exist
-            spyOn(fs,'existsSync').and.callFake(function(filePath) {
-                if(path.basename(filePath) === 'package.json') {
-                    return true;
-                } else {
-                    return false;
-                }
-            });
-            
-            //require packge.json object
-            spyOn(cordova_util, 'requireNoCache').and.returnValue(pkgJson);
-            
-            platform.add(hooksRunnerMock, projectRoot, ['android', 'https://github.com/apache/cordova-ios',
windowsPath, 'atari@1.0.0'], {'fetch': true, 'save': true})
-            .then(function() {
-                expect(cordova_util.projectConfig.calls.count()).toEqual(1);
-                expect(shell.mkdir.calls.count()).toEqual(1);
-                expect(platform.getPlatformDetailsFromDir.calls.count()).toEqual(4);
-                expect(cordova_util.getPlatformApiFunction.calls.count()).toEqual(4);
-                expect(cordova.prepare.calls.count()).toEqual(4);
-                expect(prepare.preparePlatforms.calls.count()).toEqual(4);
-                expect(platformMetadata.save.calls.count()).toEqual(4);
-                expect(lazy_load.git_clone.calls.count()).toEqual(0);
-                expect(lazy_load.based_on_config.calls.count()).toEqual(0);
-                //expect correct arugments to be passed to cordova-fetch
-                expect(fetchArgs[0]).toEqual('cordova-android@'+pinnedAndroidVer);
-                expect(fetchArgs[1]).toEqual('https://github.com/apache/cordova-ios');
-                expect(fetchArgs[2]).toContain('cordova-windows');
-                expect(fetchArgs[3]).toEqual('atari@1.0.0'); 
-                //test pkgJson is being built correctly
-                expect(fs.writeFileSync.calls.count()).toEqual(1);
-                expect(pkgJson.cordova).toBeDefined();
-                expect(pkgJson.cordova.platforms).toEqual([ 'android', 'atari', 'cordova-ios',
'cordova-windows' ]);
-                expect(cordova_util.requireNoCache.calls.count()).toEqual(5);
-                //test cfg.engines code is being run with correct arugments
-                expect(configEngines.length).toEqual(4);
-                expect(configEngines).toEqual(
-                    [ { name: 'android', spec: pinnedAndroidVer },
-                    { name: 'cordova-ios',
-                    spec: 'https://github.com/apache/cordova-ios' },
-                    { name: 'cordova-windows',
-                    spec: windowsPath },
-                    { name: 'atari', spec: '~1.0.0' } ]);
-            }).fail(function(e) {
-                expect(e).toBeUndefined();
-            })
-            .fin(done);
-        });
-
-        it('should succeed with fetch, save and no package.json. Tests npm package, gitURL,
local path and non core platforms with spec as targets', function(done) {
-            //spy for package.json to not exist
-            spyOn(fs,'existsSync').and.returnValue(false);
-            
-            //require packge.json object
-            spyOn(cordova_util, 'requireNoCache');
-     
-            platform.add(hooksRunnerMock, projectRoot, ['android', 'https://github.com/apache/cordova-ios',
windowsPath, 'atari@1.0.0'], {'fetch': true, 'save': true})
-            .then(function() {
-                expect(cordova_util.projectConfig.calls.count()).toEqual(1);
-                expect(shell.mkdir.calls.count()).toEqual(1);
-                expect(platform.getPlatformDetailsFromDir.calls.count()).toEqual(4);
-                expect(cordova_util.getPlatformApiFunction.calls.count()).toEqual(4);
-                expect(cordova.prepare.calls.count()).toEqual(4);
-                expect(prepare.preparePlatforms.calls.count()).toEqual(4);
-                expect(platformMetadata.save.calls.count()).toEqual(4);
-                expect(lazy_load.git_clone.calls.count()).toEqual(0);
-                expect(lazy_load.based_on_config.calls.count()).toEqual(0);
-                //expect correct arugments to be passed to cordova-fetch
-                expect(fetchArgs[0]).toEqual('cordova-android@'+pinnedAndroidVer);
-                expect(fetchArgs[1]).toEqual('https://github.com/apache/cordova-ios');
-                expect(fetchArgs[2]).toContain('cordova-windows');
-                expect(fetchArgs[3]).toEqual('atari@1.0.0');
-                //test pkgJson releated commands aren't being called
-                expect(fs.writeFileSync.calls.count()).toEqual(0);
-                expect(pkgJson.cordova).toBeUndefined();
-                expect(cordova_util.requireNoCache.calls.count()).toEqual(0);
-                //test cfg.engines code is being run with correct arugments
-                expect(configEngines.length).toEqual(4);
-                expect(configEngines).toEqual(
-                    [ { name: 'android', spec: pinnedAndroidVer },
-                    { name: 'cordova-ios',
-                    spec: 'https://github.com/apache/cordova-ios' },
-                    { name: 'cordova-windows',
-                    spec: windowsPath },
-                    { name: 'atari', spec: '~1.0.0' } ]);
-            }).fail(function(e) {
-                expect(e).toBeUndefined();
-            })
-            .fin(done);
-        });
-
-        //no need to worry about packagae.json in this case
-        it('should succeed with fetch, no save. Tests npm package, gitURL, local path and
non core platforms with spec as targets', function(done) {
-            //spy for package.json to not exist
-            spyOn(fs,'existsSync').and.returnValue(false);
-     
-            platform.add(hooksRunnerMock, projectRoot, ['android', 'https://github.com/apache/cordova-ios',
windowsPath, 'atari@1.0.0'], {'fetch': true, 'save': false})
-            .then(function() {
-                expect(cordova_util.projectConfig.calls.count()).toEqual(1);
-                expect(shell.mkdir.calls.count()).toEqual(1);
-                expect(platform.getPlatformDetailsFromDir.calls.count()).toEqual(4);
-                expect(cordova_util.getPlatformApiFunction.calls.count()).toEqual(4);
-                expect(cordova.prepare.calls.count()).toEqual(4);
-                expect(prepare.preparePlatforms.calls.count()).toEqual(4);
-                expect(platformMetadata.save.calls.count()).toEqual(4);
-                expect(lazy_load.git_clone.calls.count()).toEqual(0);
-                expect(lazy_load.based_on_config.calls.count()).toEqual(0);
-                //expect correct arugments to be passed to cordova-fetch
-                expect(fetchArgs[0]).toEqual('cordova-android@'+pinnedAndroidVer);
-                expect(fetchArgs[1]).toEqual('https://github.com/apache/cordova-ios');
-                expect(fetchArgs[2]).toContain('cordova-windows');
-                expect(fetchArgs[3]).toEqual('atari@1.0.0'); 
-                //test pkgJson releated commands aren't being called
-                expect(fs.writeFileSync.calls.count()).toEqual(0);
-                expect(pkgJson.cordova).toBeUndefined();
-                //test cfg.engines code is being run with correct arugments
-                expect(configEngines.length).toEqual(0);
-            }).fail(function(e) {
-                expect(e).toBeUndefined();
-            })
-            .fin(done);
-        });
-
-        it('should succeed with save, package.json and no fetch. Tests npm package, gitURL,
local path and non core platforms with spec as targets', function(done) {
-            //spy for package.json to exist
-            spyOn(fs,'existsSync').and.callFake(function(filePath) {
-                if(path.basename(filePath) === 'package.json') {
-                    return true;
-                } else {
-                    return false;
-                }
-            });
-            
-            //require packge.json object
-            spyOn(cordova_util, 'requireNoCache').and.returnValue(pkgJson);
-            
-            platform.add(hooksRunnerMock, projectRoot, ['android', 'https://github.com/apache/cordova-ios',
windowsPath, 'atari@1.0.0'], {'fetch': false, 'save': true})
-            .then(function() {
-                expect(cordova_util.projectConfig.calls.count()).toEqual(1);
-                expect(shell.mkdir.calls.count()).toEqual(1);
-                expect(platform.getPlatformDetailsFromDir.calls.count()).toEqual(4);
-                expect(cordova_util.getPlatformApiFunction.calls.count()).toEqual(4);
-                expect(cordova.prepare.calls.count()).toEqual(4);
-                expect(prepare.preparePlatforms.calls.count()).toEqual(4);
-                expect(platformMetadata.save.calls.count()).toEqual(4);
-                expect(lazy_load.git_clone.calls.count()).toEqual(1);
-                expect(lazy_load.based_on_config.calls.count()).toEqual(2);
-                //expect correct arguments to be passed to cordova-fetch
-                expect(fetchArgs.length).toEqual(0);
-                //test pkgJson is being built correctly
-                expect(fs.writeFileSync.calls.count()).toEqual(1);
-                expect(pkgJson.cordova).toBeDefined();
-                expect(pkgJson.cordova.platforms).toEqual([ 'android', 'atari', 'cordova-ios',
'cordova-windows' ]);
-                expect(cordova_util.requireNoCache.calls.count()).toEqual(5);
-                //test cfg.engines code is being run with correct arugments
-                expect(configEngines.length).toEqual(4);
-                expect(configEngines).toEqual(
-                    [ { name: 'android', spec: pinnedAndroidVer },
-                    { name: 'cordova-ios',
-                    spec: 'https://github.com/apache/cordova-ios' },
-                    { name: 'cordova-windows',
-                    spec: windowsPath },
-                    { name: 'atari', spec: '~1.0.0' } ]);
-            }).fail(function(e) {
-                expect(e).toBeUndefined();
-            })
-            .fin(done);
-        });
-
-        it('should succeed with save, no package.json and no fetch. Tests npm package, gitURL,
local path and non core platforms with spec as targets', function(done) {
-            //spy for package.json to not exist
-            spyOn(fs,'existsSync').and.returnValue(false);
-                    
-            //require packge.json object
-            spyOn(cordova_util, 'requireNoCache').and.returnValue(pkgJson);
-            
-            platform.add(hooksRunnerMock, projectRoot, ['android', 'https://github.com/apache/cordova-ios',
windowsPath, 'atari@1.0.0'], {'fetch': false, 'save': true})
-            .then(function() {
-                expect(cordova_util.projectConfig.calls.count()).toEqual(1);
-                expect(shell.mkdir.calls.count()).toEqual(1);
-                expect(platform.getPlatformDetailsFromDir.calls.count()).toEqual(4);
-                expect(cordova_util.getPlatformApiFunction.calls.count()).toEqual(4);
-                expect(cordova.prepare.calls.count()).toEqual(4);
-                expect(prepare.preparePlatforms.calls.count()).toEqual(4);
-                expect(platformMetadata.save.calls.count()).toEqual(4);
-                expect(lazy_load.git_clone.calls.count()).toEqual(1);
-                expect(lazy_load.based_on_config.calls.count()).toEqual(2);
-                //expect correct arguments to be passed to cordova-fetch
-                expect(fetchArgs.length).toEqual(0);
-                //test pkgJson releated commands aren't being called
-                expect(fs.writeFileSync.calls.count()).toEqual(0);
-                expect(pkgJson.cordova).toBeUndefined();
-                expect(cordova_util.requireNoCache.calls.count()).toEqual(0);
-                //test cfg.engines code is being run with correct arugments
-                expect(configEngines.length).toEqual(4);
-                expect(configEngines).toEqual(
-                    [ { name: 'android', spec: pinnedAndroidVer },
-                    { name: 'cordova-ios',
-                    spec: 'https://github.com/apache/cordova-ios' },
-                    { name: 'cordova-windows',
-                    spec: windowsPath },
-                    { name: 'atari', spec: '~1.0.0' } ]);
-            }).fail(function(e) {
-                expect(e).toBeUndefined();
-            })
-            .fin(done);
-        });
-
-        //no need to worry about packagae.json in this case
-        it('should succeed with no fetch, no save. Tests npm package, gitURL, local path
and non core platforms with spec as targets', function(done) {
-            //spy for package.json to not exist
-            spyOn(fs,'existsSync').and.returnValue(false);
-     
-            platform.add(hooksRunnerMock, projectRoot, ['android', 'https://github.com/apache/cordova-ios',
windowsPath, 'atari@1.0.0'], {'fetch': false, 'save': false})
-            .then(function() {
-                expect(cordova_util.projectConfig.calls.count()).toEqual(1);
-                expect(shell.mkdir.calls.count()).toEqual(1);
-                expect(platform.getPlatformDetailsFromDir.calls.count()).toEqual(4);
-                expect(cordova_util.getPlatformApiFunction.calls.count()).toEqual(4);
-                expect(cordova.prepare.calls.count()).toEqual(4);
-                expect(prepare.preparePlatforms.calls.count()).toEqual(4);
-                expect(platformMetadata.save.calls.count()).toEqual(4);
-                expect(lazy_load.git_clone.calls.count()).toEqual(1);
-                expect(lazy_load.based_on_config.calls.count()).toEqual(2);
-                //test pkgJson releated commands aren't being called
-                expect(fs.writeFileSync.calls.count()).toEqual(0);
-                expect(pkgJson.cordova).toBeUndefined();
-                //test cfg.engines code is being run with correct arugments
-                expect(configEngines.length).toEqual(0);
-            }).fail(function(e) {
-                expect(e).toBeUndefined();
-            })
-            .fin(done);
-        });
-
-        it('should succeed with fetch, save and package.json. Gets android spec from package.json',
function(done) {
-            //spy for package.json to exist
-            spyOn(fs,'existsSync').and.callFake(function(filePath) {
-                if(path.basename(filePath) === 'package.json') {
-                    return true;
-                } else {
-                    return false;
-                }
-            });
-            
-            pkgJson = {
-                'dependencies': {
-                    'cordova-android': '^6.2.1'
-                }
-            };
-            //require packge.json object
-            spyOn(cordova_util, 'requireNoCache').and.returnValue(pkgJson);
-            
-            platform.add(hooksRunnerMock, projectRoot, ['android'], {'fetch': true, 'save':
true})
-            .then(function() {
-                expect(cordova_util.projectConfig.calls.count()).toEqual(1);
-                expect(shell.mkdir.calls.count()).toEqual(1);
-                expect(platform.getPlatformDetailsFromDir.calls.count()).toEqual(1);
-                expect(cordova_util.getPlatformApiFunction.calls.count()).toEqual(1);
-                expect(cordova.prepare.calls.count()).toEqual(1);
-                expect(prepare.preparePlatforms.calls.count()).toEqual(1);
-                expect(platformMetadata.save.calls.count()).toEqual(1);
-                expect(lazy_load.git_clone.calls.count()).toEqual(0);
-                expect(lazy_load.based_on_config.calls.count()).toEqual(0);
-                //expect correct arugments to be passed to cordova-fetch
-                expect(fetchArgs).toEqual([ 'cordova-android@^6.2.1']);
-                //test pkgJson is being built correctly
-                expect(fs.writeFileSync.calls.count()).toEqual(1);
-                expect(pkgJson.cordova).toBeDefined();
-                expect(pkgJson.cordova.platforms).toEqual([ 'android']);
-                expect(cordova_util.requireNoCache.calls.count()).toEqual(2);
-                //test cfg.engines code is being run with correct arugments
-                expect(configEngines.length).toEqual(1);
-                expect(configEngines).toEqual(
-                    [ { name: 'android', spec: '~6.2.1'}]);
-            }).fail(function(e) {
-                expect(e).toBeUndefined();
-            })
-            .fin(done);
-        });
-
-        it('throws if platform already added', function (done) {
-            // spy for android to exist
-            spyOn(fs, 'existsSync').and.callFake(function (filePath) {
-                var name = path.basename(filePath);
-                if (['android'].indexOf(name) > -1) {
-                    return true;
-                } else {
-                    return false;
-                }
-            });
-            downloadPlatformRevert = platform_addHelper.__set__('module.exports.downloadPlatform',
function(proj, plat, spec, opts) {
-                console.log('calling fake');
-                return Q({
-                    platform: 'android'
-                });
-            });
-
-            platform_addHelper(hooksRunnerMock, projectRoot, ['android'], {'fetch': true,
'save': true})
-            .then(false)
-            .fail(function(e) {
-                expect(e.message).toBe('Platform android already added.');
-            })
-            .fin(done);
-        });
-
-        it('throws if the target list is undefined', function (done) {
-            var targets; // = undefined;
-            platform.add(hooksRunnerMock, projectRoot, targets, {})
-            .then(false)
-            .fail(function (error) {
-                expect(error.message).toBe('No platform specified. Please specify a platform
to add. See `cordova platform list`.');
-            }).fin(done);
-        });
-
-        it('throws if the target list is null', function (done) {
-            var targets = null; // = undefined;
-            platform.add(hooksRunnerMock, projectRoot, targets, {})
-            .then(false)
-            .fail(function (error) {
-                expect(error.message).toBe('No platform specified. Please specify a platform
to add. See `cordova platform list`.');
-            }).fin(done);
-        });
-
-        it('throws if the target list is empty', function (done) {
-            var targets = []; // = undefined;
-            platform.add(hooksRunnerMock, projectRoot, targets, {})
-            .then(false)
-            .fail(function (error) {
-                expect(error.message).toBe('No platform specified. Please specify a platform
to add. See `cordova platform list`.');
-            }).fin(done);
-        });
-    });
 });

http://git-wip-us.apache.org/repos/asf/cordova-lib/blob/2daef359/spec-cordova/platform/index.spec.js
----------------------------------------------------------------------
diff --git a/spec-cordova/platform/index.spec.js b/spec-cordova/platform/index.spec.js
index f05ca85..a39d43e 100644
--- a/spec-cordova/platform/index.spec.js
+++ b/spec-cordova/platform/index.spec.js
@@ -14,7 +14,9 @@
     specific language governing permissions and limitations
     under the License.
 */
+// TODO: remove these once eslint lands
 /* eslint-env jasmine */
+/* globals fail */
 
 var rewire = require('rewire');
 var platform = rewire('../../src/cordova/platform');

http://git-wip-us.apache.org/repos/asf/cordova-lib/blob/2daef359/spec-cordova/plugin/add.spec.js
----------------------------------------------------------------------
diff --git a/spec-cordova/plugin/add.spec.js b/spec-cordova/plugin/add.spec.js
new file mode 100644
index 0000000..4860578
--- /dev/null
+++ b/spec-cordova/plugin/add.spec.js
@@ -0,0 +1,78 @@
+/**
+    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.
+*/
+/* eslint-env jasmine */
+
+var add = require('../../src/cordova/plugin/add');
+
+describe('cordova/plugin/add', function () {
+    describe('main method', function () {
+        describe('error/warning conditions', function () {
+            it('should error out if at least one plugin is not specified');
+            it('should error out if any mandatory plugin variables are not provided');
+        });
+        describe('happy path', function () {
+            it('should fire the before_plugin_add hook');
+            it('should determine where to fetch a plugin from using determinePluginTarget
and invoke plugman.fetch with the resolved target');
+            it('should retrieve any variables for the plugin from config.xml and provide
them as cli variables only when the cli variables are not already provided via options');
+            it('should invoke plugman.install for each platform added to the project');
+            it('should save plugin variable information to package.json file (if exists)');
+            it('should overwrite plugin information in config.xml after a successful installation');
+            it('should invoke preparePlatforms if plugman.install returned a truthy value');
+            it('should fire after_plugin_add hook');
+        });
+    });
+    describe('determinePluginTarget helper method', function () {
+        it('should return the target directly if the target is pluginSpec-parseable');
+        it('should return the target directly if the target is a URL');
+        it('should return the target directly if the target is a directory');
+        it('should retrieve plugin version from package.json (if exists)');
+        it('should retrieve plugin version from config.xml as a last resort');
+        describe('with fetchOptions.save=true, writing out plugin versions retrieved from
config files (either config.xml or package.json)', function () {
+            it('should write out URL-as-plugin-spec to package.json');
+            it('should write out directory-as-plugin-spec to package.json');
+        });
+        it('should return plugin version retrieved from package.json or config.xml if it
is a URL');
+        it('should return plugin version retrieved from package.json or config.xml if it
is a directory');
+        it('should return plugin version retrieved from package.json or config.xml if it
has a scope');
+        it('should return plugin-id@plugin-version if retrieved from package.json or config.xml
');
+        describe('with no version inferred from config files or provided plugin target',
function () {
+            describe('when searchpath or noregistry flag is provided', function () {
+                it('should end up just returning the target passed in');
+            });
+            describe('when registry/npm is to be used (neither searchpath nor noregistry
flag is provided)', function () {
+                it('should retrieve plugin info via registry.info');
+                it('should feed registry.info plugin information into getFetchVersion');
+                it('should return the target as plugin-id@fetched-version');
+            });
+        });
+    });
+    // TODO: reorganize these tests once the logic here is understood! -filmaj
+    // TODO: rewrite the tests from integration-tests/plugin_fetch.spec.js to here.
+    describe('TODO! unit tests to replace integration-tests/plugin_fetch.spec.js', function
() {
+        describe('getFetchVersion helper method', function () {
+            it('should resolve with null if plugin info does not contain engines and engines.cordovaDependencies
properties');
+            it('should retrieve platform version info via getInstalledPlatformsWithVersions
and feed that information into determinePluginVersionToFetch');
+        });
+        describe('determinePluginVersionToFetch helper method', function () {
+            it('should return null if no valid semver versions exist and no upperbound constraints
were placed');
+        });
+        describe('getFailedRequirements helper method', function () {
+        });
+    });
+});

http://git-wip-us.apache.org/repos/asf/cordova-lib/blob/2daef359/spec-cordova/plugin/search.spec.js
----------------------------------------------------------------------
diff --git a/spec-cordova/plugin/search.spec.js b/spec-cordova/plugin/search.spec.js
new file mode 100644
index 0000000..b940eeb
--- /dev/null
+++ b/spec-cordova/plugin/search.spec.js
@@ -0,0 +1,28 @@
+/**
+    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.
+*/
+/* eslint-env jasmine */
+
+var search = require('../../src/cordova/plugin/search');
+
+describe('cordova/plugin/search', function () {
+    it('should fire the before_plugin_search hook');
+    it('should open a link to cordova.apache.org/plugins if no plugins are provided as parameter');
+    it('should open a link to cordova.apache.org/plugins, providing the plugins passed in
as a query-string parameter');
+    it('should fire the after_plugin_search hook');
+});

http://git-wip-us.apache.org/repos/asf/cordova-lib/blob/2daef359/spec-cordova/plugin/util.spec.js
----------------------------------------------------------------------
diff --git a/spec-cordova/plugin/util.spec.js b/spec-cordova/plugin/util.spec.js
new file mode 100644
index 0000000..f967706
--- /dev/null
+++ b/spec-cordova/plugin/util.spec.js
@@ -0,0 +1,31 @@
+/**
+    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.
+*/
+/* eslint-env jasmine */
+
+var plugin_util = require('../../src/cordova/plugin/util');
+
+describe('cordova/plugin/util', function () {
+    describe('getInstalledPlugins helper method', function () {
+        it('should return result of PluginInfoProvider\'s getAllWithinSearchPath method');
+    });
+    describe('saveToConfigXmlOn helper method', function () {
+        it('should return true if config.json\'s autosave option is truthy');
+        it('should return true if options passed in have a truthy save property');
+    });
+});

http://git-wip-us.apache.org/repos/asf/cordova-lib/blob/2daef359/src/cordova/platform/addHelper.js
----------------------------------------------------------------------
diff --git a/src/cordova/platform/addHelper.js b/src/cordova/platform/addHelper.js
index 4d999c1..4161900 100644
--- a/src/cordova/platform/addHelper.js
+++ b/src/cordova/platform/addHelper.js
@@ -185,8 +185,7 @@ function addHelper (cmd, hooksRunner, projectRoot, targets, opts) {
                 events.emit('log', (cmd === 'add' ? 'Adding ' : 'Updating ') + platform +
' project...');
                 var PlatformApi = cordova_util.getPlatformApiFunction(platDetails.libDir,
platform);
                 var destination = path.resolve(projectRoot, 'platforms', platform);
-                var promise = cmd === 'add'
-                    ? PlatformApi.createPlatform.bind(null, destination, cfg, options, events)
+                var promise = cmd === 'add' ? PlatformApi.createPlatform.bind(null, destination,
cfg, options, events)
                     : PlatformApi.updatePlatform.bind(null, destination, options, events);
                 // TODO: if we return the promise immediately, can we not unindent the promise
.then()s by one indent?
                 return promise()

http://git-wip-us.apache.org/repos/asf/cordova-lib/blob/2daef359/src/cordova/plugin/add.js
----------------------------------------------------------------------
diff --git a/src/cordova/plugin/add.js b/src/cordova/plugin/add.js
index ca12612..3b801d0 100644
--- a/src/cordova/plugin/add.js
+++ b/src/cordova/plugin/add.js
@@ -34,6 +34,7 @@ var Q = require('Q');
 var path = require('path');
 var fs = require('fs');
 var semver = require('semver');
+var url = require('url');
 
 module.exports = add;
 module.exports.determinePluginTarget = determinePluginTarget;
@@ -45,8 +46,8 @@ module.exports.getFailedRequirements = getFailedRequirements;
 module.exports.findVersion = findVersion;
 module.exports.listUnmetRequirements = listUnmetRequirements;
 
-function add (projectRoot, targets, hooksRunner, opts) {
-    if (!targets || !targets.length) {
+function add (projectRoot, hooksRunner, opts) {
+    if (!opts.plugins || !opts.plugins.length) {
         return Q.reject(new CordovaError('No plugin specified. Please specify a plugin to
add. See `' + cordova_util.binname + ' plugin search`.'));
     }
 
@@ -289,7 +290,7 @@ function determinePluginTarget (projectRoot, cfg, target, fetchOptions)
{
     // their package.json
     var shouldUseNpmInfo = !fetchOptions.searchpath && !fetchOptions.noregistry;
 
-    events.emit('verbose', 'No version for ' + parsedSpec.package + ' saved in config.xml');
+    events.emit('verbose', 'No version for ' + parsedSpec.package + ' saved in config.xml
or package.json');
     if (shouldUseNpmInfo) {
         events.emit('verbose', 'Attempting to use npm info for ' + parsedSpec.package + '
to choose a compatible release');
     } else {
@@ -307,7 +308,6 @@ function determinePluginTarget (projectRoot, cfg, target, fetchOptions)
{
 }
 
 function parseSource (target, opts) {
-    var url = require('url');
     var uri = url.parse(target);
     if (uri.protocol && uri.protocol !== 'file:' && uri.protocol[1] !== ':'
&& !target.match(/^\w+:\\/)) {
         return target;
@@ -387,6 +387,8 @@ var UPPER_BOUND_REGEX = /^<\d+\.\d+\.\d+$/;
  *      '3.0.0' : { 'cordova-ios': '>5.0.0' }
  *  }
  *
+ * TODO: provide a better function description once logic is groked
+ * TODO: update comment below once tests are rewritten/moved around.
  * See cordova-spec/plugin_fetch.spec.js for test cases and examples
  */
 function determinePluginVersionToFetch (pluginInfo, pluginMap, platformMap, cordovaVersion)
{
@@ -402,8 +404,11 @@ function determinePluginVersionToFetch (pluginInfo, pluginMap, platformMap,
cord
     var upperBoundRange = null;
     var upperBoundExists = false;
 
+    // TODO: lots of 'versions' being thrown around in this function: cordova version,
+    // platform version, plugin version. The below for loop: what version is it
+    // iterating over? plugin version? please clarify the variable name.
     for (var version in engine) {
-        if (semver.valid(semver.clean(version)) && !semver.gt(version, latest)) {
+        if (semver.valid(semver.clean(version)) && semver.lte(version, latest)) {
             versions.push(version);
         } else {
             // Check if this is an upperbound; validRange() handles whitespace

http://git-wip-us.apache.org/repos/asf/cordova-lib/blob/2daef359/src/cordova/plugin/index.js
----------------------------------------------------------------------
diff --git a/src/cordova/plugin/index.js b/src/cordova/plugin/index.js
index 7b34780..2ceae70 100644
--- a/src/cordova/plugin/index.js
+++ b/src/cordova/plugin/index.js
@@ -80,7 +80,7 @@ function plugin (command, targets, opts) {
 
         switch (command) {
         case 'add':
-            return module.exports.add(projectRoot, targets, hooksRunner, opts);
+            return module.exports.add(projectRoot, hooksRunner, opts);
         case 'rm':
         case 'remove':
             return module.exports.remove(projectRoot, targets, hooksRunner, opts);


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org
For additional commands, e-mail: commits-help@cordova.apache.org


Mime
View raw message