cordova-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ste...@apache.org
Subject [01/32] cordova-fetch git commit: CB-9858 merging initial fetch work for plugin and platform fetching
Date Tue, 06 Jun 2017 00:44:23 GMT
Repository: cordova-fetch
Updated Branches:
  refs/heads/master [created] 8a2021c48


CB-9858 merging initial fetch work for plugin and platform fetching


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

Branch: refs/heads/master
Commit: c8864a9b3df674c14a467241857fb96f4664a537
Parents: 
Author: Steve Gill <stevengill97@gmail.com>
Authored: Mon May 9 14:18:21 2016 -0700
Committer: Steve Gill <stevengill97@gmail.com>
Committed: Mon May 9 14:18:21 2016 -0700

----------------------------------------------------------------------
 .jshintrc                 |  12 ++
 README.md                 |  36 +++++
 RELEASENOTES.md           |  22 +++
 index.js                  | 236 ++++++++++++++++++++++++++++++++
 package.json              |  43 ++++++
 spec/fetch.spec.js        | 300 +++++++++++++++++++++++++++++++++++++++++
 spec/helpers.js           |  16 +++
 spec/support/jasmine.json |  11 ++
 spec/testpkg.json         |  11 ++
 9 files changed, 687 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-fetch/blob/c8864a9b/.jshintrc
