You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by st...@apache.org on 2017/01/12 01:14:23 UTC

[2/3] cordova-cli git commit: CB-12018 : updated tests and package.json to function with jasmine

CB-12018 : updated tests and package.json to function with jasmine


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

Branch: refs/heads/master
Commit: caa8306c246f08e43d1596ae2c13b6d9aaab831c
Parents: 2652919
Author: audreyso <au...@adobe.com>
Authored: Wed Jan 11 10:03:57 2017 -0800
Committer: audreyso <au...@adobe.com>
Committed: Wed Jan 11 14:51:02 2017 -0800

----------------------------------------------------------------------
 .jscs.json       | 24 ++++++++++++++++++++++++
 .jshintignore    |  4 ++++
 package.json     |  9 ++++++---
 spec/cli.spec.js | 49 +++++++++++++++++++++++--------------------------
 src/cli.js       | 18 ++++++++++--------
 src/create.js    | 10 +++++-----
 src/telemetry.js |  9 +++++----
 7 files changed, 77 insertions(+), 46 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-cli/blob/caa8306c/.jscs.json
----------------------------------------------------------------------
diff --git a/.jscs.json b/.jscs.json
new file mode 100644
index 0000000..5cc7e26
--- /dev/null
+++ b/.jscs.json
@@ -0,0 +1,24 @@
+{
+    "disallowMixedSpacesAndTabs": true,
+    "disallowTrailingWhitespace": true,
+    "validateLineBreaks": "LF",
+    "validateIndentation": 4,
+    "requireLineFeedAtFileEnd": true,
+
+    "disallowSpaceAfterPrefixUnaryOperators": true,
+    "disallowSpaceBeforePostfixUnaryOperators": true,
+    "requireSpaceAfterLineComment": true,
+    "requireCapitalizedConstructors": true,
+
+    "disallowSpacesInNamedFunctionExpression": {
+        "beforeOpeningRoundBrace": true
+    },
+
+    "requireSpaceAfterKeywords": [
+      "if",
+      "else",
+      "for",
+      "while",
+      "do"
+    ]
+}

