@appium/fake-plugin 4.0.6 → 4.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 ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "{}"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright OpenJS Foundation and other contributors, https://openjsf.org/
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
@@ -0,0 +1,2 @@
1
+ export { FakePlugin } from './plugin';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../lib/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,UAAU,EAAC,MAAM,UAAU,CAAC"}
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.FakePlugin = void 0;
4
+ var plugin_1 = require("./plugin");
5
+ Object.defineProperty(exports, "FakePlugin", { enumerable: true, get: function () { return plugin_1.FakePlugin; } });
6
+ // Handle smoke test flag
7
+ if (require.main === module && process.argv[2] === '--smoke-test') {
8
+ process.exit(0);
9
+ }
10
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../lib/index.ts"],"names":[],"mappings":";;;AAAA,mCAAoC;AAA5B,oGAAA,UAAU,OAAA;AAElB,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"}
@@ -1,103 +1,41 @@
1
- export default FakePlugin;
2
- export class FakePlugin extends BasePlugin {
3
- static newMethodMap: {
4
- readonly '/session/:sessionId/fake_data': {
5
- readonly GET: {
6
- readonly command: "getFakeSessionData";
7
- readonly neverProxy: true;
8
- };
9
- readonly POST: {
10
- readonly command: "setFakeSessionData";
11
- readonly payloadParams: {
12
- readonly required: readonly ["data"];
13
- };
14
- readonly neverProxy: true;
15
- };
16
- };
17
- readonly '/session/:sessionId/fakepluginargs': {
18
- readonly GET: {
19
- readonly command: "getFakePluginArgs";
20
- readonly neverProxy: true;
21
- };
22
- };
23
- };
24
- static newBidiCommands: {
25
- readonly 'appium:fake': {
26
- readonly getPluginThing: {
27
- readonly command: "getPluginThing";
28
- };
29
- readonly setPluginThing: {
30
- readonly command: "setPluginThing";
31
- readonly params: {
32
- readonly required: readonly ["thing"];
33
- };
34
- };
35
- readonly doSomeMath: {
36
- readonly command: "doSomeMath";
37
- readonly params: {
38
- readonly required: readonly ["num1", "num2"];
39
- };
40
- };
41
- readonly doSomeMath2: {
42
- readonly command: "doSomeMath2";
43
- readonly params: {
44
- readonly required: readonly ["num1", "num2"];
45
- };
46
- };
47
- };
48
- };
49
- /** @type {string?} */
50
- static _unexpectedData: string | null;
51
- static executeMethodMap: {
52
- readonly 'fake: getThing': {
53
- readonly command: "getFakeThing";
54
- };
55
- readonly 'fake: plugMeIn': {
56
- readonly command: "plugMeIn";
57
- readonly params: {
58
- readonly required: readonly ["socket"];
59
- };
60
- };
61
- };
62
- static fakeRoute(req: any, res: any): void;
63
- static unexpectedData(req: any, res: any): void;
64
- static updateServer(expressApp: any, httpServer: any, cliArgs: any): Promise<void>;
65
- /**
66
- * @param {string} name
67
- * @param {Record<string,unknown>} cliArgs
68
- */
69
- constructor(name: string, cliArgs: Record<string, unknown>);
70
- /**
71
- * @type {string}
72
- * @readonly
73
- */
74
- readonly fakeThing: string;
75
- /**
76
- * @type {any}
77
- */
78
- pluginThing: any;
79
- _clockRunning: boolean;
1
+ import { BasePlugin } from 'appium/plugin';
2
+ import type { Request, Response, Application } from 'express';
3
+ import type { AppiumServer, BidiModuleMap, ExecuteMethodMap, ExternalDriver, MethodMap } from '@appium/types';
4
+ /** Driver as seen by this plugin; may include plugin-specific session data */
5
+ export type DriverLike = ExternalDriver & {
6
+ fakeSessionData?: unknown;
7
+ };
8
+ export declare class FakePlugin extends BasePlugin {
9
+ private readonly fakeThing;
10
+ private pluginThing;
11
+ protected _clockRunning: boolean;
12
+ private static _unexpectedData;
13
+ static newMethodMap: MethodMap<FakePlugin>;
14
+ static newBidiCommands: BidiModuleMap;
15
+ static executeMethodMap: ExecuteMethodMap<FakePlugin>;
16
+ constructor(name: string, cliArgs?: Record<string, unknown>);
17
+ static fakeRoute(_req: Request, res: Response): void;
18
+ static unexpectedData(_req: Request, res: Response): void;
19
+ static updateServer(expressApp: Application, _httpServer: AppiumServer, cliArgs: Record<string, unknown>): Promise<void>;
80
20
  startClock(): Promise<void>;
81
- doSomeMath(next: any, driver: any, num1: any, num2: any): Promise<any>;
82
- doSomeMath2(next: any, driver: any, num1: any, num2: any): Promise<number>;
21
+ doSomeMath(next: () => Promise<number>, _driver: DriverLike, num1: number, num2: number): Promise<number>;
22
+ doSomeMath2(_next: () => Promise<unknown>, _driver: DriverLike, num1: number, num2: number): Promise<number>;
83
23
  getFakeThing(): Promise<string>;
84
- getPluginThing(): Promise<any>;
85
- /**
86
- * @param {() => Promise<any>} next
87
- * @param {import('@appium/types').Driver} driver
88
- * @param {any} thing
89
- */
90
- setPluginThing(next: () => Promise<any>, driver: import("@appium/types").Driver, thing: any): Promise<void>;
91
- plugMeIn(next: any, driver: any, socket: string): Promise<string>;
24
+ getPluginThing(): Promise<unknown>;
25
+ setPluginThing(_next: () => Promise<unknown>, _driver: DriverLike, thing: unknown): Promise<void>;
26
+ plugMeIn(_next: () => Promise<unknown>, _driver: DriverLike, socket: string): Promise<string>;
92
27
  getFakePluginArgs(): Promise<Record<string, unknown>>;
93
- getPageSource(next: any, driver: any, ...args: any[]): Promise<string>;
94
- findElement(next: any, driver: any, ...args: any[]): Promise<any>;
95
- getFakeSessionData(next: any, driver: any): Promise<any>;
96
- setFakeSessionData(next: any, driver: any, ...args: any[]): Promise<null>;
97
- getWindowHandle(next: any): Promise<string>;
98
- onUnexpectedShutdown(driver: any, cause: any): Promise<void>;
99
- execute(next: any, driver: any, script: any, args: any): Promise<unknown>;
100
- deleteSession(next: any): Promise<any>;
28
+ getPageSource(_next: () => Promise<string>, _driver: DriverLike, ...args: unknown[]): Promise<string>;
29
+ findElement(next: () => Promise<{
30
+ fake?: boolean;
31
+ } & Record<string, unknown>>, _driver: DriverLike, ...args: unknown[]): Promise<{
32
+ fake?: boolean;
33
+ } & Record<string, unknown>>;
34
+ getFakeSessionData(_next: () => Promise<unknown>, driver: DriverLike): Promise<unknown>;
35
+ setFakeSessionData(_next: () => Promise<unknown>, driver: DriverLike, ...args: unknown[]): Promise<null>;
36
+ getWindowHandle(next: () => Promise<string>): Promise<string>;
37
+ onUnexpectedShutdown(_driver: DriverLike, cause: Error | string): Promise<void>;
38
+ execute(next: () => Promise<unknown>, driver: DriverLike, script: string, args: unknown[]): Promise<unknown>;
39
+ deleteSession(next: () => Promise<unknown>): Promise<unknown>;
101
40
  }
102
- import { BasePlugin } from 'appium/plugin';
103
41
  //# sourceMappingURL=plugin.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"plugin.d.ts","sourceRoot":"","sources":["../../lib/plugin.js"],"names":[],"mappings":";AAMA;IAwBE;;;;;;;;;;;;;;;;;;;;MAYG;IAEH;;;;;;;;;;;;;;;;;;;;;;;;MAwBG;IAEH,sBAAsB;IACtB,wBADW,MAAM,OAAC,CACY;IAE9B;;;;;;;;;;MAWG;IAEH,2CAEC;IAED,gDAGC;IAGD,mFAMC;IAlFD;;;OAGG;IACH,kBAHW,MAAM,WACN,MAAM,CAAC,MAAM,EAAC,OAAO,CAAC,EAMhC;IArBD;;;OAGG;IACH,oBAHU,MAAM,CAGN;IAEV;;OAEG;IACH,aAFU,GAAG,CAEM;IAEnB,uBAAqB;IAsFrB,4BAQC;IAED,uEAGC;IAED,2EAIC;IAED,gCAGC;IAED,+BAMC;IAED;;;;OAIG;IACH,qBAJW,MAAM,OAAO,CAAC,GAAG,CAAC,UAClB,OAAO,eAAe,EAAE,MAAM,SAC9B,GAA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AAU,EACnB,GAAG,IAAI,EAAE,OAAO,EAAE,GACjB,OAAO,CAAC;QAAC,IAAI,CAAC,EAAE,OAAO,CAAA;KAAC,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAQhD,kBAAkB,CAAC,KAAK,EAAE,MAAM,OAAO,CAAC,OAAO,CAAC,EAAE,MAAM,EAAE,UAAU,GAAG,OAAO,CAAC,OAAO,CAAC;IAKvF,kBAAkB,CACtB,KAAK,EAAE,MAAM,OAAO,CAAC,OAAO,CAAC,EAC7B,MAAM,EAAE,UAAU,EAClB,GAAG,IAAI,EAAE,OAAO,EAAE,GACjB,OAAO,CAAC,IAAI,CAAC;IAMV,eAAe,CAAC,IAAI,EAAE,MAAM,OAAO,CAAC,MAAM,CAAC,GAAG,OAAO,CAAC,MAAM,CAAC;IAK7D,oBAAoB,CAAC,OAAO,EAAE,UAAU,EAAE,KAAK,EAAE,KAAK,GAAG,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAK/E,OAAO,CACX,IAAI,EAAE,MAAM,OAAO,CAAC,OAAO,CAAC,EAC5B,MAAM,EAAE,UAAU,EAClB,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,OAAO,EAAE,GACd,OAAO,CAAC,OAAO,CAAC;IAIb,aAAa,CAAC,IAAI,EAAE,MAAM,OAAO,CAAC,OAAO,CAAC,GAAG,OAAO,CAAC,OAAO,CAAC;CAIpE"}
@@ -1,33 +1,14 @@
1
1
  "use strict";
2
- // @ts-check
3
- var __importDefault = (this && this.__importDefault) || function (mod) {
4
- return (mod && mod.__esModule) ? mod : { "default": mod };
5
- };
6
2
  Object.defineProperty(exports, "__esModule", { value: true });
7
3
  exports.FakePlugin = void 0;
8
4
  const plugin_1 = require("appium/plugin");
9
- const bluebird_1 = __importDefault(require("bluebird"));
5
+ const asyncbox_1 = require("asyncbox");
10
6
  class FakePlugin extends plugin_1.BasePlugin {
11
- /**
12
- * @type {string}
13
- * @readonly
14
- */
15
7
  fakeThing;
16
- /**
17
- * @type {any}
18
- */
19
8
  pluginThing = null;
20
9
  _clockRunning = true;
21
- /**
22
- * @param {string} name
23
- * @param {Record<string,unknown>} cliArgs
24
- */
25
- constructor(name, cliArgs) {
26
- super(name, cliArgs);
27
- this.fakeThing = 'PLUGIN_FAKE_THING';
28
- this.startClock();
29
- }
30
- static newMethodMap = /** @type {const} */ ({
10
+ static _unexpectedData = null;
11
+ static newMethodMap = {
31
12
  '/session/:sessionId/fake_data': {
32
13
  GET: { command: 'getFakeSessionData', neverProxy: true },
33
14
  POST: {
@@ -39,8 +20,8 @@ class FakePlugin extends plugin_1.BasePlugin {
39
20
  '/session/:sessionId/fakepluginargs': {
40
21
  GET: { command: 'getFakePluginArgs', neverProxy: true },
41
22
  },
42
- });
43
- static newBidiCommands = /** @type {const} */ ({
23
+ };
24
+ static newBidiCommands = {
44
25
  'appium:fake': {
45
26
  getPluginThing: {
46
27
  command: 'getPluginThing',
@@ -63,29 +44,30 @@ class FakePlugin extends plugin_1.BasePlugin {
63
44
  required: ['num1', 'num2'],
64
45
  },
65
46
  },
66
- }
67
- });
68
- /** @type {string?} */
69
- static _unexpectedData = null;
70
- static executeMethodMap = /** @type {const} */ ({
71
- // this execute method overrides fake-drivers fake: getThing, for testing
47
+ },
48
+ };
49
+ static executeMethodMap = {
72
50
  'fake: getThing': {
73
51
  command: 'getFakeThing',
74
52
  },
75
- // this is a totally new execute method
76
53
  'fake: plugMeIn': {
77
54
  command: 'plugMeIn',
78
55
  params: { required: ['socket'] },
79
56
  },
80
- });
81
- static fakeRoute(req, res) {
57
+ };
58
+ constructor(name, cliArgs = {}) {
59
+ super(name, cliArgs);
60
+ this.fakeThing = 'PLUGIN_FAKE_THING';
61
+ this.startClock();
62
+ }
63
+ static fakeRoute(_req, res) {
82
64
  res.send(JSON.stringify({ fake: 'fakeResponse' }));
83
65
  }
84
- static unexpectedData(req, res) {
66
+ static unexpectedData(_req, res) {
85
67
  res.send(JSON.stringify(FakePlugin._unexpectedData));
86
68
  FakePlugin._unexpectedData = null;
87
69
  }
88
- static async updateServer(expressApp, httpServer, cliArgs) {
70
+ static async updateServer(expressApp, _httpServer, cliArgs) {
89
71
  expressApp.all('/fake', FakePlugin.fakeRoute);
90
72
  expressApp.all('/unexpected', FakePlugin.unexpectedData);
91
73
  expressApp.all('/cliArgs', (req, res) => {
@@ -94,24 +76,23 @@ class FakePlugin extends plugin_1.BasePlugin {
94
76
  }
95
77
  async startClock() {
96
78
  while (this._clockRunning) {
97
- await bluebird_1.default.delay(250);
79
+ await (0, asyncbox_1.sleep)(250);
98
80
  this.eventEmitter.emit('bidiEvent', {
99
81
  method: 'appium:clock.currentTime',
100
82
  params: { time: Date.now() },
101
83
  });
102
84
  }
103
85
  }
104
- async doSomeMath(next, driver, num1, num2) {
105
- const sum = await next(); // call driver's 'doSomeMath' which sums num1 and num2
106
- return (num1 * num2) + sum;
86
+ async doSomeMath(next, _driver, num1, num2) {
87
+ const sum = await next();
88
+ return num1 * num2 + sum;
107
89
  }
108
- async doSomeMath2(next, driver, num1, num2) {
109
- // ignore next & driver in this method
110
- await bluebird_1.default.delay(1);
90
+ async doSomeMath2(_next, _driver, num1, num2) {
91
+ await (0, asyncbox_1.sleep)(1);
111
92
  return num1 * num2;
112
93
  }
113
94
  async getFakeThing() {
114
- await bluebird_1.default.delay(1);
95
+ await (0, asyncbox_1.sleep)(1);
115
96
  return this.fakeThing;
116
97
  }
117
98
  async getPluginThing() {
@@ -121,39 +102,34 @@ class FakePlugin extends plugin_1.BasePlugin {
121
102
  });
122
103
  return this.pluginThing;
123
104
  }
124
- /**
125
- * @param {() => Promise<any>} next
126
- * @param {import('@appium/types').Driver} driver
127
- * @param {any} thing
128
- */
129
- async setPluginThing(next, driver, thing) {
105
+ async setPluginThing(_next, _driver, thing) {
130
106
  this.pluginThing = thing;
131
107
  }
132
- async plugMeIn(next, driver, /** @type {string} */ socket) {
133
- await bluebird_1.default.delay(1);
108
+ async plugMeIn(_next, _driver, socket) {
109
+ await (0, asyncbox_1.sleep)(1);
134
110
  return `Plugged in to ${socket}`;
135
111
  }
136
112
  async getFakePluginArgs() {
137
- await bluebird_1.default.delay(1);
113
+ await (0, asyncbox_1.sleep)(1);
138
114
  return this.cliArgs;
139
115
  }
140
- async getPageSource(next, driver, ...args) {
141
- await bluebird_1.default.delay(10);
116
+ async getPageSource(_next, _driver, ...args) {
117
+ await (0, asyncbox_1.sleep)(10);
142
118
  return `<Fake>${JSON.stringify(args)}</Fake>`;
143
119
  }
144
- async findElement(next, driver, ...args) {
120
+ async findElement(next, _driver, ...args) {
145
121
  this.log.info(`Before findElement is run with args ${JSON.stringify(args)}`);
146
122
  const originalRes = await next();
147
- this.log.info(`After findElement is run`);
123
+ this.log.info('After findElement is run');
148
124
  originalRes.fake = true;
149
125
  return originalRes;
150
126
  }
151
- async getFakeSessionData(next, driver) {
152
- await bluebird_1.default.delay(1);
153
- return driver.fakeSessionData || null;
127
+ async getFakeSessionData(_next, driver) {
128
+ await (0, asyncbox_1.sleep)(1);
129
+ return driver.fakeSessionData ?? null;
154
130
  }
155
- async setFakeSessionData(next, driver, ...args) {
156
- await bluebird_1.default.delay(1);
131
+ async setFakeSessionData(_next, driver, ...args) {
132
+ await (0, asyncbox_1.sleep)(1);
157
133
  driver.fakeSessionData = args[0];
158
134
  return null;
159
135
  }
@@ -161,7 +137,7 @@ class FakePlugin extends plugin_1.BasePlugin {
161
137
  const handle = await next();
162
138
  return `<<${handle}>>`;
163
139
  }
164
- async onUnexpectedShutdown(driver, cause) {
140
+ async onUnexpectedShutdown(_driver, cause) {
165
141
  this._clockRunning = false;
166
142
  FakePlugin._unexpectedData = `Session ended because ${cause}`;
167
143
  }
@@ -174,5 +150,4 @@ class FakePlugin extends plugin_1.BasePlugin {
174
150
  }
175
151
  }
176
152
  exports.FakePlugin = FakePlugin;
177
- exports.default = FakePlugin;
178
153
  //# sourceMappingURL=plugin.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"plugin.js","sourceRoot":"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,MAAkB,EAClB,GAAG,IAAe;QAElB,MAAM,IAAA,gBAAK,EAAC,CAAC,CAAC,CAAC;QACf,MAAM,CAAC,eAAe,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC;QACjC,OAAO,IAAI,CAAC;IACd,CAAC;IAED,KAAK,CAAC,eAAe,CAAC,IAA2B;QAC/C,MAAM,MAAM,GAAG,MAAM,IAAI,EAAE,CAAC;QAC5B,OAAO,KAAK,MAAM,IAAI,CAAC;IACzB,CAAC;IAED,KAAK,CAAC,oBAAoB,CAAC,OAAmB,EAAE,KAAqB;QACnE,IAAI,CAAC,aAAa,GAAG,KAAK,CAAC;QAC3B,UAAU,CAAC,eAAe,GAAG,yBAAyB,KAAK,EAAE,CAAC;IAChE,CAAC;IAED,KAAK,CAAC,OAAO,CACX,IAA4B,EAC5B,MAAkB,EAClB,MAAc,EACd,IAAe;QAEf,OAAO,MAAM,IAAI,CAAC,aAAa,CAAC,IAAI,EAAE,MAAa,EAAE,MAAM,EAAE,IAAI,CAAC,CAAC;IACrE,CAAC;IAED,KAAK,CAAC,aAAa,CAAC,IAA4B;QAC9C,IAAI,CAAC,aAAa,GAAG,KAAK,CAAC;QAC3B,OAAO,MAAM,IAAI,EAAE,CAAC;IACtB,CAAC;;AA9MH,gCA+MC"}
@@ -1 +1 @@
1
- {"version":3,"file":"fake-error.d.ts","sourceRoot":"","sources":["../../../lib/scripts/fake-error.js"],"names":[],"mappings":""}
1
+ {"version":3,"file":"fake-error.d.ts","sourceRoot":"","sources":["../../../lib/scripts/fake-error.ts"],"names":[],"mappings":""}
@@ -1,4 +1,4 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- throw Error('Unsuccessfully ran the script');
3
+ throw new Error('Unsuccessfully ran the script');
4
4
  //# sourceMappingURL=fake-error.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"fake-error.js","sourceRoot":"","sources":["../../../lib/scripts/fake-error.js"],"names":[],"mappings":";;AAAA,MAAM,KAAK,CAAC,+BAA+B,CAAC,CAAC"}
1
+ {"version":3,"file":"fake-error.js","sourceRoot":"","sources":["../../../lib/scripts/fake-error.ts"],"names":[],"mappings":";;AAAA,MAAM,IAAI,KAAK,CAAC,+BAA+B,CAAC,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"fake-success.d.ts","sourceRoot":"","sources":["../../../lib/scripts/fake-success.js"],"names":[],"mappings":""}
1
+ {"version":3,"file":"fake-success.d.ts","sourceRoot":"","sources":["../../../lib/scripts/fake-success.ts"],"names":[],"mappings":""}
@@ -1,8 +1,5 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
2
  Object.defineProperty(exports, "__esModule", { value: true });
6
- const logger_1 = __importDefault(require("../logger"));
7
- logger_1.default.info('Successfully ran the script');
3
+ // eslint-disable-next-line no-console -- script output
4
+ console.info('Successfully ran the script');
8
5
  //# sourceMappingURL=fake-success.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"fake-success.js","sourceRoot":"","sources":["../../../lib/scripts/fake-success.js"],"names":[],"mappings":";;;;;AAAA,uDAA4B;AAE5B,gBAAG,CAAC,IAAI,CAAC,6BAA6B,CAAC,CAAC"}
1
+ {"version":3,"file":"fake-success.js","sourceRoot":"","sources":["../../../lib/scripts/fake-success.ts"],"names":[],"mappings":";;AAAA,uDAAuD;AACvD,OAAO,CAAC,IAAI,CAAC,6BAA6B,CAAC,CAAC"}
package/lib/index.ts ADDED
@@ -0,0 +1,6 @@
1
+ export {FakePlugin} from './plugin';
2
+
3
+ // Handle smoke test flag
4
+ if (require.main === module && process.argv[2] === '--smoke-test') {
5
+ process.exit(0);
6
+ }
package/lib/plugin.ts ADDED
@@ -0,0 +1,222 @@
1
+ import {BasePlugin} from 'appium/plugin';
2
+ import {sleep} from 'asyncbox';
3
+ import type {Request, Response, Application} from 'express';
4
+ import type {
5
+ AppiumServer,
6
+ BidiModuleMap,
7
+ ExecuteMethodMap,
8
+ ExternalDriver,
9
+ MethodMap,
10
+ } from '@appium/types';
11
+
12
+ /** Driver as seen by this plugin; may include plugin-specific session data */
13
+ export type DriverLike = ExternalDriver & {fakeSessionData?: unknown};
14
+
15
+ export class FakePlugin extends BasePlugin {
16
+ private readonly fakeThing: string;
17
+ private pluginThing: unknown = null;
18
+ protected _clockRunning: boolean = true;
19
+ private static _unexpectedData: string | null = null;
20
+
21
+ static newMethodMap: MethodMap<FakePlugin> = {
22
+ '/session/:sessionId/fake_data': {
23
+ GET: {command: 'getFakeSessionData', neverProxy: true},
24
+ POST: {
25
+ command: 'setFakeSessionData',
26
+ payloadParams: {required: ['data']},
27
+ neverProxy: true,
28
+ },
29
+ },
30
+ '/session/:sessionId/fakepluginargs': {
31
+ GET: {command: 'getFakePluginArgs', neverProxy: true},
32
+ },
33
+ };
34
+
35
+ static newBidiCommands: BidiModuleMap = {
36
+ 'appium:fake': {
37
+ getPluginThing: {
38
+ command: 'getPluginThing',
39
+ },
40
+ setPluginThing: {
41
+ command: 'setPluginThing',
42
+ params: {
43
+ required: ['thing'],
44
+ },
45
+ },
46
+ doSomeMath: {
47
+ command: 'doSomeMath',
48
+ params: {
49
+ required: ['num1', 'num2'],
50
+ },
51
+ },
52
+ doSomeMath2: {
53
+ command: 'doSomeMath2',
54
+ params: {
55
+ required: ['num1', 'num2'],
56
+ },
57
+ },
58
+ },
59
+ };
60
+
61
+ static executeMethodMap: ExecuteMethodMap<FakePlugin> = {
62
+ 'fake: getThing': {
63
+ command: 'getFakeThing',
64
+ },
65
+ 'fake: plugMeIn': {
66
+ command: 'plugMeIn',
67
+ params: {required: ['socket']},
68
+ },
69
+ };
70
+
71
+ constructor(name: string, cliArgs: Record<string, unknown> = {}) {
72
+ super(name, cliArgs);
73
+ this.fakeThing = 'PLUGIN_FAKE_THING';
74
+ this.startClock();
75
+ }
76
+
77
+ static fakeRoute(_req: Request, res: Response): void {
78
+ res.send(JSON.stringify({fake: 'fakeResponse'}));
79
+ }
80
+
81
+ static unexpectedData(_req: Request, res: Response): void {
82
+ res.send(JSON.stringify(FakePlugin._unexpectedData));
83
+ FakePlugin._unexpectedData = null;
84
+ }
85
+
86
+ static async updateServer(
87
+ expressApp: Application,
88
+ _httpServer: AppiumServer,
89
+ cliArgs: Record<string, unknown>
90
+ ): Promise<void> {
91
+ expressApp.all('/fake', FakePlugin.fakeRoute);
92
+ expressApp.all('/unexpected', FakePlugin.unexpectedData);
93
+ expressApp.all('/cliArgs', (req, res) => {
94
+ res.send(JSON.stringify(cliArgs));
95
+ });
96
+ }
97
+
98
+ async startClock(): Promise<void> {
99
+ while (this._clockRunning) {
100
+ await sleep(250);
101
+ this.eventEmitter.emit('bidiEvent', {
102
+ method: 'appium:clock.currentTime',
103
+ params: {time: Date.now()},
104
+ });
105
+ }
106
+ }
107
+
108
+ async doSomeMath(
109
+ next: () => Promise<number>,
110
+ _driver: DriverLike,
111
+ num1: number,
112
+ num2: number
113
+ ): Promise<number> {
114
+ const sum = await next();
115
+ return num1 * num2 + sum;
116
+ }
117
+
118
+ async doSomeMath2(
119
+ _next: () => Promise<unknown>,
120
+ _driver: DriverLike,
121
+ num1: number,
122
+ num2: number
123
+ ): Promise<number> {
124
+ await sleep(1);
125
+ return num1 * num2;
126
+ }
127
+
128
+ async getFakeThing(): Promise<string> {
129
+ await sleep(1);
130
+ return this.fakeThing;
131
+ }
132
+
133
+ async getPluginThing(): Promise<unknown> {
134
+ this.eventEmitter.emit('bidiEvent', {
135
+ method: 'appium:fake.pluginThingRetrieved',
136
+ params: {},
137
+ });
138
+ return this.pluginThing;
139
+ }
140
+
141
+ async setPluginThing(
142
+ _next: () => Promise<unknown>,
143
+ _driver: DriverLike,
144
+ thing: unknown
145
+ ): Promise<void> {
146
+ this.pluginThing = thing;
147
+ }
148
+
149
+ async plugMeIn(
150
+ _next: () => Promise<unknown>,
151
+ _driver: DriverLike,
152
+ socket: string
153
+ ): Promise<string> {
154
+ await sleep(1);
155
+ return `Plugged in to ${socket}`;
156
+ }
157
+
158
+ async getFakePluginArgs(): Promise<Record<string, unknown>> {
159
+ await sleep(1);
160
+ return this.cliArgs;
161
+ }
162
+
163
+ async getPageSource(
164
+ _next: () => Promise<string>,
165
+ _driver: DriverLike,
166
+ ...args: unknown[]
167
+ ): Promise<string> {
168
+ await sleep(10);
169
+ return `<Fake>${JSON.stringify(args)}</Fake>`;
170
+ }
171
+
172
+ async findElement(
173
+ next: () => Promise<{fake?: boolean} & Record<string, unknown>>,
174
+ _driver: DriverLike,
175
+ ...args: unknown[]
176
+ ): Promise<{fake?: boolean} & Record<string, unknown>> {
177
+ this.log.info(`Before findElement is run with args ${JSON.stringify(args)}`);
178
+ const originalRes = await next();
179
+ this.log.info('After findElement is run');
180
+ originalRes.fake = true;
181
+ return originalRes;
182
+ }
183
+
184
+ async getFakeSessionData(_next: () => Promise<unknown>, driver: DriverLike): Promise<unknown> {
185
+ await sleep(1);
186
+ return driver.fakeSessionData ?? null;
187
+ }
188
+
189
+ async setFakeSessionData(
190
+ _next: () => Promise<unknown>,
191
+ driver: DriverLike,
192
+ ...args: unknown[]
193
+ ): Promise<null> {
194
+ await sleep(1);
195
+ driver.fakeSessionData = args[0];
196
+ return null;
197
+ }
198
+
199
+ async getWindowHandle(next: () => Promise<string>): Promise<string> {
200
+ const handle = await next();
201
+ return `<<${handle}>>`;
202
+ }
203
+
204
+ async onUnexpectedShutdown(_driver: DriverLike, cause: Error | string): Promise<void> {
205
+ this._clockRunning = false;
206
+ FakePlugin._unexpectedData = `Session ended because ${cause}`;
207
+ }
208
+
209
+ async execute(
210
+ next: () => Promise<unknown>,
211
+ driver: DriverLike,
212
+ script: string,
213
+ args: unknown[]
214
+ ): Promise<unknown> {
215
+ return await this.executeMethod(next, driver as any, script, args);
216
+ }
217
+
218
+ async deleteSession(next: () => Promise<unknown>): Promise<unknown> {
219
+ this._clockRunning = false;
220
+ return await next();
221
+ }
222
+ }
@@ -0,0 +1 @@
1
+ throw new Error('Unsuccessfully ran the script');
@@ -0,0 +1,2 @@
1
+ // eslint-disable-next-line no-console -- script output
2
+ console.info('Successfully ran the script');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@appium/fake-plugin",
3
- "version": "4.0.6",
3
+ "version": "4.1.0",
4
4
  "description": "A fake Appium plugin",
5
5
  "keywords": [
6
6
  "automation",
@@ -23,28 +23,31 @@
23
23
  },
24
24
  "license": "Apache-2.0",
25
25
  "author": "https://github.com/appium",
26
+ "main": "./build/lib/index.js",
27
+ "types": "./build/lib/index.d.ts",
26
28
  "directories": {
27
29
  "lib": "./lib"
28
30
  },
29
31
  "files": [
30
- "index.js",
32
+ "build/lib",
31
33
  "lib",
32
- "build",
33
- "tsconfig.json",
34
- "!build/tsconfig.tsbuildinfo",
35
- "!build/test"
34
+ "tsconfig.json"
36
35
  ],
37
36
  "scripts": {
38
37
  "test": "npm run test:unit",
39
- "test:smoke": "node ./index.js",
40
- "test:unit": "mocha \"./test/unit/**/*.spec.js\""
38
+ "test:smoke": "node ./build/lib/index.js --smoke-test",
39
+ "test:unit": "mocha \"./test/unit/**/*.spec.*ts\""
41
40
  },
42
41
  "dependencies": {
43
- "@appium/base-plugin": "^3.0.6",
44
- "@appium/support": "^7.0.5",
45
- "bluebird": "3.7.2",
42
+ "@appium/base-plugin": "^3.1.0",
43
+ "@appium/support": "^7.0.6",
44
+ "asyncbox": "6.1.0",
46
45
  "lodash": "4.17.23"
47
46
  },
47
+ "devDependencies": {
48
+ "@appium/types": "^1.2.1",
49
+ "express": "5.2.1"
50
+ },
48
51
  "peerDependencies": {
49
52
  "appium": "^3.0.0-beta.0"
50
53
  },
@@ -63,7 +66,7 @@
63
66
  "publishConfig": {
64
67
  "access": "public"
65
68
  },
66
- "gitHead": "f7b20335eab4022e5cbbb627ec86866a994444f8",
69
+ "gitHead": "980a121804ae006db879fb6860f627ac36174c15",
67
70
  "tags": [
68
71
  "appium"
69
72
  ]
package/tsconfig.json CHANGED
@@ -1,13 +1,11 @@
1
1
  {
2
2
  "compilerOptions": {
3
3
  "outDir": "build",
4
- "checkJs": true
4
+ "types": ["mocha", "chai", "chai-as-promised"]
5
5
  },
6
6
  "extends": "@appium/tsconfig/tsconfig.plugin.json",
7
- "include": ["lib"],
7
+ "include": ["lib", "test"],
8
8
  "references": [
9
- {
10
- "path": "../base-plugin"
11
- }
9
+ {"path": "../base-plugin"}
12
10
  ]
13
11
  }
@@ -1,3 +0,0 @@
1
- export default log;
2
- declare const log: import("@appium/types").AppiumLogger;
3
- //# sourceMappingURL=logger.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../../lib/logger.js"],"names":[],"mappings":";AAEA,wDAA2C"}
@@ -1,6 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const support_1 = require("appium/support");
4
- const log = support_1.logger.getLogger('FakePlugin');
5
- exports.default = log;
6
- //# sourceMappingURL=logger.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"logger.js","sourceRoot":"","sources":["../../lib/logger.js"],"names":[],"mappings":";;AAAA,4CAAsC;AAEtC,MAAM,GAAG,GAAG,gBAAM,CAAC,SAAS,CAAC,YAAY,CAAC,CAAC;AAE3C,kBAAe,GAAG,CAAC"}
package/index.js DELETED
@@ -1,3 +0,0 @@
1
- 'use strict';
2
-
3
- module.exports = require('./build/lib/plugin');
package/lib/logger.js DELETED
@@ -1,5 +0,0 @@
1
- import {logger} from 'appium/support';
2
-
3
- const log = logger.getLogger('FakePlugin');
4
-
5
- export default log;
package/lib/plugin.js DELETED
@@ -1,204 +0,0 @@
1
- // @ts-check
2
-
3
-
4
- import {BasePlugin} from 'appium/plugin';
5
- import B from 'bluebird';
6
-
7
- class FakePlugin extends BasePlugin {
8
- /**
9
- * @type {string}
10
- * @readonly
11
- */
12
- fakeThing;
13
-
14
- /**
15
- * @type {any}
16
- */
17
- pluginThing = null;
18
-
19
- _clockRunning = true;
20
-
21
- /**
22
- * @param {string} name
23
- * @param {Record<string,unknown>} cliArgs
24
- */
25
- constructor(name, cliArgs) {
26
- super(name, cliArgs);
27
- this.fakeThing = 'PLUGIN_FAKE_THING';
28
- this.startClock();
29
- }
30
-
31
- static newMethodMap = /** @type {const} */ ({
32
- '/session/:sessionId/fake_data': {
33
- GET: {command: 'getFakeSessionData', neverProxy: true},
34
- POST: {
35
- command: 'setFakeSessionData',
36
- payloadParams: {required: ['data']},
37
- neverProxy: true,
38
- },
39
- },
40
- '/session/:sessionId/fakepluginargs': {
41
- GET: {command: 'getFakePluginArgs', neverProxy: true},
42
- },
43
- });
44
-
45
- static newBidiCommands = /** @type {const} */({
46
- 'appium:fake': {
47
- getPluginThing: {
48
- command: 'getPluginThing',
49
- },
50
- setPluginThing: {
51
- command: 'setPluginThing',
52
- params: {
53
- required: ['thing'],
54
- },
55
- },
56
- doSomeMath: {
57
- command: 'doSomeMath',
58
- params: {
59
- required: ['num1', 'num2'],
60
- },
61
- },
62
- doSomeMath2: {
63
- command: 'doSomeMath2',
64
- params: {
65
- required: ['num1', 'num2'],
66
- },
67
- },
68
- }
69
- });
70
-
71
- /** @type {string?} */
72
- static _unexpectedData = null;
73
-
74
- static executeMethodMap = /** @type {const} */ ({
75
- // this execute method overrides fake-drivers fake: getThing, for testing
76
- 'fake: getThing': {
77
- command: 'getFakeThing',
78
- },
79
-
80
- // this is a totally new execute method
81
- 'fake: plugMeIn': {
82
- command: 'plugMeIn',
83
- params: {required: ['socket']},
84
- },
85
- });
86
-
87
- static fakeRoute(req, res) {
88
- res.send(JSON.stringify({fake: 'fakeResponse'}));
89
- }
90
-
91
- static unexpectedData(req, res) {
92
- res.send(JSON.stringify(FakePlugin._unexpectedData));
93
- FakePlugin._unexpectedData = null;
94
- }
95
-
96
-
97
- static async updateServer(expressApp, httpServer, cliArgs) {
98
- expressApp.all('/fake', FakePlugin.fakeRoute);
99
- expressApp.all('/unexpected', FakePlugin.unexpectedData);
100
- expressApp.all('/cliArgs', (req, res) => {
101
- res.send(JSON.stringify(cliArgs));
102
- });
103
- }
104
-
105
- async startClock() {
106
- while (this._clockRunning) {
107
- await B.delay(250);
108
- this.eventEmitter.emit('bidiEvent', {
109
- method: 'appium:clock.currentTime',
110
- params: {time: Date.now()},
111
- });
112
- }
113
- }
114
-
115
- async doSomeMath(next, driver, num1, num2) {
116
- const sum = await next(); // call driver's 'doSomeMath' which sums num1 and num2
117
- return (num1 * num2) + sum;
118
- }
119
-
120
- async doSomeMath2(next, driver, num1, num2) {
121
- // ignore next & driver in this method
122
- await B.delay(1);
123
- return num1 * num2;
124
- }
125
-
126
- async getFakeThing() {
127
- await B.delay(1);
128
- return this.fakeThing;
129
- }
130
-
131
- async getPluginThing() {
132
- this.eventEmitter.emit('bidiEvent', {
133
- method: 'appium:fake.pluginThingRetrieved',
134
- params: {},
135
- });
136
- return this.pluginThing;
137
- }
138
-
139
- /**
140
- * @param {() => Promise<any>} next
141
- * @param {import('@appium/types').Driver} driver
142
- * @param {any} thing
143
- */
144
- async setPluginThing(next, driver, thing) {
145
- this.pluginThing = thing;
146
- }
147
-
148
- async plugMeIn(next, driver, /** @type {string} */ socket) {
149
- await B.delay(1);
150
- return `Plugged in to ${socket}`;
151
- }
152
-
153
- async getFakePluginArgs() {
154
- await B.delay(1);
155
- return this.cliArgs;
156
- }
157
-
158
- async getPageSource(next, driver, ...args) {
159
- await B.delay(10);
160
- return `<Fake>${JSON.stringify(args)}</Fake>`;
161
- }
162
-
163
- async findElement(next, driver, ...args) {
164
- this.log.info(`Before findElement is run with args ${JSON.stringify(args)}`);
165
- const originalRes = await next();
166
- this.log.info(`After findElement is run`);
167
- originalRes.fake = true;
168
- return originalRes;
169
- }
170
-
171
- async getFakeSessionData(next, driver) {
172
- await B.delay(1);
173
- return driver.fakeSessionData || null;
174
- }
175
-
176
- async setFakeSessionData(next, driver, ...args) {
177
- await B.delay(1);
178
- driver.fakeSessionData = args[0];
179
- return null;
180
- }
181
-
182
- async getWindowHandle(next) {
183
- const handle = await next();
184
- return `<<${handle}>>`;
185
- }
186
-
187
-
188
- async onUnexpectedShutdown(driver, cause) {
189
- this._clockRunning = false;
190
- FakePlugin._unexpectedData = `Session ended because ${cause}`;
191
- }
192
-
193
- async execute(next, driver, script, args) {
194
- return await this.executeMethod(next, driver, script, args);
195
- }
196
-
197
- async deleteSession(next) {
198
- this._clockRunning = false;
199
- return await next();
200
- }
201
- }
202
-
203
- export {FakePlugin};
204
- export default FakePlugin;
@@ -1 +0,0 @@
1
- throw Error('Unsuccessfully ran the script');
@@ -1,3 +0,0 @@
1
- import log from '../logger';
2
-
3
- log.info('Successfully ran the script');