test(appium): replace all occurrences of 'driver'/'plugin' literals w/ constants
MODIFY
packages/appium/test/e2e/cli.e2e.spec.js
packages/appium/test/e2e/cli.e2e.spec.js
@@ -315,7 +315,7 @@ describe('CLI behavior', function () {
'--source',
'npm',
]);
- await installLocalExtension(appiumHome, 'driver', testDriverPath);
+ await installLocalExtension(appiumHome, DRIVER_TYPE, testDriverPath);
const list = await runList(['--installed']);
expect(list.fake).to.exist;
expect(list.test).to.exist;

MODIFY
packages/appium/test/e2e/config-file.e2e.spec.js
packages/appium/test/e2e/config-file.e2e.spec.js
// @ts-check
+import { DRIVER_TYPE } from '../../lib/constants';
import { readConfigFile, normalizeConfig } from '../../lib/config-file';
import { finalizeSchema, registerSchema, resetSchema } from '../../lib/schema/schema';
import extSchema from '../fixtures/driver.schema.js';
@@ -216,7 +217,7 @@ describe('config file behavior', function () {
beforeEach(function () {
resetSchema();
- registerSchema('driver', 'fake', extSchema);
+ registerSchema(DRIVER_TYPE, 'fake', extSchema);
finalizeSchema();
});

MODIFY
packages/appium/test/e2e/schema.e2e.spec.js
packages/appium/test/e2e/schema.e2e.spec.js
// @ts-check
import { fs, tempDir } from '@appium/support';
import path from 'path';
+import { DRIVER_TYPE } from '../../lib/constants';
import { resolveFixture } from '../helpers';
import { installLocalExtension, runAppium } from './e2e-helpers';
@@ -29,7 +30,7 @@ describe('CLI behavior controlled by schema', function () {
before(async function () {
await installLocalExtension(
appiumHome,
- 'driver',
+ DRIVER_TYPE,
path.dirname(resolveFixture('test-driver/package.json'))
);
help = await runAppium(appiumHome, ['server', '--help']);

MODIFY
packages/appium/test/unit/appiumdriver.spec.js
packages/appium/test/unit/appiumdriver.spec.js
// @ts-check
+import { PLUGIN_TYPE } from '../../lib/constants';
import B from 'bluebird';
import { BaseDriver } from '@appium/base-driver';
import { FakeDriver } from '@appium/fake-driver';
@@ -183,7 +184,6 @@ describe('AppiumDriver', function () {
...W3C_CAPS,
alwaysMatch: {
...W3C_CAPS.alwaysMatch,
- // @ts-expect-error
'appium:someOtherParm': 'someOtherParm',
},
};
@@ -358,7 +358,7 @@ describe('AppiumDriver', function () {
// to establish defaults, we need to register a schema for the plugin.
// note that the `noargs` plugin does not need a schema, because it
// accepts no arguments.
- registerSchema('plugin', ArgsPlugin.pluginName, {
+ registerSchema(PLUGIN_TYPE, ArgsPlugin.pluginName, {
type: 'object',
properties: {
randomArg: {
@@ -367,7 +367,7 @@ describe('AppiumDriver', function () {
}
}
});
- registerSchema('plugin', ArrayArgPlugin.pluginName, {
+ registerSchema(PLUGIN_TYPE, ArrayArgPlugin.pluginName, {
type: 'object',
properties: {
arr: {

MODIFY
packages/appium/test/unit/config.spec.js
packages/appium/test/unit/config.spec.js
@@ -4,8 +4,9 @@ import _ from 'lodash';
import { createSandbox } from 'sinon';
import { getParser } from '../../lib/cli/parser';
import { checkNodeOk, getBuildInfo, getNonDefaultServerArgs, showBuildInfo, showConfig, validateTmpDir, warnNodeDeprecations } from '../../lib/config';
+import { PLUGIN_TYPE } from '../../lib/constants';
import logger from '../../lib/logger';
-import { getDefaultsForSchema, resetSchema, registerSchema, finalizeSchema } from '../../lib/schema/schema';
+import { finalizeSchema, getDefaultsForSchema, registerSchema, resetSchema } from '../../lib/schema/schema';
describe('Config', function () {
/** @type {sinon.SinonSandbox} */
@@ -187,7 +188,7 @@ describe('Config', function () {
describe('with extension schemas', function () {
beforeEach(function () {
resetSchema();
- registerSchema('plugin', 'crypto-fiend', {type: 'object', properties: {elite: {type: 'boolean', default: true}}});
+ registerSchema(PLUGIN_TYPE, 'crypto-fiend', {type: 'object', properties: {elite: {type: 'boolean', default: true}}});
finalizeSchema();
getParser(true);
args = getDefaultsForSchema();

MODIFY
packages/appium/test/unit/extension/manifest.spec.js
packages/appium/test/unit/extension/manifest.spec.js
@@ -315,7 +315,7 @@ describe('Manifest', function () {
/** @type {ExtData<DriverType>} */
beforeEach(function () {
- manifest.addExtension('driver', 'foo', extData);
+ manifest.addExtension(DRIVER_TYPE, 'foo', extData);
});
it('should rewrite', function () {
@@ -412,7 +412,7 @@ describe('Manifest', function () {
packageJson,
'/some/path/to/package.json',
);
- expect(manifest.getExtensionData('plugin')).to.deep.equal({
+ expect(manifest.getExtensionData(PLUGIN_TYPE)).to.deep.equal({
myPlugin: {
mainClass: 'SomeClass',
pkgName: 'derp',
@@ -504,7 +504,7 @@ describe('Manifest', function () {
it('should add a found extension', async function () {
await manifest.syncWithInstalledExtensions();
- expect(manifest.getExtensionData('driver')).to.have.property(
+ expect(manifest.getExtensionData(DRIVER_TYPE)).to.have.property(
'myDriver',
);
});

MODIFY
packages/appium/test/unit/parser.spec.js
packages/appium/test/unit/parser.spec.js
-
+import { DRIVER_TYPE, PLUGIN_TYPE } from '../../lib/constants';
import { getParser } from '../../lib/cli/parser';
import { INSTALL_TYPES } from '../../lib/extension/extension-config';
import * as schema from '../../lib/schema/schema';
@@ -21,7 +21,7 @@ describe('parser', function () {
it('should accept only server and driver subcommands', function () {
p.parseArgs([]);
p.parseArgs(['server']);
- p.parseArgs(['driver', 'list']);
+ p.parseArgs([DRIVER_TYPE, 'list']);
(() => p.parseArgs(['foo'])).should.throw();
(() => p.parseArgs(['foo --bar'])).should.throw();
});
@@ -136,7 +136,7 @@ describe('parser', function () {
// we have to require() here because babel will not compile stuff in node_modules
// (even if it's in the monorepo; there may be a way around this)
// anyway, if we do that, we need to use the `default` prop.
- schema.registerSchema('driver', 'fake', require('@appium/fake-driver/build/lib/fake-driver-schema').default);
+ schema.registerSchema(DRIVER_TYPE, 'fake', require('@appium/fake-driver/build/lib/fake-driver-schema').default);
schema.finalizeSchema();
p = getParser(true);
});
@@ -160,12 +160,12 @@ describe('parser', function () {
it('should not yet apply defaults', function () {
const args = p.parseArgs([]);
- args.should.not.have.property('driver');
+ args.should.not.have.property(DRIVER_TYPE);
});
it('should nicely handle extensions w/ dashes in them', function () {
schema.resetSchema();
- schema.registerSchema('plugin', 'crypto-fiend', {type: 'object', properties: {elite: {type: 'boolean'}}});
+ schema.registerSchema(PLUGIN_TYPE, 'crypto-fiend', {type: 'object', properties: {elite: {type: 'boolean'}}});
schema.finalizeSchema();
p = getParser(true);
const args = p.parseArgs([
@@ -198,123 +198,123 @@ describe('parser', function () {
p = getParser(true);
});
it('should not allow random sub-subcommands', function () {
- (() => p.parseArgs(['driver', 'foo'])).should.throw();
+ (() => p.parseArgs([DRIVER_TYPE, 'foo'])).should.throw();
});
describe('list', function () {
it('should allow an empty argument list', function () {
- const args = p.parseArgs(['driver', 'list']);
- args.subcommand.should.eql('driver');
+ const args = p.parseArgs([DRIVER_TYPE, 'list']);
+ args.subcommand.should.eql(DRIVER_TYPE);
args.driverCommand.should.eql('list');
args.showInstalled.should.eql(false);
args.showUpdates.should.eql(false);
args.json.should.eql(false);
});
it('should allow json format', function () {
- const args = p.parseArgs(['driver', 'list', '--json']);
+ const args = p.parseArgs([DRIVER_TYPE, 'list', '--json']);
args.json.should.eql(true);
});
it('should allow --installed', function () {
- const args = p.parseArgs(['driver', 'list', '--installed']);
+ const args = p.parseArgs([DRIVER_TYPE, 'list', '--installed']);
args.showInstalled.should.eql(true);
});
it('should allow --updates', function () {
- const args = p.parseArgs(['driver', 'list', '--updates']);
+ const args = p.parseArgs([DRIVER_TYPE, 'list', '--updates']);
args.showUpdates.should.eql(true);
});
});
describe('install', function () {
it('should not allow an empty argument list', function () {
- (() => p.parseArgs(['driver', 'install'])).should.throw();
+ (() => p.parseArgs([DRIVER_TYPE, 'install'])).should.throw();
});
it('should take a driver name to install', function () {
- const args = p.parseArgs(['driver', 'install', 'foobar']);
- args.subcommand.should.eql('driver');
+ const args = p.parseArgs([DRIVER_TYPE, 'install', 'foobar']);
+ args.subcommand.should.eql(DRIVER_TYPE);
args.driverCommand.should.eql('install');
args.driver.should.eql('foobar');
should.not.exist(args.installType);
args.json.should.eql(false);
});
it('should allow json format', function () {
- const args = p.parseArgs(['driver', 'install', 'foobar', '--json']);
+ const args = p.parseArgs([DRIVER_TYPE, 'install', 'foobar', '--json']);
args.json.should.eql(true);
});
it('should allow --source', function () {
for (const source of INSTALL_TYPES) {
- const args = p.parseArgs(['driver', 'install', 'foobar', '--source', source]);
+ const args = p.parseArgs([DRIVER_TYPE, 'install', 'foobar', '--source', source]);
args.installType.should.eql(source);
}
});
it('should not allow unknown --source', function () {
- (() => p.parseArgs(['driver', 'install', 'fobar', '--source', 'blah'])).should.throw();
+ (() => p.parseArgs([DRIVER_TYPE, 'install', 'fobar', '--source', 'blah'])).should.throw();
});
});
describe('uninstall', function () {
it('should not allow an empty argument list', function () {
- (() => p.parseArgs(['driver', 'uninstall'])).should.throw();
+ (() => p.parseArgs([DRIVER_TYPE, 'uninstall'])).should.throw();
});
it('should take a driver name to uninstall', function () {
- const args = p.parseArgs(['driver', 'uninstall', 'foobar']);
- args.subcommand.should.eql('driver');
+ const args = p.parseArgs([DRIVER_TYPE, 'uninstall', 'foobar']);
+ args.subcommand.should.eql(DRIVER_TYPE);
args.driverCommand.should.eql('uninstall');
args.driver.should.eql('foobar');
args.json.should.eql(false);
});
it('should allow json format', function () {
- const args = p.parseArgs(['driver', 'uninstall', 'foobar', '--json']);
+ const args = p.parseArgs([DRIVER_TYPE, 'uninstall', 'foobar', '--json']);
args.json.should.eql(true);
});
});
describe('update', function () {
it('should not allow an empty argument list', function () {
- (() => p.parseArgs(['driver', 'update'])).should.throw();
+ (() => p.parseArgs([DRIVER_TYPE, 'update'])).should.throw();
});
it('should take a driver name to update', function () {
- const args = p.parseArgs(['driver', 'update', 'foobar']);
- args.subcommand.should.eql('driver');
+ const args = p.parseArgs([DRIVER_TYPE, 'update', 'foobar']);
+ args.subcommand.should.eql(DRIVER_TYPE);
args.driverCommand.should.eql('update');
args.driver.should.eql('foobar');
args.json.should.eql(false);
});
it('should allow json format', function () {
- const args = p.parseArgs(['driver', 'update', 'foobar', '--json']);
+ const args = p.parseArgs([DRIVER_TYPE, 'update', 'foobar', '--json']);
args.json.should.eql(true);
});
});
describe('run', function () {
it('should not allow an empty driver argument list', function () {
- (() => p.parseArgs(['driver', 'run'])).should.throw();
+ (() => p.parseArgs([DRIVER_TYPE, 'run'])).should.throw();
});
it('should not allow no driver scriptName', function () {
- (() => p.parseArgs(['driver', 'run', 'foo'])).should.throw();
+ (() => p.parseArgs([DRIVER_TYPE, 'run', 'foo'])).should.throw();
});
it('should take a driverName and scriptName to run', function () {
- const args = p.parseArgs(['driver', 'run', 'foo', 'bar']);
- args.subcommand.should.eql('driver');
+ const args = p.parseArgs([DRIVER_TYPE, 'run', 'foo', 'bar']);
+ args.subcommand.should.eql(DRIVER_TYPE);
args.driverCommand.should.eql('run');
args.driver.should.eql('foo');
args.scriptName.should.eql('bar');
args.json.should.eql(false);
});
it('should allow json format for driver', function () {
- const args = p.parseArgs(['driver', 'run', 'foo', 'bar', '--json']);
+ const args = p.parseArgs([DRIVER_TYPE, 'run', 'foo', 'bar', '--json']);
args.json.should.eql(true);
});
it('should not allow an empty plugin argument list', function () {
- (() => p.parseArgs(['plugin', 'run'])).should.throw();
+ (() => p.parseArgs([PLUGIN_TYPE, 'run'])).should.throw();
});
it('should not allow no plugin scriptName', function () {
- (() => p.parseArgs(['plugin', 'run', 'foo'])).should.throw();
+ (() => p.parseArgs([PLUGIN_TYPE, 'run', 'foo'])).should.throw();
});
it('should take a pluginName and scriptName to run', function () {
- const args = p.parseArgs(['plugin', 'run', 'foo', 'bar']);
- args.subcommand.should.eql('plugin');
+ const args = p.parseArgs([PLUGIN_TYPE, 'run', 'foo', 'bar']);
+ args.subcommand.should.eql(PLUGIN_TYPE);
args.pluginCommand.should.eql('run');
args.plugin.should.eql('foo');
args.scriptName.should.eql('bar');
args.json.should.eql(false);
});
it('should allow json format for plugin', function () {
- const args = p.parseArgs(['plugin', 'run', 'foo', 'bar', '--json']);
+ const args = p.parseArgs([PLUGIN_TYPE, 'run', 'foo', 'bar', '--json']);
args.json.should.eql(true);
});
});

MODIFY
packages/appium/test/unit/schema/arg-spec.spec.js
packages/appium/test/unit/schema/arg-spec.spec.js
// @ts-check
+import { DRIVER_TYPE } from '../../../lib/constants';
import { ArgSpec } from '../../../lib/schema/arg-spec';
const {expect} = chai;
@@ -23,7 +24,7 @@ describe('ArgSpec', function () {
describe('when provided extension information', function () {
it('should return a schema ID for a specific argument within an extension schema', function () {
- expect(ArgSpec.toSchemaRef('bar', 'driver', 'stuff')).to.equal(
+ expect(ArgSpec.toSchemaRef('bar', DRIVER_TYPE, 'stuff')).to.equal(
'driver-stuff.json#/properties/bar',
);
});
@@ -41,7 +42,7 @@ describe('ArgSpec', function () {
describe('when provided extension information', function () {
it('should return a schema ID for an extension', function () {
- expect(ArgSpec.toSchemaBaseRef('driver', 'stuff')).to.equal(
+ expect(ArgSpec.toSchemaBaseRef(DRIVER_TYPE, 'stuff')).to.equal(
'driver-stuff.json',
);
});
@@ -57,7 +58,7 @@ describe('ArgSpec', function () {
describe('when provided extension information', function () {
it('should return an extension-specific arg name', function () {
- expect(ArgSpec.toArg('no-oats', 'driver', 'bad-donkey')).to.equal(
+ expect(ArgSpec.toArg('no-oats', DRIVER_TYPE, 'bad-donkey')).to.equal(
'driver-bad-donkey-no-oats',
);
});
@@ -75,7 +76,7 @@ describe('ArgSpec', function () {
describe('when provided the schema ID of an extension schema', function () {
expect(
ArgSpec.extensionInfoFromRootSchemaId('driver-stuff.json'),
- ).to.eql({extType: 'driver', normalizedExtName: 'stuff'});
+ ).to.eql({extType: DRIVER_TYPE, normalizedExtName: 'stuff'});
});
});
});

MODIFY
packages/appium/test/unit/schema/cli-args.spec.js
packages/appium/test/unit/schema/cli-args.spec.js
// @ts-check
import _ from 'lodash';
-import {resetSchema, finalizeSchema, registerSchema} from '../../../lib/schema';
+import { PLUGIN_TYPE } from '../../../lib/constants';
+import { finalizeSchema, registerSchema, resetSchema } from '../../../lib/schema';
import { toParserArgs } from '../../../lib/schema/cli-args';
import { transformers } from '../../../lib/schema/cli-transformers';
@@ -29,7 +30,7 @@ describe('cli-args', function () {
describe('schema contents', function () {
const extName = 'blob';
- const extType = 'plugin';
+ const extType = PLUGIN_TYPE;
describe('type', function () {
let result;

test(appium): replace all occurrences of 'driver'/'plugin' literals w/ constants