http://git-wip-us.apache.org/repos/asf/cordova-cli/blob/caa8306c/.jshintignore
----------------------------------------------------------------------
diff --git a/.jshintignore b/.jshintignore
new file mode 100644
index 0000000..4422d84
--- /dev/null
+++ b/.jshintignore
@@ -0,0 +1,4 @@
+spec-cordova/fixtures/*
+spec-plugman/projects/*
+spec-plugman/plugins/*
+spec-cordova/temp/*

http://git-wip-us.apache.org/repos/asf/cordova-cli/blob/caa8306c/package.json
----------------------------------------------------------------------
diff --git a/package.json b/package.json
index 095ad4e..0c02e53 100644
--- a/package.json
+++ b/package.json
@@ -11,8 +11,10 @@
     "cordova": "./bin/cordova"
   },
   "scripts": {
-    "test": "jasmine --captureExceptions --color",
-    "cover": "jasmine"
+    "test": "npm run jshint && npm run jasmine",
+    "jshint": "jshint spec && jshint src",
+    "cover": "istanbul cover --root src --print detail jasmine",
+    "jasmine": "jasmine --captureExceptions --color"
   },
   "repository": {
     "type": "git",
@@ -38,7 +40,8 @@
   },
   "devDependencies": {
     "jasmine": "^2.5.2",
-    "istanbul": "^0.4.5"
+    "istanbul": "^0.4.5",
+    "jshint": "^2.9.4"
   },
   "author": "Anis Kadri",
   "contributors": [

http://git-wip-us.apache.org/repos/asf/cordova-cli/blob/caa8306c/spec/cli.spec.js
----------------------------------------------------------------------
diff --git a/spec/cli.spec.js b/spec/cli.spec.js
index 96b62c6..6a6d2a4 100644
--- a/spec/cli.spec.js
+++ b/spec/cli.spec.js
@@ -55,33 +55,30 @@ describe("cordova cli", function () {
     });
 
     describe("options", function () {
-      describe("version", function () {
-        var version = require("../package").version;
-
-        beforeEach(function () {
-        });
+        describe("version", function () {
+            var version = require("../package").version;
         
-        it("Test#001 : will spit out the version with -v", function (done) {
-          cli(["node", "cordova", "-v"], function() {
-            expect(logger.results.calls.mostRecent().args[0]).toMatch(version);
-            done();
-          });
-        }, 60000);
+            it("Test#001 : will spit out the version with -v", function (done) {
+              cli(["node", "cordova", "-v"], function() {
+                expect(logger.results.calls.mostRecent().args[0]).toMatch(version);
+                done();
+              });
+            }, 60000);
 
-        it("Test#002 : will spit out the version with --version", function (done) {  
-          cli(["node", "cordova", "--version"], function () {
-            expect(logger.results.calls.mostRecent().args[0]).toMatch(version);
-            done()
-          }, 60000);
-        });
+            it("Test#002 : will spit out the version with --version", function (done) {  
+              cli(["node", "cordova", "--version"], function () {
+                expect(logger.results.calls.mostRecent().args[0]).toMatch(version);
+                done()
+              }, 60000);
+            });
 
-        it("Test#003 : will spit out the version with -v anywhere", function (done) {
-          cli(["node", "cordova", "one", "-v", "three"], function () {
-            expect(logger.results.calls.mostRecent().args[0]).toMatch(version);
-            done();
-          });
-        }, 60000);
-      });
+            it("Test#003 : will spit out the version with -v anywhere", function (done) {
+              cli(["node", "cordova", "one", "-v", "three"], function () {
+                expect(logger.results.calls.mostRecent().args[0]).toMatch(version);
+                done();
+              });
+            }, 60000);
+        });
     });
 
     describe("Test#004 : project commands other than plugin and platform", function () {
@@ -131,11 +128,11 @@ describe("cordova cli", function () {
             });
         });
     });
-
+    
     describe("create", function () {
         beforeEach(function () {
             spyOn(cordova.raw, "create").and.returnValue(Q());
-            // spyOn(cordova_lib, "CordovaError");
+            spyOn(cordova_lib, "CordovaError");
         });
 
         it("Test#011 : calls cordova raw create", function (done) {

http://git-wip-us.apache.org/repos/asf/cordova-cli/blob/caa8306c/src/cli.js
----------------------------------------------------------------------
diff --git a/src/cli.js b/src/cli.js
index 5133cd8..db8d8a4 100644
--- a/src/cli.js
+++ b/src/cli.js
@@ -24,7 +24,6 @@
 
 
 var path = require('path'),
-    fs = require('fs'),
     help = require('./help'),
     nopt,
     _,
@@ -39,6 +38,9 @@ var cordova_lib = require('cordova-lib'),
     events = cordova_lib.events,
     logger = require('cordova-common').CordovaLogger.get();
 
+var msg,
+    badPlatforms;
+
 
 /*
  * init
@@ -178,10 +180,10 @@ function handleTelemetryCmd(subcommand, isOptedIn) {
     try {
         if (turnOn) {
             telemetry.turnOn();
-            console.log("Thanks for opting into telemetry to help us improve cordova.");
+            console.log('Thanks for opting into telemetry to help us improve cordova.');
         } else {
             telemetry.turnOff();
-            console.log("You have been opted out of telemetry. To change this, run: cordova telemetry on.");
+            console.log('You have been opted out of telemetry. To change this, run: cordova telemetry on.');
         }
     } catch (ex) {
         cmdSuccess = false;
@@ -288,7 +290,7 @@ function cli(inputArgs) {
     }
 
     if (/^v0.\d+[.\d+]*/.exec(process.version)) { // matches v0.* 
-        var msg = 'Warning: using node version ' + process.version +
+        msg = 'Warning: using node version ' + process.version +
                 ' which has been deprecated. Please upgrade to the latest node version available (v6.x is recommended).';
         logger.warn(msg);
     }
