Commit Graph
785 Commits
Author SHA1 Message Date
Jonathan Lipps 555b93bf55 refactor!(support): move opencv related functionality into its own package 2022-01-21 08:52:36 -08:00
Mykola Mokhnach 40a6f054dc fix: Switch colors package to a non-compomised repository (#16317) 2022-01-11 06:45:13 +01:00
Renovate Bot bc86e2800e chore(): update dependency @types/chai to v4.3.0 2021-12-08 10:48:48 +00:00
Renovate Bot 25087c3ee0 chore(gulp-plugins): update dependency @types/node to v16.11.12 2021-12-07 11:30:18 +00:00
Renovate Bot 86e5dc304e chore(): update dependency type-fest to v2.8.0 2021-12-02 10:50:37 +00:00
Renovate Bot 62f1894838 chore(gulp-plugins): update dependency eslint-plugin-promise to v5.2.0 2021-12-01 14:01:28 +00:00
Renovate Bot eafd06fa5a chore(): update dependency type-fest to v2.7.0 2021-12-01 12:27:28 +00:00
Renovate Bot 1e4c3e6f6d chore(gulp-plugins): update dependency @types/node to v16.11.11 2021-11-30 10:23:02 +00:00
Mykola Mokhnach 07887b7c18 refactor(base-driver): Always assume the returned responses are in W3C format (#16175) 2021-11-29 22:55:48 +01:00
Renovate Bot 58d408550f chore(): update dependency @types/sinon-chai to v3.2.6 2021-11-25 10:53:49 +00:00
Renovate Bot c03d98b4ee chore(gulp-plugins): update dependency @types/node to v16.11.10 2021-11-24 11:08:59 +00:00
Christopher Hiller 74a5911515 fix(appium): make object dumps less weird
The `inspectObject()` function in `utils` was doing... stuff... to display both the default caps and non-default arguments.  Arrays, in particular, wound up looking like objects.  I found this objectionable; I hope there isn't a good reason it's this way.

- Remove `utils.inspectObject()` and replace it with `inspect()`, which delegates to Node.js' built-in `util.inspect()` function (which does a bang-up job of dumping objects, including color!)
- Remove the `parser` argument (and return value!) from various functions where it was used.  e.g., `init()` in `main.js` was returning the `parser` instance, but now we don't need it, since it was only needed for `getNonDefaultServerArgs()`, which doesn't need it.  `parser` was being passed through several functions this way.
- Add a dumb test for `utils.inspect()`
- Add another dumb test for `getNonDefaultServerArgs()`
- Add `@types/express` since it was missing.
- More types in various associated places; fix other types
- Consistent naming in impl of `getNonDefaultServerArgs()`
2021-11-23 13:54:59 -08:00
Renovate Bot 5df02abe0a chore(): update dependency type-fest to v2.6.0 2021-11-23 13:56:18 +00:00
Renovate Bot 3e61d93769 chore(): update dependency appium-base-driver to v7.11.2 2021-11-23 10:56:53 +00:00
Christopher Hiller 5a2b981fb7 chore: update 'clean' script to remove any stray package lockfiles
`packages/*/package-lock.json` _should not exist_, but if it does, it will prevent proper versioning.  This fixes that problem.
2021-11-22 12:07:32 -08:00
Christopher Hiller cfa7f003b8 chore(appium): print npm output upon error
This change causes additional output if/when `npm` fails when run in a subprocess.
2021-11-22 12:04:10 -08:00
Renovate Bot 9e75670035 chore(): update dependency appium-base-driver to v7.11.1 2021-11-20 10:33:27 +00:00
Renovate Bot 4aa28b0635 chore(gulp-plugins): update dependency @types/node to v16.11.9 2021-11-19 11:43:03 +00:00
Christopher Hiller 91c3ff7f19 chore: attempt to get install-fake-driver working again in CI 2021-11-18 12:08:50 -08:00
Christopher Hiller d201d64b49 fix: use relative package references
This should (hopefully) fix the Lerna issues we've been encountering.  With this change, the root monorepo lists all packages as dependencies and uses relative `file:` URLs to do so.  This means `lerna bootstrap` is no longer necessary.

In addition, defaults to `--save-exact` in `npm install` and `lerna add`.  Also installs peer dependencies of `@appium/eslint-config-appium`.
2021-11-18 12:08:50 -08:00
Renovate Bot a237dff45c chore(): update dependency type-fest to v2.5.4 2021-11-17 14:05:19 +00:00
Renovate Bot c17a9e4ede chore(gulp-plugins): update babel monorepo to v7.16.4 2021-11-17 11:48:28 +00:00
Christopher Hiller a56cba0b03 fix(appium): ensure correct paths for schema declaration generation
- also convert script to ESM for fun
- transpiles appium just to be sure -- this generates the base schema `.json` file
2021-11-15 11:52:22 -08:00
Renovate Bot 3c14756835 chore(): update dependency @appium/fake-plugin to v1.3.0 2021-11-12 14:45:59 +00:00
Renovate Bot 4338bb8830 chore(): update dependency appium-base-driver to v7.11.0 2021-11-11 14:01:48 +00:00
Renovate Bot 6bdb7a045c chore(eslint-config-appium): update babel monorepo to v7.16.3 2021-11-11 01:49:34 +00:00
Christopher Hiller 7381a13da3 fix(appium): remove extra logging from config-file
Logging was happening here before the logger was properly initialized, which looked weird.  Just remove logs for now until we find a better solution.

In addition, fixed some typing problems:
- we need `@types/node` for node globals (like errors that have a `code` property)
- set various typings as globals: `node`, `mocha`, `chai` & its ilk
2021-11-10 14:44:37 -08:00
Renovate Bot 3929592e6d chore(test-support): update dependency sinon to v12 2021-11-10 11:55:16 -05:00
Renovate Bot d53cbcfbf6 chore(): update dependency eslint-find-rules to v4 2021-11-10 11:54:47 -05:00
Renovate Bot cc315a944e chore(): update dependency type-fest to v2.5.3 2021-11-10 14:29:50 +00:00
Renovate Bot f4cf4db4cc chore(): update dependency json-schema-to-typescript to v10.1.5 2021-11-10 10:58:17 +00:00
Christopher Hiller ad69b6bcf9 chore(gulp-plugins): remove cruft from babel config 2021-11-09 11:57:26 -08:00
Christopher Hiller 6e362a1249 chore: update 'dev' script to NOT notify 2021-11-09 11:57:26 -08:00
Christopher Hiller 0bb78f0870 chore(appium): ensure schema TS declaration is added to stage
`lint-staged` doesn't want to do it because reasons.  I don't think it necessarily supports the use case where if file _A_ is staged, then file _B_ should be staged--it only acts upon file _A_.

also replace the `lint:fix` script with use of `eslint` proper, since using `gulp` misses files _not_ in `packages/`.
2021-11-09 11:57:26 -08:00
Christopher Hiller 548310d018 chore(appium): use Ajv to validate CLI args
This now consumes Ajv directly to validate CLI args.  Since a JSON schema is made of JSON schemas, we can simply validate an argument against _the schema for that argument_.

- Replaced parser transformation functions (`parseSecurityFeatures()`, `parseJsonStringOrFile()`) with custom transforms which are bound to keyword `appiumCliTransformer`.  e.g., any option that can now accept a JSON string or filepath on the command line may use `appiumCliTransformer: 'json'`.  This is the default behavior for `array` and `object` -type options, which cannot easily be expressed on the CLI.  The config file does _not_ support this behavior, so the value must be whatever the schema `type` says (e.g., an `object` instead of a JSON string or filepath).  To this end, removed `parser-helpers.js`
- Further, we now disallow union types in the schema. A prop must have a single type.
- Added custom keywords `appiumCliDest`, `appiumCliDescription`, and `appiumCliTransformer`. Previously (if existed), this could have been any value--these are now typed by the schema--e.g., a number for `appiumCliDest` will fail.
- Added more types and TS checks around
- Fixed misspelling of "successfully" in various places
- Removed `@oclifg/errors` because we can now use `better-ajv-errors` to display them, as intended. It looks great!
- Moved all schema-related stuff to `lib/schema/` because I had too many modules
- Added more constants to please @mykola-mokhnach 😄
- Handles untyped properties or `null`-typed properties
- `getSchema()`, `validate()` etc now accept a schema ID. The schema ID is derived from the argument name. This is how we handle validation for each argument individually.  The config file is still validated against the entire schema at once.
- Fixed problem where only `driverConfigs` were ever used to call extension commands!
- Added some semaphore-like things to `ExtConfigIO` to avoid multiple reads/writes at once
- Fixed display of metavars in `--help`
- More tests; removed tests for removed code
2021-11-09 11:57:26 -08:00
Christopher Hiller d52c36e1ea feat(appium): configuration file and schema support
Summary: This PR adds support for configuration files (e.g., `.appiumrc.json`) and schema definitions.  Command-line options _and_ configuration is now derived from the schema(s), for Appium _and_ its extensions (both plugins and drivers).

## Dependencies
### Development
- Added `through2` for a custom gulp task to convert `appium/lib/appium-config-schema.js` to a JSON file
- Added `json-schema-to-typescript` for converting aforementioned JSON file to a `.d.ts` file (which gets published)

### Production (applies to `appium` only)
- Added `libconfig` for multi-format config file loading, which is a smaller drop-in replacement for `cosmiconfig`
- Added `ajv` for schema support and validation
- Added `ajv-formats` to understand optional value formats (e.g., `ipv4`)
- Added `@sidvind/better-ajv-errors` which provides nice error output on the CLI if the config file is invalid
- Added `@oclif/errors` for better error output on the CLI if _arguments_ are invalid

## New Modules of Note

- `lib/schema.js` consumes `ajv` to create and modify a schema
    - It exposes a handful of public API functions, so that consumers can query the schemas without actually running Appium.
    - The flow is basically this: read the base schema (`appium-config-schema.js`).  When extensions load and have schemas, add those to a pot.  When `finalizeSchema()` is called, throw the base schema into the pot as well, stir, and add to singleton `ajv` instance.  Now we can validate against the stew.
    - The schema for an extension is read and registered via `readExtensionSchema()`
    - Provides a way to get at default (for showing those "non-default" options) and `flattenSchema()` which squishes the finalized schema into a single `Record` key/value object, for use by the CLI.  This may make sense to move into `schema-args.js`
    - Provides access to ajv-and-JSON-schema-defined _formatters_ (which are basically just validation functions).  For example, if we want any string, it's just a `string`.  But if we want the string to match a regexp, that's a formatter.  (e.g., the `hostname` type)
-  lib/config-file.js` consumes `lilconfig` to read config files, validate them against the schema, and provide the result as CLI args
    - Handles conversion between kebab-case and camelCase
    - Contains `formatErrors()` which will be called after validation of a config file fails, which shows _exactly_ where the config file is wrong (usually).
- `lib/cli/schema-args.js` which serves as an adapter between the schema and `argparse`
    - Translates between JSON schema and `argparse`, which...well, I did what I could.  It's pretty close.
    - Wraps the formatters as mentioned above, and provides custom ones.
    - We cannot, unfortunately, wholly use schema validation against CLI args.  The flag names are different, the structure is different, there's no actual _file_ to compare against, and `argparse` does not help.  We _can_ use anything `argparse` natively provides, in addition to `ajv` formatters, and any custom ones (e.g., allowable number ranges).
    - Will likely end up adding more formatters corresponding to various JSON schema features later.  We _may_ be able to use _more_ of Ajv to do this (e.g., reuse its internal validators, if they are public APIs).
- `lib/appium-config-schema.js` which is the root schema. Extensions add to this before it is registered & compiled by `ajv`.
    - The basic shape is that there are three top-level props, `server`, `driver`, and `plugin`.  `server` contains all of the server options as you'd expect, and `driver` and `plugin` will be filled in by extensions.  Each will have properties corresponding to the extension name.  You can find examples in `sample-code` and the test fixtures
    - There's a gulp task that takes this file, rewrites it as JSON, then pipes it into another tool which outputs a `.d.ts` file, nicely described using all of the metadata from the schema.  This will be useful for mainly contributors, extension authors, and consumers of Appium (though not end-users).
- `lib/ext-config-io.js`
    - A new module which handles reading/writing of YAML extension config files only.
    - This class is a singleton.
    - Some logic pulled out of `extension-config.js` and into here
    - Previously, we would read/write this file multiple times (once per subclass of `ExtensionConfig`)
    - This module uses a naive dirty-tracker to persist the extension data automatically.
    - Subclasses of `ExtensionConfig` only have access to their "portion" of the config file; drivers can't see plugins and vice-versa.
    - `DRIVER_TYPE` and `PLUGIN_TYPE` originate here, mainly to avoid a circular dependency

## Modifications

- The single source of truth for the CLI _and_ config file options is the schema, with the caveats that:
    - Command-line arguments (for `appium server` are effectively a flat list, but the schema/config file is not.
    - Extension-specific configuration lives in an extension-type-specific property (`driver` or `plugin`) in the config file
        - Under each (`driver` or `plugin`), each extension may have a configuration section corresponding to the extension name
        - The shape of the extension-specific options _can_ be defined by a schema (and referenced in the `appium.schema` prop of the extension's `package.json`)
        - If an extension does not provide a schema, no validation will occur on any options found here -- TODO needs tests
    - This does _not_ affect _CLI commands_ added by extensions; only options for `server`.
- The `--appium-home` flag is now removed, as we can't find extensions without `APPIUM_HOME`, which means we can't parse arguments (because extensions may have added some).
- `--plugin-args` and `--driver-args` are removed.  These are replaced by individual flags for each argument, defined by the extension in its schema, e.g., `--driver-fake-host=127.0.0.1`
- Extensions can still define argument "constraints" using `argConstraints`, but this is considered deprecated
- `lib/main.js`
    - Now exports a few public APIs
    - split into functions `init` and `main`.  `init` is intended to be run via a consumer, which does what the old `main` did up to starting the server.  This bisection is not perfect, as `init` still does some CLI-related things; it needs to be further broken up.
    - `driverConfig.read()` and `pluginConfig.read()` are now called in `lib/cli/parser.js`.
    - Merges the CLI args, config file args, and defaults, in that order of precedence.
- `lib/grid-register.js`
    - Supports embedded configuration instead of just a path to a JSON file.
    - Not clear to me if `nodeconfig` is a thing we need to keep?
- `lib/extension-config.js`
    - Given `APPIUM_HOME` is where we keep the extensions, this file now defines `APPIUM_HOME`. It is exported from the `appium` package.
    - Add `getSchemaProblems()` method, which will read/validate/register the schema for an extension, if one exists.
    - Added many type annotations
    - `read()` and `write()` now delegate to the singleton `ExtConfigIO` instnace
    - Re-exports `DRIVER_TYPE` and `PLUGIN_TYPE`
- `lib/driver-config.js`
    - **Fix** the case where two drivers attempt to use the same `automationName`.  It appears this was intended, but did not work correctly.  This involved overloading `read()`.
- `lib/plugin-config.js`
    - Literally nothing, which is neat.
- `lib/config.js`
    - Remove unused validations (now occur via schema validation or are extension-specific)
    - Rename `getNonDefaultArgs` to `getNonDefaultServerArgs` to be more specific
    - Rewrote `getNonDefaultServerArgs`, which became much more complicated due to adding a config file and schema defaults to the mix. Flexed my lodash-fu, which is still kind of crappy because I'm better with `lodas/fp`.
- `lib/cli/parser.js`
    - Created a wrapper for `argparse`: class `ArgParser`, which replaces the monkeypatching we were doing here.
    - This class also stores extension-specific args in a namespace.  For example, `--driver-foo-bar=baz` would normally be stored in prop `driverFooBar`, but this moves it into `driver: {foo: {bar: 'baz'}}`, which will be provided to its associated extension
    - `addExtensionsToParser` renamed to `addExtensionCommandsToParser` which is more specific.
    - Removed `getDefaultServerArgs` since those now come from the schema.
    - Removed "shared args" stuff
    - `getParser` is now async, and constructs an `ArgParser`.  By necessity, the extension config YAML is read here (which is still wonky because we have to call `read()` twice; it only actually ends up reading once)
    - `getParser` also _finalizes_ the schema, which means "katamari-up the base schema and all extension schemas, then tell ajv about the result"
- `lib/cli/parser-helpers.js`
    - Allow security features to just be an array (as allowed in schema)
    - TODO: needs test
- `lib/cli/extension.js`
    - Use `APPIUM_HOME` exported from `lib/extension-config` instead of `args.appiumHome`
    - Avoids re-instantiating `ExtensionConfig` subclasses if not needed
- `lib/cli/args.js`
    - Remove all server argument definitions in lieu of schema; leave a few that do not make sense in a config file (like `--config`, which determines the location of the config file!)
    - Server args are now pulled from the schema via a call to `toParserArgs()` with overrides for various validation functions (which are confusingly "types" in `argparse` parlance).  Overrides can probably be removed or relocated to `schema-args`
    - Instantiates the `DriverConfig` and `PluginConfig` instances, which are exported.   These might want to move somewhere else
- Tests
    - Added unit tests for `extension-config`, `grid-register` which were missing
    - Added unit tests for new `schema` and `schema-args` and `config-file` modules
    - Added e2e test for config file handling
    - Other necessary modifications
    - Fix path to `fake-driver` in `driver-e2e-specs`
    - Removed stuff from `parser-specs` which no longer applies

## Other

- Added `scripts/generate-schema-declarations.js` which uses `json-schema-to-typescript` to create `appium-config.d.ts`
- Added config file samples in `.json` and `.yaml` formats
- Added custom gulp task to `appium/gulpfile.js` to generate schema in JSON format, since its "single source of truth" is actually just a big JS object
- Moved `appium` CLI-related tests into `test/cli`
- Added some declarations into `packages/appium/types`; the schema-related one is generated by the script mentioend above, but `types.d.ts` is just some stuff that was not expressible in a docstring
2021-11-09 11:57:26 -08:00
Renovate Bot 6bb9439089 chore(gulp-plugins): update babel monorepo to v7.16.0 2021-10-30 10:41:03 +00:00
Renovate Bot bcc441c612 chore(): update dependency type-fest to v2.5.2 2021-10-27 13:25:10 +00:00
Renovate Bot dedd1a25fa chore(): update dependency @types/sinon to v10.0.6 2021-10-27 10:11:30 +00:00
Renovate Bot 97a9d898f5 chore(): update dependency lint-staged to v11.2.6 2021-10-27 08:29:45 +00:00
Renovate Bot 05ec960c34 chore(): update dependency lint-staged to v11.2.4 2021-10-24 14:02:16 +00:00
Renovate Bot 6e28a8ffce chore(): update dependency @types/sinon to v10.0.5 2021-10-24 11:21:17 +00:00
Renovate Bot 7cbe1f220f chore(gulp-plugins): update dependency babel-plugin-istanbul to v6.1.1 2021-10-21 19:51:41 +00:00
Renovate Bot 54ed9292ac chore(): update dependency type-fest to v2.5.1 2021-10-21 18:39:38 +00:00
Renovate Bot 0d787d9002 chore(): update dependency @types/json-schema to v7.0.9 2021-10-21 12:36:38 +00:00
Renovate Bot 5c6a630686 chore(): update dependency @types/sinon to v10.0.4 2021-10-21 10:48:12 +00:00
Renovate Bot 1a6cf81d55 chore(): update dependency @types/chai to v4.2.22 2021-10-21 10:01:59 +00:00
Renovate Bot 64c5733123 chore(): update dependency lint-staged to v11.2.3 2021-10-21 06:05:33 +00:00
Renovate Bot fb602e3741 chore(gulp-plugins): update dependency mocha to v9.1.3 2021-10-21 03:54:56 +00:00
Renovate Bot b295d85198 chore(): update dependency appium-base-driver to v7.10.1 2021-10-21 01:16:51 +00:00