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 2016/01/12 06:04:57 UTC
cordova-medic git commit: Made medic-run fall back to emulator if
running via device fails because a device is not found.
Repository: cordova-medic
Updated Branches:
refs/heads/master 0958662e3 -> c66fbcacd
Made medic-run fall back to emulator if running via device fails because a device is not found.
Project: http://git-wip-us.apache.org/repos/asf/cordova-medic/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-medic/commit/c66fbcac
Tree: http://git-wip-us.apache.org/repos/asf/cordova-medic/tree/c66fbcac
Diff: http://git-wip-us.apache.org/repos/asf/cordova-medic/diff/c66fbcac
Branch: refs/heads/master
Commit: c66fbcacddabb202740b1c8939a626d082200ae3
Parents: 0958662
Author: Dmitry Blotsky <dm...@gmail.com>
Authored: Mon Jan 11 21:04:46 2016 -0800
Committer: Dmitry Blotsky <dm...@gmail.com>
Committed: Mon Jan 11 21:04:46 2016 -0800
----------------------------------------------------------------------
lib/util.js | 52 +++++++++++++++++--------------
medic/medic-run.js | 81 +++++++++++++++++++++++++++++++------------------
2 files changed, 81 insertions(+), 52 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cordova-medic/blob/c66fbcac/lib/util.js
----------------------------------------------------------------------
diff --git a/lib/util.js b/lib/util.js
index 8c7e74f..2f649ad 100644
--- a/lib/util.js
+++ b/lib/util.js
@@ -30,6 +30,30 @@ module.exports = (function () {
var RED_COLOR = ESCAPE + "[31m";
var NO_COLOR = ESCAPE + "[m";
+ function medicLog(message) {
+ console.log(RED_COLOR + "[MEDIC LOG " + new Date().toUTCString() + "]" + NO_COLOR + " " + message);
+ }
+
+ function contains(collection, item) {
+ return collection.indexOf(item) !== (-1);
+ }
+
+ function isWindows () {
+ // NOTE:
+ // - including "^" because otherwise "Darwin" matches
+ // - only "win" and not "windows" because "win32" should also match
+ return /^win/.test(os.platform());
+ }
+
+ function fatal(message) {
+ medicLog("FATAL: " + message);
+ process.exit(1);
+ }
+
+ function secToMin (seconds) {
+ return Math.ceil(seconds / 60);
+ }
+
return {
// constants
@@ -44,28 +68,10 @@ module.exports = (function () {
DEFAULT_LOG_TIME_ADDITIONAL: 2,
// functions
- fatal: function (message) {
- console.error("FATAL: " + message);
- process.exit(1);
- },
-
- isWindows: function () {
- // NOTE:
- // - including "^" because otherwise "Darwin" matches
- // - only "win" and not "windows" because "win32" should also match
- return /^win/.test(os.platform());
- },
-
- medicLog: function (message) {
- console.log(RED_COLOR + "[MEDIC LOG " + new Date().toUTCString() + "]" + NO_COLOR + " " + message);
- },
-
- contains: function (collection, item) {
- return collection.indexOf(item) !== (-1);
- },
-
- secToMin: function (seconds) {
- return Math.ceil(seconds / 60);
- }
+ fatal: fatal,
+ isWindows: isWindows,
+ medicLog: medicLog,
+ contains: contains,
+ secToMin: secToMin
};
}());
http://git-wip-us.apache.org/repos/asf/cordova-medic/blob/c66fbcac/medic/medic-run.js
----------------------------------------------------------------------
diff --git a/medic/medic-run.js b/medic/medic-run.js
index 4a33068..20bb4bc 100644
--- a/medic/medic-run.js
+++ b/medic/medic-run.js
@@ -37,6 +37,7 @@ var testwait = require("../lib/testwait");
var CORDOVA_MEDIC_DIR = "cordova-medic";
var DEFAULT_APP_PATH = "mobilespec";
var CORDOVA_ERROR_PATTERN = /^ERROR/m;
+var NO_DEVICE_PATTERN = /(^.*no .* was detected)|(^.*no devices found)/m;
var DEFAULT_APP_ENTRY = "index.html";
var ANDROID_PAGE_LOAD_TIMEOUT = 120000; // in milliseconds
var MEDIC_BUILD_PREFIX = "medic-cli-build";
@@ -279,6 +280,17 @@ function getLocalCLI() {
}
}
+function cordovaReturnedError(returnCode, output) {
+ if (returnCode !== 0 || CORDOVA_ERROR_PATTERN.test(output)) {
+ return true;
+ }
+ return false;
+}
+
+function failedBecauseNoDevice(output) {
+ return NO_DEVICE_PATTERN.test(output);
+}
+
// main
function main() {
@@ -324,8 +336,10 @@ function main() {
// 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");
+ util.fatal("it's not up, so test run can't be monitored");
process.exit(1);
+ } else {
+ util.medicLog("it's up");
}
// modify the app to run autonomously
@@ -343,12 +357,31 @@ function main() {
platformArgs = wp8SpecificPreparation(argv);
}
+ // start waiting 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);
+ }
+ );
+ util.medicLog("started waiting for test results");
+
// enter the app directory
+ util.medicLog("moving into " + appPath);
shelljs.pushd(appPath);
// compose commands
- var buildCommand = cli + " build " + platform + " -- " + platformArgs;
- var runCommand = cli + " run --device " + platform + " -- " + platformArgs;
+ var buildCommand = cli + " build " + platform + " -- " + platformArgs;
+ var runCommandEmulator = cli + " run --emulator " + platform + " -- " + platformArgs;
+ var runCommandDevice = cli + " run --device " + platform + " -- " + platformArgs;
// build the code
// NOTE:
@@ -356,7 +389,7 @@ function main() {
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)) {
+ if (cordovaReturnedError(result.code, result.output)) {
util.fatal("build failed");
}
@@ -364,34 +397,24 @@ function main() {
// 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");
+ util.medicLog(" " + runCommandDevice);
+ shelljs.exec(runCommandDevice, {silent: false, async: true}, function (returnCode, output) {
+ if (failedBecauseNoDevice(output)) {
+ util.medicLog("no device found, so switching to emulator");
+ util.medicLog("running:");
+ util.medicLog(" " + runCommandEmulator);
+ shelljs.exec(runCommandEmulator, {silent: false, async: true}, function (returnCode, output) {
+ if (cordovaReturnedError(returnCode, output)) {
+ util.fatal("running on emulator failed");
+ }
+ });
+ } else {
+ if (cordovaReturnedError(returnCode, output)) {
+ util.fatal("running on device 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);
- }
- );
-
- util.medicLog("waiting for test results ...");
-
}); // request(couchdbURI)
}
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org
For additional commands, e-mail: commits-help@cordova.apache.org