@appium/base-driver 8.5.3 → 8.5.4

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 (141) hide show
  1. package/build/lib/basedriver/capabilities.d.ts.map +1 -1
  2. package/build/lib/basedriver/capabilities.js +1 -1
  3. package/build/lib/basedriver/commands/event.js +1 -1
  4. package/build/lib/basedriver/commands/find.d.ts.map +1 -1
  5. package/build/lib/basedriver/commands/find.js +1 -1
  6. package/build/lib/basedriver/commands/index.js +1 -1
  7. package/build/lib/basedriver/commands/log.d.ts.map +1 -1
  8. package/build/lib/basedriver/commands/log.js +1 -1
  9. package/build/lib/basedriver/commands/session.js +1 -1
  10. package/build/lib/basedriver/commands/settings.d.ts.map +1 -1
  11. package/build/lib/basedriver/commands/settings.js +1 -1
  12. package/build/lib/basedriver/commands/timeout.d.ts.map +1 -1
  13. package/build/lib/basedriver/commands/timeout.js +1 -1
  14. package/build/lib/basedriver/core.d.ts +120 -139
  15. package/build/lib/basedriver/core.d.ts.map +1 -1
  16. package/build/lib/basedriver/core.js +1 -49
  17. package/build/lib/basedriver/desired-caps.d.ts +5 -2
  18. package/build/lib/basedriver/desired-caps.d.ts.map +1 -1
  19. package/build/lib/basedriver/desired-caps.js +14 -18
  20. package/build/lib/basedriver/device-settings.d.ts +9 -9
  21. package/build/lib/basedriver/device-settings.d.ts.map +1 -1
  22. package/build/lib/basedriver/device-settings.js +4 -4
  23. package/build/lib/basedriver/driver.d.ts +43 -38
  24. package/build/lib/basedriver/driver.d.ts.map +1 -1
  25. package/build/lib/basedriver/driver.js +58 -11
  26. package/build/lib/basedriver/helpers.d.ts +8 -3
  27. package/build/lib/basedriver/helpers.d.ts.map +1 -1
  28. package/build/lib/basedriver/helpers.js +4 -6
  29. package/build/lib/basedriver/logger.d.ts +1 -1
  30. package/build/lib/basedriver/logger.d.ts.map +1 -1
  31. package/build/lib/basedriver/logger.js +1 -1
  32. package/build/lib/constants.js +1 -1
  33. package/build/lib/express/crash.d.ts.map +1 -1
  34. package/build/lib/express/crash.js +1 -1
  35. package/build/lib/express/express-logging.d.ts.map +1 -1
  36. package/build/lib/express/express-logging.js +1 -1
  37. package/build/lib/express/idempotency.js +1 -1
  38. package/build/lib/express/logger.d.ts +1 -1
  39. package/build/lib/express/logger.d.ts.map +1 -1
  40. package/build/lib/express/logger.js +1 -1
  41. package/build/lib/express/middleware.d.ts.map +1 -1
  42. package/build/lib/express/middleware.js +1 -1
  43. package/build/lib/express/server.d.ts +21 -0
  44. package/build/lib/express/server.d.ts.map +1 -1
  45. package/build/lib/express/server.js +4 -9
  46. package/build/lib/express/static.d.ts.map +1 -1
  47. package/build/lib/express/static.js +2 -2
  48. package/build/lib/express/websocket.d.ts +14 -11
  49. package/build/lib/express/websocket.d.ts.map +1 -1
  50. package/build/lib/express/websocket.js +2 -2
  51. package/build/lib/helpers/capabilities.d.ts.map +1 -1
  52. package/build/lib/helpers/capabilities.js +1 -1
  53. package/build/lib/index.d.ts +2 -1
  54. package/build/lib/index.js +7 -1
  55. package/build/lib/jsonwp-proxy/protocol-converter.d.ts.map +1 -1
  56. package/build/lib/jsonwp-proxy/protocol-converter.js +2 -2
  57. package/build/lib/jsonwp-proxy/proxy.d.ts +30 -5
  58. package/build/lib/jsonwp-proxy/proxy.d.ts.map +1 -1
  59. package/build/lib/jsonwp-proxy/proxy.js +20 -4
  60. package/build/lib/jsonwp-status/status.d.ts.map +1 -1
  61. package/build/lib/jsonwp-status/status.js +2 -2
  62. package/build/lib/protocol/errors.d.ts +17 -8
  63. package/build/lib/protocol/errors.d.ts.map +1 -1
  64. package/build/lib/protocol/errors.js +9 -5
  65. package/build/lib/protocol/helpers.js +1 -1
  66. package/build/lib/protocol/index.js +1 -1
  67. package/build/lib/protocol/protocol.d.ts.map +1 -1
  68. package/build/lib/protocol/protocol.js +1 -1
  69. package/build/lib/protocol/routes.d.ts +17 -3
  70. package/build/lib/protocol/routes.d.ts.map +1 -1
  71. package/build/lib/protocol/routes.js +1 -1
  72. package/build/lib/protocol/validators.js +1 -1
  73. package/build/test/basedriver/driver-e2e-tests.js +1 -1
  74. package/build/test/basedriver/driver-tests.js +1 -1
  75. package/build/test/basedriver/index.js +1 -1
  76. package/build/test/e2e/basedriver/driver.e2e.spec.js +1 -1
  77. package/build/test/e2e/basedriver/helpers.e2e.spec.js +1 -1
  78. package/build/test/e2e/basedriver/websockets.e2e.spec.js +1 -1
  79. package/build/test/e2e/express/server.e2e.spec.js +1 -1
  80. package/build/test/e2e/jsonwp-proxy/proxy.e2e.spec.js +1 -1
  81. package/build/test/e2e/protocol/fake-driver.js +1 -1
  82. package/build/test/e2e/protocol/helpers.js +1 -1
  83. package/build/test/e2e/protocol/protocol.e2e.spec.js +13 -13
  84. package/build/test/helpers.js +1 -1
  85. package/build/test/unit/basedriver/capabilities.spec.js +12 -12
  86. package/build/test/unit/basedriver/capability.spec.js +15 -15
  87. package/build/test/unit/basedriver/commands/event.spec.js +1 -1
  88. package/build/test/unit/basedriver/commands/log.spec.js +1 -1
  89. package/build/test/unit/basedriver/device-settings.spec.js +1 -1
  90. package/build/test/unit/basedriver/driver.spec.js +1 -1
  91. package/build/test/unit/basedriver/helpers.spec.js +33 -33
  92. package/build/test/unit/basedriver/timeout.spec.js +1 -1
  93. package/build/test/unit/express/server.spec.js +1 -1
  94. package/build/test/unit/express/static.spec.js +2 -2
  95. package/build/test/unit/jsonwp-proxy/mock-request.js +1 -1
  96. package/build/test/unit/jsonwp-proxy/protocol-converter.spec.js +1 -1
  97. package/build/test/unit/jsonwp-proxy/proxy.spec.js +2 -2
  98. package/build/test/unit/jsonwp-proxy/url.spec.js +1 -1
  99. package/build/test/unit/jsonwp-status/status.spec.js +1 -1
  100. package/build/test/unit/protocol/errors.spec.js +1 -1
  101. package/build/test/unit/protocol/routes.spec.js +1 -1
  102. package/build/test/unit/protocol/validator.spec.js +1 -1
  103. package/build/tsconfig.tsbuildinfo +1 -1
  104. package/lib/basedriver/capabilities.js +95 -47
  105. package/lib/basedriver/commands/event.js +4 -4
  106. package/lib/basedriver/commands/find.js +12 -26
  107. package/lib/basedriver/commands/index.js +7 -7
  108. package/lib/basedriver/commands/log.js +5 -7
  109. package/lib/basedriver/commands/session.js +3 -3
  110. package/lib/basedriver/commands/settings.js +3 -5
  111. package/lib/basedriver/commands/timeout.js +18 -23
  112. package/lib/basedriver/core.js +150 -229
  113. package/lib/basedriver/desired-caps.js +30 -29
  114. package/lib/basedriver/device-settings.js +21 -20
  115. package/lib/basedriver/driver.js +131 -96
  116. package/lib/basedriver/helpers.js +124 -81
  117. package/lib/basedriver/logger.js +1 -1
  118. package/lib/constants.js +2 -6
  119. package/lib/express/crash.js +4 -6
  120. package/lib/express/express-logging.js +26 -24
  121. package/lib/express/idempotency.js +16 -16
  122. package/lib/express/logger.js +1 -1
  123. package/lib/express/middleware.js +49 -33
  124. package/lib/express/server.js +68 -44
  125. package/lib/express/static.js +11 -12
  126. package/lib/express/websocket.js +26 -16
  127. package/lib/helpers/capabilities.js +11 -16
  128. package/lib/index.js +50 -33
  129. package/lib/jsonwp-proxy/protocol-converter.js +85 -69
  130. package/lib/jsonwp-proxy/proxy.js +116 -53
  131. package/lib/jsonwp-status/status.js +36 -29
  132. package/lib/protocol/errors.js +469 -292
  133. package/lib/protocol/helpers.js +5 -8
  134. package/lib/protocol/index.js +22 -15
  135. package/lib/protocol/protocol.js +103 -55
  136. package/lib/protocol/routes.js +430 -273
  137. package/lib/protocol/validators.js +5 -5
  138. package/package.json +7 -6
  139. package/test/basedriver/driver-e2e-tests.js +92 -66
  140. package/test/basedriver/driver-tests.js +90 -33
  141. package/test/basedriver/index.js +1 -1
