Skip to content

Commit 4fe1964

Browse files
authored
fix: format (#547)
* fix: format * apply more
1 parent 1a7fc88 commit 4fe1964

17 files changed

+83
-86
lines changed

.github/workflows/unit-test.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,5 +29,7 @@ jobs:
2929
name: Install dev dependencies
3030
- run: npm run lint
3131
name: Run linter
32+
- run: npm run format:check
33+
name: Run Prettier check
3234
- run: npm run test
3335
name: Run unit tests

lib/chromedriver.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -865,10 +865,16 @@ export class Chromedriver extends events.EventEmitter {
865865
`Starting ${this._desiredProtocol} Chromedriver session with capabilities: ` +
866866
JSON.stringify(sessionCaps, null, 2),
867867
);
868-
const response = (await this.jwproxy.command('/session', 'POST', sessionCaps)) as NewSessionResponse;
868+
const response = (await this.jwproxy.command(
869+
'/session',
870+
'POST',
871+
sessionCaps,
872+
)) as NewSessionResponse;
869873
this.log.prefix = generateLogPrefix(this, this.jwproxy.sessionId);
870874
this.changeState(Chromedriver.STATE_ONLINE);
871-
return _.has(response, 'capabilities') && response.capabilities ? response.capabilities : (response as SessionCapabilities);
875+
return _.has(response, 'capabilities') && response.capabilities
876+
? response.capabilities
877+
: (response as SessionCapabilities);
872878
}
873879

