Skip to content

Commit 2bd1816

Browse files
fix: linter (#1134)
1 parent abe0e0c commit 2bd1816

10 files changed

Lines changed: 41 additions & 28 deletions

Scripts/fetch-prebuilt-wda.mjs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ async function fetchPrebuiltWebDriverAgentAssets () {
2929
},
3030
})).data;
3131
} catch (e) {
32-
throw new Error(`Could not fetch endpoint ${downloadUrl}. Reason: ${e.message}`);
32+
throw new Error(`Could not fetch endpoint ${downloadUrl}. Reason: ${e.message}`, {cause: e});
3333
}
3434

3535
const webdriveragentsDir = path.resolve(__dirname, '..', 'prebuilt-agents');
@@ -42,7 +42,9 @@ async function fetchPrebuiltWebDriverAgentAssets () {
4242
try {
4343
await net.downloadFile(url, targetPath);
4444
} catch (err) {
45-
throw new Error(`Problem downloading webdriveragent from url ${url}: ${err.message}`);
45+
throw new Error(`Problem downloading webdriveragent from url ${url}: ${err.message}`, {
46+
cause: err,
47+
});
4648
}
4749
}
4850

lib/appium-ios-device.d.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
declare module 'appium-ios-device' {
2+
export class Xctest {
3+
constructor(...args: any[]);
4+
start(): Promise<void>;
5+
stop(): void;
6+
}
7+
}

lib/no-session-proxy.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,9 @@ export class NoSessionProxy extends JWProxy {
1111
url = '/';
1212
}
1313
const proxyBase = `${this.scheme}://${this.server}:${this.port}${this.base}`;
14-
let remainingUrl = '';
1514
if (new RegExp('^/').test(url)) {
16-
remainingUrl = url;
17-
} else {
18-
throw new Error(`Did not know what to do with url '${url}'`);
15+
return proxyBase + url.replace(/\/$/, ''); // can't have trailing slashes
1916
}
20-
remainingUrl = remainingUrl.replace(/\/$/, ''); // can't have trailing slashes
21-
return proxyBase + remainingUrl;
17+
throw new Error(`Did not know what to do with url '${url}'`);
2218
}
2319
}

lib/utils.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import {fs, plist} from '@appium/support';
2-
import {exec, SubProcess} from 'teen_process';
2+
import {exec} from 'teen_process';
3+
import type {SubProcess} from 'teen_process';
34
import path, {dirname} from 'node:path';
45
import {fileURLToPath} from 'node:url';
56
import {log} from './logger';

lib/webdriveragent.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ const RECENT_MODULE_VERSION_ITEM_NAME = 'recentWdaModuleVersion';
3434
const URL_PROTOCOL_SEPARATOR = '://';
3535

3636
export class WebDriverAgent {
37-
bootstrapPath: string;
38-
agentPath: string;
37+
bootstrapPath!: string;
38+
agentPath!: string;
3939
readonly args: WebDriverAgentArgs;
4040
readonly device: AppleDevice;
4141
readonly platformVersion?: string;
@@ -621,7 +621,7 @@ export class WebDriverAgent {
621621
`Failed to get the status endpoint in ${timeoutMs} ms. ` +
622622
`The last error while accessing ${this.url.href}: ${lastError}. Original error:: ${err.message}.`,
623623
);
624-
throw new Error(`WDA was not ready in ${timeoutMs} ms.`);
624+
throw new Error(`WDA was not ready in ${timeoutMs} ms.`, {cause: err});
625625
}
626626
return status;
627627
}

lib/xcodebuild.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -337,11 +337,10 @@ export class XcodeBuild {
337337
}
338338
args.push('-destination', `id=${this.device.udid}`);
339339

