@appium/types 0.1.0
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/LICENSE +201 -0
- package/README.md +21 -0
- package/build/appium-config.d.ts +175 -0
- package/build/appium-config.d.ts.map +1 -0
- package/build/capabilities.d.ts +47 -0
- package/build/capabilities.d.ts.map +1 -0
- package/build/config.d.ts +80 -0
- package/build/config.d.ts.map +1 -0
- package/build/index.d.ts +422 -0
- package/build/index.d.ts.map +1 -0
- package/lib/appium-config.ts +197 -0
- package/lib/capabilities.ts +60 -0
- package/lib/config.ts +128 -0
- package/lib/index.ts +623 -0
- package/package.json +43 -0
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import type { Capabilities as WdioCaps } from '@wdio/types';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* The mask of a W3C-style namespaced capability proped name.
|
|
5
|
+
*/
|
|
6
|
+
type Namespaced = `${string}:${string}`;
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* An object with keys conforming to {@linkcode Namespaced}.
|
|
10
|
+
*/
|
|
11
|
+
type NamespacedRecord = Record<Namespaced, any>;
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* An object with keys for strings.
|
|
15
|
+
*/
|
|
16
|
+
type StringRecord = Record<string, any>;
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* All known capabilities derived from wdio's {@linkcode WdioCaps.Capabilities Capabilities} type, accepting additional optional caps.
|
|
20
|
+
* All properties are optional.
|
|
21
|
+
*/
|
|
22
|
+
type BaseCapabilities<OptionalCaps extends StringRecord = StringRecord> =
|
|
23
|
+
Partial<WdioCaps.Capabilities & OptionalCaps>;
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* All known capabilities derived from wdio's {@linkcode WdioCaps.Capabilities Capabilities} type and wdio's {@linkcode WdioCaps.AppiumCapabilities} type, accepting additional optional caps.
|
|
27
|
+
*
|
|
28
|
+
* In practice, the properties `platformName` and `automationName` are required by Appium.
|
|
29
|
+
*/
|
|
30
|
+
export type Capabilities<OptionalCaps extends StringRecord = StringRecord> =
|
|
31
|
+
BaseCapabilities<WdioCaps.AppiumCapabilities & OptionalCaps>;
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* All known capabilities derived from wdio's {@linkcode WdioCaps.Capabilities Capabilities} type and wdio's {@linkcode WdioCaps.AppiumW3CCapabilities} type, accepting additional optional _namespaced_ caps.
|
|
35
|
+
*/
|
|
36
|
+
export type AppiumW3CCapabilities<
|
|
37
|
+
OptionalNamespacedCaps extends NamespacedRecord = NamespacedRecord,
|
|
38
|
+
> = BaseCapabilities<WdioCaps.AppiumW3CCapabilities & OptionalNamespacedCaps>;
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* All known capabilities derived from wdio's {@linkcode WdioCaps.Capabilities Capabilities} type and wdio's {@linkcode WdioCaps.AppiumW3Capabilities} type, accepting additional optional _namespaced_ caps, in W3C-compatible format (`alwaysMatch`/`firstMatch`).
|
|
42
|
+
* In practice, the properties `appium:platformName` and `appium:automationName` are required by Appium _somewhere_ in this object; this cannot be expressed in TypeScript.
|
|
43
|
+
*/
|
|
44
|
+
export type W3CCapabilities<
|
|
45
|
+
OptionalNamespacedCaps extends NamespacedRecord = NamespacedRecord,
|
|
46
|
+
> = {
|
|
47
|
+
alwaysMatch: AppiumW3CCapabilities<OptionalNamespacedCaps>;
|
|
48
|
+
firstMatch: AppiumW3CCapabilities<OptionalNamespacedCaps>[];
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* These may (or should) be reused by drivers.
|
|
53
|
+
*/
|
|
54
|
+
export type AppiumAndroidCapabilities = WdioCaps.AppiumAndroidCapabilities;
|
|
55
|
+
export type AppiumIOSCapabilities = WdioCaps.AppiumIOSCapabilities;
|
|
56
|
+
export type AppiumXCUICommandTimeouts = WdioCaps.AppiumXCUICommandTimeouts;
|
|
57
|
+
export type AppiumXCUIProcessArguments = WdioCaps.AppiumXCUIProcessArguments;
|
|
58
|
+
export type AppiumXCUISafariGlobalPreferences =
|
|
59
|
+
WdioCaps.AppiumXCUISafariGlobalPreferences;
|
|
60
|
+
export type AppiumXCUITestCapabilities = WdioCaps.AppiumXCUITestCapabilities;
|
package/lib/config.ts
ADDED
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
import type { AppiumConfigJsonSchema } from '@appium/schema';
|
|
2
|
+
import { AppiumConfiguration, ServerConfig } from './appium-config';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* The Appium configuration as it would be in a user-provided configuration file.
|
|
6
|
+
*/
|
|
7
|
+
export type AppiumConfig = Partial<AppiumConfiguration>;
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Derive the "constant" type of the server properties from the schema.
|
|
11
|
+
*/
|
|
12
|
+
type AppiumServerJsonSchema =
|
|
13
|
+
typeof AppiumConfigJsonSchema['properties']['server']['properties'];
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* This type associates the types generated from the schema ({@linkcode AppiumConfiguration})
|
|
17
|
+
* with the schema itself (beginning with the `server` prop).
|
|
18
|
+
*/
|
|
19
|
+
type ServerConfigMapping = Associated<ServerConfig, AppiumServerJsonSchema>;
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Camel-cased server config. _Not_ flattened.
|
|
23
|
+
*/
|
|
24
|
+
export type NormalizedServerConfig = {
|
|
25
|
+
[Prop in keyof ServerConfigMapping as AppiumServerJsonSchema[Prop] extends WithDest
|
|
26
|
+
? AppiumServerJsonSchema[Prop]['appiumCliDest']
|
|
27
|
+
: KebabToCamel<Prop>]: ServerConfig[Prop];
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* "Normalized" config, which is camel-cased (instead of kebab-case, like the schema). It is _not_ flattened.
|
|
32
|
+
*/
|
|
33
|
+
export type NormalizedAppiumConfig = {
|
|
34
|
+
server: NormalizedServerConfig;
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* This type checks if `appiumCliDest` is present in the object via
|
|
39
|
+
* {@linkcode WithDest}, and uses the _value_ of that property for the key name;
|
|
40
|
+
* otherwise uses the camel-cased value of the key name.
|
|
41
|
+
*/
|
|
42
|
+
type SetKeyForProp<Prop extends keyof ServerConfigMapping> =
|
|
43
|
+
AppiumServerJsonSchema[Prop] extends WithDest
|
|
44
|
+
? AppiumServerJsonSchema[Prop]['appiumCliDest']
|
|
45
|
+
: KebabToCamel<Prop>;
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Checks for the existence of default values, and ensures those properties will
|
|
49
|
+
* always be defined (eliminates `| undefined` from the type).
|
|
50
|
+
* If no default value, just a type.
|
|
51
|
+
*/
|
|
52
|
+
type KeyOrDefaultForProp<Prop extends keyof ServerConfigMapping> =
|
|
53
|
+
AppiumServerJsonSchema[Prop] extends WithDefault
|
|
54
|
+
? NonNullable<ServerConfig[Prop]>
|
|
55
|
+
: ServerConfig[Prop];
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* The final shape of the parsed CLI arguments.
|
|
59
|
+
*
|
|
60
|
+
* These will be camel-cased unless overridden by `appiumCliDest` field in schema(s).
|
|
61
|
+
*/
|
|
62
|
+
export type DriverOpts = {
|
|
63
|
+
[Prop in keyof ServerConfigMapping as SetKeyForProp<Prop>]: KeyOrDefaultForProp<Prop>;
|
|
64
|
+
};
|
|
65
|
+
// begin utils
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Converts a kebab-cased string into a camel-cased string.
|
|
69
|
+
*/
|
|
70
|
+
type KebabToCamel<S extends string> =
|
|
71
|
+
S extends `${infer P1}-${infer P2}${infer P3}`
|
|
72
|
+
? `${Lowercase<P1>}${Uppercase<P2>}${KebabToCamel<P3>}`
|
|
73
|
+
: Lowercase<S>;
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Converts an object with kebab-cased keys into camel-cased keys.
|
|
77
|
+
*/
|
|
78
|
+
type ObjectToCamel<T> = {
|
|
79
|
+
[K in keyof T as KebabToCamel<string & K>]: T[K] extends Record<string, any>
|
|
80
|
+
? KeysToCamelCase<T[K]>
|
|
81
|
+
: T[K];
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Converts an object or array to have camel-cased keys.
|
|
86
|
+
*/
|
|
87
|
+
type KeysToCamelCase<T> = {
|
|
88
|
+
[K in keyof T as KebabToCamel<string & K>]: T[K] extends Array<any>
|
|
89
|
+
? KeysToCamelCase<T[K][number]>[]
|
|
90
|
+
: ObjectToCamel<T[K]>;
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* Object `B` has all the keys as object `A` (even if those keys in `A` are otherwise optional).
|
|
95
|
+
*/
|
|
96
|
+
type Associated<A extends object, B extends { [key in keyof Required<A>]: unknown }> = {
|
|
97
|
+
[Prop in keyof Required<A>]: B[Prop];
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
// end utils
|
|
101
|
+
|
|
102
|
+
// begin conditionals
|
|
103
|
+
|
|
104
|
+
// These types describe what a particular prop in the schema _could_ look like. We use them as conditionals in the above types.
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* Certain properties have an `appiumCliDest` prop, which affects the shape of
|
|
108
|
+
* `ParsedArgs`. This type helps recognize these properties.
|
|
109
|
+
*
|
|
110
|
+
* See `appium/lib/schema/keywords` for definition of `appiumCliDest`.
|
|
111
|
+
*/
|
|
112
|
+
interface WithDest {
|
|
113
|
+
appiumCliDest: string;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* Some properties have a `default` prop, which means practically they will not
|
|
118
|
+
* be `undefined` upon parsing.
|
|
119
|
+
*
|
|
120
|
+
* We use this to ensure that the `ParsedArgs` makes guarantees
|
|
121
|
+
* about the presence of properties.
|
|
122
|
+
*/
|
|
123
|
+
interface WithDefault<T = any> {
|
|
124
|
+
default: T;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
// end conditionals
|
|
128
|
+
|