cordova-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ste...@apache.org
Subject cordova-fetch git commit: CB-12895 : setting up eslint and removing jshint
Date Tue, 19 Sep 2017 22:55:50 GMT
Repository: cordova-fetch
Updated Branches:
  refs/heads/master 07a3b30c6 -> 06441bb53


CB-12895 : setting up eslint and removing jshint

 This closes #2


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

Branch: refs/heads/master
Commit: 06441bb531e6bddd2f8f2517fb21de2e0ea4c9b3
Parents: 07a3b30
Author: Audrey So <audreyso@apache.org>
Authored: Fri Jun 9 10:39:48 2017 -0700
Committer: Steve Gill <stevengill97@gmail.com>
Committed: Tue Sep 19 15:53:06 2017 -0700

----------------------------------------------------------------------
 .eslintrc.yml      |  10 +
 .jshintrc          |  12 --
 index.js           | 236 ++++++++++++------------
 package.json       |  14 +-
 spec/fetch.spec.js | 479 ++++++++++++++++++++++++------------------------
 spec/helpers.js    |  10 +-
 6 files changed, 381 insertions(+), 380 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-fetch/blob/06441bb5/.eslintrc.yml
----------------------------------------------------------------------
diff --git a/.eslintrc.yml b/.eslintrc.yml
new file mode 100644
index 0000000..f6aae32
--- /dev/null
+++ b/.eslintrc.yml
@@ -0,0 +1,10 @@
+root: true
+extends: semistandard
+rules:
+  indent:
+    - error
+    - 4
+  camelcase: off
+  padded-blocks: off
+  operator-linebreak: off
+  no-throw-literal: off

http://git-wip-us.apache.org/repos/asf/cordova-fetch/blob/06441bb5/.jshintrc
----------------------------------------------------------------------
diff --git a/.jshintrc b/.jshintrc
deleted file mode 100644
index 62edb5c..0000000
--- a/.jshintrc
+++ /dev/null
@@ -1,12 +0,0 @@
-{
-  "node": true,
-  "bitwise": true,
-  "undef": true,
-  "trailing": true,
-  "quotmark": true,
-  "indent": 4,
-  "unused": "vars",
-  "latedef": "nofunc",
-  "-W030": false,
-  "jasmine": true
-}

http://git-wip-us.apache.org/repos/asf/cordova-fetch/blob/06441bb5/index.js
----------------------------------------------------------------------
diff --git a/index.js b/index.js
index 25b60fe..fd4c583 100644
--- a/index.js
+++ b/index.js
@@ -6,9 +6,7 @@
  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
@@ -28,7 +26,7 @@ var fs = require('fs');
 var CordovaError = require('cordova-common').CordovaError;
 var isUrl = require('is-url');
 
-/* 
+/*
  * A function that npm installs a module from npm or a git url
  *
  * @param {String} target   the packageID or git url
@@ -38,69 +36,68 @@ var isUrl = require('is-url');
  * @return {String|Promise}    Returns string of the absolute path to the installed module.
  *
  */
