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:25 UTC
[cordova-paramedic] 04/08: ParamedicApp: app creation methods
extracted from paramedic.js
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 6e5e64eaff043cd18f0a3f52a21b75bfa81f26d9
Author: Jan Piotrowski <pi...@gmail.com>
AuthorDate: Mon Dec 3 17:55:05 2018 +0100
ParamedicApp: app creation methods extracted from paramedic.js
---
lib/ParamedicApp.js | 142 ++++++++++++++++++++++++++++++++++++++++++++++++++++
lib/paramedic.js | 109 ++--------------------------------------
2 files changed, 146 insertions(+), 105 deletions(-)
diff --git a/lib/ParamedicApp.js b/lib/ParamedicApp.js
new file mode 100644
index 0000000..b78b167
--- /dev/null
+++ b/lib/ParamedicApp.js
@@ -0,0 +1,142 @@
+#!/usr/bin/env node
+
+/**
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied. See the License for the
+ specific language governing permissions and limitations
+ under the License.
+*/
+
+var Q = require('q');
+var tmp = require('tmp');
+var shell = require('shelljs');
+var path = require('path');
+var exec = require('./utils').exec;
+var execPromise = require('./utils').execPromise;
+var util = require('./utils').utilities;
+var logger = require('./utils').logger;
+var PluginsManager = require('./PluginsManager');
+var appPatcher = require('./appium/helpers/appPatcher');
+
+
+
+function ParamedicApp(config, storedCWD) {
+ this.config = config;
+ this.storedCWD = storedCWD;
+ this.tempFolder = null;
+}
+
+ParamedicApp.prototype.createTempProject = function () {
+ this.tempFolder = tmp.dirSync();
+ tmp.setGracefulCleanup();
+ logger.info('cordova-paramedic: creating temp project at ' + this.tempFolder.name);
+ exec(this.config.getCli() + ' create ' + this.tempFolder.name + util.PARAMEDIC_COMMON_CLI_ARGS);
+ return this.tempFolder;
+};
+
+ParamedicApp.prototype.prepareProjectToRunTests = function () {
+ var self = this;
+
+ this.installPlugins();
+ this.setUpStartPage();
+ return this.installPlatform()
+ .then(function () {
+ return self.checkPlatformRequirements();
+ });
+};
+
+ParamedicApp.prototype.installPlugins = function () {
+ logger.info('cordova-paramedic: installing plugins');
+ var pluginsManager = new PluginsManager(this.tempFolder.name, this.storedCWD, this.config);
+ pluginsManager.installPlugins(this.config.getPlugins());
+ pluginsManager.installTestsForExistingPlugins();
+
+ var additionalPlugins = ['cordova-plugin-test-framework', path.join(__dirname, '../paramedic-plugin')];
+ if (this.config.shouldUseSauce() && !this.config.getUseTunnel()) {
+ additionalPlugins.push(path.join(__dirname, '../event-cache-plugin'));
+ }
+ if (this.config.getPlatformId() === util.WINDOWS) {
+ additionalPlugins.push(path.join(__dirname, '../debug-mode-plugin'));
+ }
+ if (this.config.getPlatformId() === util.IOS) {
+ additionalPlugins.push(path.join(__dirname, '../ios-geolocation-permissions-plugin'));
+ }
+ if (this.config.isCI()) {
+ additionalPlugins.push(path.join(__dirname, '../ci-plugin'));
+ }
+
+ pluginsManager.installPlugins(additionalPlugins);
+};
+
+ParamedicApp.prototype.setUpStartPage = function () {
+ logger.normal('cordova-paramedic: setting app start page to test page');
+ shell.sed('-i', 'src="index.html"', 'src="cdvtests/index.html"', 'config.xml');
+};
+
+ParamedicApp.prototype.installPlatform = function () {
+ var self = this;
+ var platform = this.config.getPlatform();
+ var platformId = this.config.getPlatformId();
+ logger.info('cordova-paramedic: adding platform ' + platform + " (with: " + util.PARAMEDIC_COMMON_CLI_ARGS + util.PARAMEDIC_PLATFORM_ADD_ARGS + ")");
+
+ return execPromise(this.config.getCli() + ' platform add ' + platform + util.PARAMEDIC_COMMON_CLI_ARGS + util.PARAMEDIC_PLATFORM_ADD_ARGS)
+ .then(function () {
+ logger.info('cordova-paramedic: successfully finished adding platform ' + platform);
+ if (platformId === util.ANDROID && self.config.isCI()) {
+ logger.info('cordova-paramedic: monkey patching Android platform to disable gradle daemon...');
+ var gradleBuilderFile = path.join(self.tempFolder.name, 'platforms/android/cordova/lib/builders/GradleBuilder.js');
+ // remove the line where the gradle daemon is forced on
+ if (appPatcher.monkeyPatch(gradleBuilderFile, /args\.push\('\-Dorg\.gradle\.daemon=true'\);/, '//args.push(\'-Dorg.gradle.daemon=true\');')) {
+ logger.info('cordova-paramedic: success!');
+ } else {
+ logger.info('cordova-paramedic: couldn\'t apply the patch. It must be good news: does cordova-android not hard-code gradle daemon anymore?');
+ }
+ } else if (platformId === util.BROWSER && self.config.shouldUseSauce()) {
+ logger.info('cordova-paramedic: I like patching stuff, so...');
+ logger.info('cordova-paramedic: monkey patching browser platform to disable browser pop-up.');
+ var cordovaRunFile = path.join(self.tempFolder.name, 'platforms/browser/cordova/run');
+ // we need to supply some replacement string so this method can properly return a result
+ if (appPatcher.monkeyPatch(cordovaRunFile, /return cordovaServe\.launchBrowser\(.*\)\;/, '// no pop-up please')) {
+ logger.info('cordova-paramedic: success!');
+ self.browserPatched = true;
+ } else {
+ cordovaRunFile = path.join(self.tempFolder.name, 'platforms/browser/cordova/lib/run.js');
+ if (appPatcher.monkeyPatch(cordovaRunFile, /return server\.launchBrowser\(\{'target'\: args\.target\, 'url'\: projectUrl\}\)\;/, '// no pop-up please')) {
+ logger.info('cordova-paramedic: success!');
+ self.browserPatched = true;
+ } else {
+ logger.info('cordova-paramedic: couldn\'t apply the patch. Not a big deal, though: things should work anyway.');
+ self.browserPatched = false;
+ }
+ }
+ }
+ });
+};
+
+ParamedicApp.prototype.checkPlatformRequirements = function () {
+ var platformId = this.config.getPlatformId();
+
+ if (platformId === util.BROWSER) {
+ return Q();
+ }
+
+ logger.normal('cordova-paramedic: checking requirements for platform ' + platformId);
+ return execPromise(this.config.getCli() + ' requirements ' + platformId + util.PARAMEDIC_COMMON_CLI_ARGS)
+ .then(function () {
+ logger.info('cordova-paramedic: successfully finished checking requirements for platform ' + platformId);
+ });
+};
+
+module.exports = ParamedicApp;
\ No newline at end of file
diff --git a/lib/paramedic.js b/lib/paramedic.js
index 090ea66..a2a6f79 100644
--- a/lib/paramedic.js
+++ b/lib/paramedic.js
@@ -22,7 +22,6 @@ var exec = require('./utils').exec;
var execPromise = require('./utils').execPromise;
var shell = require('shelljs');
var Server = require('./LocalServer');
-var tmp = require('tmp');
var path = require('path');
var Q = require('q');
var fs = require('fs');
@@ -33,7 +32,6 @@ var sauceConnectLauncher = require('sauce-connect-launcher');
var logger = require('./utils').logger;
var util = require('./utils').utilities;
-var PluginsManager = require('./PluginsManager');
var Reporters = require('./Reporters');
var ParamedicKill = require('./ParamedicKill');
var AppiumRunner = require('./appium/AppiumRunner');
@@ -42,6 +40,7 @@ var ParamedicLogCollector = require('./ParamedicLogCollector');
var ParamediciOSPermissions = require('./ParamediciOSPermissions');
var ParamedicTargetChooser = require('./ParamedicTargetChooser');
var ParamedicAppUninstall = require('./ParamedicAppUninstall');
+var ParamedicApp = require('./ParamedicApp');
//this will add custom promise chain methods to the driver prototype
require('./appium/helpers/wdHelper');
@@ -53,7 +52,6 @@ var INITIAL_CONNECTION_TIMEOUT = 540000; // 9mins
function ParamedicRunner(config, _callback) {
this.tempFolder = null;
- this.pluginsManager = null;
this.config = config;
this.targetObj = undefined;
@@ -69,9 +67,10 @@ ParamedicRunner.prototype.run = function () {
return Q().then(function () {
// create project and prepare (install plugins, setup test startpage, install platform, check platform requirements)
- self.createTempProject();
+ var paramedicApp = new ParamedicApp(self.config, self.storedCWD);
+ self.tempFolder = paramedicApp.createTempProject();
shell.pushd(self.tempFolder.name);
- return self.prepareProjectToRunTests();
+ return paramedicApp.prepareProjectToRunTests();
})
.then(function () {
if (self.config.runMainTests()) {
@@ -137,106 +136,6 @@ ParamedicRunner.prototype.checkConfig = function () {
logger.info('cordova-paramedic: Will use the following cli: ' + this.config.getCli());
};
-ParamedicRunner.prototype.createTempProject = function () {
- this.tempFolder = tmp.dirSync();
- tmp.setGracefulCleanup();
- logger.info('cordova-paramedic: creating temp project at ' + this.tempFolder.name);
- exec(this.config.getCli() + ' create ' + this.tempFolder.name + util.PARAMEDIC_COMMON_CLI_ARGS);
-};
-
-ParamedicRunner.prototype.prepareProjectToRunTests = function () {
- var self = this;
-
- this.installPlugins();
- this.setUpStartPage();
- return this.installPlatform()
- .then(function () {
- return self.checkPlatformRequirements();
- });
-};
-
-ParamedicRunner.prototype.installPlugins = function () {
- logger.info('cordova-paramedic: installing plugins');
- this.pluginsManager = new PluginsManager(this.tempFolder.name, this.storedCWD, this.config);
- this.pluginsManager.installPlugins(this.config.getPlugins());
- this.pluginsManager.installTestsForExistingPlugins();
-
- var additionalPlugins = ['cordova-plugin-test-framework', path.join(__dirname, '../paramedic-plugin')];
- if (this.config.shouldUseSauce() && !this.config.getUseTunnel()) {
- additionalPlugins.push(path.join(__dirname, '../event-cache-plugin'));
- }
- if (this.config.getPlatformId() === util.WINDOWS) {
- additionalPlugins.push(path.join(__dirname, '../debug-mode-plugin'));
- }
- if (this.config.getPlatformId() === util.IOS) {
- additionalPlugins.push(path.join(__dirname, '../ios-geolocation-permissions-plugin'));
- }
- if (this.config.isCI()) {
- additionalPlugins.push(path.join(__dirname, '../ci-plugin'));
- }
-
- this.pluginsManager.installPlugins(additionalPlugins);
-};
-
-ParamedicRunner.prototype.setUpStartPage = function () {
- logger.normal('cordova-paramedic: setting app start page to test page');
- shell.sed('-i', 'src="index.html"', 'src="cdvtests/index.html"', 'config.xml');
-};
-
-ParamedicRunner.prototype.installPlatform = function () {
- var self = this;
- var platform = this.config.getPlatform();
- var platformId = this.config.getPlatformId();
- logger.info('cordova-paramedic: adding platform ' + platform + " (with: " + util.PARAMEDIC_COMMON_CLI_ARGS + util.PARAMEDIC_PLATFORM_ADD_ARGS + ")");
-
- return execPromise(this.config.getCli() + ' platform add ' + platform + util.PARAMEDIC_COMMON_CLI_ARGS + util.PARAMEDIC_PLATFORM_ADD_ARGS)
- .then(function () {
- logger.info('cordova-paramedic: successfully finished adding platform ' + platform);
- if (platformId === util.ANDROID && self.config.isCI()) {
- logger.info('cordova-paramedic: monkey patching Android platform to disable gradle daemon...');
- var gradleBuilderFile = path.join(self.tempFolder.name, 'platforms/android/cordova/lib/builders/GradleBuilder.js');
- // remove the line where the gradle daemon is forced on
- if (appPatcher.monkeyPatch(gradleBuilderFile, /args\.push\('\-Dorg\.gradle\.daemon=true'\);/, '//args.push(\'-Dorg.gradle.daemon=true\');')) {
- logger.info('cordova-paramedic: success!');
- } else {
- logger.info('cordova-paramedic: couldn\'t apply the patch. It must be good news: does cordova-android not hard-code gradle daemon anymore?');
- }
- } else if (platformId === util.BROWSER && self.config.shouldUseSauce()) {
- logger.info('cordova-paramedic: I like patching stuff, so...');
- logger.info('cordova-paramedic: monkey patching browser platform to disable browser pop-up.');
- var cordovaRunFile = path.join(self.tempFolder.name, 'platforms/browser/cordova/run');
- // we need to supply some replacement string so this method can properly return a result
- if (appPatcher.monkeyPatch(cordovaRunFile, /return cordovaServe\.launchBrowser\(.*\)\;/, '// no pop-up please')) {
- logger.info('cordova-paramedic: success!');
- self.browserPatched = true;
- } else {
- cordovaRunFile = path.join(self.tempFolder.name, 'platforms/browser/cordova/lib/run.js');
- if (appPatcher.monkeyPatch(cordovaRunFile, /return server\.launchBrowser\(\{'target'\: args\.target\, 'url'\: projectUrl\}\)\;/, '// no pop-up please')) {
- logger.info('cordova-paramedic: success!');
- self.browserPatched = true;
- } else {
- logger.info('cordova-paramedic: couldn\'t apply the patch. Not a big deal, though: things should work anyway.');
- self.browserPatched = false;
- }
- }
- }
- });
-};
-
-ParamedicRunner.prototype.checkPlatformRequirements = function () {
- var platformId = this.config.getPlatformId();
-
- if (platformId === util.BROWSER) {
- return Q();
- }
-
- logger.normal('cordova-paramedic: checking requirements for platform ' + platformId);
- return execPromise(this.config.getCli() + ' requirements ' + platformId + util.PARAMEDIC_COMMON_CLI_ARGS)
- .then(function () {
- logger.info('cordova-paramedic: successfully finished checking requirements for platform ' + platformId);
- });
-};
-
ParamedicRunner.prototype.setPermissions = function () {
var applicationsToGrantPermission = [
'kTCCServiceAddressBook'
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org
For additional commands, e-mail: commits-help@cordova.apache.org