-
-
Notifications
You must be signed in to change notification settings - Fork 12
/
idb.js
87 lines (77 loc) · 2 KB
/
idb.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
import _ from 'lodash';
import methods from './tools/index.js';
import {
DEFAULT_IDB_EXEC_TIMEOUT,
IDB_EXECUTABLE, IDB_COMPANION_EXECUTABLE,
} from './helpers';
const DEFAULT_OPTS = {
udid: null,
executable: {
path: IDB_EXECUTABLE,
port: null,
grpcPort: null,
defaultArgs: [],
},
logLevel: null,
companion: {
path: IDB_COMPANION_EXECUTABLE,
port: null,
grpcPort: null,
logPath: null,
},
execTimeout: DEFAULT_IDB_EXEC_TIMEOUT,
verbose: false,
};
/**
* @typedef {Object} IdbExecutable
* @property {string} path
* @property {number?} [port]
* @property {number?} [grpcPort]
* @property {string[]} defaultArgs
*/
/**
* @typedef {Object} IdbCompanion
* @property {string} path
* @property {number?} [port]
* @property {number?} [grpcPort]
* @property {string?} [logPath]
*/
class IDB {
/** @type {string} */
udid;
/** @type {string|undefined} */
logLevel;
/** @type {number} */
execTimeout;
/** @type {boolean} */
verbose;
/** @type {IdbExecutable} */
executable;
/** @type {IdbCompanion} */
companion;
/** @type {(cmd: string[], args?: string [], opts?: import('teen_process').TeenProcessExecOptions & {timeoutCapName?: string}) => Promise<string>} */
exec;
/** @type {() => Promise<void>} */
disconnect;
/** @type {(timeout?: number) => Promise<void>} */
waitForDevice;
/** @type {(command?: string[], args?: string[], opts?: import('teen_process').SubProcessOptions) => import('teen_process').SubProcess} */
createSubProcess;
constructor (opts = {}) {
Object.assign(this, opts);
_.defaultsDeep(this, _.cloneDeep(DEFAULT_OPTS));
if (!this.udid) {
throw new Error(`UDID must be set for idb`);
}
this.executable.defaultArgs.push('--udid', this.udid);
if (this.logLevel) {
this.executable.defaultArgs.push('--log', this.logLevel);
}
}
}
// add all the methods to the IDB prototype
for (const [fnName, fn] of _.toPairs(methods)) {
IDB.prototype[fnName] = fn;
}
export default IDB;
export { IDB };