@appium/base-driver 8.5.7 → 8.7.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 (74) hide show
  1. package/build/lib/basedriver/capabilities.js +2 -2
  2. package/build/lib/basedriver/commands/execute.d.ts +11 -0
  3. package/build/lib/basedriver/commands/execute.d.ts.map +1 -0
  4. package/build/lib/basedriver/commands/execute.js +62 -0
  5. package/build/lib/basedriver/commands/index.d.ts +1 -1
  6. package/build/lib/basedriver/commands/index.d.ts.map +1 -1
  7. package/build/lib/basedriver/commands/index.js +5 -2
  8. package/build/lib/basedriver/commands/log.js +2 -4
  9. package/build/lib/basedriver/core.d.ts +11 -0
  10. package/build/lib/basedriver/core.d.ts.map +1 -1
  11. package/build/lib/basedriver/core.js +6 -1
  12. package/build/lib/basedriver/helpers.js +2 -2
  13. package/build/lib/express/server.d.ts +70 -7
  14. package/build/lib/express/server.d.ts.map +1 -1
  15. package/build/lib/express/server.js +19 -16
  16. package/build/lib/express/websocket.d.ts +12 -30
  17. package/build/lib/express/websocket.d.ts.map +1 -1
  18. package/build/lib/express/websocket.js +6 -4
  19. package/build/lib/index.d.ts +12 -180
  20. package/build/lib/index.d.ts.map +1 -1
  21. package/build/lib/index.js +107 -80
  22. package/build/lib/jsonwp-proxy/protocol-converter.js +2 -4
  23. package/build/lib/jsonwp-proxy/proxy.js +3 -7
  24. package/build/lib/protocol/index.d.ts +3 -1
  25. package/build/lib/protocol/index.js +13 -1
  26. package/build/lib/protocol/protocol.d.ts +8 -4
  27. package/build/lib/protocol/protocol.d.ts.map +1 -1
  28. package/build/lib/protocol/protocol.js +7 -7
  29. package/build/lib/protocol/routes.js +2 -6
  30. package/build/tsconfig.tsbuildinfo +1 -1
  31. package/lib/basedriver/commands/execute.js +65 -0
  32. package/lib/basedriver/commands/index.js +3 -1
  33. package/lib/basedriver/core.js +15 -0
  34. package/lib/express/server.js +126 -36
  35. package/lib/express/websocket.js +13 -11
  36. package/lib/index.js +19 -61
  37. package/lib/protocol/index.js +4 -0
  38. package/lib/protocol/protocol.js +10 -3
  39. package/package.json +17 -15
  40. package/build/test/basedriver/README.md +0 -5
  41. package/build/test/basedriver/driver-e2e-tests.js +0 -413
  42. package/build/test/basedriver/driver-tests.js +0 -572
  43. package/build/test/basedriver/index.js +0 -26
  44. package/build/test/e2e/basedriver/driver.e2e.spec.js +0 -15
  45. package/build/test/e2e/basedriver/helpers.e2e.spec.js +0 -192
  46. package/build/test/e2e/basedriver/websockets.e2e.spec.js +0 -87
  47. package/build/test/e2e/express/server.e2e.spec.js +0 -159
  48. package/build/test/e2e/jsonwp-proxy/proxy.e2e.spec.js +0 -59
  49. package/build/test/e2e/protocol/fake-driver.js +0 -163
  50. package/build/test/e2e/protocol/helpers.js +0 -25
  51. package/build/test/e2e/protocol/protocol.e2e.spec.js +0 -1186
  52. package/build/test/helpers.js +0 -55
  53. package/build/test/unit/basedriver/capabilities.spec.js +0 -672
  54. package/build/test/unit/basedriver/capability.spec.js +0 -353
  55. package/build/test/unit/basedriver/commands/event.spec.js +0 -110
  56. package/build/test/unit/basedriver/commands/log.spec.js +0 -92
  57. package/build/test/unit/basedriver/device-settings.spec.js +0 -97
  58. package/build/test/unit/basedriver/driver.spec.js +0 -15
  59. package/build/test/unit/basedriver/helpers.spec.js +0 -151
  60. package/build/test/unit/basedriver/timeout.spec.js +0 -135
  61. package/build/test/unit/express/server.spec.js +0 -155
  62. package/build/test/unit/express/static.spec.js +0 -26
  63. package/build/test/unit/jsonwp-proxy/mock-request.js +0 -91
  64. package/build/test/unit/jsonwp-proxy/protocol-converter.spec.js +0 -171
  65. package/build/test/unit/jsonwp-proxy/proxy.spec.js +0 -292
  66. package/build/test/unit/jsonwp-proxy/url.spec.js +0 -165
  67. package/build/test/unit/jsonwp-status/status.spec.js +0 -34
  68. package/build/test/unit/protocol/errors.spec.js +0 -390
  69. package/build/test/unit/protocol/routes.spec.js +0 -80
  70. package/build/test/unit/protocol/validator.spec.js +0 -149
  71. package/test/basedriver/README.md +0 -5
  72. package/test/basedriver/driver-e2e-tests.js +0 -386
  73. package/test/basedriver/driver-tests.js +0 -624
  74. package/test/basedriver/index.js +0 -6
