You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by ja...@apache.org on 2018/12/05 13:38:28 UTC

[cordova-paramedic] 07/08: fix things that were broken because of the extraction of ParamedicSauceLabs

This is an automated email from the ASF dual-hosted git repository.

janpio pushed a commit to branch janpio-split_paramedicjs
in repository https://gitbox.apache.org/repos/asf/cordova-paramedic.git

commit 572101ad358a503e7de42bb0fbd5158e670a357f
Author: Jan Piotrowski <pi...@gmail.com>
AuthorDate: Tue Dec 4 19:20:13 2018 +0100

    fix things that were broken because of the extraction of ParamedicSauceLabs
---
 lib/ParamedicSauceLabs.js | 64 ++++++++++++++++++++++++-----------------------
 lib/paramedic.js          | 17 +++++++------
 2 files changed, 42 insertions(+), 39 deletions(-)

diff --git a/lib/ParamedicSauceLabs.js b/lib/ParamedicSauceLabs.js
index 15f9a1d..a63b06d 100644
--- a/lib/ParamedicSauceLabs.js
+++ b/lib/ParamedicSauceLabs.js
@@ -34,25 +34,26 @@ var logger          = require('./utils').logger;
 var util            = require('./utils').utilities;
 var appPatcher      = require('./appium/helpers/appPatcher');
 
