node-simctl 7.3.3 → 7.3.5

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 (51) hide show
  1. package/CHANGELOG.md +15 -0
  2. package/build/lib/helpers.d.ts +6 -3
  3. package/build/lib/helpers.d.ts.map +1 -1
  4. package/build/lib/helpers.js +8 -5
  5. package/build/lib/helpers.js.map +1 -1
  6. package/build/lib/simctl.d.ts +50 -38
  7. package/build/lib/simctl.d.ts.map +1 -1
  8. package/build/lib/simctl.js +25 -18
  9. package/build/lib/simctl.js.map +1 -1
  10. package/build/lib/subcommands/bootstatus.d.ts +16 -16
  11. package/build/lib/subcommands/bootstatus.d.ts.map +1 -1
  12. package/build/lib/subcommands/bootstatus.js +7 -7
  13. package/build/lib/subcommands/create.d.ts +9 -9
  14. package/build/lib/subcommands/create.d.ts.map +1 -1
  15. package/build/lib/subcommands/create.js +3 -3
  16. package/build/lib/subcommands/erase.d.ts +2 -2
  17. package/build/lib/subcommands/erase.d.ts.map +1 -1
  18. package/build/lib/subcommands/erase.js +1 -1
  19. package/build/lib/subcommands/get_app_container.d.ts +2 -2
  20. package/build/lib/subcommands/get_app_container.d.ts.map +1 -1
  21. package/build/lib/subcommands/get_app_container.js +1 -1
  22. package/build/lib/subcommands/keychain.d.ts +7 -7
  23. package/build/lib/subcommands/keychain.d.ts.map +1 -1
  24. package/build/lib/subcommands/keychain.js +3 -3
  25. package/build/lib/subcommands/launch.d.ts +2 -2
  26. package/build/lib/subcommands/launch.d.ts.map +1 -1
  27. package/build/lib/subcommands/launch.js +1 -1
  28. package/build/lib/subcommands/list.d.ts +9 -9
  29. package/build/lib/subcommands/list.d.ts.map +1 -1
  30. package/build/lib/subcommands/list.js +5 -5
  31. package/build/lib/subcommands/pbcopy.d.ts +2 -2
  32. package/build/lib/subcommands/pbcopy.d.ts.map +1 -1
  33. package/build/lib/subcommands/pbcopy.js +1 -1
  34. package/build/lib/subcommands/pbpaste.d.ts +2 -2
  35. package/build/lib/subcommands/pbpaste.d.ts.map +1 -1
  36. package/build/lib/subcommands/pbpaste.js +1 -1
  37. package/build/lib/subcommands/spawn.d.ts +2 -2
  38. package/build/lib/subcommands/spawn.js +2 -2
  39. package/lib/helpers.js +9 -9
  40. package/lib/simctl.js +29 -20
  41. package/lib/subcommands/bootstatus.js +7 -7
  42. package/lib/subcommands/create.js +3 -3
  43. package/lib/subcommands/erase.js +1 -1
  44. package/lib/subcommands/get_app_container.js +1 -1
  45. package/lib/subcommands/keychain.js +3 -3
  46. package/lib/subcommands/launch.js +1 -1
  47. package/lib/subcommands/list.js +5 -5
  48. package/lib/subcommands/pbcopy.js +1 -1
  49. package/lib/subcommands/pbpaste.js +1 -1
  50. package/lib/subcommands/spawn.js +2 -2
  51. package/package.json +3 -3
@@ -1,16 +1,16 @@
1
1
  export default commands;
2
2
  export type CertOptions = {
3
3
  /**
4
- * [false] - whether the `cert` argument
4
+ * - whether the `cert` argument
5
5
  * is the path to the certificate on the local file system or
6
6
  * a raw certificate content
7
7
  */
8
- raw: boolean;
8
+ raw?: boolean | undefined;
9
9
  };