@@ -30,11 +30,17 @@ import {EventEmitter} from 'events';
30
30
 
31
31
  const KEEP_ALIVE_TIMEOUT_MS = 10 * 60 * 1000; // 10 minutes
32
32
 
33
- async function server(opts = {}) {
33
+ /**
34
+ *
35
+ * @param {ServerOpts} opts
36
+ * @returns {Promise<AppiumServer>}
37
+ */
38
+ async function server(opts) {
34
39
  const {
35
40
  routeConfiguringFunction,
36
41
  port,
37
- hostname = null,
42
+ hostname,
43
+ cliArgs,
38
44
  allowCors = true,
39
45
  basePath = DEFAULT_BASE_PATH,
40
46
  extraMethodMap = {},
@@ -52,7 +58,11 @@ async function server(opts = {}) {
52
58
  // way we resolve it is to use an async function here but to wrap all the inner logic in
53
59
  // try/catch so any errors can be passed to reject.
54
60
  try {
55
- configureHttp({httpServer, reject, keepAliveTimeout});
61
+ const appiumServer = configureHttp({
62
+ httpServer,
63
+ reject,
64
+ keepAliveTimeout,
65
+ });
56
66
  configureServer({
57
67
  app,
58
68
  addRoutes: routeConfiguringFunction,
@@ -62,7 +72,7 @@ async function server(opts = {}) {
62
72
  });
63
73
  // allow extensions to update the app and http server objects
64
74
  for (const updater of serverUpdaters) {
65
- await updater(app, httpServer);
75
+ await updater(app, appiumServer, cliArgs);
66
76
  }
67
77
 
68
78
  // once all configurations and updaters have been applied, make sure to set up a catchall
@@ -71,13 +81,18 @@ async function server(opts = {}) {
71
81
  app.all('*', catch404Handler);
72
82
 
73
83
  await startServer({httpServer, hostname, port, keepAliveTimeout});
74
- resolve(httpServer);
84
+
85
+ resolve(appiumServer);
75
86
  } catch (err) {
76
87
  reject(err);
77
88
  }
78
89
  });
79
90
  }
80
91
 
92
+ /**
93
+ * Sets up some Express middleware and stuff
94
+ * @param {ConfigureServerOpts} opts
95
+ */
81
96
  function configureServer({
82
97
  app,
83
98
  addRoutes,
@@ -125,20 +140,28 @@ function configureServer({
125
140
  app.all('/test/guinea-pig-app-banner', guineaPigAppBanner);
126
141
  }
127
142
 
143
+ /**
144
+ * Monkeypatches the `http.Server` instance and returns a {@linkcode AppiumServer}.
145
+ * This function _mutates_ the `httpServer` parameter.
146
+ * @param {ConfigureHttpOpts} opts
147
+ * @returns {AppiumServer}
148
+ */
128
149
  function configureHttp({httpServer, reject, keepAliveTimeout}) {
129
150
  const serverState = {
130
151
  notifier: new EventEmitter(),
131
152
  closed: false,
132
153
  };
133
- httpServer.addWebSocketHandler = addWebSocketHandler;
134
- httpServer.removeWebSocketHandler = removeWebSocketHandler;
135
- httpServer.removeAllWebSocketHandlers = removeAllWebSocketHandlers;
136
- httpServer.getWebSocketHandlers = getWebSocketHandlers;
154
+ // TS does not love monkeypatching.
155
+ const appiumServer = /** @type {AppiumServer} */ (/** @type {unknown} */ (httpServer));
156
+ appiumServer.addWebSocketHandler = addWebSocketHandler;
157
+ appiumServer.removeWebSocketHandler = removeWebSocketHandler;
158
+ appiumServer.removeAllWebSocketHandlers = removeAllWebSocketHandlers;
159
+ appiumServer.getWebSocketHandlers = getWebSocketHandlers;
137
160
 
138
161
  // http.Server.close() only stops new connections, but we need to wait until
139
162
  // all connections are closed and the `close` event is emitted
140
- const close = httpServer.close.bind(httpServer);
141
- httpServer.close = async () =>
163
+ const close = appiumServer.close.bind(appiumServer);
164
+ appiumServer.close = async () =>
142
165
  await new B((resolve, reject) => {
143
166
  // https://github.com/nodejs/node-v0.x-archive/issues/9066#issuecomment-124210576
144
167
  serverState.closed = true;
@@ -153,35 +176,41 @@ function configureHttp({httpServer, reject, keepAliveTimeout}) {
153
176
  });
154
177
  });
155
178
 
156
- httpServer.on('error', (err) => {
157
- if (err.code === 'EADDRNOTAVAIL') {
158
- log.error(
159
- 'Could not start REST http interface listener. ' + 'Requested address is not available.'
160
- );
161
- } else {
162
- log.error(
163
- 'Could not start REST http interface listener. The requested ' +
164
- 'port may already be in use. Please make sure there is no ' +
165
- 'other instance of this server running already.'
166
- );
179
+ appiumServer.on(
180
+ 'error',
181
+ /** @param {NodeJS.ErrnoException} err */ (err) => {
182
+ if (err.code === 'EADDRNOTAVAIL') {
183
+ log.error(
184
+ 'Could not start REST http interface listener. ' + 'Requested address is not available.'
185
+ );
186
+ } else {
187
+ log.error(
188
+ 'Could not start REST http interface listener. The requested ' +
189
+ 'port may already be in use. Please make sure there is no ' +
190
+ 'other instance of this server running already.'
191
+ );
192
+ }
193
+ reject(err);
167
194
  }
168
- reject(err);
169
- });
195
+ );
170
196
 
171
- httpServer.on('connection', (socket) => {
172
- socket.setTimeout(keepAliveTimeout);
173
- socket.on('error', reject);
197
+ appiumServer.on(
198
+ 'connection',
199
+ /** @param {AppiumServerSocket} socket */ (socket) => {
200
+ socket.setTimeout(keepAliveTimeout);
201
+ socket.on('error', reject);
174
202
 
175
- function destroy() {
176
- socket.destroy();
203
+ function destroy() {
204
+ socket.destroy();
205
+ }
206
+ socket._openReqCount = 0;
207
+ socket.once('close', () => serverState.notifier.removeListener('shutdown', destroy));
208
+ serverState.notifier.once('shutdown', destroy);
177
209
  }
178
- socket._openReqCount = 0;
179
- socket.once('close', () => serverState.notifier.removeListener('shutdown', destroy));
180
- serverState.notifier.once('shutdown', destroy);
181
- });
210
+ );
182
211
 
183
- httpServer.on('request', function (req, res) {
184
- const socket = req.connection || req.socket;
212
+ appiumServer.on('request', function (req, res) {
213
+ const socket = /** @type {AppiumServerSocket} */ (req.connection || req.socket);
185
214
  socket._openReqCount++;
186
215
  res.on('finish', function () {
187
216
  socket._openReqCount--;
@@ -190,11 +219,14 @@ function configureHttp({httpServer, reject, keepAliveTimeout}) {
190
219
  }
191
220
  });
192
221
  });
222
+
223
+ return appiumServer;
193
224
  }
194
225
 
195
226
  /**
196
- *
227
+ * Starts an {@linkcode AppiumServer}
197
228
  * @param {StartServerOpts} opts
229
+ * @returns {Promise<void>}
198
230
  */
199
231
  async function startServer({httpServer, port, hostname, keepAliveTimeout}) {
200
232
  // If the hostname is omitted, the server will accept
@@ -208,6 +240,11 @@ async function startServer({httpServer, port, hostname, keepAliveTimeout}) {
208
240
  await startPromise;
209
241
  }
210
242
 
243
+ /**
244
+ * Normalize base path string
245
+ * @param {string} basePath
246
+ * @returns {string}
247
+ */
211
248
  function normalizeBasePath(basePath) {
212
249
  if (!_.isString(basePath)) {
213
250
  throw new Error(`Invalid path prefix ${basePath}`);
@@ -236,3 +273,56 @@ export {server, configureServer, normalizeBasePath};
236
273
  * @property {number} keepAliveTimeout - Keep-alive timeout in milliseconds
237
274
  * @property {string} [hostname] - Optional hostname
238
275
  */
276
+
277
+ /**
278
+ * @typedef {import('@appium/types').AppiumServer} AppiumServer
279
+ * @typedef {import('@appium/types').AppiumServerSocket} AppiumServerSocket
280
+ * @typedef {import('@appium/types').MethodMap} MethodMap
281
+ */
282
+
283
+ /**
284
+ * Options for {@linkcode configureHttp}
285
+ * @typedef ConfigureHttpOpts
286
+ * @property {import('http').Server} httpServer - HTTP server instance
287
+ * @property {(error?: any) => void} reject - Rejection function from `Promise` constructor
288
+ * @property {number} keepAliveTimeout - Keep-alive timeout in milliseconds
289
+ */
290
+
291
+ /**
292
+ * Options for {@linkcode server}
293
+ * @typedef ServerOpts
294
+ * @property {RouteConfiguringFunction} routeConfiguringFunction
295
+ * @property {number} port
296
+ * @property {import('@appium/types').ServerArgs} cliArgs
297
+ * @property {string} [hostname]
298
+ * @property {boolean} [allowCors]
299
+ * @property {string} [basePath]
300
+ * @property {MethodMap} [extraMethodMap]
301
+ * @property {import('@appium/types').UpdateServerCallback[]} [serverUpdaters]
302
+ * @property {number} [keepAliveTimeout]
303
+ */
304
+
305
+ /**
306
+ * A function which configures routes
307
+ * @callback RouteConfiguringFunction
308
+ * @param {import('express').Express} app
309
+ * @param {RouteConfiguringFunctionOpts} [opts]
310
+ * @returns {void}
311
+ */
312
+
313
+ /**
314
+ * Options for a {@linkcode RouteConfiguringFunction}
315
+ * @typedef RouteConfiguringFunctionOpts
316
+ * @property {string} [basePath]
317
+ * @property {MethodMap} [extraMethodMap]
318
+ */
319
+
320
+ /**
321
+ * Options for {@linkcode configureServer}
322
+ * @typedef ConfigureServerOpts
323
+ * @property {import('express').Express} app
324
+ * @property {RouteConfiguringFunction} addRoutes
325
+ * @property {boolean} [allowCors]
326
+ * @property {string} [basePath]
327
+ * @property {MethodMap} [extraMethodMap]
328
+ */
@@ -1,3 +1,4 @@
1
+ /* eslint-disable require-await */
1
2
  import _ from 'lodash';
2
3
  import {URL} from 'url';
3
4
  import B from 'bluebird';
@@ -9,20 +10,21 @@ const DEFAULT_WS_PATHNAME_PREFIX = '/ws';
9
10
  * It is expected this function is called in Express
10
11
  * server instance context.
11
12
  *
12
- * @this {WebSocketServer} - An instance of express HTTP server.
13
+ * @this {AppiumServer} - An instance of express HTTP server.
13
14
  * @param {string} handlerPathname - Web socket endpoint path starting with
14
15
  * a single slash character. It is recommended to always add
15
16
  * DEFAULT_WS_PATHNAME_PREFIX to all web socket pathnames.
16
- * @param {Object} handlerServer - WebSocket server instance. See
17
+ * @param {import('ws').Server} handlerServer - WebSocket server instance. See
17
18
  * https://github.com/websockets/ws/pull/885 for more details
18
19
  * on how to configure the handler properly.
20
+ * @returns {Promise<void>}
19
21
  */
20
- // eslint-disable-next-line require-await
21
22
  async function addWebSocketHandler(handlerPathname, handlerServer) {
23
+ const server = /** @type {AppiumServer} */ (this);
22
24
  if (_.isUndefined(this.webSocketsMapping)) {
23
- this.webSocketsMapping = {};
25
+ server.webSocketsMapping = {};
24
26
  // https://github.com/websockets/ws/pull/885
25
- this.on('upgrade', (request, socket, head) => {
27
+ server.on('upgrade', (request, socket, head) => {
26
28
  let currentPathname;
27
29
  try {
28
30
  // @ts-expect-error
@@ -30,7 +32,7 @@ async function addWebSocketHandler(handlerPathname, handlerServer) {
30
32
  } catch {
31
33
  currentPathname = request.url;
32
34
  }
33
- for (const [pathname, wsServer] of _.toPairs(this.webSocketsMapping)) {
35
+ for (const [pathname, wsServer] of _.toPairs(server.webSocketsMapping)) {
34
36
  if (currentPathname === pathname) {
35
37
  wsServer.handleUpgrade(request, socket, head, (ws) => {
36
38
  wsServer.emit('connection', ws, request);
@@ -50,10 +52,10 @@ async function addWebSocketHandler(handlerPathname, handlerServer) {
50
52
  * It is expected this function is called in Express
51
53
  * server instance context.
52
54
  *
55
+ * @this {AppiumServer}
53
56
  * @param {string?} [keysFilter] - Only include pathnames with given
54
57
  * `keysFilter` value if set. All pairs will be included by default.
55
- * @returns {Promise<Object>} pathnames to websocket server isntances mapping
56
- * matching the search criteria or an empty object otherwise.
58
+ * @returns {Promise<Record<string, import('ws').Server>>} pathnames to websocket server instances mapping matching the search criteria or an empty object otherwise.
57
59
  */
58
60
  // eslint-disable-next-line require-await
59
61
  async function getWebSocketHandlers(keysFilter = null) {
@@ -75,7 +77,7 @@ async function getWebSocketHandlers(keysFilter = null) {
75
77
  * is not present in the handlers list.
76
78
  * It is expected this function is called in Express
77
79
  * server instance context.
78
- *
80
+ * @this {AppiumServer}
79
81
  * @param {string} handlerPathname - Websocket endpoint path.
80
82
  * @returns {Promise<boolean>} true if the handlerPathname was found and deleted
81
83
  */
@@ -104,7 +106,7 @@ async function removeWebSocketHandler(handlerPathname) {
104
106
  * Removes all existing websocket handler from express server instance.
105
107
  * It is expected this function is called in Express
106
108
  * server instance context.
107
- *
109
+ * @this {AppiumServer}
108
110
  * @returns {Promise<boolean>} true if at least one handler has been deleted
109
111
  */
110
112
  async function removeAllWebSocketHandlers() {
@@ -128,5 +130,5 @@ export {
128
130
  };
129
131
 
130
132
  /**
131
- * @typedef {import('http').Server & {webSocketsMapping: Record<string,import('ws').Server>}} WebSocketServer
133
+ * @typedef {import('@appium/types').AppiumServer} AppiumServer
132
134
  */
package/lib/index.js CHANGED
@@ -7,79 +7,37 @@ B.config({
7
7
  // BaseDriver exports
8
8
  import {BaseDriver} from './basedriver/driver';
9
9
  export {DriverCore} from './basedriver/core';
10
- import {DeviceSettings} from './basedriver/device-settings';
10
+ export {DeviceSettings} from './basedriver/device-settings';
11
11
 
12
- export {BaseDriver, DeviceSettings};
12
+ export {BaseDriver};
13
13
  export default BaseDriver;
14
14
 
15
15
  // MJSONWP exports
16
- import * as protocol from './protocol';
17
- import {DEFAULT_BASE_PATH, PROTOCOLS} from './constants';
18
-
19
- const {
20
- routeConfiguringFunction,
21
- errors,
22
- isErrorType,
23
- errorFromMJSONWPStatusCode,
24
- errorFromW3CJsonCode,
25
- ALL_COMMANDS,
26
- METHOD_MAP,
27
- routeToCommandName,
28
- NO_SESSION_ID_COMMANDS,
29
- isSessionCommand,
30
- determineProtocol,
31
- CREATE_SESSION_COMMAND,
32
- DELETE_SESSION_COMMAND,
33
- GET_STATUS_COMMAND,
34
- } = protocol;
35
-
36
- export {
37
- routeConfiguringFunction,
38
- errors,
39
- isErrorType,
40
- PROTOCOLS,
41
- errorFromMJSONWPStatusCode,
42
- errorFromW3CJsonCode,
43
- determineProtocol,
44
- errorFromMJSONWPStatusCode as errorFromCode,
45
- ALL_COMMANDS,
46
- METHOD_MAP,
47
- routeToCommandName,
48
- NO_SESSION_ID_COMMANDS,
49
- isSessionCommand,
50
- DEFAULT_BASE_PATH,
51
- CREATE_SESSION_COMMAND,
52
- DELETE_SESSION_COMMAND,
53
- GET_STATUS_COMMAND,
54
- };
16
+ export * from './protocol';
17
+ export {errorFromMJSONWPStatusCode as errorFromCode} from './protocol';
18
+ export {DEFAULT_BASE_PATH, PROTOCOLS} from './constants';
55
19
 
56
20
  // Express exports
57
- import * as staticIndex from './express/static';
58
- const {STATIC_DIR} = staticIndex;
59
- export {STATIC_DIR};
60
-
61
- import * as serverIndex from './express/server';
62
- const {server, normalizeBasePath} = serverIndex;
63
- export {server, normalizeBasePath};
21
+ export {STATIC_DIR} from './express/static';
22
+ export {server, normalizeBasePath} from './express/server';
64
23
 
65
24
  // jsonwp-proxy exports
66
- import * as proxyIndex from './jsonwp-proxy/proxy';
67
- const {JWProxy} = proxyIndex;
68
- export {JWProxy};
25
+ export {JWProxy} from './jsonwp-proxy/proxy';
69
26
 
70
27
  // jsonwp-status exports
71
- import * as statusIndex from './jsonwp-status/status';
72
- const {codes: statusCodes, getSummaryByCode} = statusIndex;
73
- export {statusCodes, getSummaryByCode};
28
+ export {getSummaryByCode, codes as statusCodes} from './jsonwp-status/status';
74
29
 
75
30
  // W3C capabilities parser
76
- import * as caps from './basedriver/capabilities';
77
- const {processCapabilities, isStandardCap, validateCaps} = caps;
78
- export {processCapabilities, isStandardCap, validateCaps};
31
+ export {
32
+ PREFIXED_APPIUM_OPTS_CAP,
33
+ processCapabilities,
34
+ isStandardCap,
35
+ validateCaps,
36
+ } from './basedriver/capabilities';
79
37
 
80
38
  // Web socket helpers
81
- import * as ws from './express/websocket';
82
- const {DEFAULT_WS_PATHNAME_PREFIX} = ws;
83
- export {DEFAULT_WS_PATHNAME_PREFIX};
39
+ export {DEFAULT_WS_PATHNAME_PREFIX} from './express/websocket';
84
40
 
85
- export {PREFIXED_APPIUM_OPTS_CAP} from './basedriver/capabilities';
41
+ /**
42
+ * @typedef {import('./express/server').ServerOpts} ServerOpts
43
+ */
@@ -5,6 +5,8 @@ import {
5
5
  CREATE_SESSION_COMMAND,
6
6
  DELETE_SESSION_COMMAND,
7
7
  GET_STATUS_COMMAND,
8
+ makeArgs,
9
+ checkParams,
8
10
  } from './protocol';
9
11
  import {NO_SESSION_ID_COMMANDS, ALL_COMMANDS, METHOD_MAP, routeToCommandName} from './routes';
10
12
  import {errors, isErrorType, errorFromMJSONWPStatusCode, errorFromW3CJsonCode} from './errors';
@@ -13,6 +15,8 @@ export {
13
15
  routeConfiguringFunction,
14
16
  errors,
15
17
  isErrorType,
18
+ makeArgs,
19
+ checkParams,
16
20
  errorFromMJSONWPStatusCode,
17
21
  errorFromW3CJsonCode,
18
22
  ALL_COMMANDS,
@@ -94,7 +94,7 @@ function unwrapParams(paramSets, jsonObj) {
94
94
  return res;
95
95
  }
96
96
 
97
- function checkParams(paramSets, jsonObj, protocol) {
97
+ export function checkParams(paramSets, jsonObj, protocol) {
98
98
  let requiredParams = [];
99
99
  let optionalParams = [];
100
100
  let receivedParams = _.keys(jsonObj);
@@ -162,7 +162,7 @@ function checkParams(paramSets, jsonObj, protocol) {
162
162
  * on handling parameters. This method returns an array of arguments which will
163
163
  * be applied to a command.
164
164
  */
165
- function makeArgs(requestParams, jsonObj, payloadParams, protocol) {
165
+ export function makeArgs(requestParams, jsonObj, payloadParams, protocol) {
166
166
  // We want to pass the "url" parameters to the commands in reverse order
167
167
  // since the command will sometimes want to ignore, say, the sessionId.
168
168
  // This has the effect of putting sessionId last, which means in JS we can
@@ -212,18 +212,25 @@ function makeArgs(requestParams, jsonObj, payloadParams, protocol) {
212
212
  return args;
213
213
  }
214
214
 
215
+ /**
216
+ *
217
+ * @param {import('@appium/types').Core} driver
218
+ * @returns {import('../express/server').RouteConfiguringFunction}
219
+ */
215
220
  function routeConfiguringFunction(driver) {
216
221
  if (!driver.sessionExists) {
217
222
  throw new Error('Drivers must implement `sessionExists` property');
218
223
  }
219
224
 
225
+ // "execute" isn't defined anywhere
226
+ // @ts-expect-error
220
227
  if (!(driver.executeCommand || driver.execute)) {
221
228
  throw new Error('Drivers must implement `executeCommand` or `execute` method');
222
229
  }
223
230
 
224
231
  // return a function which will add all the routes to the driver. Here extraMethods might be
225
232
  // passed in as defined by Appium plugins, so we need to add those to the default list
226
- return function addRoutes(app, {basePath = DEFAULT_BASE_PATH, extraMethodMap = {}}) {
233
+ return function addRoutes(app, {basePath = DEFAULT_BASE_PATH, extraMethodMap = {}} = {}) {
227
234
  // store basePath on the driver instance so it can use it if necessary
228
235
  // for example in determining proxy avoidance
229
236
  driver.basePath = basePath;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@appium/base-driver",
3
- "version": "8.5.7",
3
+ "version": "8.7.0",
4
4
  "description": "Base driver class for Appium drivers",
5
5
  "keywords": [
6
6
  "automation",
@@ -31,28 +31,29 @@
31
31
  "index.d.ts",
32
32
  "lib",
33
33
  "static",
34
- "test/basedriver",
35
- "!test/e2e/fixtures",
36
- "build",
37
- "!build/test/e2e/fixtures"
34
+ "build"
38
35
  ],
39
36
  "scripts": {
40
- "build": "run-s build:*",
41
- "build:distfiles": "babel lib --root-mode=upward --out-dir=build/lib",
42
- "build:test": "babel test --root-mode=upward --out-dir=build/test --copy-files",
43
- "dev": "run-p \"build:distfiles -- --watch\" \"build:test -- --watch\"",
37
+ "build": "babel lib --root-mode=upward --out-dir=build/lib",
38
+ "dev": "npm run build -- --watch",
44
39
  "fix": "npm run lint -- --fix",
45
40
  "lint": "eslint -c ../../.eslintrc --ignore-path ../../.eslintignore .",
46
41
  "prepare": "npm run build",
47
42
  "test": "npm run test:unit",
48
43
  "test:e2e": "mocha --timeout 20s --slow 10s \"./test/e2e/**/*.spec.js\"",
44
+ "test:smoke": "node ./index.js",
49
45
  "test:unit": "mocha \"./test/unit/**/*.spec.js\""
50
46
  },
51
47
  "dependencies": {
52
- "@appium/support": "^2.59.2",
53
- "@babel/runtime": "7.18.3",
48
+ "@appium/support": "^2.59.5",
49
+ "@babel/runtime": "7.18.9",
54
50
  "@colors/colors": "1.5.0",
55
- "async-lock": "1.3.1",
51
+ "@types/async-lock": "1.1.5",
52
+ "@types/bluebird": "3.5.36",
53
+ "@types/express": "4.17.13",
54
+ "@types/method-override": "0.0.32",
55
+ "@types/serve-favicon": "2.5.3",
56
+ "async-lock": "1.3.2",
56
57
  "asyncbox": "2.9.2",
57
58
  "axios": "0.27.2",
58
59
  "bluebird": "3.7.2",
@@ -61,20 +62,21 @@
61
62
  "express": "4.18.1",
62
63
  "http-status-codes": "2.2.0",
63
64
  "lodash": "4.17.21",
64
- "lru-cache": "7.10.1",
65
+ "lru-cache": "7.13.2",
65
66
  "method-override": "3.0.0",
66
67
  "morgan": "1.10.0",
67
68
  "serve-favicon": "2.5.0",
68
69
  "source-map-support": "0.5.21",
70
+ "type-fest": "2.18.0",
69
71
  "validate.js": "0.13.1"
70
72
  },
71
73
  "engines": {
72
74
  "node": ">=14",
73
- "npm": ">=6"
75
+ "npm": ">=8"
74
76
  },
75
77
  "publishConfig": {
76
78
  "access": "public"
77
79
  },
78
80
  "types": "./build/lib/index.d.ts",
79
- "gitHead": "4cf2cc92d066ed32adda27e0439547290a4b71ce"
81
+ "gitHead": "c58f32441daba3aae9768a57d0a412fe92f4b587"
80
82
  }
@@ -1,5 +0,0 @@
1
- # Driver Test Helpers
2
-
3
- This directory contains modules which expose test suites that an external driver can use to test against the base implementation. They are published in the `@appium/base-driver` package.
4
-
5
- Drivers wanting to leverage these suites will want to add `@appium/base-driver` to their `devDependencies`.