You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by db...@apache.org on 2015/12/04 00:11:43 UTC

cordova-medic git commit: Fixing linter errors. Adding check to medic-run that aborts the run if the results server is down.

Repository: cordova-medic
Updated Branches:
  refs/heads/master 5fd1c869e -> 09fa69981


Fixing linter errors. Adding check to medic-run that aborts the run if the results server is down.


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

Branch: refs/heads/master
Commit: 09fa6998172fd4a8f33a050f6637e0c2ba0a88dd
Parents: 5fd1c86
Author: Dmitry Blotsky <dm...@gmail.com>
Authored: Thu Dec 3 15:11:26 2015 -0800
Committer: Dmitry Blotsky <dm...@gmail.com>
Committed: Thu Dec 3 15:11:26 2015 -0800

----------------------------------------------------------------------
 lib/couchdb.js     |  69 +++++++++++++--------
 lib/testwait.js    |   5 +-
 lib/util.js        |  15 +++--
 medic/medic-run.js | 155 ++++++++++++++++++++++++++----------------------
 package.json       |   6 +-
 5 files changed, 146 insertions(+), 104 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-medic/blob/09fa6998/lib/couchdb.js
----------------------------------------------------------------------
diff --git a/lib/couchdb.js b/lib/couchdb.js
index c151f0c..340c495 100644
--- a/lib/couchdb.js
+++ b/lib/couchdb.js
@@ -19,6 +19,8 @@
 
 /* jshint node: true */
 
+"use strict";
+
 var request = require('request');
 var follow = require('follow');
 