@@ -312,8 +314,8 @@ function cli(inputArgs) {
     var undashed = remain.slice(0, remain.length - unparsedArgs.length);
     var cmd = undashed[0];
     var subcommand;
-    var msg;
     var known_platforms = Object.keys(cordova_lib.cordova_platforms);
+    msg = '';
 
     if ( !cmd || cmd == 'help' || args.help ) {
         if (!args.help && remain[0] == 'help') {
@@ -344,7 +346,7 @@ function cli(inputArgs) {
     if (cmd == 'emulate' || cmd == 'build' || cmd == 'prepare' || cmd == 'compile' || cmd == 'run' || cmd === 'clean') {
         // All options without dashes are assumed to be platform names
         opts.platforms = undashed.slice(1);
-        var badPlatforms = _.difference(opts.platforms, known_platforms);
+        badPlatforms = _.difference(opts.platforms, known_platforms);
         if( !_.isEmpty(badPlatforms) ) {
             msg = 'Unknown platforms: ' + badPlatforms.join(', ');
             throw new CordovaError(msg);
@@ -362,7 +364,7 @@ function cli(inputArgs) {
     } else if (cmd === 'requirements') {
         // All options without dashes are assumed to be platform names
         opts.platforms = undashed.slice(1);
-        var badPlatforms = _.difference(opts.platforms, known_platforms);
+        badPlatforms = _.difference(opts.platforms, known_platforms);
         if( !_.isEmpty(badPlatforms) ) {
             msg = 'Unknown platforms: ' + badPlatforms.join(', ');
             throw new CordovaError(msg);
@@ -413,7 +415,7 @@ function cli(inputArgs) {
                 // CB-9171
                 var eq = s.indexOf('=');
                 if (eq == -1)
-                    throw new CordovaError("invalid variable format: " + s);
+                    throw new CordovaError('invalid variable format: ' + s);
                 var key = s.substr(0, eq).toUpperCase();
                 var val = s.substr(eq + 1, s.length);
                 cli_vars[key] = val;

http://git-wip-us.apache.org/repos/asf/cordova-cli/blob/caa8306c/src/create.js
----------------------------------------------------------------------
diff --git a/src/create.js b/src/create.js
index 8ec2956..8ad7d87 100644
--- a/src/create.js
+++ b/src/create.js
@@ -36,10 +36,10 @@ CordovaCliCreate.prototype.run = function (args, undashed) {
     cfg = this.parseConfig(undashed[4]);
     
     // create(dir, id, name, cfg)
-    cordova.raw.create( undashed[1]  // dir to create the project in
-                      , undashed[2]  // App id
-                      , undashed[3]  // App name
-                      , cfg
+    cordova.raw.create(undashed[1] , // dir to create the project in
+                       undashed[2] , // App id
+                       undashed[3] , // App name
+                       cfg
     ).done();
 };
 
@@ -65,7 +65,7 @@ CordovaCliCreate.prototype.parseConfig = function (jsondata) {
 CordovaCliCreate.prototype.customWww = function (args) {
 
     // handle custom www
-    if (customWww = args['copy-from'] || args['link-to']) {
+    if (!!(customWww = args['copy-from'] || args['link-to'])) {
 
         if (customWww.indexOf(':') != -1) {
             throw new CordovaError(

http://git-wip-us.apache.org/repos/asf/cordova-cli/blob/caa8306c/src/telemetry.js
----------------------------------------------------------------------
diff --git a/src/telemetry.js b/src/telemetry.js
index eea939e..6983884 100644
--- a/src/telemetry.js
+++ b/src/telemetry.js
@@ -46,14 +46,14 @@ function showPrompt() {
 
     var deferred = Q.defer();
     
-    var msg = "May Cordova anonymously report usage statistics to improve the tool over time?";
+    var msg = 'May Cordova anonymously report usage statistics to improve the tool over time?';
     insight.askPermission(msg, function (unused, optIn) {
         var EOL = require('os').EOL;
         if (optIn) {
-            console.log(EOL + "Thanks for opting into telemetry to help us improve cordova.");
+            console.log(EOL + 'Thanks for opting into telemetry to help us improve cordova.');
             track('telemetry', 'on', 'via-cli-prompt-choice', 'successful');
         } else {
-            console.log(EOL + "You have been opted out of telemetry. To change this, run: cordova telemetry on.");
+            console.log(EOL + 'You have been opted out of telemetry. To change this, run: cordova telemetry on.');
             // Always track telemetry opt-outs! (whether opted-in or opted-out)
             track('telemetry', 'off', 'via-cli-prompt-choice', 'successful');
         }
@@ -100,7 +100,8 @@ function isOptedIn() {
  * Has the user already answered the telemetry prompt? (thereby opting in or out?)
  */
 function hasUserOptedInOrOut() {
-    return !(insight.optOut === undefined);
+    var insightOptOut = insight.optOut === undefined;
+    return !(insightOptOut);
 }
 
 /**


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