@appium/base-plugin 3.0.5 → 3.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/build/lib/index.d.ts +2 -0
- package/build/lib/index.d.ts.map +1 -0
- package/build/lib/index.js +14 -0
- package/build/lib/index.js.map +1 -0
- package/build/lib/plugin.d.ts +16 -62
- package/build/lib/plugin.d.ts.map +1 -1
- package/build/lib/plugin.js +12 -66
- package/build/lib/plugin.js.map +1 -1
- package/lib/index.ts +6 -0
- package/lib/plugin.ts +81 -0
- package/package.json +12 -11
- package/tsconfig.json +3 -9
- package/index.js +0 -1
- package/lib/plugin.js +0 -107
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../lib/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,UAAU,EAAE,OAAO,EAAC,MAAM,UAAU,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.default = exports.BasePlugin = void 0;
|
|
7
|
+
var plugin_1 = require("./plugin");
|
|
8
|
+
Object.defineProperty(exports, "BasePlugin", { enumerable: true, get: function () { return plugin_1.BasePlugin; } });
|
|
9
|
+
Object.defineProperty(exports, "default", { enumerable: true, get: function () { return __importDefault(plugin_1).default; } });
|
|
10
|
+
// Handle smoke test flag
|
|
11
|
+
if (require.main === module && process.argv[2] === '--smoke-test') {
|
|
12
|
+
process.exit(0);
|
|
13
|
+
}
|
|
14
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../lib/index.ts"],"names":[],"mappings":";;;;;;AAAA,mCAA6C;AAArC,oGAAA,UAAU,OAAA;AAAE,kHAAA,OAAO,OAAA;AAE3B,yBAAyB;AACzB,IAAI,OAAO,CAAC,IAAI,KAAK,MAAM,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,cAAc,EAAE,CAAC;IAClE,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAClB,CAAC"}
|
package/build/lib/plugin.d.ts
CHANGED
|
@@ -1,71 +1,25 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
export type NextPluginCallback = import("@appium/types").NextPluginCallback;
|
|
4
|
-
export type Constraints = import("@appium/types").Constraints;
|
|
5
|
-
export type Driver<C extends Constraints> = import("@appium/types").Driver<C>;
|
|
1
|
+
import { ExtensionCore } from '@appium/base-driver';
|
|
2
|
+
import type { AppiumLogger, Constraints, Driver, ExecuteMethodMap, MethodMap, NextPluginCallback, Plugin, StringRecord } from '@appium/types';
|
|
6
3
|
/**
|
|
7
|
-
*
|
|
4
|
+
* Base plugin class for Appium plugins.
|
|
5
|
+
* Subclasses should use type `import('@appium/types').MethodMap<SubclassName>` for
|
|
6
|
+
* `newMethodMap` and `ExecuteMethodMap<SubclassName>` for `executeMethodMap`.
|
|
8
7
|
*/
|
|
9
|
-
export class BasePlugin extends ExtensionCore implements Plugin {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
*
|
|
13
|
-
* This will verify that the commands in the `newMethodMap` property are
|
|
14
|
-
* valid. It is impossible to use a generic type param here; the type of this should really
|
|
15
|
-
* be something like `MethodMap<T extends BasePlugin>` but that isn't a thing TS does.
|
|
16
|
-
*
|
|
17
|
-
* ```ts
|
|
18
|
-
* static newMethodMap = {
|
|
19
|
-
* '/session/:sessionId/fake_data': {
|
|
20
|
-
* GET: {command: 'getFakeSessionData', neverProxy: true},
|
|
21
|
-
* }
|
|
22
|
-
* } as const;
|
|
23
|
-
* ```
|
|
24
|
-
*/
|
|
25
|
-
static newMethodMap: {};
|
|
26
|
-
/**
|
|
27
|
-
* Subclasses should use type `import('@appium/types').ExecuteMethodMap<SubclassName>`.
|
|
28
|
-
*
|
|
29
|
-
* Building up this map allows the use of the convenience function `executeMethod`, which
|
|
30
|
-
* basically does verification of names and parameters for execute methods implemented by this
|
|
31
|
-
* plugin.
|
|
32
|
-
*
|
|
33
|
-
* ```ts
|
|
34
|
-
* static executeMethodMap = {
|
|
35
|
-
* 'foo: bar': {
|
|
36
|
-
* command: 'commandName',
|
|
37
|
-
* params: {required: ['thing1', 'thing2'], optional: ['thing3']},
|
|
38
|
-
* },
|
|
39
|
-
* } as const;
|
|
40
|
-
* ```
|
|
41
|
-
*/
|
|
42
|
-
static executeMethodMap: {};
|
|
43
|
-
/**
|
|
44
|
-
* @param {string} name
|
|
45
|
-
* @param {Record<string,unknown>} [cliArgs]
|
|
46
|
-
* @param {string|null} driverId
|
|
47
|
-
*/
|
|
48
|
-
constructor(name: string, cliArgs?: Record<string, unknown>, driverId?: string | null);
|
|
8
|
+
export declare class BasePlugin extends ExtensionCore implements Plugin {
|
|
9
|
+
name: string;
|
|
10
|
+
cliArgs: Record<string, unknown>;
|
|
49
11
|
/**
|
|
50
12
|
* @deprecated Use this.log instead of this.logger
|
|
51
|
-
* @type {import('@appium/types').AppiumLogger}
|
|
52
13
|
*/
|
|
53
|
-
logger:
|
|
54
|
-
|
|
55
|
-
|
|
14
|
+
logger: AppiumLogger;
|
|
15
|
+
static newMethodMap: MethodMap<BasePlugin>;
|
|
16
|
+
static executeMethodMap: ExecuteMethodMap<BasePlugin>;
|
|
17
|
+
constructor(name: string, cliArgs?: Record<string, unknown>, driverId?: string | null);
|
|
56
18
|
/**
|
|
57
|
-
* A convenience method
|
|
58
|
-
*
|
|
59
|
-
* `next` and `driver` objects since naturally we'd want to make sure to trigger the driver's own
|
|
60
|
-
* `executeMethod` call if an execute method is not found on the plugin itself.
|
|
61
|
-
*
|
|
62
|
-
* @template {Constraints} C
|
|
63
|
-
* @param {NextPluginCallback} next
|
|
64
|
-
* @param {Driver<C>} driver
|
|
65
|
-
* @param {string} script
|
|
66
|
-
* @param {readonly [import('@appium/types').StringRecord<unknown>] | readonly any[]} protoArgs
|
|
19
|
+
* A convenience method for plugins that implement their own `executeMethodMap`.
|
|
20
|
+
* Pass through to the driver's execute method if the plugin does not handle the script.
|
|
67
21
|
*/
|
|
68
|
-
executeMethod<C extends Constraints>(next: NextPluginCallback, driver: Driver<C>, script: string, protoArgs: readonly [
|
|
22
|
+
executeMethod<C extends Constraints>(next: NextPluginCallback, driver: Driver<C>, script: string, protoArgs: readonly [StringRecord<unknown>] | readonly unknown[]): Promise<unknown>;
|
|
69
23
|
}
|
|
70
|
-
|
|
24
|
+
export default BasePlugin;
|
|
71
25
|
//# sourceMappingURL=plugin.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugin.d.ts","sourceRoot":"","sources":["../../lib/plugin.
|
|
1
|
+
{"version":3,"file":"plugin.d.ts","sourceRoot":"","sources":["../../lib/plugin.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,aAAa,EAGd,MAAM,qBAAqB,CAAC;AAC7B,OAAO,KAAK,EACV,YAAY,EACZ,WAAW,EACX,MAAM,EACN,gBAAgB,EAChB,SAAS,EACT,kBAAkB,EAClB,MAAM,EAEN,YAAY,EACb,MAAM,eAAe,CAAC;AAEvB;;;;GAIG;AACH,qBAAa,UAAW,SAAQ,aAAc,YAAW,MAAM;IAC7D,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAEjC;;OAEG;IACK,MAAM,EAAE,YAAY,CAAC;IAE7B,MAAM,CAAC,YAAY,EAAE,SAAS,CAAC,UAAU,CAAC,CAAM;IAEhD,MAAM,CAAC,gBAAgB,EAAE,gBAAgB,CAAC,UAAU,CAAC,CAAM;gBAGzD,IAAI,EAAE,MAAM,EACZ,OAAO,GAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAM,EACrC,QAAQ,GAAE,MAAM,GAAG,IAAW;IAWhC;;;OAGG;IACG,aAAa,CAAC,CAAC,SAAS,WAAW,EACvC,IAAI,EAAE,kBAAkB,EACxB,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC,EACjB,MAAM,EAAE,MAAM,EACd,SAAS,EAAE,SAAS,CAAC,YAAY,CAAC,OAAO,CAAC,CAAC,GAAG,SAAS,OAAO,EAAE,GAC/D,OAAO,CAAC,OAAO,CAAC;CAoBpB;AAED,eAAe,UAAU,CAAC"}
|
package/build/lib/plugin.js
CHANGED
|
@@ -3,52 +3,15 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.BasePlugin = void 0;
|
|
4
4
|
const base_driver_1 = require("@appium/base-driver");
|
|
5
5
|
/**
|
|
6
|
-
*
|
|
6
|
+
* Base plugin class for Appium plugins.
|
|
7
|
+
* Subclasses should use type `import('@appium/types').MethodMap<SubclassName>` for
|
|
8
|
+
* `newMethodMap` and `ExecuteMethodMap<SubclassName>` for `executeMethodMap`.
|
|
7
9
|
*/
|
|
8
10
|
class BasePlugin extends base_driver_1.ExtensionCore {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
* @type {import('@appium/types').AppiumLogger}
|
|
12
|
-
*/
|
|
13
|
-
logger;
|
|
14
|
-
/**
|
|
15
|
-
* Subclasses should use type `import('@appium/types').MethodMap<SubclassName>`.
|
|
16
|
-
*
|
|
17
|
-
* This will verify that the commands in the `newMethodMap` property are
|
|
18
|
-
* valid. It is impossible to use a generic type param here; the type of this should really
|
|
19
|
-
* be something like `MethodMap<T extends BasePlugin>` but that isn't a thing TS does.
|
|
20
|
-
*
|
|
21
|
-
* ```ts
|
|
22
|
-
* static newMethodMap = {
|
|
23
|
-
* '/session/:sessionId/fake_data': {
|
|
24
|
-
* GET: {command: 'getFakeSessionData', neverProxy: true},
|
|
25
|
-
* }
|
|
26
|
-
* } as const;
|
|
27
|
-
* ```
|
|
28
|
-
*/
|
|
11
|
+
name;
|
|
12
|
+
cliArgs;
|
|
29
13
|
static newMethodMap = {};
|
|
30
|
-
/**
|
|
31
|
-
* Subclasses should use type `import('@appium/types').ExecuteMethodMap<SubclassName>`.
|
|
32
|
-
*
|
|
33
|
-
* Building up this map allows the use of the convenience function `executeMethod`, which
|
|
34
|
-
* basically does verification of names and parameters for execute methods implemented by this
|
|
35
|
-
* plugin.
|
|
36
|
-
*
|
|
37
|
-
* ```ts
|
|
38
|
-
* static executeMethodMap = {
|
|
39
|
-
* 'foo: bar': {
|
|
40
|
-
* command: 'commandName',
|
|
41
|
-
* params: {required: ['thing1', 'thing2'], optional: ['thing3']},
|
|
42
|
-
* },
|
|
43
|
-
* } as const;
|
|
44
|
-
* ```
|
|
45
|
-
*/
|
|
46
14
|
static executeMethodMap = {};
|
|
47
|
-
/**
|
|
48
|
-
* @param {string} name
|
|
49
|
-
* @param {Record<string,unknown>} [cliArgs]
|
|
50
|
-
* @param {string|null} driverId
|
|
51
|
-
*/
|
|
52
15
|
constructor(name, cliArgs = {}, driverId = null) {
|
|
53
16
|
super();
|
|
54
17
|
if (driverId) {
|
|
@@ -59,38 +22,21 @@ class BasePlugin extends base_driver_1.ExtensionCore {
|
|
|
59
22
|
this.logger = this.log;
|
|
60
23
|
}
|
|
61
24
|
/**
|
|
62
|
-
* A convenience method
|
|
63
|
-
*
|
|
64
|
-
* `next` and `driver` objects since naturally we'd want to make sure to trigger the driver's own
|
|
65
|
-
* `executeMethod` call if an execute method is not found on the plugin itself.
|
|
66
|
-
*
|
|
67
|
-
* @template {Constraints} C
|
|
68
|
-
* @param {NextPluginCallback} next
|
|
69
|
-
* @param {Driver<C>} driver
|
|
70
|
-
* @param {string} script
|
|
71
|
-
* @param {readonly [import('@appium/types').StringRecord<unknown>] | readonly any[]} protoArgs
|
|
25
|
+
* A convenience method for plugins that implement their own `executeMethodMap`.
|
|
26
|
+
* Pass through to the driver's execute method if the plugin does not handle the script.
|
|
72
27
|
*/
|
|
73
28
|
async executeMethod(next, driver, script, protoArgs) {
|
|
74
|
-
const
|
|
75
|
-
const commandMetadata = { ...
|
|
29
|
+
const PluginClass = this.constructor;
|
|
30
|
+
const commandMetadata = { ...PluginClass.executeMethodMap?.[script] };
|
|
76
31
|
if (!commandMetadata.command || !(commandMetadata.command in this)) {
|
|
77
|
-
this.
|
|
32
|
+
this.log.info(`Plugin did not know how to handle method '${script}'. Passing control to next`);
|
|
78
33
|
return await next();
|
|
79
34
|
}
|
|
80
|
-
const command =
|
|
81
|
-
const args = (0, base_driver_1.validateExecuteMethodParams)(
|
|
35
|
+
const command = this[commandMetadata.command];
|
|
36
|
+
const args = (0, base_driver_1.validateExecuteMethodParams)(protoArgs, commandMetadata.params);
|
|
82
37
|
return await command.call(this, next, driver, ...args);
|
|
83
38
|
}
|
|
84
39
|
}
|
|
85
40
|
exports.BasePlugin = BasePlugin;
|
|
86
41
|
exports.default = BasePlugin;
|
|
87
|
-
/**
|
|
88
|
-
* @typedef {import('@appium/types').Plugin} Plugin
|
|
89
|
-
* @typedef {import('@appium/types').NextPluginCallback} NextPluginCallback
|
|
90
|
-
* @typedef {import('@appium/types').Constraints} Constraints
|
|
91
|
-
*/
|
|
92
|
-
/**
|
|
93
|
-
* @template {Constraints} C
|
|
94
|
-
* @typedef {import('@appium/types').Driver<C>} Driver
|
|
95
|
-
*/
|
|
96
42
|
//# sourceMappingURL=plugin.js.map
|
package/build/lib/plugin.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugin.js","sourceRoot":"","sources":["../../lib/plugin.
|
|
1
|
+
{"version":3,"file":"plugin.js","sourceRoot":"","sources":["../../lib/plugin.ts"],"names":[],"mappings":";;;AAAA,qDAI6B;AAa7B;;;;GAIG;AACH,MAAa,UAAW,SAAQ,2BAAa;IAC3C,IAAI,CAAS;IACb,OAAO,CAA0B;IAOjC,MAAM,CAAC,YAAY,GAA0B,EAAE,CAAC;IAEhD,MAAM,CAAC,gBAAgB,GAAiC,EAAE,CAAC;IAE3D,YACE,IAAY,EACZ,UAAmC,EAAE,EACrC,WAA0B,IAAI;QAE9B,KAAK,EAAE,CAAC;QACR,IAAI,QAAQ,EAAE,CAAC;YACb,IAAI,CAAC,eAAe,CAAC,GAAG,IAAA,qCAAuB,EAAC,IAAI,CAAC,KAAK,QAAQ,GAAG,CAAC,CAAC;QACzE,CAAC;QACD,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QACvB,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,GAAG,CAAC;IACzB,CAAC;IAED;;;OAGG;IACH,KAAK,CAAC,aAAa,CACjB,IAAwB,EACxB,MAAiB,EACjB,MAAc,EACd,SAAgE;QAEhE,MAAM,WAAW,GAAG,IAAI,CAAC,WAAgC,CAAC;QAC1D,MAAM,eAAe,GAAG,EAAC,GAAG,WAAW,CAAC,gBAAgB,EAAE,CAAC,MAAM,CAAC,EAAC,CAAC;QAEpE,IAAI,CAAC,eAAe,CAAC,OAAO,IAAI,CAAC,CAAC,eAAe,CAAC,OAAO,IAAI,IAAI,CAAC,EAAE,CAAC;YACnE,IAAI,CAAC,GAAG,CAAC,IAAI,CACX,6CAA6C,MAAM,4BAA4B,CAChF,CAAC;YACF,OAAO,MAAM,IAAI,EAAE,CAAC;QACtB,CAAC;QAED,MAAM,OAAO,GAAG,IAAI,CAClB,eAAe,CAAC,OAAqB,CACV,CAAC;QAC9B,MAAM,IAAI,GAAG,IAAA,yCAA2B,EACtC,SAAsB,EACtB,eAAe,CAAC,MAAM,CACvB,CAAC;QACF,OAAO,MAAM,OAAO,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE,GAAG,IAAI,CAAC,CAAC;IACzD,CAAC;;AAvDH,gCAwDC;AAED,kBAAe,UAAU,CAAC"}
|
package/lib/index.ts
ADDED
package/lib/plugin.ts
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import {
|
|
2
|
+
ExtensionCore,
|
|
3
|
+
generateDriverLogPrefix,
|
|
4
|
+
validateExecuteMethodParams,
|
|
5
|
+
} from '@appium/base-driver';
|
|
6
|
+
import type {
|
|
7
|
+
AppiumLogger,
|
|
8
|
+
Constraints,
|
|
9
|
+
Driver,
|
|
10
|
+
ExecuteMethodMap,
|
|
11
|
+
MethodMap,
|
|
12
|
+
NextPluginCallback,
|
|
13
|
+
Plugin,
|
|
14
|
+
PluginCommand,
|
|
15
|
+
StringRecord,
|
|
16
|
+
} from '@appium/types';
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Base plugin class for Appium plugins.
|
|
20
|
+
* Subclasses should use type `import('@appium/types').MethodMap<SubclassName>` for
|
|
21
|
+
* `newMethodMap` and `ExecuteMethodMap<SubclassName>` for `executeMethodMap`.
|
|
22
|
+
*/
|
|
23
|
+
export class BasePlugin extends ExtensionCore implements Plugin {
|
|
24
|
+
name: string;
|
|
25
|
+
cliArgs: Record<string, unknown>;
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* @deprecated Use this.log instead of this.logger
|
|
29
|
+
*/
|
|
30
|
+
declare logger: AppiumLogger;
|
|
31
|
+
|
|
32
|
+
static newMethodMap: MethodMap<BasePlugin> = {};
|
|
33
|
+
|
|
34
|
+
static executeMethodMap: ExecuteMethodMap<BasePlugin> = {};
|
|
35
|
+
|
|
36
|
+
constructor(
|
|
37
|
+
name: string,
|
|
38
|
+
cliArgs: Record<string, unknown> = {},
|
|
39
|
+
driverId: string | null = null
|
|
40
|
+
) {
|
|
41
|
+
super();
|
|
42
|
+
if (driverId) {
|
|
43
|
+
this.updateLogPrefix(`${generateDriverLogPrefix(this)} <${driverId}>`);
|
|
44
|
+
}
|
|
45
|
+
this.name = name;
|
|
46
|
+
this.cliArgs = cliArgs;
|
|
47
|
+
this.logger = this.log;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* A convenience method for plugins that implement their own `executeMethodMap`.
|
|
52
|
+
* Pass through to the driver's execute method if the plugin does not handle the script.
|
|
53
|
+
*/
|
|
54
|
+
async executeMethod<C extends Constraints>(
|
|
55
|
+
next: NextPluginCallback,
|
|
56
|
+
driver: Driver<C>,
|
|
57
|
+
script: string,
|
|
58
|
+
protoArgs: readonly [StringRecord<unknown>] | readonly unknown[]
|
|
59
|
+
): Promise<unknown> {
|
|
60
|
+
const PluginClass = this.constructor as typeof BasePlugin;
|
|
61
|
+
const commandMetadata = {...PluginClass.executeMethodMap?.[script]};
|
|
62
|
+
|
|
63
|
+
if (!commandMetadata.command || !(commandMetadata.command in this)) {
|
|
64
|
+
this.log.info(
|
|
65
|
+
`Plugin did not know how to handle method '${script}'. Passing control to next`
|
|
66
|
+
);
|
|
67
|
+
return await next();
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
const command = this[
|
|
71
|
+
commandMetadata.command as keyof this
|
|
72
|
+
] as PluginCommand<Driver<C>>;
|
|
73
|
+
const args = validateExecuteMethodParams(
|
|
74
|
+
protoArgs as unknown[],
|
|
75
|
+
commandMetadata.params
|
|
76
|
+
);
|
|
77
|
+
return await command.call(this, next, driver, ...args);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
export default BasePlugin;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@appium/base-plugin",
|
|
3
|
-
"version": "3.0
|
|
3
|
+
"version": "3.1.0",
|
|
4
4
|
"description": "The base plugin used to create Appium plugins",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"automation",
|
|
@@ -23,25 +23,26 @@
|
|
|
23
23
|
},
|
|
24
24
|
"license": "Apache-2.0",
|
|
25
25
|
"author": "https://github.com/appium",
|
|
26
|
-
"
|
|
26
|
+
"main": "./build/lib/index.js",
|
|
27
|
+
"types": "./build/lib/index.d.ts",
|
|
27
28
|
"directories": {
|
|
28
29
|
"lib": "./lib"
|
|
29
30
|
},
|
|
30
31
|
"files": [
|
|
32
|
+
"build/lib",
|
|
31
33
|
"lib",
|
|
32
|
-
"
|
|
33
|
-
"index.js",
|
|
34
|
-
"tsconfig.json",
|
|
35
|
-
"!build/tsconfig.tsbuildinfo"
|
|
34
|
+
"tsconfig.json"
|
|
36
35
|
],
|
|
37
36
|
"scripts": {
|
|
37
|
+
"build": "tsc",
|
|
38
38
|
"test": "npm run test:unit",
|
|
39
|
-
"test:smoke": "node ./index.js",
|
|
40
|
-
"test:unit": "mocha \"./test/unit/**/*.spec
|
|
39
|
+
"test:smoke": "node ./build/lib/index.js --smoke-test",
|
|
40
|
+
"test:unit": "mocha \"./test/unit/**/*.spec.*ts\""
|
|
41
41
|
},
|
|
42
42
|
"dependencies": {
|
|
43
|
-
"@appium/base-driver": "^10.1
|
|
44
|
-
"@appium/support": "^7.0.
|
|
43
|
+
"@appium/base-driver": "^10.2.1",
|
|
44
|
+
"@appium/support": "^7.0.6",
|
|
45
|
+
"@appium/types": "^1.2.1"
|
|
45
46
|
},
|
|
46
47
|
"engines": {
|
|
47
48
|
"node": "^20.19.0 || ^22.12.0 || >=24.0.0",
|
|
@@ -50,7 +51,7 @@
|
|
|
50
51
|
"publishConfig": {
|
|
51
52
|
"access": "public"
|
|
52
53
|
},
|
|
53
|
-
"gitHead": "
|
|
54
|
+
"gitHead": "980a121804ae006db879fb6860f627ac36174c15",
|
|
54
55
|
"tags": [
|
|
55
56
|
"appium"
|
|
56
57
|
]
|
package/tsconfig.json
CHANGED
|
@@ -1,14 +1,8 @@
|
|
|
1
1
|
{
|
|
2
|
-
"extends": "@appium/tsconfig/tsconfig.json",
|
|
3
2
|
"compilerOptions": {
|
|
4
3
|
"outDir": "build",
|
|
5
|
-
"
|
|
6
|
-
"strict": true,
|
|
7
|
-
"paths": {
|
|
8
|
-
"@appium/support": ["../support"],
|
|
9
|
-
"@appium/types": ["../types"]
|
|
10
|
-
}
|
|
4
|
+
"types": ["mocha", "chai"]
|
|
11
5
|
},
|
|
12
|
-
"
|
|
13
|
-
"
|
|
6
|
+
"extends": "@appium/tsconfig/tsconfig.plugin.json",
|
|
7
|
+
"include": ["lib", "test"]
|
|
14
8
|
}
|
package/index.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
module.exports = require('./build/lib/plugin');
|
package/lib/plugin.js
DELETED
|
@@ -1,107 +0,0 @@
|
|
|
1
|
-
import {ExtensionCore, generateDriverLogPrefix, validateExecuteMethodParams} from '@appium/base-driver';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* @implements {Plugin}
|
|
5
|
-
*/
|
|
6
|
-
class BasePlugin extends ExtensionCore {
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* @deprecated Use this.log instead of this.logger
|
|
10
|
-
* @type {import('@appium/types').AppiumLogger}
|
|
11
|
-
*/
|
|
12
|
-
logger;
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* Subclasses should use type `import('@appium/types').MethodMap<SubclassName>`.
|
|
16
|
-
*
|
|
17
|
-
* This will verify that the commands in the `newMethodMap` property are
|
|
18
|
-
* valid. It is impossible to use a generic type param here; the type of this should really
|
|
19
|
-
* be something like `MethodMap<T extends BasePlugin>` but that isn't a thing TS does.
|
|
20
|
-
*
|
|
21
|
-
* ```ts
|
|
22
|
-
* static newMethodMap = {
|
|
23
|
-
* '/session/:sessionId/fake_data': {
|
|
24
|
-
* GET: {command: 'getFakeSessionData', neverProxy: true},
|
|
25
|
-
* }
|
|
26
|
-
* } as const;
|
|
27
|
-
* ```
|
|
28
|
-
*/
|
|
29
|
-
static newMethodMap = {};
|
|
30
|
-
|
|
31
|
-
/**
|
|
32
|
-
* Subclasses should use type `import('@appium/types').ExecuteMethodMap<SubclassName>`.
|
|
33
|
-
*
|
|
34
|
-
* Building up this map allows the use of the convenience function `executeMethod`, which
|
|
35
|
-
* basically does verification of names and parameters for execute methods implemented by this
|
|
36
|
-
* plugin.
|
|
37
|
-
*
|
|
38
|
-
* ```ts
|
|
39
|
-
* static executeMethodMap = {
|
|
40
|
-
* 'foo: bar': {
|
|
41
|
-
* command: 'commandName',
|
|
42
|
-
* params: {required: ['thing1', 'thing2'], optional: ['thing3']},
|
|
43
|
-
* },
|
|
44
|
-
* } as const;
|
|
45
|
-
* ```
|
|
46
|
-
*/
|
|
47
|
-
static executeMethodMap = {};
|
|
48
|
-
|
|
49
|
-
/**
|
|
50
|
-
* @param {string} name
|
|
51
|
-
* @param {Record<string,unknown>} [cliArgs]
|
|
52
|
-
* @param {string|null} driverId
|
|
53
|
-
*/
|
|
54
|
-
constructor(name, cliArgs = {}, driverId = null) {
|
|
55
|
-
super();
|
|
56
|
-
if (driverId) {
|
|
57
|
-
this.updateLogPrefix(`${generateDriverLogPrefix(this)} <${driverId}>`);
|
|
58
|
-
}
|
|
59
|
-
this.name = name;
|
|
60
|
-
this.cliArgs = cliArgs;
|
|
61
|
-
this.logger = this.log;
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
/**
|
|
65
|
-
* A convenience method that can be called by plugins who implement their own `executeMethodMap`.
|
|
66
|
-
* Only useful if your plugin has defined `executeMethodMap`. This helper requires passing in the
|
|
67
|
-
* `next` and `driver` objects since naturally we'd want to make sure to trigger the driver's own
|
|
68
|
-
* `executeMethod` call if an execute method is not found on the plugin itself.
|
|
69
|
-
*
|
|
70
|
-
* @template {Constraints} C
|
|
71
|
-
* @param {NextPluginCallback} next
|
|
72
|
-
* @param {Driver<C>} driver
|
|
73
|
-
* @param {string} script
|
|
74
|
-
* @param {readonly [import('@appium/types').StringRecord<unknown>] | readonly any[]} protoArgs
|
|
75
|
-
*/
|
|
76
|
-
async executeMethod(next, driver, script, protoArgs) {
|
|
77
|
-
const Plugin = /** @type {import('@appium/types').PluginClass<Plugin>} */ (this.constructor);
|
|
78
|
-
const commandMetadata = {...Plugin.executeMethodMap?.[script]};
|
|
79
|
-
|
|
80
|
-
if (!commandMetadata.command || !(commandMetadata.command in this)) {
|
|
81
|
-
this.logger.info(
|
|
82
|
-
`Plugin did not know how to handle method '${script}'. Passing control to next`
|
|
83
|
-
);
|
|
84
|
-
return await next();
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
const command = /** @type {import('@appium/types').PluginCommand<Driver<C>>} */ (
|
|
88
|
-
this[commandMetadata.command]
|
|
89
|
-
);
|
|
90
|
-
const args = validateExecuteMethodParams(/** @type {any[]} */ (protoArgs), commandMetadata.params);
|
|
91
|
-
return await command.call(this, next, driver, ...args);
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
export default BasePlugin;
|
|
96
|
-
export {BasePlugin};
|
|
97
|
-
|
|
98
|
-
/**
|
|
99
|
-
* @typedef {import('@appium/types').Plugin} Plugin
|
|
100
|
-
* @typedef {import('@appium/types').NextPluginCallback} NextPluginCallback
|
|
101
|
-
* @typedef {import('@appium/types').Constraints} Constraints
|
|
102
|
-
*/
|
|
103
|
-
|
|
104
|
-
/**
|
|
105
|
-
* @template {Constraints} C
|
|
106
|
-
* @typedef {import('@appium/types').Driver<C>} Driver
|
|
107
|
-
*/
|