@appium/fake-driver 4.2.2 → 5.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.
Files changed (69) hide show
  1. package/build/lib/commands/alert.d.ts +330 -13
  2. package/build/lib/commands/alert.d.ts.map +1 -1
  3. package/build/lib/commands/alert.js +80 -53
  4. package/build/lib/commands/alert.js.map +1 -1
  5. package/build/lib/commands/contexts.d.ts +330 -14
  6. package/build/lib/commands/contexts.d.ts.map +1 -1
  7. package/build/lib/commands/contexts.js +101 -86
  8. package/build/lib/commands/contexts.js.map +1 -1
  9. package/build/lib/commands/element.d.ts +315 -22
  10. package/build/lib/commands/element.d.ts.map +1 -1
  11. package/build/lib/commands/element.js +112 -123
  12. package/build/lib/commands/element.js.map +1 -1
  13. package/build/lib/commands/find.d.ts +328 -18
  14. package/build/lib/commands/find.d.ts.map +1 -1
  15. package/build/lib/commands/find.js +118 -107
  16. package/build/lib/commands/find.js.map +1 -1
  17. package/build/lib/commands/general.d.ts +332 -28
  18. package/build/lib/commands/general.d.ts.map +1 -1
  19. package/build/lib/commands/general.js +101 -106
  20. package/build/lib/commands/general.js.map +1 -1
  21. package/build/lib/commands/index.d.ts +1523 -2
  22. package/build/lib/commands/index.d.ts.map +1 -1
  23. package/build/lib/commands/index.js +96 -18
  24. package/build/lib/commands/index.js.map +1 -1
  25. package/build/lib/driver.d.ts +145 -33
  26. package/build/lib/driver.d.ts.map +1 -1
  27. package/build/lib/driver.js +200 -145
  28. package/build/lib/driver.js.map +1 -1
  29. package/build/lib/fake-app.d.ts +15 -6
  30. package/build/lib/fake-app.d.ts.map +1 -1
  31. package/build/lib/fake-app.js +155 -194
  32. package/build/lib/fake-app.js.map +1 -1
  33. package/build/lib/fake-driver-schema.js +34 -26
  34. package/build/lib/fake-driver-schema.js.map +1 -1
  35. package/build/lib/fake-element.js +87 -121
  36. package/build/lib/fake-element.js.map +1 -1
  37. package/build/lib/index.d.ts +6 -5
  38. package/build/lib/index.d.ts.map +1 -1
  39. package/build/lib/index.js +19 -36
  40. package/build/lib/index.js.map +1 -1
  41. package/build/lib/logger.d.ts +1 -1
  42. package/build/lib/logger.d.ts.map +1 -1
  43. package/build/lib/logger.js +5 -15
  44. package/build/lib/logger.js.map +1 -1
  45. package/build/lib/scripts/fake-error.js +1 -5
  46. package/build/lib/scripts/fake-error.js.map +1 -1
  47. package/build/lib/scripts/fake-success.js +8 -11
  48. package/build/lib/scripts/fake-success.js.map +1 -1
  49. package/build/lib/server.d.ts +1 -1
  50. package/build/lib/server.d.ts.map +1 -1
  51. package/build/lib/server.js +18 -27
  52. package/build/lib/server.js.map +1 -1
  53. package/build/lib/types.d.ts +36 -0
  54. package/build/lib/types.d.ts.map +1 -0
  55. package/build/lib/types.js +3 -0
  56. package/build/lib/types.js.map +1 -0
  57. package/build/tsconfig.tsbuildinfo +1 -1
  58. package/lib/commands/alert.js +74 -34
  59. package/lib/commands/contexts.js +89 -52
  60. package/lib/commands/element.js +115 -98
  61. package/lib/commands/find.js +106 -77
  62. package/lib/commands/general.js +112 -75
  63. package/lib/commands/index.js +12 -17
  64. package/lib/driver.js +132 -39
  65. package/lib/fake-app.js +20 -6
  66. package/lib/index.js +9 -7
  67. package/lib/types.ts +42 -0
  68. package/package.json +13 -12
  69. package/tsconfig.json +20 -0
@@ -1,82 +1,119 @@
1
- import _ from 'lodash';
2
1
  import {errors} from 'appium/driver';
3
2
 