-function ParamedicSauceLabs() {
+function ParamedicSauceLabs(config, runner) {
+    this.config = config;
+    this.runner = runner;
 }
+module.exports = ParamedicSauceLabs;
 
 ParamedicSauceLabs.prototype.checkSauceRequirements = function () {
-    if (this.config.shouldUseSauce()) {
-        var platformId = this.config.getPlatformId();
-        if (platformId !== util.ANDROID && platformId !== util.IOS && platformId !== util.BROWSER) {
-            logger.warn('Saucelabs only supports Android and iOS (and browser), falling back to testing locally.');
-            this.config.setShouldUseSauce(false);
-        } else if (!this.config.getSauceKey()) {
-            throw new Error('Saucelabs key not set. Please set it via environmental variable ' +
-                util.SAUCE_KEY_ENV_VAR + ' or pass it with the --sauceKey parameter.');
-        } else if (!this.config.getSauceUser()) {
-            throw new Error('Saucelabs user not set. Please set it via environmental variable ' +
-                util.SAUCE_USER_ENV_VAR + ' or pass it with the --sauceUser parameter.');
-        } else if (!this.shouldWaitForTestResult()) {
-            // don't throw, just silently disable Sauce
-            this.config.setShouldUseSauce(false);
-        }
+    var platformId = this.config.getPlatformId();
+    if (platformId !== util.ANDROID && platformId !== util.IOS && platformId !== util.BROWSER) {
+        logger.warn('Saucelabs only supports Android and iOS (and browser), falling back to testing locally.');
+        this.config.setShouldUseSauce(false);
+    } else if (!this.config.getSauceKey()) {
+        throw new Error('Saucelabs key not set. Please set it via environmental variable ' +
+            util.SAUCE_KEY_ENV_VAR + ' or pass it with the --sauceKey parameter.');
+    } else if (!this.config.getSauceUser()) {
+        throw new Error('Saucelabs user not set. Please set it via environmental variable ' +
+            util.SAUCE_USER_ENV_VAR + ' or pass it with the --sauceUser parameter.');
+    } else if (!this.runner.shouldWaitForTestResult()) {
+        // don't throw, just silently disable Sauce
+        this.config.setShouldUseSauce(false);
     }
 };
 
@@ -65,7 +66,7 @@ ParamedicSauceLabs.prototype.packageApp = function () {
                 shell.pushd(self.getPackageFolder());
                 shell.rm('-rf', self.getPackageName());
                 console.log('Running command: ' + zipCommand + ' in dir: ' + shell.pwd());
-                exec(zipCommand, { silent: !self.config.isVerbose() }, function (code, stdout, stderr) {
+                exec(zipCommand, function (code, stdout, stderr) {
                     shell.popd();
                     if (code) {
                         reject('zip command returned with error code ' + code);
@@ -124,11 +125,11 @@ ParamedicSauceLabs.prototype.getPackageFolders = function () {
     var packageFolders;
     switch (this.config.getPlatformId()) {
         case util.ANDROID:
-            packageFolders =  [ path.join(this.tempFolder.name, 'platforms/android/app/build/outputs/apk/debug'),
-                                path.join(this.tempFolder.name, 'platforms/android/build/outputs/apk') ];
+            packageFolders =  [ path.join(this.runner.tempFolder.name, 'platforms/android/app/build/outputs/apk/debug'),
+                                path.join(this.runner.tempFolder.name, 'platforms/android/build/outputs/apk') ];
             break;
         case util.IOS:
-            packageFolders = [ path.join(this.tempFolder.name, 'platforms/ios/build/emulator') ];
+            packageFolders = [ path.join(this.runner.tempFolder.name, 'platforms/ios/build/emulator') ];
             break;
         default:
             throw new Error('Don\t know where the package foler is for platform: ' + this.config.getPlatformId());
@@ -183,6 +184,7 @@ ParamedicSauceLabs.prototype.getBinaryName = function () {
 // Returns a name of the file at the SauceLabs storage
 ParamedicSauceLabs.prototype.getAppName = function () {
     if (this.appName) {
+        // exit if we did this before
         return this.appName;
     }
     var appName = randomstring.generate();
@@ -196,7 +198,7 @@ ParamedicSauceLabs.prototype.getAppName = function () {
         default:
             throw new Error('Don\'t know the app name for platform: ' + this.config.getPlatformId());
     }
-    this.appName = appName;
+    this.appName = appName; // save for additional function calls
     return appName;
 };
 
@@ -247,9 +249,9 @@ ParamedicSauceLabs.prototype.displaySauceDetails = function (buildName) {
 };
 
 ParamedicSauceLabs.prototype.getSauceCaps = function () {
-    this.sauceBuildName = this.sauceBuildName || this.config.getBuildName();
+    this.runner.sauceBuildName = this.runner.sauceBuildName || this.config.getBuildName();
     var caps = {
-        name: this.sauceBuildName,
+        name: this.runner.sauceBuildName,
         idleTimeout: '100', // in seconds
         maxDuration: util.SAUCE_MAX_DURATION,
         tunnelIdentifier: this.config.getSauceTunnelId(),
@@ -381,9 +383,9 @@ ParamedicSauceLabs.prototype.runSauceTests = function () {
             // we do it by just running "cordova run" and ignoring the chrome instance that pops up
             return Q()
                 .then(function() {
-                    appPatcher.addCspSource(self.tempFolder.name, 'connect-src', 'http://*');
-                    appPatcher.permitAccess(self.tempFolder.name, '*');
-                    return self.getCommandForStartingTests();
+                    appPatcher.addCspSource(self.runner.tempFolder.name, 'connect-src', 'http://*');
+                    appPatcher.permitAccess(self.runner.tempFolder.name, '*');
+                    return self.runner.getCommandForStartingTests();
                 })
                 .then(function (command) {
                     console.log('$ ' + command);
@@ -393,7 +395,7 @@ ParamedicSauceLabs.prototype.runSauceTests = function () {
                     });
                 });
         } else {
-            return self.buildApp()
+            return self.runner.buildApp()
                 .then(self.packageApp.bind(self))
                 .then(self.uploadApp.bind(self));
         }
@@ -462,7 +464,7 @@ ParamedicSauceLabs.prototype.runSauceTests = function () {
                     driver.pollForEvents(platform, skipBuster)
                     .then(function (events) {
                         for (var i = 0; i < events.length; i++) {
-                            self.server.emit(events[i].eventName, events[i].eventObject);
+                            self.runner.server.emit(events[i].eventName, events[i].eventObject);
                         }
                         polling = false;
                     })
@@ -474,7 +476,7 @@ ParamedicSauceLabs.prototype.runSauceTests = function () {
             }, 2500);
         }
 
-        return self.waitForTests();
+        return self.runner.waitForTests();
     })
     .then(function (result) {
         logger.normal('cordova-paramedic: Tests finished');
@@ -491,9 +493,9 @@ ParamedicSauceLabs.prototype.runSauceTests = function () {
         }
     })
     .fin(function () {
-        if (self.config.getPlatformId() === util.BROWSER && !self.browserPatched) {
+        if (self.config.getPlatformId() === util.BROWSER && !self.runner.browserPatched) {
             // we need to kill chrome
-            self.killEmulatorProcess();
+            self.runner.killEmulatorProcess();
         }
         if (runProcess) {
             // as well as we need to kill the spawned node process serving our app
diff --git a/lib/paramedic.js b/lib/paramedic.js
index d9f369b..2bef3e2 100644
--- a/lib/paramedic.js
+++ b/lib/paramedic.js
@@ -36,6 +36,7 @@ var ParamediciOSPermissions = require('./ParamediciOSPermissions');
 var ParamedicTargetChooser  = require('./ParamedicTargetChooser');
 var ParamedicAppUninstall   = require('./ParamedicAppUninstall');
 var ParamedicApp   = require('./ParamedicApp');
+var ParamedicSauceLabs      = require('./ParamedicSauceLabs');
 
 //this will add custom promise chain methods to the driver prototype
 require('./appium/helpers/wdHelper');
@@ -65,7 +66,7 @@ ParamedicRunner.prototype.run = function () {
 
     return Q().then(function () {
         // create project and prepare (install plugins, setup test startpage, install platform, check platform requirements)
-        var paramedicApp = new ParamedicApp(self.config, self.storedCWD);
+        var paramedicApp = new ParamedicApp(self.config, self.storedCWD, self);
         self.tempFolder = paramedicApp.createTempProject();
         shell.pushd(self.tempFolder.name);
         return paramedicApp.prepareProjectToRunTests();
@@ -115,7 +116,7 @@ ParamedicRunner.prototype.run = function () {
                     self.killEmulatorProcess();
                 });
         }
-        return self.displaySauceDetails(self.sauceBuildName);
+        return self.paramedicSauceLabs.displaySauceDetails(self.sauceBuildName);
     })
     .fin(function () {
         self.cleanUpProject();
@@ -124,7 +125,7 @@ ParamedicRunner.prototype.run = function () {
 
 ParamedicRunner.prototype.checkConfig = function () {
     if (this.config.shouldUseSauce()) {
-        this.paramedicSauceLabs = new ParamedicSauceLabs();
+        this.paramedicSauceLabs = new ParamedicSauceLabs(this.config, this);
         this.paramedicSauceLabs.checkSauceRequirements();
     }
     if (!this.config.runMainTests() && !this.config.runAppiumTests()) {
@@ -323,10 +324,10 @@ ParamedicRunner.prototype.runAppiumTests = function (useSauce) {
         cli: self.config.getCli(),
     };
     if (useSauce) {
-        options.sauceAppPath = 'sauce-storage:' + this.getAppName();
+        options.sauceAppPath = 'sauce-storage:' + this.paramedicSauceLabs.getAppName();
         options.sauceUser = this.config.getSauceUser();
         options.sauceKey = this.config.getSauceKey();
-        options.sauceCaps = this.getSauceCaps();
+        options.sauceCaps = this.paramedicSauceLabs.getSauceCaps();
         options.sauceCaps.name += '_Appium';
     }
 
@@ -341,8 +342,8 @@ ParamedicRunner.prototype.runAppiumTests = function (useSauce) {
     })
     .then(function () {
         if (useSauce) {
-            return self.packageApp()
-            .then(self.uploadApp.bind(self));
+            return self.paramedicSauceLabs.packageApp()
+            .then(self.paramedicSauceLabs.uploadApp.bind(self));
         }
     })
     .then(function () {
@@ -355,7 +356,7 @@ ParamedicRunner.prototype.runTests = function () {
     var self = this;
     // Sauce Labs
     if (this.config.shouldUseSauce()) {
-        return this.runSauceTests()
+        return this.paramedicSauceLabs.runSauceTests()
         .then(function (result) {
             isTestPassed = result;
             return self.runAppiumTests(true);


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