Skip to content

Commit bed549f

Browse files
feat: Switch from babel to typescript (#190)
1 parent 229d312 commit bed549f

File tree

16 files changed

+88
-66
lines changed

16 files changed

+88
-66
lines changed

.eslintrc.json

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,22 @@
11
{
2-
"extends": "@appium/eslint-config-appium",
2+
"extends": ["@appium/eslint-config-appium-ts"],
33
"overrides": [
44
{
55
"files": "test/**/*.js",
66
"rules": {
7-
"func-names": "off"
7+
"func-names": "off",
8+
"@typescript-eslint/no-var-requires": "off"
9+
}
10+
},
11+
{
12+
"files": "scripts/**/*",
13+
"parserOptions": {"sourceType": "script"},
14+
"rules": {
15+
"@typescript-eslint/no-var-requires": "off"
816
}
917
}
10-
]
18+
],
19+
"rules": {
20+
"require-await": "error"
21+
}
1122
}

.mocharc.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
module.exports = {
2-
require: ['@babel/register'],
2+
require: ['ts-node/register'],
33
forbidOnly: Boolean(process.env.CI)
44
};

babel.config.json

Lines changed: 0 additions & 25 deletions
This file was deleted.

lib/simctl.js

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,17 @@ const DEFAULT_OPTS = {
5454

5555

5656
class Simctl {
57+
/** @type {any?} */
58+
xcrun;
59+
60+
/** @type {number} */
61+
execTimeout;
62+
63+
/** @type {boolean} */
64+
logErrors;
65+
5766
/**
58-
* @param {SimctlOpts} opts
67+
* @param {Partial<SimctlOpts>} opts
5968
*/
6069
constructor (opts = {}) {
6170
opts = _.cloneDeep(opts);
@@ -111,8 +120,8 @@ class Simctl {
111120
* @param {string} subcommand - One of available simctl subcommands.
112121
* Execute `xcrun simctl` in Terminal to see the full list
113122
* of available subcommands.
114-
* @param {ExecOpts?} opts
115-
* @return {Promise<ExecResult|SubProcess>} Either the result of teen process's `exec` or
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
116125
* `SubProcess` instance depending of `opts.asynchronous` value.
117126
* @throws {Error} If the simctl subcommand command returns non-zero return code.
118127
*/
@@ -154,6 +163,7 @@ class Simctl {
154163
);
155164
execArgs = ['arch', [...archArgs, xcrun, ...args], execOpts];
156165
}
166+
// @ts-ignore We know what we are doing here
157167
return asynchronous ? new SubProcess(...execArgs) : await tpExec(...execArgs);
158168
} catch (e) {
159169
if (!this.logErrors || !logErrors) {

lib/subcommands/addmedia.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ const commands = {};
66
*
77
* @param {string} filePath - Full path to a media file on the local
88
* file system.
9-
* @return {Promise<ExecResult>} Command execution result.
9+
* @return {Promise<import('teen_process').TeenProcessExecResult>} Command execution result.
1010
* @throws {Error} If the corresponding simctl subcommand command
1111
* returns non-zero return code.
1212
* @throws {Error} If the `udid` instance property is unset

lib/subcommands/bootstatus.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ const commands = {};
2222
* until Simulator booting is completed.
2323
* The method is only available since Xcode8.
2424
*
25-
* @param {BootMonitorOptions} opts - Monitoring options.
26-
* @returns {Promise<SubProcess>} The instance of the corresponding monitoring process.
25+
* @param {Partial<BootMonitorOptions>} opts - Monitoring options.
26+
* @returns {Promise<import('teen_process').SubProcess>} The instance of the corresponding monitoring process.
2727
* @throws {Error} If the Simulator fails to finish booting within the given timeout and onFinished
2828
* property is not set.
2929
* @throws {Error} If the `udid` instance property is unset

lib/subcommands/create.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ const commands = {};
2323
* @param {string} name - The device name to be created.
2424
* @param {string} deviceTypeId - Device type, for example 'iPhone 6'.
2525
* @param {string} platformVersion - Platform version, for example '10.3'.
26-
* @param {SimCreationOpts} opts - Simulator options for creating devices.
26+
* @param {Partial<SimCreationOpts>} opts - Simulator options for creating devices.
2727
* @return {Promise<string>} The UDID of the newly created device.
2828
* @throws {Error} If the corresponding simctl subcommand command
2929
* returns non-zero return code.
@@ -92,7 +92,7 @@ commands.createDevice = async function createDevice (name, deviceTypeId, platfor
9292
}
9393

9494
// make sure that it gets out of the "Creating" state
95-
const retries = parseInt(timeout / 1000, 10);
95+
const retries = parseInt(`${timeout / 1000}`, 10);
9696
await retryInterval(retries, 1000, async () => {
9797
const devices = _.values(await this.getDevices());
9898
for (const deviceArr of _.values(devices)) {

lib/subcommands/erase.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ const commands = {};
1414
*/
1515
commands.eraseDevice = async function eraseDevice (timeout = 1000) {
1616
// retry erase with a sleep in between because it's flakey
17-
const retries = parseInt(timeout / 200, 10);
17+
const retries = parseInt(`${timeout / 200}`, 10);
1818
await retryInterval(retries, 200,
1919
async () => await this.exec('erase', {
2020
args: [this.requireUdid('erase')]

lib/subcommands/keychain.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ async function handleRawPayload (payload, onPayloadStored) {
3636
* @param {string} cert the full path to a valid .cert file containing
3737
* the certificate content or the certificate content itself, depending on
3838
* options
39-
* @param {CertOptions} opts
39+
* @param {Partial<CertOptions>} opts
4040
* @throws {Error} if the current SDK version does not support the command
4141
* or there was an error while adding the certificate
4242
* @throws {Error} If the `udid` instance property is unset
@@ -62,7 +62,7 @@ commands.addRootCertificate = async function addRootCertificate (cert, opts = {}
6262
* @param {string} cert the full path to a valid .cert file containing
6363
* the certificate content or the certificate content itself, depending on
6464
* options
65-
* @param {CertOptions} opts
65+
* @param {Partial<CertOptions>} opts
6666
* @throws {Error} if the current SDK version does not support the command
6767
* or there was an error while adding the certificate
6868
* @throws {Error} If the `udid` instance property is unset

lib/subcommands/launch.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ const commands = {};
1818
* @throws {Error} If the `udid` instance property is unset
1919
*/
2020
commands.launchApp = async function launchApp (bundleId, tries = 5) {
21+
// @ts-ignore A string will always be returned
2122
return await retryInterval(tries, 1000, async () => {
2223
const {stdout} = await this.exec('launch', {
2324
args: [this.requireUdid('launch'), bundleId],

0 commit comments

Comments
 (0)