refactor: move all cli related functionality into a cli dir
RENAME
lib/cli-args.js
lib/cli/args.js
import { DEFAULT_BASE_PATH } from 'appium-base-driver';
import { parseSecurityFeatures, parseDefaultCaps, parseInstallTypes } from './parser-helpers';
-import { INSTALL_TYPES, DEFAULT_APPIUM_HOME } from './driver-config';
+import { INSTALL_TYPES, DEFAULT_APPIUM_HOME } from '../driver-config';
// sharedArgs will be added to every subcommand
const sharedArgs = [

RENAME
lib/driver-cli.js
lib/cli/driver.js
import _ from 'lodash';
import path from 'path';
-import { KNOWN_DRIVERS } from './drivers';
+import { KNOWN_DRIVERS } from '../drivers';
import DriverConfig, { INSTALL_TYPE_NPM, INSTALL_TYPE_GIT, INSTALL_TYPE_GITHUB,
- INSTALL_TYPE_LOCAL } from './driver-config';
+ INSTALL_TYPE_LOCAL } from '../driver-config';
import NPM from './npm';
-import { errAndQuit, log, spinWith, JSON_SPACES } from './cli-utils';
+import { errAndQuit, log, spinWith, JSON_SPACES } from './utils';
import { util, fs } from 'appium-support';
const REQ_DRIVER_FIELDS = ['driverName', 'automationName', 'platformNames', 'mainClass'];
@@ -36,6 +36,8 @@ async function runDriverCommand (args) {
if (json) {
console.log(JSON.stringify(jsonResult, null, JSON_SPACES));
}
+
+ return jsonResult;
}
class DriverCommand {

RENAME
lib/npm.js
lib/cli/npm.js
RENAME
lib/parser-helpers.js
lib/cli/parser-helpers.js
import fs from 'fs';
import _ from 'lodash';
-import { INSTALL_TYPES } from './driver-config';
+import { INSTALL_TYPES } from '../driver-config';
// serverArgs will be added to the `server` (default) subcommand
function parseSecurityFeatures (features) {

RENAME
lib/parser.js
lib/cli/parser.js
@@ -2,8 +2,8 @@ import path from 'path';
import _ from 'lodash';
import { ArgumentParser } from 'argparse';
import { sharedArgs, serverArgs, driverListArgs, driverInstallArgs, driverUninstallArgs,
- driverUpdateArgs } from './cli-args';
-import { rootDir } from './utils';
+ driverUpdateArgs } from './args';
+import { rootDir } from '../utils';
function getParser (debug = false) {
const parser = new ArgumentParser({

RENAME
lib/cli-utils.js
lib/cli/utils.js
MODIFY
lib/main.js
lib/main.js
@@ -6,7 +6,7 @@ import logger from './logger'; // logger needs to remain first of imports
import _ from 'lodash';
import { server as baseServer, routeConfiguringFunction as makeRouter } from 'appium-base-driver';
import { asyncify } from 'asyncbox';
-import { default as getParser, getDefaultServerArgs } from './parser';
+import { default as getParser, getDefaultServerArgs } from './cli/parser';
import { logger as logFactory, util } from 'appium-support';
import {
showConfig, checkNodeOk, validateServerArgs,
@@ -14,7 +14,7 @@ import {
getGitRev, APPIUM_VER
} from './config';
import DriverConfig from './driver-config';
-import { runDriverCommand } from './driver-cli';
+import { runDriverCommand } from './cli/driver';
import { AppiumDriver } from './appium';
import registerNode from './grid-register';
import { inspectObject } from './utils';

MODIFY
test/config-specs.js
test/config-specs.js
@@ -8,7 +8,7 @@ import { getGitRev, getBuildInfo, checkNodeOk, warnNodeDeprecations,
getNonDefaultArgs, validateServerArgs,
validateTmpDir, showConfig, checkValidPort, updateBuildInfo,
APPIUM_VER } from '../lib/config';
-import getParser from '../lib/parser';
+import getParser from '../lib/cli/parser';
import logger from '../lib/logger';
import { fs } from 'appium-support';
import axios from 'axios';

MODIFY
test/driver-e2e-specs.js
test/driver-e2e-specs.js
@@ -7,10 +7,11 @@ import chaiAsPromised from 'chai-as-promised';
import wd from 'wd';
import axios from 'axios';
import { main as appiumServer } from '../lib/main';
-import { DEFAULT_APPIUM_HOME } from '../lib/driver-config';
+import { DEFAULT_APPIUM_HOME, INSTALL_TYPE_NPM } from '../lib/driver-config';
import { TEST_FAKE_APP, TEST_HOST, TEST_PORT } from './helpers';
import { BaseDriver } from 'appium-base-driver';
import { FakeDriver } from 'appium-fake-driver';
+import { runDriverCommand } from '../lib/cli/driver';
import sinon from 'sinon';
chai.use(chaiAsPromised);
@@ -26,13 +27,31 @@ const caps = {
describe('FakeDriver - via HTTP', function () {
let server = null;
+ const appiumHome = DEFAULT_APPIUM_HOME;
const baseUrl = `http://${TEST_HOST}:${TEST_PORT}/wd/hub/session`;
before(async function () {
+ // first ensure we have fakedriver installed
+ const driverList = await runDriverCommand({
+ appiumHome,
+ driverCommand: 'list',
+ showInstalled: true,
+ });
+ if (!_.has(driverList, 'fake')) {
+ await runDriverCommand({
+ appiumHome,
+ driverCommand: 'install',
+ driver: 'appium-fake-driver',
+ installType: INSTALL_TYPE_NPM,
+ });
+ }
+
+ // then start server if we need to
if (shouldStartServer) {
- let args = {port: TEST_PORT, host: TEST_HOST, appiumHome: DEFAULT_APPIUM_HOME};
+ let args = {port: TEST_PORT, host: TEST_HOST, appiumHome};
server = await appiumServer(args);
}
});
+
after(async function () {
if (server) {
await server.close();

MODIFY
test/parser-specs.js
test/parser-specs.js
// transpile:mocha
-import { getParser } from '../lib/parser';
+import { getParser } from '../lib/cli/parser';
import { INSTALL_TYPES, DEFAULT_APPIUM_HOME } from '../lib/driver-config';
import chai from 'chai';

refactor: move all cli related functionality into a cli dir