----------------------------------------------------------------------
diff --git a/.jshintrc b/.jshintrc
new file mode 100644
index 0000000..62edb5c
--- /dev/null
+++ b/.jshintrc
@@ -0,0 +1,12 @@
+{
+  "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/c8864a9b/README.md
----------------------------------------------------------------------
diff --git a/README.md b/README.md
new file mode 100644
index 0000000..5cc75e9
--- /dev/null
+++ b/README.md
@@ -0,0 +1,36 @@
+<!--
+#
+# 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.
+#
+-->
+
+# cordova-fetch
+
+This module is used for fetching modules from npm and gitURLs. It fetches the modules via
`npm install`. 
+
+Usage:
+```
+var fetch = require('cordova-fetch');
+
+fetch(spec, dest, opts);
+```
+
+`spec` can be a string containg a npm `packageID` or a `git URL`. 
+`dest` is string of the directory location you wish to `npm install` these modules.
+`opts` is an Object of options cordova fetch handles. Currently, fetch only support the `save`
option.
+    eg. `{'save':true}`

http://git-wip-us.apache.org/repos/asf/cordova-fetch/blob/c8864a9b/RELEASENOTES.md
----------------------------------------------------------------------
diff --git a/RELEASENOTES.md b/RELEASENOTES.md
new file mode 100644
index 0000000..305cdc6
--- /dev/null
+++ b/RELEASENOTES.md
@@ -0,0 +1,22 @@
+<!--
+#
+# 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.
+#
+-->
+# Cordova-fetch Release Notes
+

http://git-wip-us.apache.org/repos/asf/cordova-fetch/blob/c8864a9b/index.js
----------------------------------------------------------------------
diff --git a/index.js b/index.js
new file mode 100644
index 0000000..0e3c3fe
--- /dev/null
+++ b/index.js
@@ -0,0 +1,236 @@
+/**
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements.  See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership.  The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ 'License'); you may not use this file except in compliance
+ with the License.  You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ 'AS IS' BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied.  See the License for the
+ specific language governing permissions and limitations
+ under the License.
+ */
+
+var Q = require('q');
+var shell = require('shelljs');
+var superspawn = require('cordova-common').superspawn;
+var events = require('cordova-common').events;
+var depls = require('dependency-ls');
+var path = require('path');
+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
+ * @param {String} dest     destination of where to install the module
+ * @param {Object} opts     [opts={save:true}] options to pass to fetch module
+ *
+ * @return {String|Promise}    Returns string of the absolute path to the installed module.
+ *
+ */
+module.exports = function(target, dest, opts) {
+    var fetchArgs = ['install'];
+    opts = opts || {};
+    var tree1;
+
+    //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'));
+            }
+        
+            //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);
+    }) 
+    .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. 
+ * cordova-fetch will use trimID in that case.
+ *
+ * @param {Object} obj1     json object representing installed modules before latest npm
install
+ * @param {Object} obj2     json object representing installed modules after latest npm install
+ *
+ * @return {String}         String containing the key value of the difference between the
two objects
+ *
+ */
+function getJsonDiff(obj1, obj2) {
+    var 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 (key.search(re) === -1) {
+            if(obj2[key] != obj1[key]) result = key;
+        }
+    }
+    return result;
+}
+
+/*
+ * 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 
+ * get the moduleID of the installed module.
+ *
+ * @param {String} target    target that was passed into cordova-fetch.
+ *                           can be moduleID, moduleID@version or gitURL
+ *
+ * @return {String} ID       moduleID without version.
+ */
+function trimID(target) {
+    var parts;
+
+    //If GITURL, set target to repo name
+    if (isUrl(target)) {
+        var re = /.*\/(.*).git/;
+        parts = target.match(re);
+        target = parts[1];
+    }
+    
+    //strip away everything after '@'
+    if(target.indexOf('@') != -1) {
+        parts = target.split('@');
+        target = parts[0];
+    }        
+    
+    return target;
+}
+
+/* 
+ * Takes the moduleID and destination and returns an absolute path to the module
+ *
+ * @param {String} id       the packageID
+ * @param {String} dest     destination of where to fetch the modules
+ *
+ * @return {String|Error}  Returns the absolute url for the module or throws a error
+ *
+ */
+
+function getPath(id, dest) {
+    var finalDest = path.resolve(path.join(dest, id));
+    
+    //Sanity check it exists
+    if(fs.existsSync(finalDest)){
+        return finalDest;
+    } else return Q.reject(new CordovaError('Failed to get absolute path to installed module'));
+}
+
+
+/*
+ * Checks to see if npm is installed on the users system
+ * @return {Promise|Error} Returns true or a cordova error.
+ */
+
+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 
+ *
+ * @param {String} target   the packageID
+ * @param {String} dest     destination of where to uninstall the module from
+ * @param {Object} opts     [opts={save:true}] options to pass to npm uninstall
+ *
+ * @return {Promise|Error}    Returns a promise with the npm uninstall output or an error.
+ *
+ */
+module.exports.uninstall = function(target, dest, opts) {
+    var fetchArgs = ['uninstall'];
+    opts = opts || {};
+
+    //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'); 
+        }
+
+        //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/c8864a9b/package.json
----------------------------------------------------------------------
diff --git a/package.json b/package.json
new file mode 100644
index 0000000..2e7e330
--- /dev/null
+++ b/package.json
@@ -0,0 +1,43 @@
+{
+  "name": "cordova-fetch",
+  "version": "1.0.0-dev",
+  "description": "Apache Cordova fetch module. Fetches from git and npm.",
+  "main": "index.js",
+  "repository": {
+    "type": "git",
+    "url": "git://git-wip-us.apache.org/repos/asf/cordova-lib.git"
+  },
+  "keywords": [
+    "cordova",
+    "fetch",
+    "apache",
+    "ecosystem:cordova",
+    "cordova:tool"
+  ],
+  "author": "Apache Software Foundation",
+  "license": "Apache-2.0",
+  "bugs": {
+    "url": "https://issues.apache.org/jira/browse/CB",
+    "email": "dev@cordova.apache.org"
+  },
+  "dependencies": {
+    "cordova-common": "^1.0.0",
+    "dependency-ls": "^1.0.0",
+    "is-url": "^1.2.1",
+    "q": "^1.4.1",
+    "shelljs": "^0.7.0"
+  },
+  "devDependencies": {
+    "jasmine": "^2.4.1",
+    "jshint": "^2.8.0"
+  },
+  "scripts": {
+    "test": "npm run jshint && npm run jasmine",
+    "jshint": "jshint index.js spec/fetch.spec.js",
+    "jasmine": "jasmine spec/fetch.spec.js"
+  },
+  "engines": {
+    "node": ">= 0.12.0",
+    "npm": ">= 2.5.1"
+  }
+}

