appium-adb 9.2.3 → 9.4.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.
@@ -197,6 +197,12 @@ systemCallMethods.getBinaryFromPath = async function getBinaryFromPath (binaryNa
197
197
  }
198
198
  };
199
199
 
200
+ /**
201
+ * @typedef {Object} ConnectedDevicesOptions
202
+ * @property {?boolean} verbose - Whether to get long output, which includes extra properties in each device.
203
+ * Akin to running `adb devices -l`.
204
+ */
205
+
200
206
  /**
201
207
  * @typedef {Object} Device
202
208
  * @property {string} udid - The device udid.
@@ -204,18 +210,33 @@ systemCallMethods.getBinaryFromPath = async function getBinaryFromPath (binaryNa
204
210
  * _adb devices -l_ output.
205
211
  */
206
212
 
213
+ /**
214
+ * @typedef {Device} VerboseDevice Additional properties returned when `verbose` is true.
215
+ * @property {string} product - The product codename of the device, such as "razor".
216
+ * @property {string} model - The model name of the device, such as "Nexus_7".
217
+ * @property {string} device - The device codename, such as "flow".
218
+ * @property {?string} usb - Represents the USB port the device is connected to, such as "1-1".
219
+ * @property {?string} transport_id - The Transport ID for the device, such as "1".
220
+ */
221
+
207
222
  /**
208
223
  * Retrieve the list of devices visible to adb.
209
224
  *
225
+ * @param {?ConnectedDevicesOptions} opts [{}] - Additional options mapping.
210
226
  * @return {Array.<Device>} The list of devices or an empty list if
211
227
  * no devices are connected.
212
228
  * @throws {Error} If there was an error while listing devices.
213
229
  */
214
- systemCallMethods.getConnectedDevices = async function getConnectedDevices () {
230
+ systemCallMethods.getConnectedDevices = async function getConnectedDevices (opts = {}) {
215
231
  log.debug('Getting connected devices');
232
+ const args = [...this.executable.defaultArgs, 'devices'];
233
+ if (opts.verbose) {
234
+ args.push('-l');
235
+ }
236
+
216
237
  let stdout;
217
238
  try {
218
- ({stdout} = await exec(this.executable.path, [...this.executable.defaultArgs, 'devices']));
239
+ ({stdout} = await exec(this.executable.path, args));
219
240
  } catch (e) {
220
241
  throw new Error(`Error while getting connected devices. Original error: ${e.message}`);
221
242
  }
@@ -236,12 +257,21 @@ systemCallMethods.getConnectedDevices = async function getConnectedDevices () {
236
257
  const devices = stdout.split('\n')
237
258
  .map(_.trim)
238
259
  .filter((line) => line && !excludedLines.some((x) => line.includes(x)))
239
- .reduce((acc, line) => {
260
+ .map((line) => {
240
261
  // state is "device", afaic
241
- const [udid, state] = line.split(/\s+/);
242
- acc.push({udid, state});
243
- return acc;
244
- }, []);
262
+ const [udid, state, ...description] = line.split(/\s+/);
263
+ const device = {udid, state};
264
+ if (opts.verbose) {
265
+ for (const entry of description) {
266
+ if (entry.includes(':')) {
267
+ // each entry looks like key:value
268
+ const [key, value] = entry.split(':');
269
+ device[key] = value;
270
+ }
271
+ }
272
+ }
273
+ return device;
274
+ });
245
275
  if (_.isEmpty(devices)) {
246
276
  log.debug('No connected devices have been detected');
247
277
  } else {
@@ -577,12 +607,13 @@ systemCallMethods.getPortFromEmulatorString = function getPortFromEmulatorString
577
607
  /**
578
608
  * Retrieve the list of currently connected emulators.
579
609
  *
610
+ * @param {?ConnectedDevicesOptions} opts [{}] - Additional options mapping.
580
611
  * @return {Array.<Device>} The list of connected devices.
581
612
  */
582
- systemCallMethods.getConnectedEmulators = async function getConnectedEmulators () {
613
+ systemCallMethods.getConnectedEmulators = async function getConnectedEmulators (opts = {}) {
583
614
  log.debug('Getting connected emulators');
584
615
  try {
585
- let devices = await this.getConnectedDevices();
616
+ let devices = await this.getConnectedDevices(opts);
586
617
  let emulators = [];
587
618
  for (let device of devices) {
588
619
  let port = this.getPortFromEmulatorString(device.udid);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "appium-adb",
3
- "version": "9.2.3",
3
+ "version": "9.4.0",
4
4
  "description": "Android Debug Bridge interface",
5
5
  "main": "./build/index.js",
6
6
  "scripts": {
@@ -77,7 +77,7 @@
77
77
  "mocha-multi-reporters": "^1.1.7",
78
78
  "pre-commit": "^1.1.3",
79
79
  "semantic-release": "^19.0.2",
80
- "sinon": "^13.0.0",
80
+ "sinon": "^14.0.0",
81
81
  "temp": "^0.x"
82
82
  }
83
83
  }