appium 2.0.0-beta.55 → 2.0.0-beta.56

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/appium.js CHANGED
@@ -10,6 +10,7 @@ import {
10
10
  DELETE_SESSION_COMMAND,
11
11
  GET_STATUS_COMMAND,
12
12
  promoteAppiumOptions,
13
+ promoteAppiumOptionsForObject,
13
14
  } from '@appium/base-driver';
14
15
  import AsyncLock from 'async-lock';
15
16
  import {parseCapsForInnerDriver, pullSettings} from './utils';
@@ -44,7 +45,7 @@ class AppiumDriver extends DriverCore {
44
45
  * It is not recommended to access this property directly from the outside
45
46
  * @type {Record<string,ExternalDriver>}
46
47
  */
47
- sessions = {};
48
+ sessions;
48
49
 
49
50
  /**
50
51
  * Access to pending drivers list must be guarded with a Semaphore, because
@@ -52,14 +53,14 @@ class AppiumDriver extends DriverCore {
52
53
  * It is not recommended to access this property directly from the outside
53
54
  * @type {Record<string,ExternalDriver[]>}
54
55
  */
55
- pendingDrivers = {};
56
+ pendingDrivers;
56
57
 
57
58
  /**
58
59
  * Note that {@linkcode AppiumDriver} has no `newCommandTimeout` method.
59
60
  * `AppiumDriver` does not set and observe its own timeouts; individual
60
61
  * sessions (managed drivers) do instead.
61
62
  */
62
- newCommandTimeoutMs = 0;
63
+ newCommandTimeoutMs;
63
64
 
64
65
  /**
65
66
  * List of active plugins
@@ -71,13 +72,13 @@ class AppiumDriver extends DriverCore {
71
72
  * map of sessions to actual plugin instances per session
72
73
  * @type {Record<string,InstanceType<PluginClass>[]>}
73
74
  */
74
- sessionPlugins = {};
75
+ sessionPlugins;
75
76
 
76
77
  /**
77
78
  * some commands are sessionless, so we need a set of plugins for them
78
79
  * @type {InstanceType<PluginClass>[]}
79
80
  */
80
- sessionlessPlugins = [];
81
+ sessionlessPlugins;
81
82
 
82
83
  /** @type {DriverConfig} */
83
84
  driverConfig;
@@ -85,7 +86,11 @@ class AppiumDriver extends DriverCore {
85
86
  /** @type {AppiumServer} */
86
87
  server;
87
88
 
88
- desiredCapConstraints = desiredCapabilityConstraints;
89
+ /**
90
+ * @type {AppiumDriverConstraints}
91
+ * @readonly
92
+ */
93
+ desiredCapConstraints;
89
94
 
90
95
  /** @type {DriverOpts} */
91
96
  args;
@@ -105,6 +110,13 @@ class AppiumDriver extends DriverCore {
105
110
  super(opts);
106
111
 
107
112
  this.args = {...opts};
113
+ this.sessions = {};
114
+ this.pendingDrivers = {};
115
+ this.newCommandTimeoutMs = 0;
116
+ this.pluginClasses = new Map();
117
+ this.sessionPlugins = {};
118
+ this.sessionlessPlugins = [];
119
+ this.desiredCapConstraints = desiredCapabilityConstraints;
108
120
 
109
121
  // allow this to happen in the background, so no `await`
110
122
  (async () => {
@@ -243,7 +255,7 @@ class AppiumDriver extends DriverCore {
243
255
  jsonwpCaps,
244
256
  promoteAppiumOptions(w3cCapabilities),
245
257
  this.desiredCapConstraints,
246
- defaultCapabilities
258
+ defaultCapabilities ? promoteAppiumOptionsForObject(defaultCapabilities) : undefined
247
259
  );
248
260
 
249
261
  const {desiredCaps, processedJsonwpCapabilities, processedW3CCapabilities} =
@@ -693,7 +693,7 @@ class ExtensionCommand {
693
693
  );
694
694
  }
695
695
 
696
- if (!(scriptName in extScripts)) {
696
+ if (!(scriptName in /** @type {Record<string,string>} */ (extScripts))) {
697
697
  throw this._createFatalError(
698
698
  `The ${this.type} named '${installSpec}' does not support the script: '${scriptName}'`
699
699
  );
@@ -435,7 +435,7 @@ export class ExtensionConfig {
435
435
  /**
436
436
  * @param {string} extName
437
437
  * @param {ExtManifest<ExtType>} extManifest
438
- * @param {ExtensionConfigMutationOpts} [opts]
438
+ * @param {ExtensionConfigMutationOpts} opts
439
439
  * @returns {Promise<void>}
440
440
  */
441
441
  async addExtension(extName, extManifest, {write = true} = {}) {
@@ -448,7 +448,7 @@ export class ExtensionConfig {
448
448
  /**
449
449
  * @param {ExtName<ExtType>} extName
450
450
  * @param {ExtManifest<ExtType>} extManifest
451
- * @param {ExtensionConfigMutationOpts} [opts]
451
+ * @param {ExtensionConfigMutationOpts} opts
452
452
  * @returns {Promise<void>}
453
453
  */
454
454
  async updateExtension(extName, extManifest, {write = true} = {}) {
@@ -465,7 +465,7 @@ export class ExtensionConfig {
465
465
  * Remove an extension from the list of installed extensions, and optionally avoid a write to the manifest file.
466
466
  *
467
467
  * @param {ExtName<ExtType>} extName
468
- * @param {ExtensionConfigMutationOpts} [opts]
468
+ * @param {ExtensionConfigMutationOpts} opts
469
469
  * @returns {Promise<void>}
470
470
  */
471
471
  async removeExtension(extName, {write = true} = {}) {
@@ -94,7 +94,7 @@ export class ArgSpec {
94
94
  * The _constructor_ is private. Use {@link ArgSpec.create} instead.
95
95
  * @private
96
96
  * @param {string} name
97
- * @param {ArgSpecOptions<D>} [opts]
97
+ * @param {ArgSpecOptions<D>} opts
98
98
  */
99
99
  constructor(name, {extType, extName, dest, defaultValue} = {}) {
100
100
  // we must normalize the extension name to fit into our convention for CLI
@@ -41,7 +41,9 @@ export class RoachHotelMap extends Map {
41
41
  /**
42
42
  * Extensions that an extension schema file can have.
43
43
  */
44
- export const ALLOWED_SCHEMA_EXTENSIONS = new Set(['.json', '.js', '.cjs']);
44
+ export const ALLOWED_SCHEMA_EXTENSIONS = Object.freeze(
45
+ new Set(/** @type {AllowedSchemaExtension[]} */ (['.json', '.js', '.cjs']))
46
+ );
45
47
 
46
48
  const SCHEMA_KEY = '$schema';
47
49
 
@@ -57,44 +59,39 @@ class AppiumSchema {
57
59
  * An "argument" is a CLI argument or a config property.
58
60
  *
59
61
  * Used to provide easy lookups of argument metadata when converting between different representations of those arguments.
60
- * @private
61
62
  * @type {RoachHotelMap<string,ArgSpec>}
62
63
  */
63
- _argSpecs = new RoachHotelMap();
64
+ #argSpecs = new RoachHotelMap();
64
65
 
65
66
  /**
66
67
  * A map of extension types to extension names to schema objects.
67
68
  *
68
69
  * This data structure is used to ensure there are no naming conflicts. The schemas
69
70
  * are stored here in memory until the instance is _finalized_.
70
- * @private
71
71
  * @type {Record<ExtensionType,Map<string,SchemaObject>>}
72
72
  */
73
- _registeredSchemas = {[DRIVER_TYPE]: new Map(), [PLUGIN_TYPE]: new Map()};
73
+ #registeredSchemas = {[DRIVER_TYPE]: new Map(), [PLUGIN_TYPE]: new Map()};
74
74
 
75
75
  /**
76
76
  * Ajv instance
77
77
  *
78
- * @private
79
78
  * @type {Ajv}
80
79
  */
81
- _ajv;
80
+ #ajv;
82
81
 
83
82
  /**
84
83
  * Singleton instance.
85
- * @private
86
84
  * @type {AppiumSchema}
87
85
  */
88
- static _instance;
86
+ static #instance;
89
87
 
90
88
  /**
91
89
  * Lookup of schema IDs to finalized schemas.
92
90
  *
93
91
  * This does not include references, but rather the root schemas themselves.
94
- * @private
95
92
  * @type {Record<string,StrictSchemaObject>?}
96
93
  */
97
- _finalizedSchemas = null;
94
+ #finalizedSchemas = null;
98
95
 
99
96
  /**
100
97
  * Initializes Ajv, adds standard formats and our custom keywords.
@@ -102,7 +99,7 @@ class AppiumSchema {
102
99
  * @private
103
100
  */
104
101
  constructor() {
105
- this._ajv = AppiumSchema._instantiateAjv();
102
+ this.#ajv = AppiumSchema._instantiateAjv();
106
103
  }
107
104
 
108
105
  /**
@@ -113,9 +110,9 @@ class AppiumSchema {
113
110
  * @returns {AppiumSchema}
114
111
  */
115
112
  static create() {
116
- if (!AppiumSchema._instance) {
113
+ if (!AppiumSchema.#instance) {
117
114
  const instance = new AppiumSchema();
118
- AppiumSchema._instance = instance;
115
+ AppiumSchema.#instance = instance;
119
116
  _.bindAll(instance, [
120
117
  'finalize',
121
118
  'flatten',
@@ -133,7 +130,7 @@ class AppiumSchema {
133
130
  ]);
134
131
  }
135
132
 
136
- return AppiumSchema._instance;
133
+ return AppiumSchema.#instance;
137
134
  }
138
135
 
139
136
  /**
@@ -145,7 +142,7 @@ class AppiumSchema {
145
142
  * @returns {boolean} If registered
146
143
  */
147
144
  hasRegisteredSchema(extType, extName) {
148
- return this._registeredSchemas[extType].has(extName);
145
+ return this.#registeredSchemas[extType].has(extName);
149
146
  }
150
147
 
151
148
  /**
@@ -154,11 +151,11 @@ class AppiumSchema {
154
151
  * @returns {boolean} If finalized
155
152
  */
156
153
  isFinalized() {
157
- return Boolean(this._finalizedSchemas);
154
+ return Boolean(this.#finalizedSchemas);
158
155
  }
159
156
 
160
157
  getAllArgSpecs() {
161
- return this._argSpecs;
158
+ return this.#argSpecs;
162
159
  }
163
160
 
164
161
  /**
@@ -182,10 +179,10 @@ class AppiumSchema {
182
179
  */
183
180
  finalize() {
184
181
  if (this.isFinalized()) {
185
- return /** @type {NonNullable<typeof this._finalizedSchemas>} */ (this._finalizedSchemas);
182
+ return /** @type {Record<string,StrictSchemaObject>} */ (this.#finalizedSchemas);
186
183
  }
187
184
 
188
- const ajv = this._ajv;
185
+ const ajv = this.#ajv;
189
186
 
190
187
  // Ajv will _mutate_ the schema, so we need to clone it.
191
188
  const baseSchema = _.cloneDeep(AppiumConfigJsonSchema);
@@ -205,7 +202,7 @@ class AppiumSchema {
205
202
  extName,
206
203
  });
207
204
  const {arg} = argSpec;
208
- this._argSpecs.set(arg, argSpec);
205
+ this.#argSpecs.set(arg, argSpec);
209
206
  }
210
207
  };
211
208
 
@@ -217,7 +214,7 @@ class AppiumSchema {
217
214
  const finalizedSchemas = {};
218
215
 
219
216
  const finalSchema = _.reduce(
220
- this._registeredSchemas,
217
+ this.#registeredSchemas,
221
218
  /**
222
219
  * @param {typeof baseSchema} baseSchema
223
220
  * @param {Map<string,SchemaObject>} extensionSchemas
@@ -246,7 +243,7 @@ class AppiumSchema {
246
243
  finalizedSchemas[APPIUM_CONFIG_SCHEMA_ID] = finalSchema;
247
244
  ajv.validateSchema(finalSchema, true);
248
245
 
249
- this._finalizedSchemas = finalizedSchemas;
246
+ this.#finalizedSchemas = finalizedSchemas;
250
247
  return Object.freeze(finalizedSchemas);
251
248
  }
252
249
 
@@ -283,18 +280,18 @@ class AppiumSchema {
283
280
  * @returns {void}
284
281
  */
285
282
  reset() {
286
- for (const schemaId of Object.keys(this._finalizedSchemas ?? {})) {
287
- this._ajv.removeSchema(schemaId);
283
+ for (const schemaId of Object.keys(this.#finalizedSchemas ?? {})) {
284
+ this.#ajv.removeSchema(schemaId);
288
285
  }
289
- this._argSpecs = new RoachHotelMap();
290
- this._registeredSchemas = {
286
+ this.#argSpecs = new RoachHotelMap();
287
+ this.#registeredSchemas = {
291
288
  [DRIVER_TYPE]: new Map(),
292
289
  [PLUGIN_TYPE]: new Map(),
293
290
  };
294
- this._finalizedSchemas = null;
291
+ this.#finalizedSchemas = null;
295
292
 
296
293
  // Ajv seems to have an over-eager cache, so we have to dump the object entirely.
297
- this._ajv = AppiumSchema._instantiateAjv();
294
+ this.#ajv = AppiumSchema._instantiateAjv();
298
295
  }
299
296
 
300
297
  /**
@@ -318,14 +315,14 @@ class AppiumSchema {
318
315
  }
319
316
  const normalizedExtName = _.kebabCase(extName);
320
317
  if (this.hasRegisteredSchema(extType, normalizedExtName)) {
321
- if (_.isEqual(this._registeredSchemas[extType].get(normalizedExtName), schema)) {
318
+ if (_.isEqual(this.#registeredSchemas[extType].get(normalizedExtName), schema)) {
322
319
  return;
323
320
  }
324
321
  throw new SchemaNameConflictError(extType, extName);
325
322
  }
326
- this._ajv.validateSchema(schema, true);
323
+ this.#ajv.validateSchema(schema, true);
327
324
 
328
- this._registeredSchemas[extType].set(normalizedExtName, schema);
325
+ this.#registeredSchemas[extType].set(normalizedExtName, schema);
329
326
  }
330
327
 
331
328
  /**
@@ -336,7 +333,7 @@ class AppiumSchema {
336
333
  * @returns {ArgSpec|undefined} ArgSpec or `undefined` if not found
337
334
  */
338
335
  getArgSpec(name, extType, extName) {
339
- return this._argSpecs.get(ArgSpec.toArg(name, extType, extName));
336
+ return this.#argSpecs.get(ArgSpec.toArg(name, extType, extName));
340
337
  }
341
338
 
342
339
  /**
@@ -347,7 +344,7 @@ class AppiumSchema {
347
344
  * @returns {boolean} `true` if such an {@link ArgSpec} exists
348
345
  */
349
346
  hasArgSpec(name, extType, extName) {
350
- return this._argSpecs.has(ArgSpec.toArg(name, extType, extName));
347
+ return this.#argSpecs.has(ArgSpec.toArg(name, extType, extName));
351
348
  }
352
349
 
353
350
  /**
@@ -391,7 +388,7 @@ class AppiumSchema {
391
388
 
392
389
  /** @type {DefaultValues<Flattened>} */
393
390
  const retval = {};
394
- return [...this._argSpecs.values()].reduce(reducer, retval);
391
+ return [...this.#argSpecs.values()].reduce(reducer, retval);
395
392
  }
396
393
 
397
394
  /**
@@ -405,7 +402,7 @@ class AppiumSchema {
405
402
  if (!this.isFinalized()) {
406
403
  throw new SchemaFinalizationError();
407
404
  }
408
- const specs = [...this._argSpecs.values()].filter(
405
+ const specs = [...this.#argSpecs.values()].filter(
409
406
  (spec) => spec.extType === extType && spec.extName === extName
410
407
  );
411
408
  return specs.reduce((defaults, {defaultValue, rawDest}) => {
@@ -506,7 +503,7 @@ class AppiumSchema {
506
503
  * @returns {import('ajv').ValidateFunction}
507
504
  */
508
505
  _getValidator(id = APPIUM_CONFIG_SCHEMA_ID) {
509
- const validator = this._ajv.getSchema(id);
506
+ const validator = this.#ajv.getSchema(id);
510
507
  if (!validator) {
511
508
  if (id === APPIUM_CONFIG_SCHEMA_ID) {
512
509
  throw new SchemaFinalizationError();
@@ -532,11 +529,13 @@ class AppiumSchema {
532
529
 
533
530
  /**
534
531
  * Returns `true` if `filename`'s file extension is allowed (in {@link ALLOWED_SCHEMA_EXTENSIONS}).
535
- * @param {string} filename
532
+ * @param {import('type-fest').LiteralUnion<AllowedSchemaExtension, string>} filename
536
533
  * @returns {boolean}
537
534
  */
538
535
  static isAllowedSchemaFileExtension(filename) {
539
- return ALLOWED_SCHEMA_EXTENSIONS.has(path.extname(filename));
536
+ return ALLOWED_SCHEMA_EXTENSIONS.has(
537
+ /** @type {AllowedSchemaExtension} */ (path.extname(filename))
538
+ );
540
539
  }
541
540
 
542
541
  /**
@@ -720,3 +719,7 @@ export const {isAllowedSchemaFileExtension} = AppiumSchema;
720
719
  * @template {boolean|undefined} Flattened
721
720
  * @typedef {Record<string,Flattened extends true ? ArgSpecDefaultValue : ArgSpecDefaultValue | NestedArgSpecDefaultValue>} DefaultValues
722
721
  */
722
+
723
+ /**
724
+ * @typedef {'.json'|'.js'|'.cjs'} AllowedSchemaExtension
725
+ */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "appium",
3
- "version": "2.0.0-beta.55",
3
+ "version": "2.0.0-beta.56",
4
4
  "description": "Automation for Apps.",
5
5
  "keywords": [
6
6
  "automation",
@@ -59,12 +59,12 @@
59
59
  "test:unit": "mocha \"./test/unit/**/*.spec.js\""
60
60
  },
61
61
  "dependencies": {
62
- "@appium/base-driver": "^9.3.1",
63
- "@appium/base-plugin": "^2.2.1",
64
- "@appium/docutils": "^0.2.1",
65
- "@appium/schema": "^0.2.4",
66
- "@appium/support": "^3.1.5",
67
- "@appium/types": "^0.9.1",
62
+ "@appium/base-driver": "^9.3.2",
63
+ "@appium/base-plugin": "^2.2.2",
64
+ "@appium/docutils": "^0.2.2",
65
+ "@appium/schema": "^0.2.5",
66
+ "@appium/support": "^3.1.6",
67
+ "@appium/types": "^0.10.0",
68
68
  "@sidvind/better-ajv-errors": "2.1.0",
69
69
  "@types/argparse": "2.0.10",
70
70
  "@types/bluebird": "3.5.38",
@@ -77,7 +77,7 @@
77
77
  "argparse": "2.0.1",
78
78
  "async-lock": "1.4.0",
79
79
  "asyncbox": "2.9.4",
80
- "axios": "1.2.3",
80
+ "axios": "1.3.4",
81
81
  "bluebird": "3.7.2",
82
82
  "cross-env": "7.0.3",
83
83
  "find-up": "5.0.0",
@@ -92,7 +92,7 @@
92
92
  "semver": "7.3.8",
93
93
  "source-map-support": "0.5.21",
94
94
  "teen_process": "2.0.2",
95
- "type-fest": "3.5.6",
95
+ "type-fest": "3.6.0",
96
96
  "winston": "3.8.2",
97
97
  "wrap-ansi": "7.0.0",
98
98
  "yaml": "2.2.1"
@@ -105,7 +105,7 @@
105
105
  "access": "public",
106
106
  "tag": "next"
107
107
  },
108
- "gitHead": "29a5bdac9aead8eca0329d5672c5e2afc2bdf86c",
108
+ "gitHead": "7b4935632222123a4fa7422461f6312f1f0dfbe4",
109
109
  "typedoc": {
110
110
  "entryPoint": "./lib/main.js"
111
111
  }