10
10
  declare namespace commands {
11
11
  /**
12
12
  * @typedef {Object} CertOptions
13
- * @property {boolean} raw [false] - whether the `cert` argument
13
+ * @property {boolean} [raw=false] - whether the `cert` argument
14
14
  * is the path to the certificate on the local file system or
15
15
  * a raw certificate content
16
16
  */
@@ -21,12 +21,12 @@ declare namespace commands {
21
21
  * @param {string} cert the full path to a valid .cert file containing
22
22
  * the certificate content or the certificate content itself, depending on
23
23
  * options
24
- * @param {Partial<CertOptions>} opts
24
+ * @param {CertOptions} [opts={}]
25
25
  * @throws {Error} if the current SDK version does not support the command
26
26
  * or there was an error while adding the certificate
27
27
  * @throws {Error} If the `udid` instance property is unset
28
28
  */
29
- function addRootCertificate(cert: string, opts?: Partial<CertOptions>): Promise<void>;
29
+ function addRootCertificate(cert: string, opts?: CertOptions | undefined): Promise<void>;
30
30
  /**
31
31
  * Adds the given certificate to the Keychain Store on the simulator
32
32
  *
@@ -34,12 +34,12 @@ declare namespace commands {
34
34
  * @param {string} cert the full path to a valid .cert file containing
35
35
  * the certificate content or the certificate content itself, depending on
36
36
  * options
37
- * @param {Partial<CertOptions>} opts
37
+ * @param {CertOptions} [opts={}]
38
38
  * @throws {Error} if the current SDK version does not support the command
39
39
  * or there was an error while adding the certificate
40
40
  * @throws {Error} If the `udid` instance property is unset
41
41
  */
42
- function addCertificate(cert: string, opts?: Partial<CertOptions>): Promise<void>;
42
+ function addCertificate(cert: string, opts?: CertOptions | undefined): Promise<void>;
43
43
  /**
44
44
  * Resets the simulator keychain
45
45
  *
@@ -1 +1 @@
1
- {"version":3,"file":"keychain.d.ts","sourceRoot":"","sources":["../../../lib/subcommands/keychain.js"],"names":[],"mappings":";;;;;;;SA0Bc,OAAO;;;IAFrB;;;;;OAKG;IAEH;;;;;;;;;;;OAWG;IACH,sFAYC;IAED;;;;;;;;;;;OAWG;IACH,kFAYC;IAED;;;;;;;OAOG;IACH,wCAIC"}
1
+ {"version":3,"file":"keychain.d.ts","sourceRoot":"","sources":["../../../lib/subcommands/keychain.js"],"names":[],"mappings":";;;;;;;;;;IAwBA;;;;;OAKG;IAEH;;;;;;;;;;;OAWG;IACH,yFAYC;IAED;;;;;;;;;;;OAWG;IACH,qFAYC;IAED;;;;;;;OAOG;IACH,wCAIC"}
@@ -27,7 +27,7 @@ async function handleRawPayload(payload, onPayloadStored) {
27
27
  }
28
28
  /**
29
29
  * @typedef {Object} CertOptions
30
- * @property {boolean} raw [false] - whether the `cert` argument
30
+ * @property {boolean} [raw=false] - whether the `cert` argument
31
31
  * is the path to the certificate on the local file system or
32
32
  * a raw certificate content
33
33
  */
@@ -38,7 +38,7 @@ async function handleRawPayload(payload, onPayloadStored) {
38
38
  * @param {string} cert the full path to a valid .cert file containing
39
39
  * the certificate content or the certificate content itself, depending on
40
40
  * options
41
- * @param {Partial<CertOptions>} opts
41
+ * @param {CertOptions} [opts={}]
42
42
  * @throws {Error} if the current SDK version does not support the command
43
43
  * or there was an error while adding the certificate
44
44
  * @throws {Error} If the `udid` instance property is unset
@@ -62,7 +62,7 @@ commands.addRootCertificate = async function addRootCertificate(cert, opts = {})
62
62
  * @param {string} cert the full path to a valid .cert file containing
63
63
  * the certificate content or the certificate content itself, depending on
64
64
  * options
65
- * @param {Partial<CertOptions>} opts
65
+ * @param {CertOptions} [opts={}]
66
66
  * @throws {Error} if the current SDK version does not support the command
67
67
  * or there was an error while adding the certificate
68
68
  * @throws {Error} If the `udid` instance property is unset
@@ -7,13 +7,13 @@ declare namespace commands {
7
7
  *
8
8
  * @param {string} bundleId - Bundle identifier of the application,
9
9
  * which is going to be removed.
10
- * @param {number} tries [5] - The maximum number of retries before
10
+ * @param {number} [tries=5] - The maximum number of retries before
11
11
  * throwing an exception.
12
12
  * @return {Promise<string>} the actual command output
13
13
  * @throws {Error} If the corresponding simctl subcommand command
14
14
  * returns non-zero return code.
15
15
  * @throws {Error} If the `udid` instance property is unset
16
16
  */
17
- function launchApp(bundleId: string, tries?: number): Promise<string>;
17
+ function launchApp(bundleId: string, tries?: number | undefined): Promise<string>;
18
18
  }
19
19
  //# sourceMappingURL=launch.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"launch.d.ts","sourceRoot":"","sources":["../../../lib/subcommands/launch.js"],"names":[],"mappings":";;IAKA;;;;;;;;;;;;;OAaG;IACH,sEAQC"}
1
+ {"version":3,"file":"launch.d.ts","sourceRoot":"","sources":["../../../lib/subcommands/launch.js"],"names":[],"mappings":";;IAKA;;;;;;;;;;;;;OAaG;IACH,kFAQC"}
@@ -13,7 +13,7 @@ const commands = {};
13
13
  *
14
14
  * @param {string} bundleId - Bundle identifier of the application,
15
15
  * which is going to be removed.
16
- * @param {number} tries [5] - The maximum number of retries before
16
+ * @param {number} [tries=5] - The maximum number of retries before
17
17
  * throwing an exception.
18
18
  * @return {Promise<string>} the actual command output
19
19
  * @throws {Error} If the corresponding simctl subcommand command
@@ -29,22 +29,22 @@ declare namespace commands {
29
29
  * Parse the list of existing Simulator devices to represent
30
30
  * it as convenient mapping.
31
31
  *
32
- * @param {string?} platform - The platform name, for example 'watchOS'.
32
+ * @param {string?} [platform] - The platform name, for example 'watchOS'.
33
33
  * @return {Promise<Record<string, any>>} The resulting mapping. Each key is platform version,
34
34
  * for example '10.3' and the corresponding value is an
35
35
  * array of the matching {@link DeviceInfo} instances.
36
36
  * @throws {Error} If the corresponding simctl subcommand command
37
37
  * returns non-zero return code.
38
38
  */
39
- function getDevicesByParsing(platform: string | null): Promise<Record<string, any>>;
39
+ function getDevicesByParsing(platform?: string | null | undefined): Promise<Record<string, any>>;
40
40
  /**
41
41
  * Parse the list of existing Simulator devices to represent
42
42
  * it as convenient mapping for the particular platform version.
43
43
  *
44
- * @param {string?} forSdk - The sdk version,
44
+ * @param {string?} [forSdk] - The sdk version,
45
45
  * for which the devices list should be parsed,
46
46
  * for example '10.3'.
47
- * @param {string?} platform - The platform name, for example 'watchOS'.
47
+ * @param {string?} [platform] - The platform name, for example 'watchOS'.
48
48
  * @return {Promise<Object|DeviceInfo[]>} If _forSdk_ is set then the list
49
49
  * of devices for the particular platform version.
50
50
  * Otherwise the same result as for {@link getDevicesByParsing}
@@ -53,27 +53,27 @@ declare namespace commands {
53
53
  * returns non-zero return code or if no matching
54
54
  * platform version is found in the system.
55
55
  */
56
- function getDevices(forSdk: string | null, platform: string | null): Promise<any>;
56
+ function getDevices(forSdk?: string | null | undefined, platform?: string | null | undefined): Promise<any>;
57
57
  /**
58
58
  * Get the runtime for the particular platform version using --json flag
59
59
  *
60
60
  * @param {string} platformVersion - The platform version name,
61
61
  * for example '10.3'.
62
- * @param {string} platform - The platform name, for example 'watchOS'.
62
+ * @param {string} [platform='iOS'] - The platform name, for example 'watchOS'.
63
63
  * @return {Promise<string>} The corresponding runtime name for the given
64
64
  * platform version.
65
65
  */
66
- function getRuntimeForPlatformVersionViaJson(platformVersion: string, platform?: string): Promise<string>;
66
+ function getRuntimeForPlatformVersionViaJson(platformVersion: string, platform?: string | undefined): Promise<string>;
67
67
  /**
68
68
  * Get the runtime for the particular platform version.
69
69
  *
70
70
  * @param {string} platformVersion - The platform version name,
71
71
  * for example '10.3'.
72
- * @param {string} platform - The platform name, for example 'watchOS'.
72
+ * @param {string} [platform='iOS'] - The platform name, for example 'watchOS'.
73
73
  * @return {Promise<string>} The corresponding runtime name for the given
74
74
  * platform version.
75
75
  */
76
- function getRuntimeForPlatformVersion(platformVersion: string, platform?: string): Promise<string>;
76
+ function getRuntimeForPlatformVersion(platformVersion: string, platform?: string | undefined): Promise<string>;
77
77
  /**
78
78
  * Get the list of device types available in the current Xcode installation
79
79
  *
@@ -1 +1 @@
1
- {"version":3,"file":"list.d.ts","sourceRoot":"","sources":["../../../lib/subcommands/list.js"],"names":[],"mappings":";;;;;UASc,MAAM;;;;UACN,MAAM;;;;WACN,MAAM;;;;SACN,MAAM;;;IALpB;;;;;;OAMG;IAEH;;;;;;;;;;OAUG;IACH,oFA4DC;IAED;;;;;;;;;;;;;;;OAeG;IACH,kFAmEC;IAED;;;;;;;;OAQG;IACH,0GAYC;IAED;;;;;;;;OAQG;IACH,mGAoBC;IAED;;;;;OAKG;IACH,6CAqBC;IAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAiCG;IACH,8BASC"}
1
+ {"version":3,"file":"list.d.ts","sourceRoot":"","sources":["../../../lib/subcommands/list.js"],"names":[],"mappings":";;;;;UASc,MAAM;;;;UACN,MAAM;;;;WACN,MAAM;;;;SACN,MAAM;;;IALpB;;;;;;OAMG;IAEH;;;;;;;;;;OAUG;IACH,iGA4DC;IAED;;;;;;;;;;;;;;;OAeG;IACH,4GAmEC;IAED;;;;;;;;OAQG;IACH,sHAYC;IAED;;;;;;;;OAQG;IACH,+GAoBC;IAED;;;;;OAKG;IACH,6CAqBC;IAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAiCG;IACH,8BASC"}
@@ -41,7 +41,7 @@ const commands = {};
41
41
  * Parse the list of existing Simulator devices to represent
42
42
  * it as convenient mapping.
43
43
  *
44
- * @param {string?} platform - The platform name, for example 'watchOS'.
44
+ * @param {string?} [platform] - The platform name, for example 'watchOS'.
45
45
  * @return {Promise<Record<string, any>>} The resulting mapping. Each key is platform version,
46
46
  * for example '10.3' and the corresponding value is an
47
47
  * array of the matching {@link DeviceInfo} instances.
@@ -111,10 +111,10 @@ commands.getDevicesByParsing = async function getDevicesByParsing(platform) {
111
111
  * Parse the list of existing Simulator devices to represent
112
112
  * it as convenient mapping for the particular platform version.
113
113
  *
114
- * @param {string?} forSdk - The sdk version,
114
+ * @param {string?} [forSdk] - The sdk version,
115
115
  * for which the devices list should be parsed,
116
116
  * for example '10.3'.
117
- * @param {string?} platform - The platform name, for example 'watchOS'.
117
+ * @param {string?} [platform] - The platform name, for example 'watchOS'.
118
118
  * @return {Promise<Object|DeviceInfo[]>} If _forSdk_ is set then the list
119
119
  * of devices for the particular platform version.
120
120
  * Otherwise the same result as for {@link getDevicesByParsing}
@@ -193,7 +193,7 @@ commands.getDevices = async function getDevices(forSdk, platform) {
193
193
  *
194
194
  * @param {string} platformVersion - The platform version name,
195
195
  * for example '10.3'.
196
- * @param {string} platform - The platform name, for example 'watchOS'.
196
+ * @param {string} [platform='iOS'] - The platform name, for example 'watchOS'.
197
197
  * @return {Promise<string>} The corresponding runtime name for the given
198
198
  * platform version.
199
199
  */
@@ -214,7 +214,7 @@ commands.getRuntimeForPlatformVersionViaJson = async function getRuntimeForPlatf
214
214
  *
215
215
  * @param {string} platformVersion - The platform version name,
216
216
  * for example '10.3'.
217
- * @param {string} platform - The platform name, for example 'watchOS'.
217
+ * @param {string} [platform='iOS'] - The platform name, for example 'watchOS'.
218
218
  * @return {Promise<string>} The corresponding runtime name for the given
219
219
  * platform version.
220
220
  */
@@ -6,12 +6,12 @@ declare namespace commands {
6
6
  *
7
7
  * @since Xcode SDK 8.1
8
8
  * @param {string} content - The actual string content to be set.
9
- * @param {string} encoding [utf8] - The encoding of the given pasteboard content.
9
+ * @param {string} [encoding='utf8'] - The encoding of the given pasteboard content.
10
10
  * UTF-8 by default.
11
11
  * @throws {Error} If the corresponding simctl subcommand command
12
12
  * returns non-zero return code.
13
13
  * @throws {Error} If the `udid` instance property is unset
14
14
  */
15
- function setPasteboard(content: string, encoding?: string): Promise<void>;
15
+ function setPasteboard(content: string, encoding?: string | undefined): Promise<void>;
16
16
  }
17
17
  //# sourceMappingURL=pbcopy.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"pbcopy.d.ts","sourceRoot":"","sources":["../../../lib/subcommands/pbcopy.js"],"names":[],"mappings":";;IAEA;;;;;;;;;;;OAWG;IACH,0EAYC"}
1
+ {"version":3,"file":"pbcopy.d.ts","sourceRoot":"","sources":["../../../lib/subcommands/pbcopy.js"],"names":[],"mappings":";;IAEA;;;;;;;;;;;OAWG;IACH,sFAYC"}
@@ -7,7 +7,7 @@ const commands = {};
7
7
  *
8
8
  * @since Xcode SDK 8.1
9
9
  * @param {string} content - The actual string content to be set.
10
- * @param {string} encoding [utf8] - The encoding of the given pasteboard content.
10
+ * @param {string} [encoding='utf8'] - The encoding of the given pasteboard content.
11
11
  * UTF-8 by default.
12
12
  * @throws {Error} If the corresponding simctl subcommand command
13
13
  * returns non-zero return code.
@@ -5,13 +5,13 @@ declare namespace commands {
5
5
  * It is required that Simulator is in _booted_ state.
6
6
  *
7
7
  * @since Xcode 8.1 SDK
8
- * @param {string} encoding ['utf-8'] - The encoding of the returned pasteboard content.
8
+ * @param {string} [encoding='utf8'] - The encoding of the returned pasteboard content.
9
9
  * UTF-8 by default.
10
10
  * @return {Promise<string>} Current content of Simulator pasteboard or an empty string.
11
11
  * @throws {Error} If the corresponding simctl subcommand command
12
12
  * returns non-zero return code.
13
13
  * @throws {Error} If the `udid` instance property is unset
14
14
  */
15
- function getPasteboard(encoding?: string): Promise<string>;
15
+ function getPasteboard(encoding?: string | undefined): Promise<string>;
16
16
  }
17
17
  //# sourceMappingURL=pbpaste.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"pbpaste.d.ts","sourceRoot":"","sources":["../../../lib/subcommands/pbpaste.js"],"names":[],"mappings":";;IAEA;;;;;;;;;;;OAWG;IACH,2DAMC"}
1
+ {"version":3,"file":"pbpaste.d.ts","sourceRoot":"","sources":["../../../lib/subcommands/pbpaste.js"],"names":[],"mappings":";;IAEA;;;;;;;;;;;OAWG;IACH,uEAMC"}
@@ -6,7 +6,7 @@ const commands = {};
6
6
  * It is required that Simulator is in _booted_ state.
7
7
  *
8
8
  * @since Xcode 8.1 SDK
9
- * @param {string} encoding ['utf-8'] - The encoding of the returned pasteboard content.
9
+ * @param {string} [encoding='utf8'] - The encoding of the returned pasteboard content.
10
10
  * UTF-8 by default.
11
11
  * @return {Promise<string>} Current content of Simulator pasteboard or an empty string.
12
12
  * @throws {Error} If the corresponding simctl subcommand command
@@ -5,7 +5,7 @@ declare namespace commands {
5
5
  * It is required that Simulator is in _booted_ state.
6
6
  *
7
7
  * @param {string|string[]} args - Spawn arguments
8
- * @param {object} env [{}] - Additional environment variables mapping.
8
+ * @param {object} [env={}] - Additional environment variables mapping.
9
9
  * @return {Promise<import('teen_process').TeenProcessExecResult>} Command execution result.
10
10
  * @throws {Error} If the corresponding simctl subcommand command
11
11
  * returns non-zero return code.
@@ -17,7 +17,7 @@ declare namespace commands {
17
17
  * on Simulator.
18
18
  *
19
19
  * @param {string|string[]} args - Spawn arguments
20
- * @param {object} env [{}] - Additional environment variables mapping.
20
+ * @param {object} [env={}] - Additional environment variables mapping.
21
21
  * @return {Promise<import('teen_process').SubProcess>} The instance of the process to be spawned.
22
22
  * @throws {Error} If the `udid` instance property is unset
23
23
  */
@@ -10,7 +10,7 @@ const commands = {};
10
10
  * It is required that Simulator is in _booted_ state.
11
11
  *
12
12
  * @param {string|string[]} args - Spawn arguments
13
- * @param {object} env [{}] - Additional environment variables mapping.
13
+ * @param {object} [env={}] - Additional environment variables mapping.
14
14
  * @return {Promise<import('teen_process').TeenProcessExecResult>} Command execution result.
15
15
  * @throws {Error} If the corresponding simctl subcommand command
16
16
  * returns non-zero return code.
@@ -30,7 +30,7 @@ commands.spawnProcess = async function spawnProcess(args, env = {}) {
30
30
  * on Simulator.
31
31
  *
32
32
  * @param {string|string[]} args - Spawn arguments
33
- * @param {object} env [{}] - Additional environment variables mapping.
33
+ * @param {object} [env={}] - Additional environment variables mapping.
34
34
  * @return {Promise<import('teen_process').SubProcess>} The instance of the process to be spawned.
35
35
  * @throws {Error} If the `udid` instance property is unset
36
36
  */
package/lib/helpers.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import semver from 'semver';
2
2
 
3
- const DEFAULT_EXEC_TIMEOUT = 10 * 60 * 1000; // ms
4
- const SIM_RUNTIME_NAME = 'com.apple.CoreSimulator.SimRuntime.';
3
+ export const DEFAULT_EXEC_TIMEOUT = 10 * 60 * 1000; // ms
4
+ export const SIM_RUNTIME_NAME = 'com.apple.CoreSimulator.SimRuntime.';
5
5
 
6
6
  /**
7
7
  * "Normalize" the version, since iOS uses 'major.minor' but the runtimes can
@@ -11,7 +11,7 @@ const SIM_RUNTIME_NAME = 'com.apple.CoreSimulator.SimRuntime.';
11
11
  * @return {string} The version in 'major.minor' form
12
12
  * @throws {Error} If the version not parseable by the `semver` package
13
13
  */
14
- function normalizeVersion (version) {
14
+ export function normalizeVersion (version) {
15
15
  const semverVersion = semver.coerce(version);
16
16
  if (!semverVersion) {
17
17
  throw new Error(`Unable to parse version '${version}'`);
@@ -19,9 +19,9 @@ function normalizeVersion (version) {
19
19
  return `${semverVersion.major}.${semverVersion.minor}`;
20
20
  }
21
21
 
22
- export {
23
- DEFAULT_EXEC_TIMEOUT, SIM_RUNTIME_NAME,
24
- normalizeVersion,
25
- };
26
-
27
- export const getXcrunBinary = () => process.env.XCRUN_BINARY || 'xcrun';
22
+ /**
23
+ * @returns {string}
24
+ */
25
+ export function getXcrunBinary () {
26
+ return process.env.XCRUN_BINARY || 'xcrun';
27
+ }
package/lib/simctl.js CHANGED
@@ -16,45 +16,50 @@ const DEFAULT_OPTS = {
16
16
  logErrors: true,
17
17
  };
18
18
 
19
+ /**
20
+ * @typedef {Object} XCRun
21
+ * @property {string?} path Full path to the xcrun script
22
+ */
23
+
19
24
  /**
20
25
  * @typedef {Object} ExecOpts
21
- * @property {string[]} args [[]] - The list of additional subcommand arguments.
26
+ * @property {string[]} [args=[]] - The list of additional subcommand arguments.
22
27
  * It's empty by default.
23
- * @property {Object} env [{}] - Environment variables mapping. All these variables
28
+ * @property {Record<string, any>} [env={}] - Environment variables mapping. All these variables
24
29
  * will be passed Simulator and used in the executing function.
25
- * @property {boolean} logErrors [true] - Set it to _false_ to throw execution errors
30
+ * @property {boolean} [logErrors=true] - Set it to _false_ to throw execution errors
26
31
  * immediately without logging any additional information.
27
- * @property {boolean} asynchronous [false] - Whether to execute the given command
32
+ * @property {boolean} [asynchronous=false] - Whether to execute the given command
28
33
  * 'synchronously' or 'asynchronously'. Affects the returned result of the function.
29
- * @property {string?} encoding - Explicitly sets streams encoding for the executed
34
+ * @property {string} [encoding] - Explicitly sets streams encoding for the executed
30
35
  * command input and outputs.
31
- * @property {string|string[]} architectures - One or more architecture names to be enforced while
36
+ * @property {string|string[]} [architectures] - One or more architecture names to be enforced while
32
37
  * executing xcrun. See https://github.com/appium/appium/issues/18966 for more details.
33
38
  */
34
39
 
35
40
 
36
41
  /**
37
42
  * @typedef {Object} SimctlOpts
38
- * @property {Object?} xcrun - The xcrun properties. Currently only one property
43
+ * @property {XCRun} [xcrun] - The xcrun properties. Currently only one property
39
44
  * is supported, which is `path` and it by default contains `null`, which enforces
40
45
  * the instance to automatically detect the full path to `xcrun` tool and to throw
41
46
  * an exception if it cannot be detected. If the path is set upon instance creation
42
47
  * then it is going to be used by `exec` and no autodetection will happen.
43
- * @property {number} execTimeout [600000] - The maximum number of milliseconds
48
+ * @property {number} [execTimeout=600000] - The maximum number of milliseconds
44
49
  * to wait for single synchronous xcrun command.
45
- * @property {boolean} logErrors [true] - Whether to wire xcrun error messages
50
+ * @property {boolean} [logErrors=true] - Whether to wire xcrun error messages
46
51
  * into debug log before throwing them.
47
- * @property {string?} udid - The unique identifier of the current device, which is
52
+ * @property {string?} [udid] - The unique identifier of the current device, which is
48
53
  * going to be implicitly passed to all methods, which require it. It can either be set
49
54
  * upon instance creation if it is already known in advance or later when/if needed via the
50
55
  * corresponding instance setter.
51
- * @property {string?} devicesSetPath - Full path to the set of devices that you want to manage.
56
+ * @property {string?} [devicesSetPath] - Full path to the set of devices that you want to manage.
52
57
  * By default this path usually equals to ~/Library/Developer/CoreSimulator/Devices
53
58
  */
54
59
 
55
60
 
56
61
  class Simctl {
57
- /** @type {any?} */
62
+ /** @type {XCRun} */
58
63
  xcrun;
59
64
 
60
65
  /** @type {number} */
@@ -64,7 +69,7 @@ class Simctl {
64
69
  logErrors;
65
70
 
66
71
  /**
67
- * @param {Partial<SimctlOpts>} opts
72
+ * @param {SimctlOpts} [opts={}]
68
73
  */
69
74
  constructor (opts = {}) {
70
75
  opts = _.cloneDeep(opts);
@@ -72,7 +77,9 @@ class Simctl {
72
77
  for (const key of _.keys(DEFAULT_OPTS)) {
73
78
  this[key] = opts[key];
74
79
  }
80
+ /** @type {string?} */
75
81
  this._udid = _.isNil(opts.udid) ? null : opts.udid;
82
+ /** @type {string?} */
76
83
  this._devicesSetPath = _.isNil(opts.devicesSetPath) ? null : opts.devicesSetPath;
77
84
  }
78
85
 
@@ -118,10 +125,10 @@ class Simctl {
118
125
  * Execute the particular simctl command.
119
126
  *
120
127
  * @param {string} subcommand - One of available simctl subcommands.
121
- * Execute `xcrun simctl` in Terminal to see the full list
122
- * of available subcommands.
123
- * @param {Partial<ExecOpts>} opts
124
- * @return {Promise<import('teen_process').TeenProcessExecResult|import('teen_process').SubProcess>} Either the result of teen process's `exec` or
128
+ * Execute `xcrun simctl` in Terminal to see the full list of available subcommands.
129
+ * @param {ExecOpts} [opts={}]
130
+ * @return {Promise<import('teen_process').TeenProcessExecResult|import('teen_process').SubProcess>}
131
+ * Either the result of teen process's `exec` or
125
132
  * `SubProcess` instance depending of `opts.asynchronous` value.
126
133
  * @throws {Error} If the simctl subcommand command returns non-zero return code.
127
134
  */
@@ -135,7 +142,8 @@ class Simctl {
135
142
  architectures,
136
143
  } = opts;
137
144
  // run a particular simctl command
138
- args = ['simctl',
145
+ args = [
146
+ 'simctl',
139
147
  ...(this.devicesSetPath ? ['--set', this.devicesSetPath] : []),
140
148
  subcommand,
141
149
  ...args
@@ -145,7 +153,8 @@ class Simctl {
145
153
  env = _.defaults(
146
154
  _.mapKeys(env,
147
155
  (value, key) => _.startsWith(key, SIMCTL_ENV_PREFIX) ? key : `${SIMCTL_ENV_PREFIX}${key}`),
148
- process.env);
156
+ process.env
157
+ );
149
158
 
150
159
  const execOpts = {
151
160
  env,
@@ -157,7 +166,7 @@ class Simctl {
157
166
  const xcrun = await this.requireXcrun();
158
167
  try {
159
168
  let execArgs = [xcrun, args, execOpts];
160
- if (!_.isEmpty(architectures)) {
169
+ if (architectures?.length) {
161
170
  const archArgs = _.flatMap(
162
171
  (_.isArray(architectures) ? architectures : [architectures]).map((arch) => ['-arch', arch])
163
172
  );
@@ -6,13 +6,13 @@ const commands = {};
6
6
 
7
7
  /**
8
8
  * @typedef {Object} BootMonitorOptions
9
- * @property {number} timeout [240000] - Simulator booting timeout in ms.
10
- * @property {Function?} onWaitingDataMigration - This event is fired when data migration stage starts.
11
- * @property {Function?} onWaitingSystemApp - This event is fired when system app wait stage starts.
12
- * @property {Function?} onFinished - This event is fired when Simulator is fully booted.
13
- * @property {Function?} onError - This event is fired when there was an error while monitoring the booting process
9
+ * @property {number} [timeout=240000] - Simulator booting timeout in ms.
10
+ * @property {Function} [onWaitingDataMigration] - This event is fired when data migration stage starts.
11
+ * @property {Function} [onWaitingSystemApp] - This event is fired when system app wait stage starts.
12
+ * @property {Function} [onFinished] - This event is fired when Simulator is fully booted.
13
+ * @property {Function} [onError] - This event is fired when there was an error while monitoring the booting process
14
14
  * or when the timeout has expired.
15
- * @property {boolean} shouldPreboot [false] Whether to preboot the Simulator
15
+ * @property {boolean} [shouldPreboot=false] Whether to preboot the Simulator
16
16
  * if this command is called and it is not already in booted or booting state.
17
17
  */
18
18
 
@@ -22,7 +22,7 @@ const commands = {};
22
22
  * until Simulator booting is completed.
23
23
  * The method is only available since Xcode8.
24
24
  *
25
- * @param {Partial<BootMonitorOptions>} opts - Monitoring options.
25
+ * @param {BootMonitorOptions} [opts={}] - Monitoring options.
26
26
  * @returns {Promise<import('teen_process').SubProcess>} The instance of the corresponding monitoring process.
27
27
  * @throws {Error} If the Simulator fails to finish booting within the given timeout and onFinished
28
28
  * property is not set.
@@ -11,8 +11,8 @@ const commands = {};
11
11
 
12
12
  /**
13
13
  * @typedef {Object} SimCreationOpts
14
- * @property {string} platform [iOS] - Platform name in order to specify runtime such as 'iOS', 'tvOS', 'watchOS'
15
- * @property {number} timeout [10000] - The maximum number of milliseconds to wait
14
+ * @property {string} [platform='iOS'] - Platform name in order to specify runtime such as 'iOS', 'tvOS', 'watchOS'
15
+ * @property {number} [timeout=10000] - The maximum number of milliseconds to wait
16
16
  * unit device creation is completed.
17
17
  */
18
18
 
@@ -23,7 +23,7 @@ const commands = {};
23
23
  * @param {string} name - The device name to be created.
24
24
  * @param {string} deviceTypeId - Device type, for example 'iPhone 6'.
25
25
  * @param {string} platformVersion - Platform version, for example '10.3'.
26
- * @param {Partial<SimCreationOpts>} opts - Simulator options for creating devices.
26
+ * @param {SimCreationOpts} [opts={}] - Simulator options for creating devices.
27
27
  * @return {Promise<string>} The UDID of the newly created device.
28
28
  * @throws {Error} If the corresponding simctl subcommand command
29
29
  * returns non-zero return code.
@@ -6,7 +6,7 @@ const commands = {};
6
6
  * Reset the content and settings of the particular Simulator.
7
7
  * It is required that Simulator is in _shutdown_ state.
8
8
  *
9
- * @param {number} timeout [10000] - The maximum number of milliseconds to wait
9
+ * @param {number} [timeout=10000] - The maximum number of milliseconds to wait
10
10
  * unit device reset is completed.
11
11
  * @throws {Error} If the corresponding simctl subcommand command
12
12
  * returns non-zero return code.
@@ -8,7 +8,7 @@ const commands = {};
8
8
  * It is required that Simulator is in _booted_ state.
9
9
  *
10
10
  * @param {string} bundleId - Bundle identifier of an application.
11
- * @param {string?} containerType - Which container type to return. Possible values
11
+ * @param {string?} [containerType=null] - Which container type to return. Possible values
12
12
  * are 'app', 'data', 'groups', '<A specific App Group container>'.
13
13
  * The default value is 'app'.
14
14
  * @return {Promise<string>} Full path to the given application container on the local
@@ -24,7 +24,7 @@ async function handleRawPayload (payload, onPayloadStored) {
24
24
 
25
25
  /**
26
26
  * @typedef {Object} CertOptions
27
- * @property {boolean} raw [false] - whether the `cert` argument
27
+ * @property {boolean} [raw=false] - whether the `cert` argument
28
28
  * is the path to the certificate on the local file system or
29
29
  * a raw certificate content
30
30
  */
@@ -36,7 +36,7 @@ async function handleRawPayload (payload, onPayloadStored) {
36
36
  * @param {string} cert the full path to a valid .cert file containing
37
37
  * the certificate content or the certificate content itself, depending on
38
38
  * options
39
- * @param {Partial<CertOptions>} opts
39
+ * @param {CertOptions} [opts={}]
40
40
  * @throws {Error} if the current SDK version does not support the command
41
41
  * or there was an error while adding the certificate
42
42
  * @throws {Error} If the `udid` instance property is unset
@@ -62,7 +62,7 @@ commands.addRootCertificate = async function addRootCertificate (cert, opts = {}
62
62
  * @param {string} cert the full path to a valid .cert file containing
63
63
  * the certificate content or the certificate content itself, depending on
64
64
  * options
65
- * @param {Partial<CertOptions>} opts
65
+ * @param {CertOptions} [opts={}]
66
66
  * @throws {Error} if the current SDK version does not support the command
67
67
  * or there was an error while adding the certificate
68
68
  * @throws {Error} If the `udid` instance property is unset
@@ -10,7 +10,7 @@ const commands = {};
10
10
  *
11
11
  * @param {string} bundleId - Bundle identifier of the application,
12
12
  * which is going to be removed.
13
- * @param {number} tries [5] - The maximum number of retries before
13
+ * @param {number} [tries=5] - The maximum number of retries before
14
14
  * throwing an exception.
15
15
  * @return {Promise<string>} the actual command output
16
16
  * @throws {Error} If the corresponding simctl subcommand command
@@ -17,7 +17,7 @@ const commands = {};
17
17
  * Parse the list of existing Simulator devices to represent
18
18
  * it as convenient mapping.
19
19
  *
20
- * @param {string?} platform - The platform name, for example 'watchOS'.
20
+ * @param {string?} [platform] - The platform name, for example 'watchOS'.
21
21
  * @return {Promise<Record<string, any>>} The resulting mapping. Each key is platform version,
22
22
  * for example '10.3' and the corresponding value is an
23
23
  * array of the matching {@link DeviceInfo} instances.
@@ -90,10 +90,10 @@ commands.getDevicesByParsing = async function getDevicesByParsing (platform) {
90
90
  * Parse the list of existing Simulator devices to represent
91
91
  * it as convenient mapping for the particular platform version.
92
92
  *
93
- * @param {string?} forSdk - The sdk version,
93
+ * @param {string?} [forSdk] - The sdk version,
94
94
  * for which the devices list should be parsed,
95
95
  * for example '10.3'.
96
- * @param {string?} platform - The platform name, for example 'watchOS'.
96
+ * @param {string?} [platform] - The platform name, for example 'watchOS'.
97
97
  * @return {Promise<Object|DeviceInfo[]>} If _forSdk_ is set then the list
98
98
  * of devices for the particular platform version.
99
99
  * Otherwise the same result as for {@link getDevicesByParsing}
@@ -176,7 +176,7 @@ commands.getDevices = async function getDevices (forSdk, platform) {
176
176
  *
177
177
  * @param {string} platformVersion - The platform version name,
178
178
  * for example '10.3'.
179
- * @param {string} platform - The platform name, for example 'watchOS'.
179
+ * @param {string} [platform='iOS'] - The platform name, for example 'watchOS'.
180
180
  * @return {Promise<string>} The corresponding runtime name for the given
181
181
  * platform version.
182
182
  */
@@ -199,7 +199,7 @@ commands.getRuntimeForPlatformVersionViaJson = async function getRuntimeForPlatf
199
199
  *
200
200
  * @param {string} platformVersion - The platform version name,
201
201
  * for example '10.3'.
202
- * @param {string} platform - The platform name, for example 'watchOS'.
202
+ * @param {string} [platform='iOS'] - The platform name, for example 'watchOS'.
203
203
  * @return {Promise<string>} The corresponding runtime name for the given
204
204
  * platform version.
205
205
  */