-module.exports = function(target, dest, opts) {
+module.exports = function (target, dest, opts) {
     var fetchArgs = opts.link ? ['link'] : ['install'];
     opts = opts || {};
     var tree1;
 
-    //check if npm is installed
+    // check if npm is installed
     return isNpmInstalled()
-    .then(function() {
-        if(dest && target) {
-            //add target to fetchArgs Array
-            fetchArgs.push(target);
-        
-            //append node_modules to dest if it doesn't come included
-            if (path.basename(dest) !== 'node_modules') {
-                dest = path.resolve(path.join(dest, 'node_modules'));
+        .then(function () {
+            if (dest && target) {
+                // add target to fetchArgs Array
+                fetchArgs.push(target);
+
+                // append node_modules to dest if it doesn't come included
+                if (path.basename(dest) !== 'node_modules') {
+                    dest = path.resolve(path.join(dest, 'node_modules'));
+                }
+                // create dest if it doesn't exist
+                if (!fs.existsSync(dest)) {
+                    shell.mkdir('-p', dest);
+                }
+            } else return Q.reject(new CordovaError('Need to supply a target and destination'));
+
+            // set the directory where npm install will be run
+            opts.cwd = dest;
+
+            // if user added --save flag, pass it to npm install command
+            if (opts.save) {
+                events.emit('verbose', 'saving');
+                fetchArgs.push('--save');
             }
-            //create dest if it doesn't exist
-            if(!fs.existsSync(dest)) {
-                shell.mkdir('-p', dest);         
-            } 
-        } else return Q.reject(new CordovaError('Need to supply a target and destination'));
-
-        //set the directory where npm install will be run
-        opts.cwd = dest;
-
-        //if user added --save flag, pass it to npm install command
-        if(opts.save) {
-            events.emit('verbose', 'saving');
-            fetchArgs.push('--save'); 
-        } 
-    
-        //Grab json object of installed modules before npm install
-        return depls(dest);
-    })
-    .then(function(depTree) {
-        tree1 = depTree;
 
-        //install new module
-        return superspawn.spawn('npm', fetchArgs, opts);
-    })
-    .then(function(output) {
-        //Grab object of installed modules after npm install
-        return depls(dest);
-    })
-    .then(function(depTree2) {
-        var tree2 = depTree2;
-
-        //getJsonDiff will fail if the module already exists in node_modules.
-        //Need to use trimID in that case. 
-        //This could happen on a platform update.
-        var id = getJsonDiff(tree1, tree2) || trimID(target); 
-
-        return getPath(id, dest, target);
-    }) 
-    .fail(function(err){
-        return Q.reject(new CordovaError(err));
-    });
+            // Grab json object of installed modules before npm install
+            return depls(dest);
+        })
+        .then(function (depTree) {
+            tree1 = depTree;
+
+            // install new module
+            return superspawn.spawn('npm', fetchArgs, opts);
+        })
+        .then(function (output) {
+            // Grab object of installed modules after npm install
+            return depls(dest);
+        })
+        .then(function (depTree2) {
+            var tree2 = depTree2;
+
+            // getJsonDiff will fail if the module already exists in node_modules.
+            // Need to use trimID in that case.
+            // This could happen on a platform update.
+            var id = getJsonDiff(tree1, tree2) || trimID(target);
+
+            return getPath(id, dest, target);
+        })
+        .fail(function (err) {
+            return Q.reject(new CordovaError(err));
+        });
 };
 
-
 /*
  * Takes two JSON objects and returns the key of the new property as a string.
- * If a module already exists in node_modules, the diff will be blank. 
+ * If a module already exists in node_modules, the diff will be blank.
  * cordova-fetch will use trimID in that case.
  *
  * @param {Object} obj1     json object representing installed modules before latest npm
install
@@ -109,16 +106,16 @@ module.exports = function(target, dest, opts) {
  * @return {String}         String containing the key value of the difference between the
two objects
  *
  */
-function getJsonDiff(obj1, obj2) {
+function getJsonDiff (obj1, obj2) {
     var result = '';
 
-    //regex to filter out peer dependency warnings from result
+    // regex to filter out peer dependency warnings from result
     var re = /UNMET PEER DEPENDENCY/;
 
     for (var key in obj2) {
-        //if it isn't a unmet peer dependency, continue
+        // if it isn't a unmet peer dependency, continue
         if (key.search(re) === -1) {
-            if(obj2[key] != obj1[key]) result = key;
+            if (obj2[key] !== obj1[key]) result = key;
         }
     }
     return result;
@@ -126,9 +123,9 @@ function getJsonDiff(obj1, obj2) {
 
 /*
  * Takes the specified target and returns the moduleID
- * If the git repoName is different than moduleID, then the 
- * output from this function will be incorrect. This is the 
- * backup way to get ID. getJsonDiff is the preferred way to 
+ * If the git repoName is different than moduleID, then the
+ * output from this function will be incorrect. This is the
+ * backup way to get ID. getJsonDiff is the preferred way to
  * get the moduleID of the installed module.
  *
  * @param {String} target    target that was passed into cordova-fetch.
@@ -136,46 +133,47 @@ function getJsonDiff(obj1, obj2) {
  *
  * @return {String} ID       moduleID without version.
  */
-function trimID(target) {
+function trimID (target) {
     var parts;
-    //If GITURL, set target to repo name
+    // If GITURL, set target to repo name
     if (isUrl(target)) {
-        //strip away .git and everything that follows       
+        // strip away .git and everything that follows
         var strippedTarget = target.split('.git');
         var re = /.*\/(.*)/;
-        //Grabs everything in url after last `/`
+        // Grabs everything in url after last `/`
         parts = strippedTarget[0].match(re);
-        
+
         target = parts[1];
     }
 
     // If local path exists, try to get plugin id from package.json or set target to final
directory
     if (fs.existsSync(target)) {
-        var pluginId, pkgJsonPath = path.join(target, 'package.json');
+        var pluginId;
+        var pkgJsonPath = path.join(target, 'package.json');
 
         if (fs.existsSync(pkgJsonPath)) {
             pluginId = JSON.parse(fs.readFileSync(pkgJsonPath)).name;
         }
 
-        target = pluginId ? pluginId : path.basename(target);
+        target = pluginId || path.basename(target);
     }
-    
-    //strip away everything after '@'
-    //also support scoped packages
-    if(target.indexOf('@') != -1) {
+
+    // strip away everything after '@'
+    // also support scoped packages
+    if (target.indexOf('@') !== -1) {
         parts = target.split('@');
         if (parts.length > 1 && parts[0] === '') {
-            //scoped package
+            // scoped package
             target = '@' + parts[1];
         } else {
             target = parts[0];
         }
-    }        
-    
+    }
+
     return target;
 }
 
-/* 
+/*
  * Takes the moduleID and destination and returns an absolute path to the module
  *
  * @param {String} id       the packageID
@@ -185,7 +183,7 @@ function trimID(target) {
  *
  */
 
-function getPath(id, dest, target) {
+function getPath (id, dest, target) {
     var destination = path.resolve(path.join(dest, id));
     var finalDest = fs.existsSync(destination) ? destination : searchDirForTarget(dest, target);
 
@@ -196,7 +194,7 @@ function getPath(id, dest, target) {
     return finalDest;
 }
 
-/* 
+/*
  * Make an additional search in destination folder using repository.url property from package.json
  *
  * @param {String} dest     destination of where to fetch the modules
@@ -206,21 +204,21 @@ function getPath(id, dest, target) {
  *
  */
 
-function searchDirForTarget(dest, target) {
+function searchDirForTarget (dest, target) {
     if (!isUrl(target)) {
         return;
     }
 
     var targetPathname = url.parse(target).pathname;
 
-    var pkgJsonPath = fs.readdirSync(dest).map(function(dir) {
+    var pkgJsonPath = fs.readdirSync(dest).map(function (dir) {
         return path.join(dest, dir, 'package.json');
     })
-    .filter(fs.existsSync)
-    .find(function(pkgJsonPath) {
-        var repo = JSON.parse(fs.readFileSync(pkgJsonPath)).repository;
-        return repo && url.parse(repo.url).pathname === targetPathname;
-    });
+        .filter(fs.existsSync)
+        .find(function (pkgJsonPath) {
+            var repo = JSON.parse(fs.readFileSync(pkgJsonPath)).repository;
+            return repo && url.parse(repo.url).pathname === targetPathname;
+        });
 
     return pkgJsonPath && path.dirname(pkgJsonPath);
 }
@@ -230,15 +228,15 @@ function searchDirForTarget(dest, target) {
  * @return {Promise|Error} Returns true or a cordova error.
  */
 
-function isNpmInstalled() {
-    if(!shell.which('npm')) {
+function isNpmInstalled () {
+    if (!shell.which('npm')) {
         return Q.reject(new CordovaError('"npm" command line tool is not installed: make
sure it is accessible on your PATH.'));
     }
     return Q();
 }
 
-/* 
- * A function that deletes the target from node_modules and runs npm uninstall 
+/*
+ * A function that deletes the target from node_modules and runs npm uninstall
  *
  * @param {String} target   the packageID
  * @param {String} dest     destination of where to uninstall the module from
@@ -247,38 +245,38 @@ function isNpmInstalled() {
  * @return {Promise|Error}    Returns a promise with the npm uninstall output or an error.
  *
  */
-module.exports.uninstall = function(target, dest, opts) {
+module.exports.uninstall = function (target, dest, opts) {
     var fetchArgs = ['uninstall'];
     opts = opts || {};
 
-    //check if npm is installed on the system
+    // check if npm is installed on the system
     return isNpmInstalled()
-    .then(function() {    
-        if(dest && target) {
-            //add target to fetchArgs Array
-            fetchArgs.push(target);  
-        } else return Q.reject(new CordovaError('Need to supply a target and destination'));
-
-        //set the directory where npm uninstall will be run
-        opts.cwd = dest;
-
-        //if user added --save flag, pass it to npm uninstall command
-        if(opts.save) {
-            fetchArgs.push('--save'); 
-        }
+        .then(function () {
+            if (dest && target) {
+                // add target to fetchArgs Array
+                fetchArgs.push(target);
+            } else return Q.reject(new CordovaError('Need to supply a target and destination'));
+
+            // set the directory where npm uninstall will be run
+            opts.cwd = dest;
+
+            // if user added --save flag, pass it to npm uninstall command
+            if (opts.save) {
+                fetchArgs.push('--save');
+            }
 
-        //run npm uninstall, this will remove dependency
-        //from package.json if --save was used.
-        return superspawn.spawn('npm', fetchArgs, opts);
-    })
-    .then(function(res) {
-        var pluginDest = path.join(dest, 'node_modules', target);
-        if(fs.existsSync(pluginDest)) {
-            shell.rm('-rf', pluginDest);
-        } 
-        return res;
-    })
-    .fail(function(err) {
-        return Q.reject(new CordovaError(err));
-    });
+            // run npm uninstall, this will remove dependency
+            // from package.json if --save was used.
+            return superspawn.spawn('npm', fetchArgs, opts);
+        })
+        .then(function (res) {
+            var pluginDest = path.join(dest, 'node_modules', target);
+            if (fs.existsSync(pluginDest)) {
+                shell.rm('-rf', pluginDest);
+            }
+            return res;
+        })
+        .fail(function (err) {
+            return Q.reject(new CordovaError(err));
+        });
 };

http://git-wip-us.apache.org/repos/asf/cordova-fetch/blob/06441bb5/package.json
----------------------------------------------------------------------
diff --git a/package.json b/package.json
index d9c3a07..3b9d8bf 100644
--- a/package.json
+++ b/package.json
@@ -28,12 +28,18 @@
     "shelljs": "^0.7.0"
   },
   "devDependencies": {
-    "jasmine": "^2.4.1",
-    "jshint": "^2.8.0"
+    "eslint": "^3.19.0",
+    "eslint-config-semistandard": "^11.0.0",
+    "eslint-config-standard": "^10.2.1",
+    "eslint-plugin-import": "^2.3.0",
+    "eslint-plugin-node": "^5.0.0",
+    "eslint-plugin-promise": "^3.5.0",
+    "eslint-plugin-standard": "^3.0.1",
+    "jasmine": "^2.4.1"
   },
   "scripts": {
-    "test": "npm run jshint && npm run jasmine",
-    "jshint": "jshint index.js spec/fetch.spec.js",
+    "test": "npm run eslint && npm run jasmine",
+    "eslint": "eslint index.js spec/fetch.spec.js",
     "jasmine": "jasmine spec/fetch.spec.js"
   },
   "engines": {

http://git-wip-us.apache.org/repos/asf/cordova-fetch/blob/06441bb5/spec/fetch.spec.js
----------------------------------------------------------------------
diff --git a/spec/fetch.spec.js b/spec/fetch.spec.js
index 8cdc6e2..bb8424a 100644
--- a/spec/fetch.spec.js
+++ b/spec/fetch.spec.js
@@ -6,9 +6,7 @@
     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
@@ -17,6 +15,7 @@
     under the License.
 */
 
+/* eslint-env jasmine */
 var fetch = require('../index.js');
 var uninstall = require('../index.js').uninstall;
 var shell = require('shelljs');
@@ -29,176 +28,176 @@ describe('platform fetch/uninstall tests via npm & git', function
() {
     var tmpDir = helpers.tmpDir('plat_fetch');
     var opts = {};
 
-    beforeEach(function() {
+    beforeEach(function () {
         process.chdir(tmpDir);
     });
 
-    afterEach(function() {
-        process.chdir(path.join(__dirname, '..'));  // Needed to rm the dir on Windows.
+    afterEach(function () {
+        process.chdir(path.join(__dirname, '..')); // Needed to rm the dir on Windows.
         shell.rm('-rf', tmpDir);
     });
 
-    it('should fetch and uninstall a cordova platform via npm & git', function(done)
{
+    it('should fetch and uninstall a cordova platform via npm & git', function (done)
{
 
         fetch('cordova-android', tmpDir, opts)
-        .then(function(result) {
-            var pkgJSON = require(path.join(result,'package.json'));
-            expect(result).toBeDefined();
-            expect(fs.existsSync(result)).toBe(true);
-            expect(pkgJSON.name).toBe('cordova-android');
-
-            return uninstall('cordova-android', tmpDir, opts);
-        })
-        .then(function() {
-            expect(fs.existsSync(path.join(tmpDir,'node_modules', 'cordova-android'))).toBe(false);
-
-            return fetch('https://github.com/apache/cordova-ios.git', tmpDir, opts);
-        })
-        .then(function(result) {
-            var pkgJSON = require(path.join(result,'package.json'));
-            expect(result).toBeDefined();
-            expect(fs.existsSync(result)).toBe(true);
-            expect(pkgJSON.name).toBe('cordova-ios');
-
-            return uninstall('cordova-ios', tmpDir, opts);
-        })
-        .then(function() {
-            expect(fs.existsSync(path.join(tmpDir,'node_modules', 'cordova-ios'))).toBe(false);
   
-            
-            //return fetch('git+ssh://git@github.com/apache/cordova-browser.git#487d91d1ded96b8e2029f2ee90f12a8b20499f54',
tmpDir, opts);
-            // can't test ssh right now as it is requiring ssh password
-            return fetch('https://github.com/apache/cordova-browser.git', tmpDir, opts);
-        })
-        .then(function(result) {
-            var pkgJSON = require(path.join(result,'package.json'));
-            expect(result).toBeDefined();
-            expect(fs.existsSync(result)).toBe(true);
-            expect(pkgJSON.name).toBe('cordova-browser');
-        })
-        .fail(function(err) {
-            console.error(err);
-            expect(err).toBeUndefined();
-        })
-        .fin(done);
+            .then(function (result) {
+                var pkgJSON = require(path.join(result, 'package.json'));
+                expect(result).toBeDefined();
+                expect(fs.existsSync(result)).toBe(true);
+                expect(pkgJSON.name).toBe('cordova-android');
+
+                return uninstall('cordova-android', tmpDir, opts);
+            })
+            .then(function () {
+                expect(fs.existsSync(path.join(tmpDir, 'node_modules', 'cordova-android'))).toBe(false);
+
+                return fetch('https://github.com/apache/cordova-ios.git', tmpDir, opts);
+            })
+            .then(function (result) {
+                var pkgJSON = require(path.join(result, 'package.json'));
+                expect(result).toBeDefined();
+                expect(fs.existsSync(result)).toBe(true);
+                expect(pkgJSON.name).toBe('cordova-ios');
+
+                return uninstall('cordova-ios', tmpDir, opts);
+            })
+            .then(function () {
+                expect(fs.existsSync(path.join(tmpDir, 'node_modules', 'cordova-ios'))).toBe(false);
+
+                // return fetch('git+ssh://git@github.com/apache/cordova-browser.git#487d91d1ded96b8e2029f2ee90f12a8b20499f54',
tmpDir, opts);
+                // can't test ssh right now as it is requiring ssh password
+                return fetch('https://github.com/apache/cordova-browser.git', tmpDir, opts);
+            })
+            .then(function (result) {
+                var pkgJSON = require(path.join(result, 'package.json'));
+                expect(result).toBeDefined();
+                expect(fs.existsSync(result)).toBe(true);
+                expect(pkgJSON.name).toBe('cordova-browser');
+            })
+            .fail(function (err) {
+                console.error(err);
+                expect(err).toBeUndefined();
+            })
+            .fin(done);
     }, 60000);
 });
 
 describe('platform fetch/uninstall test via npm & git tags with --save', function ()
{
 
     var tmpDir = helpers.tmpDir('plat_fetch_save');
-    var opts = {'save':true};
+    var opts = {'save': true};
 
-    beforeEach(function() {
-        //copy package.json from spec directory to tmpDir
-        shell.cp('spec/testpkg.json', path.join(tmpDir,'package.json'));
+    beforeEach(function () {
+        // copy package.json from spec directory to tmpDir
+        shell.cp('spec/testpkg.json', path.join(tmpDir, 'package.json'));
         process.chdir(tmpDir);
     });
 
-    afterEach(function() {
-        process.chdir(path.join(__dirname, '..'));  // Needed to rm the dir on Windows.
+    afterEach(function () {
+        process.chdir(path.join(__dirname, '..')); // Needed to rm the dir on Windows.
         shell.rm('-rf', tmpDir);
     });
 
-    it('should fetch and uninstall a cordova platform via npm & git tags/branches', function(done)
{
+    it('should fetch and uninstall a cordova platform via npm & git tags/branches', function
(done) {
         fetch('cordova-android@5.1.1', tmpDir, opts)
-        .then(function(result) {
-            var pkgJSON = require(path.join(result,'package.json'));
-            expect(result).toBeDefined();
-            expect(fs.existsSync(result)).toBe(true);
-            expect(pkgJSON.name).toBe('cordova-android');
-            expect(pkgJSON.version).toBe('5.1.1');
-
-            var rootPJ = require(path.join(tmpDir,'package.json'));
-            expect(rootPJ.dependencies['cordova-android']).toBe('^5.1.1');
-
-            return uninstall('cordova-android', tmpDir, opts);
-        })
-        .then(function() {
-            var rootPJ = JSON.parse(fs.readFileSync(path.join(tmpDir,'package.json'), 'utf8'));
-            expect(Object.keys(rootPJ.dependencies).length).toBe(0);
-            expect(fs.existsSync(path.join(tmpDir,'node_modules', 'cordova-android'))).toBe(false);
-
-            return fetch('https://github.com/apache/cordova-ios.git#rel/4.1.1', tmpDir, opts);
-        })
-        .then(function(result) {
-            var pkgJSON = require(path.join(result,'package.json'));
-            expect(result).toBeDefined();
-            expect(fs.existsSync(result)).toBe(true);
-            expect(pkgJSON.name).toBe('cordova-ios');
-            expect(pkgJSON.version).toBe('4.1.1');
-
-            var rootPJ = JSON.parse(fs.readFileSync(path.join(tmpDir,'package.json'), 'utf8'));
-            expect(rootPJ.dependencies['cordova-ios']).toBe('git+https://github.com/apache/cordova-ios.git#rel/4.1.1');
-
-            return uninstall('cordova-ios', tmpDir, opts);
-        })
-        .then(function() {
-            var rootPJ = JSON.parse(fs.readFileSync(path.join(tmpDir,'package.json'), 'utf8'));
-            expect(Object.keys(rootPJ.dependencies).length).toBe(0);
-            expect(fs.existsSync(path.join(tmpDir,'node_modules', 'cordova-ios'))).toBe(false);
-
-            return fetch('https://github.com/apache/cordova-android.git#4.1.x', tmpDir, opts);
-        })
-        .then(function(result) {
-            var pkgJSON = JSON.parse(fs.readFileSync(path.join(result,'package.json'), 'utf8'));
-            expect(result).toBeDefined();
-            expect(fs.existsSync(result)).toBe(true);
-            expect(pkgJSON.name).toBe('cordova-android');
-            expect(pkgJSON.version).toBe('4.1.1');
-
-            var rootPJ = JSON.parse(fs.readFileSync(path.join(tmpDir,'package.json'), 'utf8'));
-            expect(rootPJ.dependencies['cordova-android']).toBe('git+https://github.com/apache/cordova-android.git#4.1.x');
-
-            return uninstall('cordova-android', tmpDir, opts);
-        })
-        .fail(function(err) {
-            console.error(err);
-            expect(err).toBeUndefined();
-        })
-        .fin(done);
+            .then(function (result) {
+                var pkgJSON = require(path.join(result, 'package.json'));
+                expect(result).toBeDefined();
+                expect(fs.existsSync(result)).toBe(true);
+                expect(pkgJSON.name).toBe('cordova-android');
+                expect(pkgJSON.version).toBe('5.1.1');
+
+                var rootPJ = require(path.join(tmpDir, 'package.json'));
+                expect(rootPJ.dependencies['cordova-android']).toBe('^5.1.1');
+
+                return uninstall('cordova-android', tmpDir, opts);
+            })
+            .then(function () {
+                var rootPJ = JSON.parse(fs.readFileSync(path.join(tmpDir, 'package.json'),
'utf8'));
+                expect(Object.keys(rootPJ.dependencies).length).toBe(0);
+                expect(fs.existsSync(path.join(tmpDir, 'node_modules', 'cordova-android'))).toBe(false);
+
+                return fetch('https://github.com/apache/cordova-ios.git#rel/4.1.1', tmpDir,
opts);
+            })
+            .then(function (result) {
+                var pkgJSON = require(path.join(result, 'package.json'));
+                expect(result).toBeDefined();
+                expect(fs.existsSync(result)).toBe(true);
+                expect(pkgJSON.name).toBe('cordova-ios');
+                expect(pkgJSON.version).toBe('4.1.1');
+
+                var rootPJ = JSON.parse(fs.readFileSync(path.join(tmpDir, 'package.json'),
'utf8'));
+                expect(rootPJ.dependencies['cordova-ios']).toBe('git+https://github.com/apache/cordova-ios.git#rel/4.1.1');
+
+                return uninstall('cordova-ios', tmpDir, opts);
+            })
+            .then(function () {
+                var rootPJ = JSON.parse(fs.readFileSync(path.join(tmpDir, 'package.json'),
'utf8'));
+                expect(Object.keys(rootPJ.dependencies).length).toBe(0);
+                expect(fs.existsSync(path.join(tmpDir, 'node_modules', 'cordova-ios'))).toBe(false);
+
+                return fetch('https://github.com/apache/cordova-android.git#4.1.x', tmpDir,
opts);
+            })
+            .then(function (result) {
+                var pkgJSON = JSON.parse(fs.readFileSync(path.join(result, 'package.json'),
'utf8'));
+                expect(result).toBeDefined();
+                expect(fs.existsSync(result)).toBe(true);
+                expect(pkgJSON.name).toBe('cordova-android');
+                expect(pkgJSON.version).toBe('4.1.1');
+
+                var rootPJ = JSON.parse(fs.readFileSync(path.join(tmpDir, 'package.json'),
'utf8'));
+                expect(rootPJ.dependencies['cordova-android']).toBe('git+https://github.com/apache/cordova-android.git#4.1.x');
+
+                return uninstall('cordova-android', tmpDir, opts);
+            })
+            .fail(function (err) {
+                console.error(err);
+                expect(err).toBeUndefined();
+            })
+            .fin(done);
     }, 150000);
 });
 
 describe('plugin fetch/uninstall test with --save', function () {
 
     var tmpDir = helpers.tmpDir('plug_fetch_save');
-    var opts = {'save':true};
+    var opts = {'save': true};
 
-    beforeEach(function() {
-        //copy package.json from spec directory to tmpDir
-        shell.cp('spec/testpkg.json', path.join(tmpDir,'package.json'));
+    beforeEach(function () {
+        // copy package.json from spec directory to tmpDir
+        shell.cp('spec/testpkg.json', path.join(tmpDir, 'package.json'));
         process.chdir(tmpDir);
     });
 
-    afterEach(function() {
-        process.chdir(path.join(__dirname, '..'));  // Needed to rm the dir on Windows.
+    afterEach(function () {
+        process.chdir(path.join(__dirname, '..')); // Needed to rm the dir on Windows.
         shell.rm('-rf', tmpDir);
     });
 
-    it('should fetch and uninstall a cordova plugin via git commit sha', function(done) {
+    it('should fetch and uninstall a cordova plugin via git commit sha', function (done)
{
         fetch('https://github.com/apache/cordova-plugin-contacts.git#7db612115755c2be73a98dda76ff4c5fd9d8a575',
tmpDir, opts)
-        .then(function(result) {
-            var pkgJSON = require(path.join(result,'package.json'));
-            expect(result).toBeDefined();
-            expect(fs.existsSync(result)).toBe(true);
-            expect(pkgJSON.name).toBe('cordova-plugin-contacts');
-            expect(pkgJSON.version).toBe('2.0.2-dev');
-
-            var rootPJ = require(path.join(tmpDir,'package.json'));
-            expect(rootPJ.dependencies['cordova-plugin-contacts']).toBe('git+https://github.com/apache/cordova-plugin-contacts.git#7db612115755c2be73a98dda76ff4c5fd9d8a575');
-
-            return uninstall('cordova-plugin-contacts', tmpDir, opts);
-        })
-        .then(function() {
-            var rootPJ = JSON.parse(fs.readFileSync(path.join(tmpDir,'package.json'), 'utf8'));
-            expect(Object.keys(rootPJ.dependencies).length).toBe(0);
-            expect(fs.existsSync(path.join(tmpDir,'node_modules', 'cordova-plugin-contacts'))).toBe(false);
-        })
-        .fail(function(err) {
-            console.error(err);
-            expect(err).toBeUndefined();
-        })
-        .fin(done);
+            .then(function (result) {
+                var pkgJSON = require(path.join(result, 'package.json'));
+                expect(result).toBeDefined();
+                expect(fs.existsSync(result)).toBe(true);
+                expect(pkgJSON.name).toBe('cordova-plugin-contacts');
+                expect(pkgJSON.version).toBe('2.0.2-dev');
+
+                var rootPJ = require(path.join(tmpDir, 'package.json'));
+                expect(rootPJ.dependencies['cordova-plugin-contacts']).toBe('git+https://github.com/apache/cordova-plugin-contacts.git#7db612115755c2be73a98dda76ff4c5fd9d8a575');
+
+                return uninstall('cordova-plugin-contacts', tmpDir, opts);
+            })
+            .then(function () {
+                var rootPJ = JSON.parse(fs.readFileSync(path.join(tmpDir, 'package.json'),
'utf8'));
+                expect(Object.keys(rootPJ.dependencies).length).toBe(0);
+                expect(fs.existsSync(path.join(tmpDir, 'node_modules', 'cordova-plugin-contacts'))).toBe(false);
+            })
+            .fail(function (err) {
+                console.error(err);
+                expect(err).toBeUndefined();
+            })
+            .fin(done);
     }, 30000);
 });
 
@@ -207,82 +206,82 @@ describe('test trimID method for npm and git', function () {
     var tmpDir;
     var opts = {};
 
-    beforeEach(function() {
+    beforeEach(function () {
         tmpDir = helpers.tmpDir('plug_trimID');
         process.chdir(tmpDir);
     });
 
-    afterEach(function() {
-        process.chdir(path.join(__dirname, '..'));  // Needed to rm the dir on Windows.
+    afterEach(function () {
+        process.chdir(path.join(__dirname, '..')); // Needed to rm the dir on Windows.
         shell.rm('-rf', tmpDir);
     });
 
-    it('should fetch the same cordova plugin twice in a row', function(done) {
+    it('should fetch the same cordova plugin twice in a row', function (done) {
         fetch('cordova-plugin-device', tmpDir, opts)
-        .then(function(result) {
-            var pkgJSON = require(path.join(result,'package.json'));
-            expect(result).toBeDefined();
-            expect(fs.existsSync(result)).toBe(true);
-            expect(pkgJSON.name).toBe('cordova-plugin-device');
-
-            return fetch('https://github.com/apache/cordova-plugin-media.git', tmpDir, opts);
-        })
-        .then(function(result) {
-            var pkgJSON = require(path.join(result,'package.json'));
-            expect(result).toBeDefined();
-            expect(fs.existsSync(result)).toBe(true);
-            expect(pkgJSON.name).toBe('cordova-plugin-media');
-
-            //refetch to trigger trimID
-            return fetch('cordova-plugin-device', tmpDir, opts);
-
-        })
-        .then(function(result) {
-            expect(result).toBeDefined();
-            expect(fs.existsSync(result)).toBe(true);
-            expect(result).toMatch('cordova-plugin-device');
-
-            //refetch to trigger trimID
-            return fetch('https://github.com/apache/cordova-plugin-media.git', tmpDir, opts);
-        })
-        .then(function(result) {
-            expect(result).toBeDefined();
-            expect(fs.existsSync(result)).toBe(true);
-            expect(result).toMatch('cordova-plugin-media');
-
-            //refetch to trigger trimID, this time no .git
-            return fetch('https://github.com/apache/cordova-plugin-media', tmpDir, opts);
-        })
-        .then(function(result) {
-            expect(result).toBeDefined();
-            expect(fs.existsSync(result)).toBe(true);
-            expect(result).toMatch('cordova-plugin-media');
-        })
-        .fail(function(err) {
-            console.error(err);
-            expect(err).toBeUndefined();
-        })
-        .fin(done);
+            .then(function (result) {
+                var pkgJSON = require(path.join(result, 'package.json'));
+                expect(result).toBeDefined();
+                expect(fs.existsSync(result)).toBe(true);
+                expect(pkgJSON.name).toBe('cordova-plugin-device');
+
+                return fetch('https://github.com/apache/cordova-plugin-media.git', tmpDir,
opts);
+            })
+            .then(function (result) {
+                var pkgJSON = require(path.join(result, 'package.json'));
+                expect(result).toBeDefined();
+                expect(fs.existsSync(result)).toBe(true);
+                expect(pkgJSON.name).toBe('cordova-plugin-media');
+
+                // refetch to trigger trimID
+                return fetch('cordova-plugin-device', tmpDir, opts);
+
+            })
+            .then(function (result) {
+                expect(result).toBeDefined();
+                expect(fs.existsSync(result)).toBe(true);
+                expect(result).toMatch('cordova-plugin-device');
+
+                // refetch to trigger trimID
+                return fetch('https://github.com/apache/cordova-plugin-media.git', tmpDir,
opts);
+            })
+            .then(function (result) {
+                expect(result).toBeDefined();
+                expect(fs.existsSync(result)).toBe(true);
+                expect(result).toMatch('cordova-plugin-media');
+
+                // refetch to trigger trimID, this time no .git
+                return fetch('https://github.com/apache/cordova-plugin-media', tmpDir, opts);
+            })
+            .then(function (result) {
+                expect(result).toBeDefined();
+                expect(fs.existsSync(result)).toBe(true);
+                expect(result).toMatch('cordova-plugin-media');
+            })
+            .fail(function (err) {
+                console.error(err);
+                expect(err).toBeUndefined();
+            })
+            .fin(done);
     }, 40000);
 
-    it('should fetch same plugin twice in a row if git repo name differ from plugin id',
function(done) {
+    it('should fetch same plugin twice in a row if git repo name differ from plugin id',
function (done) {
         fetch('https://github.com/AzureAD/azure-activedirectory-library-for-cordova.git',
tmpDir, opts)
-        .then(function(result) {
-            expect(result).toBeDefined();
-            expect(fs.existsSync(result)).toBe(true);
-            expect(result).toMatch('cordova-plugin-ms-adal');
-            return fetch('https://github.com/AzureAD/azure-activedirectory-library-for-cordova.git',
tmpDir, opts);
-        })
-        .then(function(result) {
-            expect(result).toBeDefined();
-            expect(fs.existsSync(result)).toBe(true);
-            expect(result).toMatch('cordova-plugin-ms-adal');
-        })
-        .fail(function(err) {
-            console.error(err);
-            expect(err).toBeUndefined();
-        })
-        .fin(done);
+            .then(function (result) {
+                expect(result).toBeDefined();
+                expect(fs.existsSync(result)).toBe(true);
+                expect(result).toMatch('cordova-plugin-ms-adal');
+                return fetch('https://github.com/AzureAD/azure-activedirectory-library-for-cordova.git',
tmpDir, opts);
+            })
+            .then(function (result) {
+                expect(result).toBeDefined();
+                expect(fs.existsSync(result)).toBe(true);
+                expect(result).toMatch('cordova-plugin-ms-adal');
+            })
+            .fail(function (err) {
+                console.error(err);
+                expect(err).toBeUndefined();
+            })
+            .fin(done);
     }, 30000);
 });
 
@@ -291,25 +290,25 @@ describe('fetch failure with unknown module', function () {
     var tmpDir = helpers.tmpDir('fetch_fails_npm');
     var opts = {};
 
-    beforeEach(function() {
+    beforeEach(function () {
         process.chdir(tmpDir);
     });
 
-    afterEach(function() {
-        process.chdir(path.join(__dirname, '..'));  // Needed to rm the dir on Windows.
+    afterEach(function () {
+        process.chdir(path.join(__dirname, '..')); // Needed to rm the dir on Windows.
         shell.rm('-rf', tmpDir);
     });
 
-    it('should fail fetching a module that does not exist on npm', function(done) {
+    it('should fail fetching a module that does not exist on npm', function (done) {
         fetch('NOTAMODULE', tmpDir, opts)
-        .then(function(result) {
-            console.log('This should fail and it should not be seen');
-        })
-        .fail(function(err) {
-            expect(err.message.code).toBe(1);
-            expect(err).toBeDefined();
-        })
-        .fin(done);
+            .then(function (result) {
+                console.log('This should fail and it should not be seen');
+            })
+            .fail(function (err) {
+                expect(err.message.code).toBe(1);
+                expect(err).toBeDefined();
+            })
+            .fin(done);
     }, 30000);
 });
 
@@ -318,25 +317,25 @@ describe('fetch failure with git subdirectory', function () {
     var tmpDir = helpers.tmpDir('fetch_fails_subdirectory');
     var opts = {};
 
-    beforeEach(function() {
+    beforeEach(function () {
         process.chdir(tmpDir);
     });
 
-    afterEach(function() {
-        process.chdir(path.join(__dirname, '..'));  // Needed to rm the dir on Windows.
+    afterEach(function () {
+        process.chdir(path.join(__dirname, '..')); // Needed to rm the dir on Windows.
         shell.rm('-rf', tmpDir);
     });
 
-    it('should fail fetching a giturl which contains a subdirectory', function(done) {
+    it('should fail fetching a giturl which contains a subdirectory', function (done) {
         fetch('https://github.com/apache/cordova-plugins.git#:keyboard', tmpDir, opts)
-        .then(function(result) {
-            console.log('This should fail and it should not be seen');
-        })
-        .fail(function(err) {
-            expect(err.message.code).toBe(1);
-            expect(err).toBeDefined();
-        })
-        .fin(done);
+            .then(function (result) {
+                console.log('This should fail and it should not be seen');
+            })
+            .fail(function (err) {
+                expect(err.message.code).toBe(1);
+                expect(err).toBeDefined();
+            })
+            .fin(done);
     }, 30000);
 });
 
@@ -345,27 +344,27 @@ describe('scoped plugin fetch/uninstall tests via npm', function ()
{
     var tmpDir = helpers.tmpDir('scoped_plug_fetch');
     var opts = {};
 
-    beforeEach(function() {
+    beforeEach(function () {
         process.chdir(tmpDir);
     });
 
-    afterEach(function() {
-        process.chdir(path.join(__dirname, '..'));  // Needed to rm the dir on Windows.
+    afterEach(function () {
+        process.chdir(path.join(__dirname, '..')); // Needed to rm the dir on Windows.
         shell.rm('-rf', tmpDir);
     });
 
-    it('should fetch a scoped plugin from npm', function(done) {
+    it('should fetch a scoped plugin from npm', function (done) {
         fetch('@stevegill/cordova-plugin-device', tmpDir, opts)
-        .then(function(result) {
-            var pkgJSON = require(path.join(result,'package.json'));
-            expect(result).toBeDefined();
-            expect(fs.existsSync(result)).toBe(true);
-            expect(pkgJSON.name).toBe('@stevegill/cordova-plugin-device');
-        })
-        .fail(function(err) {
-            console.error(err);
-            expect(err).toBeUndefined();
-        })
-        .fin(done);
+            .then(function (result) {
+                var pkgJSON = require(path.join(result, 'package.json'));
+                expect(result).toBeDefined();
+                expect(fs.existsSync(result)).toBe(true);
+                expect(pkgJSON.name).toBe('@stevegill/cordova-plugin-device');
+            })
+            .fail(function (err) {
+                console.error(err);
+                expect(err).toBeUndefined();
+            })
+            .fin(done);
     }, 30000);
 });

http://git-wip-us.apache.org/repos/asf/cordova-fetch/blob/06441bb5/spec/helpers.js
----------------------------------------------------------------------
diff --git a/spec/helpers.js b/spec/helpers.js
index 8fd325b..e081a78 100644
--- a/spec/helpers.js
+++ b/spec/helpers.js
@@ -17,17 +17,17 @@
  under the License.
  */
 
-var path    = require('path'),
-    fs      = require('fs'),
-    shell   = require('shelljs'),
-    os      = require('os');
+var path = require('path');
+var fs = require('fs');
+var shell = require('shelljs');
+var os = require('os');
 
 module.exports.tmpDir = function (subdir) {
     var dir = path.join(os.tmpdir(), 'e2e-test');
     if (subdir) {
         dir = path.join(dir, subdir);
     }
-    if(fs.existsSync(dir)) {
+    if (fs.existsSync(dir)) {
         shell.rm('-rf', dir);
     }
     shell.mkdir('-p', dir);


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


Mime
View raw message