http://git-wip-us.apache.org/repos/asf/cordova-fetch/blob/c8864a9b/spec/fetch.spec.js
----------------------------------------------------------------------
diff --git a/spec/fetch.spec.js b/spec/fetch.spec.js
new file mode 100644
index 0000000..2f6513a
--- /dev/null
+++ b/spec/fetch.spec.js
@@ -0,0 +1,300 @@
+/**
+    Licensed to the Apache Software Foundation (ASF) under one
+    or more contributor license agreements.  See the NOTICE file
+    distributed with this work for additional information
+    regarding copyright ownership.  The ASF licenses this file
+    to you under the Apache License, Version 2.0 (the
+    "License"); you may not use this file except in compliance
+    with the License.  You may obtain a copy of the License at
+
+    http://www.apache.org/licenses/LICENSE-2.0
+
+    Unless required by applicable law or agreed to in writing,
+    software distributed under the License is distributed on an
+    "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+    KIND, either express or implied.  See the License for the
+    specific language governing permissions and limitations
+    under the License.
+*/
+
+var fetch = require('../index.js');
+var uninstall = require('../index.js').uninstall;
+var shell = require('shelljs');
+var path = require('path');
+var fs = require('fs');
+var helpers = require('./helpers.js');
+
+describe('platform fetch/uninstall tests via npm & git', function () {
+
+    var tmpDir = helpers.tmpDir('plat_fetch');
+    var opts = {};
+
+    beforeEach(function() {
+        process.chdir(tmpDir);
+    });
+    
+    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)
{
+        
+        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);
   
+        })
+        .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};
+    
+    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.
+        shell.rm('-rf', tmpDir);
+    });
+
+    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);
+    }, 60000);
+});
+
+describe('plugin fetch/uninstall test with --save', function () {
+
+    var tmpDir = helpers.tmpDir('plug_fetch_save');
+    var opts = {'save':true};
+    
+    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.
+        shell.rm('-rf', tmpDir);
+    });
+
+    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);
+    }, 30000);
+});
+
+describe('test trimID method for npm and git', function () {
+
+    var tmpDir = helpers.tmpDir('plug_trimID');
+    var opts = {};
+    
+    beforeEach(function() {
+        process.chdir(tmpDir);
+    });
+    
+    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) {
+        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);
+
+            //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);
+        })
+        .fail(function(err) {
+            console.error(err);
+            expect(err).toBeUndefined();
+        })
+        .fin(done);
+    }, 30000);
+});
+
+describe('fetch failure with unknown module', function () {
+
+    var tmpDir = helpers.tmpDir('fetch_fails_npm');
+    var opts = {};
+    
+    beforeEach(function() {
+        process.chdir(tmpDir);
+    });
+    
+    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) {
+        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);
+    }, 30000);
+});
+
+describe('fetch failure with git subdirectory', function () {
+
+    var tmpDir = helpers.tmpDir('fetch_fails_subdirectory');
+    var opts = {};
+
+    beforeEach(function() {
+        process.chdir(tmpDir);
+    });
+    
+    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) {
+        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);
+    }, 30000);
+});

http://git-wip-us.apache.org/repos/asf/cordova-fetch/blob/c8864a9b/spec/helpers.js
----------------------------------------------------------------------
diff --git a/spec/helpers.js b/spec/helpers.js
new file mode 100644
index 0000000..ee3f57b
--- /dev/null
+++ b/spec/helpers.js
@@ -0,0 +1,16 @@
+var path    = require('path'),
+    fs      = require('fs'),
+    shell   = require('shelljs'),
+    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)) {
+        shell.rm('-rf', dir);
+    }
+    shell.mkdir('-p', dir);
+    return dir;
+};

http://git-wip-us.apache.org/repos/asf/cordova-fetch/blob/c8864a9b/spec/support/jasmine.json
----------------------------------------------------------------------
diff --git a/spec/support/jasmine.json b/spec/support/jasmine.json
new file mode 100644
index 0000000..3ea3166
--- /dev/null
+++ b/spec/support/jasmine.json
@@ -0,0 +1,11 @@
+{
+  "spec_dir": "spec",
+  "spec_files": [
+    "**/*[sS]pec.js"
+  ],
+  "helpers": [
+    "helpers/**/*.js"
+  ],
+  "stopSpecOnExpectationFailure": false,
+  "random": false
+}

http://git-wip-us.apache.org/repos/asf/cordova-fetch/blob/c8864a9b/spec/testpkg.json
----------------------------------------------------------------------
diff --git a/spec/testpkg.json b/spec/testpkg.json
new file mode 100644
index 0000000..94e7f64
--- /dev/null
+++ b/spec/testpkg.json
@@ -0,0 +1,11 @@
+{
+  "name": "test",
+  "version": "1.0.0",
+  "description": "",
+  "main": "fetch.spec.js",
+  "scripts": {
+    "test": "echo \"Error: no test specified\" && exit 1"
+  },
+  "author": "",
+  "license": "ISC"
+}


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


Mime
View raw message