340-
let versionMatch: RegExpMatchArray | null = null;
341-
if (
342-
this.platformVersion &&
343-
(versionMatch = new RegExp(/^(\d+)\.(\d+)/).exec(this.platformVersion))
344-
) {
340+
const versionMatch = this.platformVersion
341+
? new RegExp(/^(\d+)\.(\d+)/).exec(this.platformVersion)
342+
: null;
343+
if (versionMatch) {
345344
args.push(
346345
`${isTvOS(this.platformName || '') ? 'TV' : 'IPHONE'}OS_DEPLOYMENT_TARGET=${versionMatch[1]}.${versionMatch[2]}`,
347346
);
@@ -472,7 +471,9 @@ export class XcodeBuild {
472471
this.log.debug(`WebDriverAgent information:`);
473472
this.log.debug(JSON.stringify(currentStatus, null, 2));
474473
} catch (err: any) {
475-
throw new Error(`Unable to connect to running WebDriverAgent: ${err.message}`);
474+
throw new Error(`Unable to connect to running WebDriverAgent: ${err.message}`, {
475+
cause: err,
476+
});
476477
} finally {
477478
(noSessionProxy as any).timeout = proxyTimeout;
478479
}
@@ -491,6 +492,7 @@ export class XcodeBuild {
491492
throw new Error(
492493
`We were not able to retrieve the /status response from the WebDriverAgent server after ${timeout}ms timeout.` +
493494
`Try to increase the value of 'appium:wdaLaunchTimeout' capability as a possible workaround.`,
495+
{cause: err},
494496
);
495497
}
496498
return currentStatus;

package.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,12 @@
5454
"@appium/types": "^1.0.0-rc.1",
5555
"@semantic-release/changelog": "^6.0.1",
5656
"@semantic-release/git": "^10.0.1",
57+
"@types/async-lock": "^1.4.2",
58+
"@types/chai": "^5.2.3",
59+
"@types/chai-as-promised": "^8.0.2",
5760
"@types/mocha": "^10.0.1",
5861
"@types/node": "^25.0.0",
62+
"@types/sinon": "^21.0.1",
5963
"appium-xcode": "^6.0.0",
6064
"chai": "^6.0.0",
6165
"chai-as-promised": "^8.0.0",
@@ -77,7 +81,7 @@
7781
"appium-ios-simulator": "^8.0.0",
7882
"async-lock": "^1.0.0",
7983
"asyncbox": "^6.1.0",
80-
"axios": "^1.4.0",
84+
"axios": "^1.16.0",
8185
"teen_process": "^4.0.7"
8286
},
8387
"files": [

test/unit/utils-specs.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ describe('utils', function () {
4242
await expect(getXctestrunFilePath(deviceInfo, sdkVersion, bootstrapPath)).to.eventually.equal(
4343
path.resolve(`${bootstrapPath}/${udid}_${sdkVersion}.xctestrun`),
4444
);
45-
sandbox.assert.notCalled(fs.copyFile);
45+
sandbox.assert.notCalled(fs.copyFile as any);
4646
});
4747

4848
it('should return sdk based path without udid, copy them', async function () {
@@ -102,7 +102,7 @@ describe('utils', function () {
102102
await expect(getXctestrunFilePath(deviceInfo, sdkVersion, bootstrapPath)).to.eventually.equal(
103103
path.resolve(`${bootstrapPath}/${udid}_${platformVersion}.xctestrun`),
104104
);
105-
sandbox.assert.notCalled(fs.copyFile);
105+
sandbox.assert.notCalled(fs.copyFile as any);
106106
});
107107

108108
it('should return platform based path without udid, copy them', async function () {

test/unit/webdriveragent-specs.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ describe('WebDriverAgent', function () {
236236

237237
beforeEach(function () {
238238
wda = new WebDriverAgent(fakeConstructorArgs);
239-
wdaStub = sinon.stub(wda, 'getStatus');
239+
wdaStub = sinon.stub(wda as any, 'getStatus');
240240
wdaStubUninstall = sinon.stub(wda as any, 'uninstall');
241241
});
242242

@@ -312,7 +312,7 @@ describe('WebDriverAgent', function () {
312312
...fakeConstructorArgs,
313313
updatedWDABundleId: 'com.example.WebDriverAgent',
314314
});
315-
wdaStub = sinon.stub(wda, 'getStatus');
315+
wdaStub = sinon.stub(wda as any, 'getStatus');
316316
wdaStubUninstall = sinon.stub(wda as any, 'uninstall');
317317

318318
wdaStub.callsFake(function () {
@@ -336,7 +336,7 @@ describe('WebDriverAgent', function () {
336336
wdaStub.callsFake(function () {
337337
return {build: {upgradedAt: '1'}};
338338
});
339-
getTimestampStub.callsFake(() => '2');
339+
getTimestampStub.callsFake(async () => 2);
340340
wdaStubUninstall.callsFake(() => {});
341341

342342
await wda.setupCaching();
@@ -348,7 +348,7 @@ describe('WebDriverAgent', function () {
348348
wdaStub.callsFake(function () {
349349
return {build: {upgradedAt: '1'}};
350350
});
351-
getTimestampStub.callsFake(() => '1');
351+
getTimestampStub.callsFake(async () => 1);
352352
wdaStubUninstall.callsFake(() => {});
353353

354354
await wda.setupCaching();
@@ -360,7 +360,7 @@ describe('WebDriverAgent', function () {
360360
wdaStub.callsFake(function () {
361361
return {build: {}};
362362
});
363-
getTimestampStub.callsFake(() => '1');
363+
getTimestampStub.callsFake(async () => 1);
364364
wdaStubUninstall.callsFake(() => {});
365365

366366
await wda.setupCaching();
@@ -372,7 +372,7 @@ describe('WebDriverAgent', function () {
372372
wdaStub.callsFake(function () {
373373
return {build: {upgradedAt: '1'}};
374374
});
375-
getTimestampStub.callsFake(() => null);
375+
getTimestampStub.callsFake(async () => null);
376376
wdaStubUninstall.callsFake(() => {});
377377

378378
await wda.setupCaching();

tsconfig.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
"esModuleInterop": true,
66
"outDir": "build",
77
"types": ["node", "mocha"],
8-
"checkJs": true
8+
"checkJs": true,
9+
"strict": true
910
},
1011
"ts-node": {
1112
"transpileOnly": true,

0 commit comments

Comments
 (0)