CB-10681: added test to confirm we aren't using cached template
diff --git a/index.js b/index.js
index 3f29dd2..d29b8a4 100644
--- a/index.js
+++ b/index.js
@@ -195,7 +195,6 @@
         events.emit('verbose', 'Copying assets."');
         isGit = cfg.lib.www.template && isUrl(cfg.lib.www.url);
         isNPM = cfg.lib.www.template && (cfg.lib.www.url.indexOf('@') > -1 || !fs.existsSync(path.resolve(cfg.lib.www.url))) && !isGit;
-
         //Always use cordova fetch to obtain the npm or git template
         if (isGit || isNPM) {
             //Saved to .Cordova folder (ToDo: Delete installed template after using)
diff --git a/package.json b/package.json
index 4f05f69..371e798 100644
--- a/package.json
+++ b/package.json
@@ -34,7 +34,8 @@
   },
   "devDependencies": {
     "jasmine": "^2.4.1",
-    "jshint": "2.5.8"
+    "jshint": "2.5.8",
+    "semver": "^5.3.0"
   },
   "scripts": {
     "test": "npm run jshint && npm run jasmine",
diff --git a/spec/create.spec.js b/spec/create.spec.js
index 78ca432..407ee46 100644
--- a/spec/create.spec.js
+++ b/spec/create.spec.js
@@ -24,6 +24,7 @@
     ConfigParser = require('cordova-common').ConfigParser,
     create = require('../index'),
     fs = require('fs'),
+    semver = require('semver'),
     CordovaLogger = require('cordova-common').CordovaLogger.get().setLevel('error');
 
 var tmpDir = helpers.tmpDir('create_test');
@@ -31,6 +32,13 @@
 var appId = 'org.testing';
 var project = path.join(tmpDir, appName);
 
+// Global configuration paths
+var global_config_path = process.env.CORDOVA_HOME;
+if (!global_config_path) {
+    var HOME = process.env[(process.platform.slice(0, 3) == 'win') ? 'USERPROFILE' : 'HOME'];
+    global_config_path = path.join(HOME, '.cordova');
+}
+
 var configSubDirPkgJson = {
     lib: {
         www: {
@@ -61,11 +69,21 @@
     }
 };
 
+var configNPMold = {
+    lib: {
+        www: {
+            template: true,
+            url: 'phonegap-template-vue-f7-tabs@1.0.0',
+            version: ''
+        }
+    }
+};
+
 var configNPM = {
     lib: {
         www: {
             template: true,
-            url: 'cordova-app-hello-world',
+            url: 'phonegap-template-vue-f7-tabs',
             version: ''
         }
     }
@@ -197,18 +215,29 @@
         .fin(done);
     }, 60000);
 
-    // it('should successfully run with NPM package', function(done) {
-    //     // Call cordova create with no args, should return help.
-  
-    //     // Create a real project
-    //     return create(project, appId, appName, configNPM)
-    //     .then(checkProject)
-    //     .fail(function(err) {
-    //         console.log(err && err.stack);
-    //         expect(err).toBeUndefined();
-    //     })
-    //     .fin(done);
-    // }, 60000);
+    it('should successfully run with NPM package and not use old cache of template on second create', function(done) {
+        var templatePkgJsonPath = path.join(global_config_path, 'node_modules', 'phonegap-template-vue-f7-tabs', 'package.json');
+        // Call cordova create with no args, should return help.
+        // Create a real project
+        //uses phonegap-template-vue-f7-tabs
+        return create(project, appId, appName, configNPMold)
+        .then(checkProject)
+        .then(function() {
+            shell.rm('-rf', project);
+            delete require.cache[require.resolve(templatePkgJsonPath)];
+            var pkgJson = require(templatePkgJsonPath);
+            expect(pkgJson.version).toBe('1.0.0');
+            return create(project, appId, appName, configNPM);
+        }).then(function() {
+            delete require.cache[require.resolve(templatePkgJsonPath)];
+            var pkgJson = require(templatePkgJsonPath);
+            expect(semver.gt(pkgJson.version, '1.0.0')).toBeTruthy();
+        }).fail(function(err) {
+            console.log(err && err.stack);
+            expect(err).toBeUndefined();
+        })
+        .fin(done);
+    }, 60000);
     
     it('should successfully run with template not having a package.json at toplevel', function(done) {
         // Call cordova create with no args, should return help.
@@ -415,6 +444,7 @@
                     
                     // Check that we got the right config.xml
                     expect(configXml.description()).toEqual('this is the correct config.xml');
+                    
                     delete require.cache[require.resolve(path.join(project, 'package.json'))];
                     // Check that we got package.json (the correct one) and it was changed
                     var pkjson = require(path.join(project, 'package.json'));
@@ -498,10 +528,5 @@
                     .fin(done);
             }, 60000);
 
-        });
-
-    
-
-
-                
+        });     
 });