@@ -1,6 +1,6 @@
1
1
  import _ from 'lodash';
2
- import { duplicateKeys } from '../basedriver/helpers';
3
- import { MJSONWP_ELEMENT_KEY, W3C_ELEMENT_KEY } from '../constants';
2
+ import {duplicateKeys} from '../basedriver/helpers';
3
+ import {MJSONWP_ELEMENT_KEY, W3C_ELEMENT_KEY} from '../constants';
4
4
 
5
5
  /**
6
6
  * Preprocesses the resulting value for API responses,
@@ -11,7 +11,7 @@ import { MJSONWP_ELEMENT_KEY, W3C_ELEMENT_KEY } from '../constants';
11
11
  * @returns {?Object} Either modified value or the same one if
12
12
  * nothing has been modified
13
13
  */
14
- function formatResponseValue (resValue) {
14
+ function formatResponseValue(resValue) {
15
15
  if (_.isUndefined(resValue)) {
16
16
  // convert undefined to null
17
17
  return null;
@@ -28,11 +28,8 @@ function formatResponseValue (resValue) {
28
28
  * @param {Object} responseBody
29
29
  * @returns {Object} The fixed response body
30
30
  */
31
- function formatStatus (responseBody) {
31
+ function formatStatus(responseBody) {
32
32
  return _.isPlainObject(responseBody) ? _.omit(responseBody, ['status']) : responseBody;
33
33
  }
34
34
 
35
-
36
- export {
37
- MJSONWP_ELEMENT_KEY, W3C_ELEMENT_KEY, formatResponseValue, formatStatus
38
- };
35
+ export {MJSONWP_ELEMENT_KEY, W3C_ELEMENT_KEY, formatResponseValue, formatStatus};
@@ -1,20 +1,27 @@
1
- // transpile:main
2
-
3
1
  import {
4
- isSessionCommand, routeConfiguringFunction, determineProtocol,
5
- CREATE_SESSION_COMMAND, DELETE_SESSION_COMMAND, GET_STATUS_COMMAND
2
+ isSessionCommand,
3
+ routeConfiguringFunction,
4
+ determineProtocol,
5
+ CREATE_SESSION_COMMAND,
6
+ DELETE_SESSION_COMMAND,
7
+ GET_STATUS_COMMAND,
6
8
  } from './protocol';
7
- import {
8
- NO_SESSION_ID_COMMANDS, ALL_COMMANDS, METHOD_MAP,
9
- routeToCommandName
10
- } from './routes';
11
- import {
12
- errors, isErrorType, errorFromMJSONWPStatusCode, errorFromW3CJsonCode
13
- } from './errors';
9
+ import {NO_SESSION_ID_COMMANDS, ALL_COMMANDS, METHOD_MAP, routeToCommandName} from './routes';
10
+ import {errors, isErrorType, errorFromMJSONWPStatusCode, errorFromW3CJsonCode} from './errors';
14
11
 
15
12
  export {
16
- routeConfiguringFunction, errors, isErrorType,
17
- errorFromMJSONWPStatusCode, errorFromW3CJsonCode, ALL_COMMANDS, METHOD_MAP,
18
- routeToCommandName, NO_SESSION_ID_COMMANDS, isSessionCommand, determineProtocol,
19
- CREATE_SESSION_COMMAND, DELETE_SESSION_COMMAND, GET_STATUS_COMMAND
13
+ routeConfiguringFunction,
14
+ errors,
15
+ isErrorType,
16
+ errorFromMJSONWPStatusCode,
17
+ errorFromW3CJsonCode,
18
+ ALL_COMMANDS,
19
+ METHOD_MAP,
20
+ routeToCommandName,
21
+ NO_SESSION_ID_COMMANDS,
22
+ isSessionCommand,
23
+ determineProtocol,
24
+ CREATE_SESSION_COMMAND,
25
+ DELETE_SESSION_COMMAND,
26
+ GET_STATUS_COMMAND,
20
27
  };
@@ -1,26 +1,28 @@
1
1
  import _ from 'lodash';
2
- import { util, logger, node } from '@appium/support';
3
- import { validators } from './validators';
2
+ import {util, logger, node} from '@appium/support';
3
+ import {validators} from './validators';
4
4
  import {
5
- errors, isErrorType, getResponseForW3CError,
6
- errorFromMJSONWPStatusCode, errorFromW3CJsonCode,
5
+ errors,
6
+ isErrorType,
7
+ getResponseForW3CError,
8
+ errorFromMJSONWPStatusCode,
9
+ errorFromW3CJsonCode,
7
10
  } from './errors';
8
- import { METHOD_MAP, NO_SESSION_ID_COMMANDS } from './routes';
11
+ import {METHOD_MAP, NO_SESSION_ID_COMMANDS} from './routes';
9
12
  import B from 'bluebird';
10
- import { formatResponseValue, formatStatus } from './helpers';
11
- import { MAX_LOG_BODY_LENGTH, PROTOCOLS, DEFAULT_BASE_PATH } from '../constants';
12
- import { isW3cCaps } from '../helpers/capabilities';
13
-
13
+ import {formatResponseValue, formatStatus} from './helpers';
14
+ import {MAX_LOG_BODY_LENGTH, PROTOCOLS, DEFAULT_BASE_PATH} from '../constants';
15
+ import {isW3cCaps} from '../helpers/capabilities';
14
16
 
15
17
  const CREATE_SESSION_COMMAND = 'createSession';
16
18
  const DELETE_SESSION_COMMAND = 'deleteSession';
17
19
  const GET_STATUS_COMMAND = 'getStatus';
18
20
 
19
- function determineProtocol (createSessionArgs) {
21
+ function determineProtocol(createSessionArgs) {
20
22
  return _.some(createSessionArgs, isW3cCaps) ? PROTOCOLS.W3C : PROTOCOLS.MJSONWP;
21
23
  }
22
24
 
23
- function extractProtocol (driver, sessionId = null) {
25
+ function extractProtocol(driver, sessionId = null) {
24
26
  const dstDriver = _.isFunction(driver.driverForSession)
25
27
  ? driver.driverForSession(sessionId)
26
28
  : driver;
@@ -35,14 +37,21 @@ function extractProtocol (driver, sessionId = null) {
35
37
  return dstDriver?.protocol ?? PROTOCOLS.W3C;
36
38
  }
37
39
 
38
- function isSessionCommand (command) {
40
+ function isSessionCommand(command) {
39
41
  return !_.includes(NO_SESSION_ID_COMMANDS, command);
40
42
  }
41
43
 
42
- function getLogger (driver, sessionId = null) {
43
- const dstDriver = sessionId && _.isFunction(driver.driverForSession)
44
- ? (driver.driverForSession(sessionId) ?? driver)
45
- : driver;
44
+ /**
45
+ *
46
+ * @param {import('@appium/types').ExternalDriver} driver
47
+ * @param {string?} [sessionId]
48
+ * @returns {import('@appium/types').AppiumLogger}
49
+ */
50
+ function getLogger(driver, sessionId = null) {
51
+ const dstDriver =
52
+ sessionId && _.isFunction(driver.driverForSession)
53
+ ? driver.driverForSession(sessionId) ?? driver
54
+ : driver;
46
55
  if (_.isFunction(dstDriver.log?.info)) {
47
56
  return dstDriver.log;
48
57
  }
@@ -56,7 +65,7 @@ function getLogger (driver, sessionId = null) {
56
65
  return logger.getLogger(logPrefix);
57
66
  }
58
67
 
59
- function wrapParams (paramSets, jsonObj) {
68
+ function wrapParams(paramSets, jsonObj) {
60
69
  /* There are commands like performTouch which take a single parameter (primitive type or array).
61
70
  * Some drivers choose to pass this parameter as a value (eg. [action1, action2...]) while others to
62
71
  * wrap it within an object(eg' {gesture: [action1, action2...]}), which makes it hard to validate.
@@ -71,7 +80,7 @@ function wrapParams (paramSets, jsonObj) {
71
80
  return res;
72
81
  }
73
82
 
74
- function unwrapParams (paramSets, jsonObj) {
83
+ function unwrapParams(paramSets, jsonObj) {
75
84
  /* There are commands like setNetworkConnection which send parameters wrapped inside a key such as
76
85
  * "parameters". This function unwraps them (eg. {"parameters": {"type": 1}} becomes {"type": 1}).
77
86
  */
@@ -85,7 +94,7 @@ function unwrapParams (paramSets, jsonObj) {
85
94
  return res;
86
95
  }
87
96
 
88
- function checkParams (paramSets, jsonObj, protocol) {
97
+ function checkParams(paramSets, jsonObj, protocol) {
89
98
  let requiredParams = [];
90
99
  let optionalParams = [];
91
100
  let receivedParams = _.keys(jsonObj);
@@ -134,8 +143,10 @@ function checkParams (paramSets, jsonObj, protocol) {
134
143
 
135
144
  // go through the required parameters and check against our arguments
136
145
  for (let params of requiredParams) {
137
- if (_.difference(receivedParams, params, optionalParams).length === 0 &&
138
- _.difference(params, receivedParams).length === 0) {
146
+ if (
147
+ _.difference(receivedParams, params, optionalParams).length === 0 &&
148
+ _.difference(params, receivedParams).length === 0
149
+ ) {
139
150
  // we have a set of parameters that is correct
140
151
  // so short-circuit
141
152
  return;
@@ -151,7 +162,7 @@ function checkParams (paramSets, jsonObj, protocol) {
151
162
  * on handling parameters. This method returns an array of arguments which will
152
163
  * be applied to a command.
153
164
  */
154
- function makeArgs (requestParams, jsonObj, payloadParams, protocol) {
165
+ function makeArgs(requestParams, jsonObj, payloadParams, protocol) {
155
166
  // We want to pass the "url" parameters to the commands in reverse order
156
167
  // since the command will sometimes want to ignore, say, the sessionId.
157
168
  // This has the effect of putting sessionId last, which means in JS we can
@@ -201,7 +212,7 @@ function makeArgs (requestParams, jsonObj, payloadParams, protocol) {
201
212
  return args;
202
213
  }
203
214
 
204
- function routeConfiguringFunction (driver) {
215
+ function routeConfiguringFunction(driver) {
205
216
  if (!driver.sessionExists) {
206
217
  throw new Error('Drivers must implement `sessionExists` property');
207
218
  }
@@ -212,7 +223,7 @@ function routeConfiguringFunction (driver) {
212
223
 
213
224
  // return a function which will add all the routes to the driver. Here extraMethods might be
214
225
  // passed in as defined by Appium plugins, so we need to add those to the default list
215
- return function addRoutes (app, {basePath = DEFAULT_BASE_PATH, extraMethodMap = {}}) {
226
+ return function addRoutes(app, {basePath = DEFAULT_BASE_PATH, extraMethodMap = {}}) {
216
227
  // store basePath on the driver instance so it can use it if necessary
217
228
  // for example in determining proxy avoidance
218
229
  driver.basePath = basePath;
@@ -222,13 +233,20 @@ function routeConfiguringFunction (driver) {
222
233
  for (const [path, methods] of _.toPairs(allMethods)) {
223
234
  for (const [method, spec] of _.toPairs(methods)) {
224
235
  // set up the express route handler
225
- buildHandler(app, method, `${basePath}${path}`, spec, driver, isSessionCommand(spec.command));
236
+ buildHandler(
237
+ app,
238
+ method,
239
+ `${basePath}${path}`,
240
+ spec,
241
+ driver,
242
+ isSessionCommand(spec.command)
243
+ );
226
244
  }
227
245
  }
228
246
  };
229
247
  }
230
248
 
231
- function buildHandler (app, method, path, spec, driver, isSessCmd) {
249
+ function buildHandler(app, method, path, spec, driver, isSessCmd) {
232
250
  let asyncHandler = async (req, res) => {
233
251
  let jsonObj = req.body;
234
252
  let httpResBody = {};
@@ -253,14 +271,18 @@ function buildHandler (app, method, path, spec, driver, isSessCmd) {
253
271
  // plugin)
254
272
  let didPluginOverrideProxy = false;
255
273
  if (isSessCmd && !spec.neverProxy && driverShouldDoJwpProxy(driver, req, spec.command)) {
256
- if (!driver.pluginsToHandleCmd ||
257
- driver.pluginsToHandleCmd(spec.command, req.params.sessionId).length === 0) {
274
+ if (
275
+ !driver.pluginsToHandleCmd ||
276
+ driver.pluginsToHandleCmd(spec.command, req.params.sessionId).length === 0
277
+ ) {
258
278
  await doJwpProxy(driver, req, res);
259
279
  return;
260
280
  }
261
- getLogger(driver, req.params.sessionId).debug(`Would have proxied ` +
262
- `command directly, but a plugin exists which might require its value, so will let ` +
263
- `its value be collected internally and made part of plugin chain`);
281
+ getLogger(driver, req.params.sessionId).debug(
282
+ `Would have proxied ` +
283
+ `command directly, but a plugin exists which might require its value, so will let ` +
284
+ `its value be collected internally and made part of plugin chain`
285
+ );
264
286
  didPluginOverrideProxy = true;
265
287
  }
266
288
 
@@ -283,7 +305,9 @@ function buildHandler (app, method, path, spec, driver, isSessCmd) {
283
305
  if (spec.command === CREATE_SESSION_COMMAND) {
284
306
  // try to determine protocol by session creation args, so we can throw a
285
307
  // properly formatted error if arguments validation fails
286
- currentProtocol = determineProtocol(makeArgs(req.params, jsonObj, spec.payloadParams || {}));
308
+ currentProtocol = determineProtocol(
309
+ makeArgs(req.params, jsonObj, spec.payloadParams || {})
310
+ );
287
311
  }
288
312
 
289
313
  // ensure that the json payload conforms to the spec
@@ -299,9 +323,11 @@ function buildHandler (app, method, path, spec, driver, isSessCmd) {
299
323
  }
300
324
 
301
325
  // run the driver command wrapped inside the argument validators
302
- getLogger(driver, req.params.sessionId).debug(`Calling ` +
303
- `${driver.constructor.name}.${spec.command}() with args: ` +
304
- _.truncate(JSON.stringify(args), {length: MAX_LOG_BODY_LENGTH}));
326
+ getLogger(driver, req.params.sessionId).debug(
327
+ `Calling ` +
328
+ `${driver.constructor.name}.${spec.command}() with args: ` +
329
+ _.truncate(JSON.stringify(args), {length: MAX_LOG_BODY_LENGTH})
330
+ );
305
331
 
306
332
  if (didPluginOverrideProxy) {
307
333
  // TODO for now we add this information on the args list, but that's mixing purposes here.
@@ -328,8 +354,9 @@ function buildHandler (app, method, path, spec, driver, isSessCmd) {
328
354
  // unpack createSession response
329
355
  if (spec.command === CREATE_SESSION_COMMAND) {
330
356
  newSessionId = driverRes[0];
331
- getLogger(driver, newSessionId)
332
- .debug(`Cached the protocol value '${currentProtocol}' for the new session ${newSessionId}`);
357
+ getLogger(driver, newSessionId).debug(
358
+ `Cached the protocol value '${currentProtocol}' for the new session ${newSessionId}`
359
+ );
333
360
  if (currentProtocol === PROTOCOLS.MJSONWP) {
334
361
  driverRes = driverRes[1];
335
362
  } else if (currentProtocol === PROTOCOLS.W3C) {
@@ -343,42 +370,59 @@ function buildHandler (app, method, path, spec, driver, isSessCmd) {
343
370
 
344
371
  // delete should not return anything even if successful
345
372
  if (spec.command === DELETE_SESSION_COMMAND) {
346
- getLogger(driver, req.params.sessionId)
347
- .debug(`Received response: ${_.truncate(JSON.stringify(driverRes), {length: MAX_LOG_BODY_LENGTH})}`);
373
+ getLogger(driver, req.params.sessionId).debug(
374
+ `Received response: ${_.truncate(JSON.stringify(driverRes), {
375
+ length: MAX_LOG_BODY_LENGTH,
376
+ })}`
377
+ );
348
378
  getLogger(driver, req.params.sessionId).debug('But deleting session, so not returning');
349
379
  driverRes = null;
350
380
  }
351
381
 
352
382
  // if the status is not 0, throw the appropriate error for status code.
353
383
  if (util.hasValue(driverRes)) {
354
- if (util.hasValue(driverRes.status) && !isNaN(driverRes.status) && parseInt(driverRes.status, 10) !== 0) {
384
+ if (
385
+ util.hasValue(driverRes.status) &&
386
+ !isNaN(driverRes.status) &&
387
+ parseInt(driverRes.status, 10) !== 0
388
+ ) {
355
389
  throw errorFromMJSONWPStatusCode(driverRes.status, driverRes.value);
356
390
  } else if (_.isPlainObject(driverRes.value) && driverRes.value.error) {
357
- throw errorFromW3CJsonCode(driverRes.value.error, driverRes.value.message, driverRes.value.stacktrace);
391
+ throw errorFromW3CJsonCode(
392
+ driverRes.value.error,
393
+ driverRes.value.message,
394
+ driverRes.value.stacktrace
395
+ );
358
396
  }
359
397
  }
360
398
 
361
399
  httpResBody.value = driverRes;
362
- getLogger(driver, req.params.sessionId || newSessionId).debug(`Responding ` +
363
- `to client with driver.${spec.command}() result: ${_.truncate(JSON.stringify(driverRes), {length: MAX_LOG_BODY_LENGTH})}`);
400
+ getLogger(driver, req.params.sessionId || newSessionId).debug(
401
+ `Responding ` +
402
+ `to client with driver.${spec.command}() result: ${_.truncate(JSON.stringify(driverRes), {
403
+ length: MAX_LOG_BODY_LENGTH,
404
+ })}`
405
+ );
364
406
  } catch (err) {
365
407
  // if anything goes wrong, figure out what our response should be
366
408
  // based on the type of error that we encountered
367
409
  let actualErr = err;
368
410
 
369
- currentProtocol = currentProtocol || extractProtocol(driver, req.params.sessionId || newSessionId);
411
+ currentProtocol =
412
+ currentProtocol || extractProtocol(driver, req.params.sessionId || newSessionId);
370
413
 
371
414
  let errMsg = err.stacktrace || err.stack;
372
415
  if (!_.includes(errMsg, err.message)) {
373
416
  // if the message has more information, add it. but often the message
374
417
  // is the first part of the stack trace
375
- errMsg = `${err.message}${errMsg ? ('\n' + errMsg) : ''}`;
418
+ errMsg = `${err.message}${errMsg ? '\n' + errMsg : ''}`;
376
419
  }
377
420
  if (isErrorType(err, errors.ProxyRequestError)) {
378
421
  actualErr = err.getActualError();
379
422
  } else {
380
- getLogger(driver, req.params.sessionId || newSessionId)
381
- .debug(`Encountered internal error running command: ${errMsg}`);
423
+ getLogger(driver, req.params.sessionId || newSessionId).debug(
424
+ `Encountered internal error running command: ${errMsg}`
425
+ );
382
426
  }
383
427
 
384
428
  [httpStatus, httpResBody] = getResponseForW3CError(actualErr);
@@ -412,7 +456,7 @@ function buildHandler (app, method, path, spec, driver, isSessCmd) {
412
456
  });
413
457
  }
414
458
 
415
- function driverShouldDoJwpProxy (driver, req, command) {
459
+ function driverShouldDoJwpProxy(driver, req, command) {
416
460
  // drivers need to explicitly say when the proxy is active
417
461
  if (!driver.proxyActive(req.params.sessionId)) {
418
462
  return false;
@@ -433,9 +477,10 @@ function driverShouldDoJwpProxy (driver, req, command) {
433
477
  return true;
434
478
  }
435
479
 
436
- async function doJwpProxy (driver, req, res) {
437
- getLogger(driver, req.params.sessionId)
438
- .info('Driver proxy active, passing request on via HTTP proxy');
480
+ async function doJwpProxy(driver, req, res) {
481
+ getLogger(driver, req.params.sessionId).info(
482
+ 'Driver proxy active, passing request on via HTTP proxy'
483
+ );
439
484
 
440
485
  // check that the inner driver has a proxy function
441
486
  if (!driver.canProxy(req.params.sessionId)) {
@@ -452,9 +497,12 @@ async function doJwpProxy (driver, req, res) {
452
497
  }
453
498
  }
454
499
 
455
-
456
500
  export {
457
- routeConfiguringFunction, isSessionCommand,
458
- driverShouldDoJwpProxy, determineProtocol, CREATE_SESSION_COMMAND,
459
- DELETE_SESSION_COMMAND, GET_STATUS_COMMAND,
501
+ routeConfiguringFunction,
502
+ isSessionCommand,
503
+ driverShouldDoJwpProxy,
504
+ determineProtocol,
505
+ CREATE_SESSION_COMMAND,
506
+ DELETE_SESSION_COMMAND,
507
+ GET_STATUS_COMMAND,
460
508
  };