874880
private changeState(state: string): void {

lib/constants.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,3 @@ export const CPU = {
2222
ARM: 'arm',
2323
} as const;
2424
export const APPLE_ARM_SUFFIXES = ['64_m1', '_arm64'] as const;
25-

lib/protocol-helpers.ts

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ const W3C_PREFIX = 'goog:';
99
* @returns The W3C-formatted capability name.
1010
*/
1111
export function toW3cCapName(capName: string): string {
12-
return (_.isString(capName) && !capName.includes(':') && !isStandardCap(capName))
12+
return _.isString(capName) && !capName.includes(':') && !isStandardCap(capName)
1313
? `${W3C_PREFIX}${capName}`
1414
: capName;
1515
}
@@ -21,7 +21,11 @@ export function toW3cCapName(capName: string): string {
2121
* @param defaultValue - Optional default value to return if the capability is not found.
2222
* @returns The capability value or the default value.
2323
*/
24-
export function getCapValue(allCaps: Record<string, any> = {}, rawCapName: string, defaultValue?: any): any {
24+
export function getCapValue(
25+
allCaps: Record<string, any> = {},
26+
rawCapName: string,
27+
defaultValue?: any,
28+
): any {
2529
for (const [capName, capValue] of _.toPairs(allCaps)) {
2630
if (toW3cCapName(capName) === toW3cCapName(rawCapName)) {
2731
return capValue;
@@ -36,9 +40,12 @@ export function getCapValue(allCaps: Record<string, any> = {}, rawCapName: strin
3640
* @returns A new object with W3C-formatted capability names.
3741
*/
3842
export function toW3cCapNames(originalCaps: Record<string, any> = {}): Record<string, any> {
39-
return _.reduce(originalCaps, (acc, value, key) => {
40-
acc[toW3cCapName(key)] = value;
41-
return acc;
42-
}, {} as Record<string, any>);
43+
return _.reduce(
44+
originalCaps,
45+
(acc, value, key) => {
46+
acc[toW3cCapName(key)] = value;
47+
return acc;
48+
},
49+
{} as Record<string, any>,
50+
);
4351
}
44-

lib/storage-client/chromelabs.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ const log = logger.getLogger('ChromedriverChromelabsStorageClient');
1717
* @throws {Error} if the JSON cannot be parsed or has an unsupported format
1818
*/
1919
export function parseKnownGoodVersionsWithDownloadsJson(
20-
jsonStr: string
20+
jsonStr: string,
2121
): ChromedriverDetailsMapping {
2222
let json: KnownGoodVersionsJson;
2323
try {
@@ -83,7 +83,7 @@ export function parseKnownGoodVersionsWithDownloadsJson(
8383
const osNameMatch = /^[a-z]+/i.exec(downloadEntry.platform);
8484
if (!osNameMatch) {
8585
log.debug(
86-
`The entry '${downloadEntry.url}' does not contain valid platform name. Skipping it`
86+
`The entry '${downloadEntry.url}' does not contain valid platform name. Skipping it`,
8787
);
8888
continue;
8989
}

lib/storage-client/googleapis.ts

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,7 @@ import {select as xpathSelect} from 'xpath';
33
import {util, logger} from '@appium/support';
44
import {retrieveData} from '../utils';
55
import B from 'bluebird';
6-
import {
7-
STORAGE_REQ_TIMEOUT_MS,
8-
GOOGLEAPIS_CDN,
9-
ARCH,
10-
CPU,
11-
APPLE_ARM_SUFFIXES,
12-
} from '../constants';
6+
import {STORAGE_REQ_TIMEOUT_MS, GOOGLEAPIS_CDN, ARCH, CPU, APPLE_ARM_SUFFIXES} from '../constants';
137
import {DOMParser} from '@xmldom/xmldom';
148
import path from 'node:path';
159
import type {
@@ -32,7 +26,7 @@ const MAX_PARALLEL_DOWNLOADS = 5;
3226
export function findChildNode(
3327
parent: Node | Attr,
3428
childName: string | null = null,
35-
text: string | null = null
29+
text: string | null = null,
3630
): Node | Attr | null {
3731
if (!childName && !text) {
3832
return null;
@@ -94,7 +88,7 @@ export function parseNotes(content: string): AdditionalDriverDetails {
9488
*/
9589
export async function parseGoogleapiStorageXml(
9690
xml: string,
97-
shouldParseNotes = true
91+
shouldParseNotes = true,
9892
): Promise<ChromedriverDetailsMapping> {
9993
const doc = new DOMParser().parseFromString(xml, 'text/xml');
10094
const driverNodes = xpathSelect(`//*[local-name(.)='Contents']`, doc) as Array<Node | Attr>;
@@ -142,7 +136,7 @@ export async function parseGoogleapiStorageXml(
142136
const notesPath = `${cdInfo.version}/notes.txt`;
143137
const isNotesPresent = !!driverNodes.reduce(
144138
(acc, node) => Boolean(acc || findChildNode(node, 'Key', notesPath)),
145-
false
139+
false,
146140
);
147141
if (!isNotesPresent) {
148142
cdInfo.minBrowserVersion = null;
@@ -155,7 +149,7 @@ export async function parseGoogleapiStorageXml(
155149
}
156150

157151
const promise = B.resolve(
158-
retrieveAdditionalDriverInfo(key, `${GOOGLEAPIS_CDN}/${notesPath}`, cdInfo)
152+
retrieveAdditionalDriverInfo(key, `${GOOGLEAPIS_CDN}/${notesPath}`, cdInfo),
159153
);
160154
promises.push(promise);
161155
chunk.push(promise);
@@ -182,21 +176,21 @@ async function retrieveAdditionalDriverInfo(
182176
driverKey: string,
183177
notesUrl: string,
184178
infoDict: ChromedriverDetails,
185-
timeout = STORAGE_REQ_TIMEOUT_MS
179+
timeout = STORAGE_REQ_TIMEOUT_MS,
186180
): Promise<void> {
187181
const notes = await retrieveData(
188182
notesUrl,
189183
{
190184
'user-agent': 'appium',
191185
accept: '*/*',
192186
},
193-
{timeout}
187+
{timeout},
194188
);
195189
const {minBrowserVersion} = parseNotes(notes);
196190
if (!minBrowserVersion) {
197191
log.debug(
198192
`The driver '${driverKey}' does not contain valid release notes at ${notesUrl}. ` +
199-
`Skipping it`
193+
`Skipping it`,
200194
);
201195
return;
202196
}

lib/storage-client/storage-client.ts

Lines changed: 28 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,4 @@
1-
import {
2-
getChromedriverDir,
3-
retrieveData,
4-
getOsInfo,
5-
convertToInt,
6-
getCpuType,
7-
} from '../utils';
1+
import {getChromedriverDir, retrieveData, getOsInfo, convertToInt, getCpuType} from '../utils';
82
import _ from 'lodash';
93
import B from 'bluebird';
104
import path from 'node:path';
@@ -19,7 +13,10 @@ import {
1913
CPU,
2014
} from '../constants';
2115
import {parseGoogleapiStorageXml} from './googleapis';
22-
import {parseKnownGoodVersionsWithDownloadsJson, parseLatestKnownGoodVersionsJson} from './chromelabs';
16+
import {
17+
parseKnownGoodVersionsWithDownloadsJson,
18+
parseLatestKnownGoodVersionsJson,
19+
} from './chromelabs';
2320
import {compareVersions} from 'compare-versions';
2421
import * as semver from 'semver';
2522
import type {
@@ -77,23 +74,26 @@ export class ChromedriverStorageClient {
7774
* @returns Promise<ChromedriverDetailsMapping>
7875
*/
7976
async retrieveMapping(shouldParseNotes = true): Promise<ChromedriverDetailsMapping> {
80-
const retrieveResponseSafely = async ({url, accept}: StorageInfo): Promise<string | undefined> => {
77+
const retrieveResponseSafely = async ({
78+
url,
79+
accept,
80+
}: StorageInfo): Promise<string | undefined> => {
8181
try {
8282
return await retrieveData(
8383
url,
8484
{
8585
'user-agent': USER_AGENT,
8686
accept: `${accept}, */*`,
8787
},
88-
{timeout: this.timeout}
88+
{timeout: this.timeout},
8989
);
9090
} catch (e) {
9191
const err = e as Error;
9292
log.debug(err.stack);
9393
log.warn(
9494
`Cannot retrieve Chromedrivers info from ${url}. ` +
9595
`Make sure this URL is accessible from your network. ` +
96-
`Original error: ${err.message}`
96+
`Original error: ${err.message}`,
9797
);
9898
}
9999
};
@@ -105,7 +105,7 @@ export class ChromedriverStorageClient {
105105
`Cannot retrieve the information about available Chromedrivers from ` +
106106
`${STORAGE_INFOS.map(({url}) => url)}. Please make sure these URLs are available ` +
107107
`within your local network, check Appium server logs and/or ` +
108-
`consult the driver troubleshooting guide.`
108+
`consult the driver troubleshooting guide.`,
109109
);
110110
}
111111
this.mapping = xmlStr ? await parseGoogleapiStorageXml(xmlStr, shouldParseNotes) : {};
@@ -137,7 +137,7 @@ export class ChromedriverStorageClient {
137137
}
138138
log.debug(
139139
`Got ${util.pluralize('driver', driversToSync.length, true)} to sync: ` +
140-
JSON.stringify(driversToSync, null, 2)
140+
JSON.stringify(driversToSync, null, 2),
141141
);
142142

143143
const synchronizedDrivers: string[] = [];
@@ -151,7 +151,7 @@ export class ChromedriverStorageClient {
151151
if (await this.retrieveDriver(idx, driverKey, archivesRoot, !_.isEmpty(opts))) {
152152
synchronizedDrivers.push(driverKey);
153153
}
154-
})()
154+
})(),
155155
);
156156
promises.push(promise);
157157
chunk.push(promise);
@@ -167,7 +167,7 @@ export class ChromedriverStorageClient {
167167
if (!_.isEmpty(synchronizedDrivers)) {
168168
log.info(
169169
`Successfully synchronized ` +
170-
`${util.pluralize('chromedriver', synchronizedDrivers.length, true)}`
170+
`${util.pluralize('chromedriver', synchronizedDrivers.length, true)}`,
171171
);
172172
} else {
173173
log.info(`No chromedrivers were synchronized`);
@@ -190,14 +190,14 @@ export class ChromedriverStorageClient {
190190
'user-agent': USER_AGENT,
191191
accept: `application/json, */*`,
192192
},
193-
{timeout: STORAGE_REQ_TIMEOUT_MS}
193+
{timeout: STORAGE_REQ_TIMEOUT_MS},
194194
);
195195
} catch (e) {
196196
const err = e as Error;
197197
throw new Error(
198198
`Cannot fetch the latest Chromedriver version. ` +
199199
`Make sure you can access ${CHROME_FOR_TESTING_LAST_GOOD_VERSIONS} from your machine or provide a mirror by setting ` +
200-
`a custom value to CHROMELABS_URL environment variable. Original error: ${err.message}`
200+
`a custom value to CHROMELABS_URL environment variable. Original error: ${err.message}`,
201201
);
202202
}
203203
return parseLatestKnownGoodVersionsJson(jsonStr);
@@ -219,7 +219,7 @@ export class ChromedriverStorageClient {
219219
// Handle only selected versions if requested
220220
log.debug(`Selecting chromedrivers whose versions match to ${versions}`);
221221
driversToSync = driversToSync.filter((cdName) =>
222-
versions.includes(`${this.mapping[cdName].version}`)
222+
versions.includes(`${this.mapping[cdName].version}`),
223223
);
224224

225225
log.debug(`Got ${util.pluralize('item', driversToSync.length, true)}`);
@@ -232,14 +232,14 @@ export class ChromedriverStorageClient {
232232
if (minBrowserVersionInt !== null) {
233233
// Only select drivers that support the current browser whose major version number equals to `minBrowserVersion`
234234
log.debug(
235-
`Selecting chromedrivers whose minimum supported browser version matches to ${minBrowserVersionInt}`
235+
`Selecting chromedrivers whose minimum supported browser version matches to ${minBrowserVersionInt}`,
236236
);
237237
let closestMatchedVersionNumber = 0;
238238
// Select the newest available and compatible chromedriver
239239
for (const cdName of driversToSync) {
240240
const currentMinBrowserVersion = parseInt(
241241
String(this.mapping[cdName].minBrowserVersion),
242-
10
242+
10,
243243
);
244244
if (
245245
!Number.isNaN(currentMinBrowserVersion) &&
@@ -252,7 +252,7 @@ export class ChromedriverStorageClient {
252252
driversToSync = driversToSync.filter(
253253
(cdName) =>
254254
`${this.mapping[cdName].minBrowserVersion}` ===
255-
`${closestMatchedVersionNumber > 0 ? closestMatchedVersionNumber : minBrowserVersionInt}`
255+
`${closestMatchedVersionNumber > 0 ? closestMatchedVersionNumber : minBrowserVersionInt}`,
256256
);
257257

258258
log.debug(`Got ${util.pluralize('item', driversToSync.length, true)}`);
@@ -261,7 +261,7 @@ export class ChromedriverStorageClient {
261261
}
262262
log.debug(
263263
`Will select candidate ${util.pluralize('driver', driversToSync.length)} ` +
264-
`versioned as '${_.uniq(driversToSync.map((cdName) => this.mapping[cdName].version))}'`
264+
`versioned as '${_.uniq(driversToSync.map((cdName) => this.mapping[cdName].version))}'`,
265265
);
266266
}
267267

@@ -277,7 +277,7 @@ export class ChromedriverStorageClient {
277277
name,
278278
arch: ARCH.X86,
279279
cpu,
280-
})
280+
}),
281281
);
282282
}
283283
if (_.isEmpty(result) && name === OS.MAC && cpu === CPU.ARM) {
@@ -287,7 +287,7 @@ export class ChromedriverStorageClient {
287287
name,
288288
arch,
289289
cpu: CPU.INTEL,
290-
})
290+
}),
291291
);
292292
}
293293
driversToSync = result;
@@ -328,7 +328,7 @@ export class ChromedriverStorageClient {
328328
selectedVersions.add(sortedVersions[0]);
329329
}
330330
driversToSync = driversToSync.filter((cdName) =>
331-
selectedVersions.has(this.mapping[cdName].version)
331+
selectedVersions.has(this.mapping[cdName].version),
332332
);
333333
}
334334
}
@@ -378,7 +378,7 @@ export class ChromedriverStorageClient {
378378
index: number,
379379
driverKey: string,
380380
archivesRoot: string,
381-
isStrict = false
381+
isStrict = false,
382382
): Promise<boolean> {
383383
const {url, etag, version} = this.mapping[driverKey];
384384
const archivePath = path.resolve(archivesRoot, `${index}.zip`);
@@ -437,11 +437,11 @@ export class ChromedriverStorageClient {
437437
tmpRoot,
438438
true,
439439
(itemPath, isDirectory) =>
440-
!isDirectory && _.toLower(path.parse(itemPath).name) === 'chromedriver'
440+
!isDirectory && _.toLower(path.parse(itemPath).name) === 'chromedriver',
441441
);
442442
if (!chromedriverPath) {
443443
throw new Error(
444-
'The archive was unzipped properly, but we could not find any chromedriver executable'
444+
'The archive was unzipped properly, but we could not find any chromedriver executable',
445445
);
446446
}
447447
log.debug(`Moving the extracted '${path.basename(chromedriverPath)}' to '${dst}'`);
@@ -453,4 +453,3 @@ export class ChromedriverStorageClient {
453453
}
454454
}
455455
}
456-

0 commit comments

Comments
 (0)