4
- let commands = {},
5
- helpers = {},
6
- extensions = {};
7
-
8
- commands.title = async function title() {
9
- this.assertWebviewContext();
10
- return this.appModel.title;
11
- };
12
-
13
- commands.keys = async function keys(value) {
14
- if (!this.focusedElId) {
15
- throw new errors.InvalidElementStateError();
16
- }
17
- await this.setValue(value, this.focusedElId);
18
- };
19
-
20
- commands.setGeoLocation = async function setGeoLocation(location) {
21
- // TODO test this adequately once WD bug is fixed
22
- this.appModel.lat = location.latitude;
23
- this.appModel.long = location.longitude;
24
- };
25
-
26
- commands.getGeoLocation = async function getGeoLocation() {
27
- return this.appModel.currentGeoLocation;
28
- };
29
-
30
- commands.getPageSource = async function getPageSource() {
31
- return this.appModel.rawXml;
32
- };
33
-
34
- commands.getOrientation = async function getOrientation() {
35
- return this.appModel.orientation;
36
- };
37
-
38
- commands.setOrientation = async function setOrientation(o) {
39
- if (!_.includes(['LANDSCAPE', 'PORTRAIT'], o)) {
40
- throw new errors.UnknownError('Orientation must be LANDSCAPE or PORTRAIT');
3
+ const ORIENTATIONS = new Set(['LANDSCAPE', 'PORTRAIT']);
4
+
5
+ /**
6
+ * @template {Class<import('../types').IContextsCommands & import('../types').IElementCommands>} T
7
+ * @param {T} Base
8
+ */
9
+ export function GeneralMixin(Base) {
10
+ /**
11
+ * @implements {IGeneralCommands}
12
+ */
13
+ class GeneralCommands extends Base {
14
+ async title() {
15
+ this.assertWebviewContext();
16
+ return this.appModel.title;
17
+ }
18
+
19
+ async keys(value) {
20
+ if (!this.focusedElId) {
21
+ throw new errors.InvalidElementStateError();
22
+ }
23
+ await this.setValue(value, this.focusedElId);
24
+ }
25
+
26
+ async setGeoLocation(location) {
27
+ // TODO test this adequately once WD bug is fixed
28
+ this.appModel.lat = location.latitude;
29
+ this.appModel.long = location.longitude;
30
+ }
31
+
32
+ async getGeoLocation() {
33
+ return this.appModel.currentGeoLocation;
34
+ }
35
+
36
+ async getPageSource() {
37
+ return this.appModel.rawXml;
38
+ }
39
+
40
+ async getOrientation() {
41
+ return this.appModel.orientation;
42
+ }
43
+
44
+ /**
45
+ *
46
+ * @param {import('../types').FakeDriverCaps['orientation']} o
47
+ */
48
+ async setOrientation(o) {
49
+ if (!ORIENTATIONS.has(o)) {
50
+ throw new errors.UnknownError('Orientation must be LANDSCAPE or PORTRAIT');
51
+ }
52
+ this.appModel.orientation = o;
53
+ }
54
+
55
+ async getScreenshot() {
56
+ return this.appModel.getScreenshot();
57
+ }
58
+
59
+ async getWindowSize() {
60
+ return {width: this.appModel.width, height: this.appModel.height};
61
+ }
62
+
63
+ async getWindowRect() {
64
+ return {width: this.appModel.width, height: this.appModel.height, x: 0, y: 0};
65
+ }
66
+
67
+ async performActions(actions) {
68
+ this.appModel.actionLog.push(actions);
69
+ }
70
+
71
+ async releaseActions() {}
72
+
73
+ async getLog(type) {
74
+ switch (type) {
75
+ case 'actions':
76
+ return this.appModel.actionLog;
77
+ default:
78
+ throw new Error(`Don't understand log type '${type}'`);
79
+ }
80
+ }
81
+
82
+ async mobileShake() {
83
+ this.shook = true;
84
+ }
85
+
86
+ async doubleClick() {}
87
+
88
+ async execute(script, args) {
89
+ return await this.executeMethod(script, args);
90
+ }
91
+
92
+ /**
93
+ * Add two or maybe even three numbers
94
+ *
95
+ * @param {number} num1
96
+ * @param {number} num2
97
+ * @param {number} [num3]
98
+ * @returns {Promise<number>}
99
+ */
100
+ async fakeAddition(num1, num2, num3 = 0) {
101
+ return num1 + num2 + (num3 ?? 0);
102
+ }
41
103
  }
42
- this.appModel.orientation = o;
43
- };
44
-
45
- commands.getScreenshot = async function getScreenshot() {
46
- return this.appModel.getScreenshot();
47
- };
48
-
49
- commands.getWindowSize = async function getWindowSize() {
50
- return {width: this.appModel.width, height: this.appModel.height};
51
- };
52
104
 
53
- commands.getWindowRect = async function getWindowRect() {
54
- return {width: this.appModel.width, height: this.appModel.height, x: 0, y: 0};
55
- };
56
-
57
- commands.performActions = async function performActions(actions) {
58
- this.appModel.actionLog.push(actions);
59
- };
60
-
61
- commands.releaseActions = async function releaseActions() {};
62
-
63
- commands.getLog = async function getLog(type) {
64
- switch (type) {
65
- case 'actions':
66
- return this.appModel.actionLog;
67
- default:
68
- throw new Error(`Don't understand log type '${type}'`);
69
- }
70
- };
105
+ return GeneralCommands;
106
+ }
71
107
 
72
- commands.execute = async function execute(script, args) {
73
- return await this.executeMethod(script, args);
74
- };
108
+ /**
109
+ * @typedef {import('../driver').FakeDriverCore} FakeDriverCore
110
+ */
75
111
 
76
- commands.fakeAddition = async function fakeAddition(num1, num2, num3) {
77
- return num1 + num2 + (num3 ?? 0);
78
- };
112
+ /**
113
+ * @template T,[U={}],[V=Array<any>]
114
+ * @typedef {import('@appium/types').Class<T,U,V>} Class
115
+ */
79
116
 
80
- Object.assign(extensions, commands, helpers);
81
- export {commands, helpers};
82
- export default extensions;
117
+ /**
118
+ * @typedef {import('../types').IGeneralCommands} IGeneralCommands
119
+ */
@@ -1,21 +1,16 @@
1
- import contextCommands from './contexts';
2
- import findCommands from './find';
3
- import elementCommands from './element';
4
- import generalCommands from './general';
5
- import alertCommands from './alert';
1
+ import {AlertMixin} from './alert';
2
+ import {ContextsMixin} from './contexts';
3
+ import {ElementMixin} from './element';
4
+ import {FindMixin} from './find';
5
+ import {GeneralMixin} from './general';
6
6
 
7
- let commands = {};
8
-
9
- Object.assign(
10
- commands,
11
- contextCommands,
12
- findCommands,
13
- elementCommands,
14
- generalCommands,
15
- alertCommands
16
- );
17
-
18
- export default commands;
7
+ /**
8
+ *
9
+ * @param {import('@appium/types').Class<import('../driver').FakeDriverCore>} Base
10
+ */
11
+ export function FakeDriverMixin(Base) {
12
+ return GeneralMixin(FindMixin(ElementMixin(AlertMixin(ContextsMixin(Base)))));
13
+ }
19
14
 
20
15
  /* // TODO:
21
16
  //rest.post('/wd/hub/session/:sessionId?/touch/click', controller.doClick);
package/lib/driver.js CHANGED
@@ -1,28 +1,44 @@
1
1
  import B from 'bluebird';
2
- import _ from 'lodash';
3
2
  import {BaseDriver, errors} from 'appium/driver';
3
+ import {deprecatedCommandsLogged} from '@appium/base-driver/build/lib/protocol/protocol';
4
4
  import {FakeApp} from './fake-app';
5
- import commands from './commands';
5
+ import {FakeDriverMixin} from './commands';
6
+
7
+ const FAKE_DRIVER_CONSTRAINTS = /** @type {const} */ ({
8
+ app: {
9
+ presence: true,
10
+ isString: true,
11
+ },
12
+ uniqueApp: {
13
+ isBoolean: true,
14
+ },
15
+ });
16
+
17
+ /**
18
+ * @typedef {typeof FAKE_DRIVER_CONSTRAINTS} FakeDriverConstraints
19
+ */
20
+
21
+ /**
22
+ * @extends {BaseDriver<FakeDriverConstraints>}
23
+ * @implements {ExternalDriver<FakeDriverConstraints>}
24
+ */
25
+ export class FakeDriverCore extends BaseDriver {
26
+ desiredCapConstraints = FAKE_DRIVER_CONSTRAINTS;
27
+
28
+ /** @type {string} */
29
+ curContext;
30
+
31
+ appModel = new FakeApp();
6
32
 
7
- class FakeDriver extends BaseDriver {
8
33
  constructor(opts = {}, shouldValidateCaps = true) {
9
34
  super(opts, shouldValidateCaps);
10
- this.appModel = null;
11
35
  this.curContext = 'NATIVE_APP';
12
36
  this.elMap = {};
13
37
  this.focusedElId = null;
14
38
  this.maxElId = 0;
15
- this.caps = {};
16
39
  this.fakeThing = null;
17
- this.cliArgs = {};
18
40
  this._proxyActive = false;
19
-
20
- this.desiredCapConstraints = {
21
- app: {
22
- presence: true,
23
- isString: true,
24
- },
25
- };
41
+ this.shook = false;
26
42
  }
27
43
 
28
44
  proxyActive() {
@@ -42,22 +58,30 @@ class FakeDriver extends BaseDriver {
42
58
  res.status(200).send(JSON.stringify(resBodyObj));
43
59
  }
44
60
 
45
- proxyCommand(/*url, method, body*/) {
46
- return 'proxied via proxyCommand';
61
+ /**
62
+ * @template [T=any]
63
+ * @returns {Promise<T>}
64
+ */
65
+ async proxyCommand(/*url, method, body*/) {
66
+ return /** @type {T} */ (/** @type {unknown} */ ('proxied via proxyCommand'));
47
67
  }
48
68
 
49
- async createSession(
50
- jsonwpDesiredCapabilities,
51
- jsonwpRequiredCaps,
52
- w3cCapabilities,
53
- otherSessionData = []
54
- ) {
69
+ /**
70
+ * Comment for `createSession` in `FakeDriver`
71
+ * @param {W3CFakeDriverCaps} w3cCapabilities1 W3C Capabilities
72
+ * @param {W3CFakeDriverCaps} [w3cCapabilities2] W3C Capabilities
73
+ * @param {W3CFakeDriverCaps} [w3cCapabilities3] W3C Capabilities
74
+ * @param {import('@appium/types').DriverData[]} [driverData] Other session data
75
+ * @override
76
+ * @returns {Promise<[string,FakeDriverCaps]>} Session ID and normalized capabilities
77
+ */
78
+ async createSession(w3cCapabilities1, w3cCapabilities2, w3cCapabilities3, driverData = []) {
55
79
  // TODO add validation on caps.app that we will get for free from
56
80
  // BaseDriver
57
81
 
58
82
  // check to see if any other sessions have set uniqueApp. If so, emulate
59
83
  // not being able to start a session because of system resources
60
- for (let d of otherSessionData) {
84
+ for (let d of driverData) {
61
85
  if (d.isUnique) {
62
86
  throw new errors.SessionNotCreatedError(
63
87
  'Cannot start session; another ' +
@@ -66,16 +90,9 @@ class FakeDriver extends BaseDriver {
66
90
  }
67
91
  }
68
92
 
69
- let [sessionId, caps] = await super.createSession(
70
- jsonwpDesiredCapabilities,
71
- jsonwpRequiredCaps,
72
- w3cCapabilities,
73
- otherSessionData
93
+ let [sessionId, caps] = /** @type {[string, FakeDriverCaps]} */ (
94
+ await super.createSession(w3cCapabilities1, w3cCapabilities2, w3cCapabilities3, driverData)
74
95
  );
75
- this.appModel = new FakeApp();
76
- if (_.isArray(caps) === true && caps.length === 1) {
77
- caps = caps[0];
78
- }
79
96
  this.caps = caps;
80
97
  await this.appModel.loadApp(caps.app);
81
98
  return [sessionId, caps];
@@ -92,32 +109,75 @@ class FakeDriver extends BaseDriver {
92
109
  return this.fakeThing;
93
110
  }
94
111
 
112
+ /**
113
+ * Set the 'thing' value (so that it can be retrieved later)
114
+ *
115
+ * @param {any} thing
116
+ * @returns {Promise<null>}
117
+ */
95
118
  async setFakeThing(thing) {
96
119
  await B.delay(1);
97
120
  this.fakeThing = thing;
98
121
  return null;
99
122
  }
100
123
 
124
+ /**
125
+ * Get the driver args that were sent in via the CLI
126
+ *
127
+ * @returns {Promise<typeof this.cliArgs>}
128
+ */
101
129
  async getFakeDriverArgs() {
102
130
  await B.delay(1);
103
131
  return this.cliArgs;
104
132
  }
105
133
 
106
- static newMethodMap = {
134
+ /**
135
+ * This is a command that will return a list of deprecated command names called
136
+ *
137
+ * @returns {Promise<string[]>}
138
+ */
139
+ async getDeprecatedCommandsCalled() {
140
+ await B.delay(1);
141
+ return Array.from(deprecatedCommandsLogged);
142
+ }
143
+
144
+ /**
145
+ * This is a command that exists just to be an example of a deprecated command
146
+ *
147
+ * @returns {Promise<void>}
148
+ */
149
+ async callDeprecatedCommand() {
150
+ await B.delay(1);
151
+ }
152
+
153
+ static newMethodMap = /** @type {const} */ ({
107
154
  '/session/:sessionId/fakedriver': {
108
155
  GET: {command: 'getFakeThing'},
156
+ /**
157
+ * Sets a fake thing
158
+ */
109
159
  POST: {command: 'setFakeThing', payloadParams: {required: ['thing']}},
110
160
  },
111
161
  '/session/:sessionId/fakedriverargs': {
112
162
  GET: {command: 'getFakeDriverArgs'},
113
163
  },
114
- };
164
+ '/session/:sessionId/deprecated': {
165
+ POST: {command: 'callDeprecatedCommand', deprecated: true},
166
+ },
167
+ // this next one exists to override a deprecated method
168
+ '/session/:sessionId/doubleclick': {
169
+ POST: {command: 'doubleClick'},
170
+ },
171
+ });
115
172
 
116
- static executeMethodMap = {
173
+ static executeMethodMap = /** @type {const} */ ({
117
174
  'fake: addition': {
118
175
  command: 'fakeAddition',
119
176
  params: {required: ['num1', 'num2'], optional: ['num3']},
120
177
  },
178
+ /**
179
+ * Gets a thing (a fake thing)
180
+ */
121
181
  'fake: getThing': {
122
182
  command: 'getFakeThing',
123
183
  },
@@ -125,7 +185,23 @@ class FakeDriver extends BaseDriver {
125
185
  command: 'setFakeThing',
126
186
  params: {required: ['thing']},
127
187
  },
128
- };
188
+ 'fake: getDeprecatedCommandsCalled': {
189
+ command: 'getDeprecatedCommandsCalled',
190
+ },
191
+ });
192
+
193
+ /**
194
+ * Add two or maybe even three numbers
195
+ *
196
+ * @param {number} num1
197
+ * @param {number} num2
198
+ * @param {number} [num3]
199
+ * @returns {Promise<number>}
200
+ */
201
+ // eslint-disable-next-line no-unused-vars
202
+ async fakeAddition(num1, num2, num3 = 0) {
203
+ throw new errors.NotImplementedError();
204
+ }
129
205
 
130
206
  static fakeRoute(req, res) {
131
207
  res.send(JSON.stringify({fakedriver: 'fakeResponse'}));
@@ -133,13 +209,30 @@ class FakeDriver extends BaseDriver {
133
209
 
134
210
  static async updateServer(expressApp, httpServer, cliArgs) {
135
211
  // eslint-disable-line require-await
136
- expressApp.all('/fakedriver', FakeDriver.fakeRoute);
212
+ expressApp.all('/fakedriver', FakeDriverCore.fakeRoute);
137
213
  expressApp.all('/fakedriverCliArgs', (req, res) => {
138
214
  res.send(JSON.stringify(cliArgs));
139
215
  });
140
216
  }
141
217
  }
142
218
 
143
- Object.assign(FakeDriver.prototype, commands);
144
-
145
- export {FakeDriver};
219
+ /**
220
+ * @extends FakeDriverCore
221
+ */
222
+ export class FakeDriver extends FakeDriverMixin(FakeDriverCore) {}
223
+ export default FakeDriver;
224
+
225
+ /**
226
+ * @typedef {import('./types').FakeDriverCaps} FakeDriverCaps
227
+ * @typedef {import('./types').W3CFakeDriverCaps} W3CFakeDriverCaps
228
+ */
229
+
230
+ /**
231
+ * @template {import('@appium/types').Driver} D
232
+ * @typedef {import('@appium/types').DriverClass<D>} DriverClass
233
+ */
234
+
235
+ /**
236
+ * @template {import('@appium/types').Constraints} C
237
+ * @typedef {import('@appium/types').ExternalDriver<C>} ExternalDriver
238
+ */
package/lib/fake-app.js CHANGED
@@ -29,9 +29,13 @@ class FakeApp {
29
29
  if (nodes.length < 1) {
30
30
  throw new Error('No title!');
31
31
  }
32
- return nodes[0].firstChild.data;
32
+ const node = /** @type {Node} */ (nodes[0]);
33
+ return /** @type {ElementWithData} */ (node.firstChild).data;
33
34
  }
34
35
 
36
+ /**
37
+ * @type {import('@appium/types').Location}
38
+ */
35
39
  get currentGeoLocation() {
36
40
  return {
37
41
  latitude: this.lat,
@@ -47,18 +51,24 @@ class FakeApp {
47
51
  this.currentOrientation = o;
48
52
  }
49
53
 
54
+ /**
55
+ * @type {number}
56
+ */
50
57
  get width() {
51
58
  if (this._width === null) {
52
59
  this.setDims();
53
60
  }
54
- return this._width;
61
+ return /** @type {number} */ (this._width);
55
62
  }
56
63
 
64
+ /**
65
+ * @type {number}
66
+ */
57
67
  get height() {
58
68
  if (this._width === null) {
59
69
  this.setDims();
60
70
  }
61
- return this._width;
71
+ return /** @type {number} */ (this._width);
62
72
  }
63
73
 
64
74
  setDims() {
@@ -133,10 +143,10 @@ class FakeApp {
133
143
  }
134
144
 
135
145
  setAlertText(text) {
136
- if (!this.activeAlert.hasPrompt()) {
146
+ if (!this.activeAlert?.hasPrompt()) {
137
147
  throw new Error('No prompt to set text of');
138
148
  }
139
- this.activeAlert.setAttr('prompt', text);
149
+ this.activeAlert?.setAttr('prompt', text);
140
150
  }
141
151
 
142
152
  showAlert(alertId) {
@@ -148,7 +158,7 @@ class FakeApp {
148
158
  }
149
159
 
150
160
  alertText() {
151
- return this.activeAlert.getAttr('prompt') || this.activeAlert.nodeAttrs.text;
161
+ return this.activeAlert?.getAttr('prompt') || this.activeAlert?.nodeAttrs.text;
152
162
  }
153
163
 
154
164
  handleAlert() {
@@ -167,3 +177,7 @@ class FakeWebView {
167
177
  }
168
178
 
169
179
  export {FakeApp};
180
+
181
+ /**
182
+ * @typedef {Element & {data: any}} ElementWithData
183
+ */
package/lib/index.js CHANGED
@@ -1,20 +1,22 @@
1
- import * as driver from './driver';
2
- import * as server from './server';
3
-
4
- const {FakeDriver} = driver;
5
- const {startServer} = server;
1
+ import {FakeDriver} from './driver';
2
+ import {startServer} from './server';
6
3
 
7
4
  const DEFAULT_HOST = 'localhost';
8
5
  const DEFAULT_PORT = 4774;
9
6
 
10
7
  async function main() {
11
- const getArgValue = (argName) => {
8
+ const getArgValue = (/** @type {string} */ argName) => {
12
9
  const argIndex = process.argv.indexOf(argName);
13
10
  return argIndex > 0 ? process.argv[argIndex + 1] : null;
14
11
  };
15
- const port = parseInt(getArgValue('--port'), 10) || DEFAULT_PORT;
12
+ const port = parseInt(String(getArgValue('--port')), 10) || DEFAULT_PORT;
16
13
  const host = getArgValue('--host') || DEFAULT_HOST;
17
14
  return await startServer(port, host);
18
15
  }
19
16
 
20
17
  export {FakeDriver, startServer, main};
18
+
19
+ /**
20
+ * @typedef {import('./types').W3CFakeDriverCaps} W3CFakeDriverCaps
21
+ * @typedef {import('./types').FakeDriverCaps} FakeDriverCaps
22
+ */
package/lib/types.ts ADDED
@@ -0,0 +1,42 @@
1
+ import type {DriverCaps, ExternalDriver, W3CDriverCaps} from '@appium/types';
2
+ import type {FakeDriverConstraints} from './driver';
3
+ import {FakeApp} from './fake-app';
4
+ import {FakeElement} from './fake-element';
5
+
6
+ /**
7
+ * W3C-style caps for {@link FakeDriver}
8
+ * @public
9
+ */
10
+ export type W3CFakeDriverCaps = W3CDriverCaps<FakeDriverConstraints>;
11
+
12
+ /**
13
+ * Capabilities for {@link FakeDriver}
14
+ * @public
15
+ */
16
+ export type FakeDriverCaps = DriverCaps<FakeDriverConstraints>;
17
+
18
+ export interface IFakeDriver extends ExternalDriver<FakeDriverConstraints> {
19
+ elMap: Record<string, FakeElement>;
20
+ maxElId: number;
21
+ appModel: FakeApp;
22
+ focusedElId: string;
23
+ curContext: string;
24
+ }
25
+
26
+ export interface IGeneralCommands extends IFakeDriver {
27
+ fakeAddition(num1: number, num2: number, num3?: number): Promise<number>;
28
+ }
29
+
30
+ export interface IContextsCommands extends IFakeDriver {
31
+ assertWebviewContext(): void;
32
+ }
33
+
34
+ export interface IElementCommands extends IFakeDriver {
35
+ getElement(id: string): FakeElement;
36
+ getElements(ids: string[]): FakeElement[];
37
+ setValue(text: string, id: string): Promise<void>;
38
+ }
39
+
40
+ export interface IAlertCommands extends IFakeDriver {
41
+ assertNoAlert(): void;
42
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@appium/fake-driver",
3
- "version": "4.2.2",
3
+ "version": "5.1.0",
4
4
  "description": "Mock driver used internally by Appium for testing. Ignore",
5
5
  "keywords": [
6
6
  "automation",
@@ -33,23 +33,21 @@
33
33
  "index.js",
34
34
  "lib",
35
35
  "build",
36
- "test/fixtures"
36
+ "test/fixtures",
37
+ "tsconfig.json"
37
38
  ],
38
39
  "scripts": {
39
- "build": "babel lib --root-mode=upward --out-dir=build/lib --copy-files",
40
- "dev": "npm run build -- --watch",
41
- "fix": "npm run lint -- --fix",
42
- "lint": "eslint -c ../../.eslintrc --ignore-path ../../.eslintignore .",
43
- "prepare": "npm run build",
40
+ "build": "cpy lib/screen.png build",
41
+ "clean": "npx rimraf build/lib/screen.png",
44
42
  "test": "npm run test:unit",
45
43
  "test:e2e": "mocha --timeout 20s --slow 10s \"./test/e2e/**/*.spec.js\"",
46
44
  "test:smoke": "node ./build/lib/index.js",
47
45
  "test:unit": "mocha \"./test/unit/**/*.spec.js\""
48
46
  },
49
47
  "dependencies": {
50
- "@types/bluebird": "3.5.37",
51
- "@xmldom/xmldom": "0.8.3",
52
- "asyncbox": "2.9.2",
48
+ "@types/bluebird": "3.5.38",
49
+ "@xmldom/xmldom": "0.8.6",
50
+ "asyncbox": "2.9.4",
53
51
  "bluebird": "3.7.2",
54
52
  "lodash": "4.17.21",
55
53
  "source-map-support": "0.5.21",
@@ -59,7 +57,7 @@
59
57
  "appium": "^2.0.0-beta.35"
60
58
  },
61
59
  "engines": {
62
- "node": ">=14",
60
+ "node": "^14.17.0 || ^16.13.0 || >=18.0.0",
63
61
  "npm": ">=8"
64
62
  },
65
63
  "publishConfig": {
@@ -79,6 +77,9 @@
79
77
  "fake-success": "./build/lib/scripts/fake-success.js"
80
78
  }
81
79
  },
80
+ "typedoc": {
81
+ "entryPoint": "./lib/index.js"
82
+ },
82
83
  "types": "./build/lib/index.d.ts",
83
- "gitHead": "f545a6cde58d83f3289072f8957468793947ba66"
84
+ "gitHead": "422142302f2f540a31c7eaf5178e2642b53a30d2"
84
85
  }