@@ -41,15 +43,14 @@ db.prototype = {
     get:function(id, callback) {
         // Gets a specific document by id
 
-        var db = this;
         var url = this.db_url + '/' + id;
         request.get(url, function(error, response, body) {
             if (error) {
                 callback(error);
             } else {
-                if (response.statusCode == 200) {
+                if (response.statusCode === 200) {
                     callback(false, JSON.parse(body));
-                } else if (response.statusCode == 404) {
+                } else if (response.statusCode === 404) {
                     callback(true, 404);
                 } else {
                     callback(true, response.statusCode);
@@ -60,15 +61,14 @@ db.prototype = {
     query_view:function(design, view, callback) {
         // Queries a view.
 
-        var db = this;
         var url = this.db_url + '/_design/' + design + '/_view/' + view;
         request.get(url, function(error, response, body) {
             if (error) {
                 callback(error);
             } else {
-                if (response.statusCode == 200) {
+                if (response.statusCode === 200) {
                     callback(false, JSON.parse(body));
-                } else if (response.statusCode == 404) {
+                } else if (response.statusCode === 404) {
                     callback(true, 404);
                 } else {
                     callback(true, response.statusCode);
@@ -78,7 +78,6 @@ db.prototype = {
     },
     clobber:function(id, document, callback) {
         // Overwrites a document
-        var db = this;
         var url = this.db_url + '/' + id;
 
         request.put({
@@ -92,41 +91,54 @@ db.prototype = {
             }
 
             var status = response.statusCode;
-            if (status == 201) callback(false, body);
-            else if (status == 409) {
+            if (status === 201) {
+                callback(false, body);
+            } else if (status === 409) {
                 request.get(url, function(err, resp, bod) {
-                    if (err) callback(err);
-                    else {
-                        if (resp.statusCode == 200) {
+                    if (err) {
+                        callback(err);
+                    } else {
+                        if (resp.statusCode === 200) {
                             var existing = JSON.parse(bod);
                             var rev = existing._rev;
                             request.del({
                                 url:url + '?rev=' + rev,
                             }, function(er, res, boday) {
-                                if (er) callback(er);
-                                else {
-                                    if (res.statusCode == 200) {
+                                if (er) {
+                                    callback(er);
+                                }  else {
+                                    if (res.statusCode === 200) {
                                         request.put({
                                             url:url,
                                             json:document
                                         }, function(argh, r, bodee) {
-                                            if (argh) callback(argh);
-                                            else {
-                                                if(r){
-                                                    if (r.statusCode == 201) callback(false, bodee);
-                                                    else callback(true, r.statusCode);
+                                            if (argh) {
+                                                callback(argh);
+                                            } else {
+                                                if (r) {
+                                                    if (r.statusCode === 201) {
+                                                        callback(false, bodee);
+                                                    } else {
+                                                        callback(true, r.statusCode);
+                                                    }
                                                 } else {
                                                     callback(true,"URL failed?");
                                                 }
                                             }
                                         });
-                                    } else callback(true, res.statusCode);
+                                    } else {
+                                        callback(true, res.statusCode);
+                                    }
                                 }
                             });
-                        } else callback(true, resp.statusCode);
+                        } else {
+                            callback(true, resp.statusCode);
+                        }
                     }
                 });
-            } else callback(true, response.statusCode);
+            } else {
+                callback(true, response.statusCode);
+            }
 
         });
     },
@@ -138,11 +150,16 @@ db.prototype = {
                 since:'now',
                 include_docs:true
             }, function(err, change) {
-                if (!err) callback(false, change);
-                else callback(err);
+                if (!err) {
+                    callback(false, change);
+                } else {
+                    callback(err);
+                }
             });
             return true;
-        } else return false;
+        } else {
+            return false;
+        }
     }
 };
 

http://git-wip-us.apache.org/repos/asf/cordova-medic/blob/09fa6998/lib/testwait.js
----------------------------------------------------------------------
diff --git a/lib/testwait.js b/lib/testwait.js
index 0eee4f2..67939f1 100644
--- a/lib/testwait.js
+++ b/lib/testwait.js
@@ -19,8 +19,9 @@
 
 /* jshint node: true */
 
-var shell = require("shelljs");
-var q     = require("q");
+"use strict";
+
+var q = require("q");
 
 var couchdb = require("./couchdb");
 

http://git-wip-us.apache.org/repos/asf/cordova-medic/blob/09fa6998/lib/util.js
----------------------------------------------------------------------
diff --git a/lib/util.js b/lib/util.js
index 2190dc2..8c7e74f 100644
--- a/lib/util.js
+++ b/lib/util.js
@@ -19,10 +19,17 @@
 
 /* jshint node: true */
 
-module.exports = function () {
+"use strict";
+
+module.exports = (function () {
 
     var os = require("os");
 
+    // constants
+    var ESCAPE    = String.fromCharCode(27);
+    var RED_COLOR = ESCAPE + "[31m";
+    var NO_COLOR  = ESCAPE + "[m";
+
     return {
 
         // constants
@@ -50,17 +57,15 @@ module.exports = function () {
         },
 
         medicLog: function (message) {
-            var RED_COLOR = "\033[31m";
-            var NO_COLOR  = "\033[m";
             console.log(RED_COLOR + "[MEDIC LOG " + new Date().toUTCString() + "]" + NO_COLOR + " " + message);
         },
 
         contains: function (collection, item) {
-            return collection.indexOf(item) != (-1);
+            return collection.indexOf(item) !== (-1);
         },
 
         secToMin: function (seconds) {
             return Math.ceil(seconds / 60);
         }
     };
-}();
+}());

http://git-wip-us.apache.org/repos/asf/cordova-medic/blob/09fa6998/medic/medic-run.js
----------------------------------------------------------------------
diff --git a/medic/medic-run.js b/medic/medic-run.js
index 0447d8b..1feefd7 100644
--- a/medic/medic-run.js
+++ b/medic/medic-run.js
@@ -25,26 +25,25 @@
 
 var fs   = require("fs");
 var path = require("path");
-var cp   = require("child_process");
 
 var shelljs  = require("shelljs");
 var optimist = require("optimist");
+var request  = require("request");
 
 var util     = require("../lib/util");
 var testwait = require("../lib/testwait");
 
-var logProcess;
-
 // constants
-var CORDOVA_MEDIC_DIR       = "cordova-medic";
-var DEFAULT_APP_PATH        = "mobilespec";
-var CORDOVA_ERROR_PATTERN   = /^ERROR/m;
-var DEFAULT_APP_ENTRY       = "index.html";
-var ANDROID_TIMEOUT         = 120000; // in milliseconds
-var MEDIC_BUILD_PREFIX      = "medic-cli-build";
-var DEFAULT_WINDOWS_VERSION = "store";
-var WINDOWS_VERSION_CHOICES = ["store", "store80", "phone"];
-var DEFAULT_TIMEOUT         = 600; // in seconds
+var CORDOVA_MEDIC_DIR         = "cordova-medic";
+var DEFAULT_APP_PATH          = "mobilespec";
+var CORDOVA_ERROR_PATTERN     = /^ERROR/m;
+var DEFAULT_APP_ENTRY         = "index.html";
+var ANDROID_PAGE_LOAD_TIMEOUT = 120000; // in milliseconds
+var MEDIC_BUILD_PREFIX        = "medic-cli-build";
+var DEFAULT_WINDOWS_VERSION   = "store";
+var WINDOWS_VERSION_CHOICES   = ["store", "store80", "phone"];
+var DEFAULT_TIMEOUT           = 600; // in seconds
+var SERVER_RESPONSE_TIMEOUT   = 3000; // in milliseconds
 
 // helpers
 function currentMillisecond() {
@@ -186,7 +185,7 @@ function androidSpecificPreparation(argv) {
     var appPath   = argv.app;
     var extraArgs = "--gradle";
 
-    changeAndroidLoadTimeout(appPath, ANDROID_TIMEOUT);
+    changeAndroidLoadTimeout(appPath, ANDROID_PAGE_LOAD_TIMEOUT);
 
     return extraArgs;
 }
@@ -313,71 +312,87 @@ function main() {
         util.fatal("app " + appPath + " does not exist");
     }
 
-    // modify the app to run autonomously
-    createMedicJson(appPath, buildId, couchdbURI);
-    setEntryPoint(appPath, entryPoint);
-    addURIToWhitelist(appPath, couchdbURI);
-
-    // do platform-specific preparations
-    var platformArgs = "";
-    if (platform === util.ANDROID) {
-        platformArgs = androidSpecificPreparation(argv);
-    } else if (platform === util.WINDOWS) {
-        platformArgs = windowsSpecificPreparation(argv);
-    } else if (platform === util.WP8) {
-        platformArgs = wp8SpecificPreparation(argv);
-    }
+    util.medicLog("checking if " + couchdbURI + " is up");
 
-    // enter the app directory
-    shelljs.pushd(appPath);
+    // check if results server is up
+    request({
+        uri:     couchdbURI,
+        method:  "GET",
+        timeout: SERVER_RESPONSE_TIMEOUT
+    },
+    function (error, response, body) {
 
-    // compose commands
-    var buildCommand = cli + " build " + platform + " -- " + platformArgs;
-    var runCommand   = cli + " run " + platform + " -- " + platformArgs;
+        // bail if the results server is down
+        if (error || response.statusCode !== 200) {
+            util.fatal("results server is down, so test run can't be monitored");
+            process.exit(1);
+        }
 
-    // build the code
-    // NOTE:
-    //      this is SYNCHRONOUS
-    util.medicLog("running:");
-    util.medicLog("    " + buildCommand);
-    var result = shelljs.exec(buildCommand, {silent: false, async: false});
-    if (result.code !== 0 || CORDOVA_ERROR_PATTERN.test(result.output)) {
-        util.fatal("build failed");
-    }
+        // modify the app to run autonomously
+        createMedicJson(appPath, buildId, couchdbURI);
+        setEntryPoint(appPath, entryPoint);
+        addURIToWhitelist(appPath, couchdbURI);
+
+        // do platform-specific preparations
+        var platformArgs = "";
+        if (platform === util.ANDROID) {
+            platformArgs = androidSpecificPreparation(argv);
+        } else if (platform === util.WINDOWS) {
+            platformArgs = windowsSpecificPreparation(argv);
+        } else if (platform === util.WP8) {
+            platformArgs = wp8SpecificPreparation(argv);
+        }
 
-    // run the code
-    // NOTE:
-    //      this is ASYNCHRONOUS
-    util.medicLog("running:");
-    util.medicLog("    " + runCommand);
-    shelljs.exec(runCommand, {silent: false, async: true}, function (returnCode, output) {
-        if (returnCode !== 0 || CORDOVA_ERROR_PATTERN.test(output)) {
-            util.fatal("run failed");
+        // enter the app directory
+        shelljs.pushd(appPath);
+
+        // compose commands
+        var buildCommand = cli + " build " + platform + " -- " + platformArgs;
+        var runCommand   = cli + " run " + platform + " -- " + platformArgs;
+
+        // build the code
+        // NOTE:
+        //      this is SYNCHRONOUS
+        util.medicLog("running:");
+        util.medicLog("    " + buildCommand);
+        var result = shelljs.exec(buildCommand, {silent: false, async: false});
+        if (result.code !== 0 || CORDOVA_ERROR_PATTERN.test(result.output)) {
+            util.fatal("build failed");
         }
-    });
 
-    // exit the app directory
-    shelljs.popd();
+        // run the code
+        // NOTE:
+        //      this is ASYNCHRONOUS
+        util.medicLog("running:");
+        util.medicLog("    " + runCommand);
+        shelljs.exec(runCommand, {silent: false, async: true}, function (returnCode, output) {
+            if (returnCode !== 0 || CORDOVA_ERROR_PATTERN.test(output)) {
+                util.fatal("run failed");
+            }
+        });
+
+        // exit the app directory
+        shelljs.popd();
+
+        // wait for test results
+        // NOTE:
+        //      timeout needs to be in milliseconds, but it's
+        //      given in seconds, so we multiply by 1000
+        testwait.init(couchdbURI);
+        testwait.waitTestsCompleted(buildId, timeout * 1000).then(
+            function onFulfilled(value) {
+                util.medicLog("got test results");
+                process.exit(0);
+            },
+            function onRejected(error) {
+                console.error("didn't get test results: " + error);
+                process.exit(1);
+            }
+        );
 
-    // wait for test results
-    // NOTE:
-    //      timeout needs to be in milliseconds, but it's
-    //      given in seconds, so we multiply by 1000
-    testwait.init(couchdbURI);
-    testwait.waitTestsCompleted(buildId, timeout * 1000).then(
-        function onFulfilled(value) {
-            logProcess && logProcess.kill('SIGINT');
-            util.medicLog("got test results");
-            process.exit(0);
-        },
-        function onRejected(error) {
-            logProcess && logProcess.kill('SIGINT');
-            console.error("didn't get test results: " + error);
-            process.exit(1);
-        }
-    );
+        util.medicLog("waiting for test results ...");
 
-    util.medicLog("waiting for test results ...");
+    }); // request(couchdbURI)
 }
 
 main();

http://git-wip-us.apache.org/repos/asf/cordova-medic/blob/09fa6998/package.json
----------------------------------------------------------------------
diff --git a/package.json b/package.json
index 5cb7534..695e3cc 100644
--- a/package.json
+++ b/package.json
@@ -25,6 +25,10 @@
     }
   ],
   "scripts": {
-    "jshint": "jshint medic lib"
+    "test": "npm run lint",
+    "lint": "node_modules/.bin/jshint medic lib"
+  },
+  "devDependencies": {
+    "jshint": "^2.8.0"
   }
 }


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