Skip to content

Commit 218bfec

Browse files
authored
chore: apply prettier format to js,ts files (#1973)
1 parent b8c85c8 commit 218bfec

File tree

103 files changed

+1494
-1394
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

103 files changed

+1494
-1394
lines changed

.mocharc.js

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

.wallaby.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,7 @@ module.exports = (wallaby) => {
1515
env: {
1616
type: 'node',
1717
},
18-
files: [
19-
'package.json',
20-
'lib/**/*',
21-
'test/unit/helpers.js',
22-
],
18+
files: ['package.json', 'lib/**/*', 'test/unit/helpers.js'],
2319
testFramework: 'mocha',
2420
tests: ['test/unit/**/*-specs.js'],
2521
workers: {

index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { XCUITestDriver } from './lib/driver';
1+
import {XCUITestDriver} from './lib/driver';
22

3-
export { XCUITestDriver };
3+
export {XCUITestDriver};
44
export default XCUITestDriver;

lib/app-utils.js

Lines changed: 44 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import _ from 'lodash';
22
import path from 'path';
3-
import { plist, fs, util, tempDir, zip } from 'appium/support';
3+
import {plist, fs, util, tempDir, zip} from 'appium/support';
44
import log from './logger.js';
55

66
const STRINGSDICT_RESOURCE = '.stringsdict';
@@ -19,7 +19,7 @@ const PLIST_CACHE = new WeakMap();
1919
* @returns {Promise<any | undefined>} Either the extracted value or undefined if no such key has been found in the plist.
2020
* @throws {Error} If the application's Info.plist cannot be parsed.
2121
*/
22-
async function extractPlistEntry (app, entryName) {
22+
async function extractPlistEntry(app, entryName) {
2323
const plistPath = path.resolve(app, 'Info.plist');
2424

2525
const parseFile = async () => {
@@ -47,17 +47,17 @@ async function extractPlistEntry (app, entryName) {
4747
return plistObj[entryName];
4848
}
4949

50-
async function extractBundleId (app) {
50+
async function extractBundleId(app) {
5151
const bundleId = await extractPlistEntry.bind(this)(app, 'CFBundleIdentifier');
5252
log.debug(`Getting bundle ID from app '${app}': '${bundleId}'`);
5353
return bundleId;
5454
}
5555

56-
async function extractBundleVersion (app) {
56+
async function extractBundleVersion(app) {
5757
return await extractPlistEntry.bind(this)(app, 'CFBundleVersion');
5858
}
5959

60-
async function fetchSupportedAppPlatforms (app) {
60+
async function fetchSupportedAppPlatforms(app) {
6161
try {
6262
const result = await extractPlistEntry.bind(this)(app, 'CFBundleSupportedPlatforms');
6363
if (!_.isArray(result)) {
@@ -67,7 +67,7 @@ async function fetchSupportedAppPlatforms (app) {
6767
return result;
6868
} catch (err) {
6969
log.warn(
70-
`Cannot extract the list of supported platforms from '${path.basename(app)}': ${err.message}`
70+
`Cannot extract the list of supported platforms from '${path.basename(app)}': ${err.message}`,
7171
);
7272
return [];
7373
}
@@ -88,26 +88,27 @@ async function fetchSupportedAppPlatforms (app) {
8888
* @param {PlatformOpts} expectedPlatform
8989
* @throws {Error} If bundle architecture does not match the expected device architecture.
9090
*/
91-
async function verifyApplicationPlatform (app, expectedPlatform) {
91+
async function verifyApplicationPlatform(app, expectedPlatform) {
9292
log.debug('Verifying application platform');
9393

9494
const supportedPlatforms = await fetchSupportedAppPlatforms.bind(this)(app);
9595
log.debug(`CFBundleSupportedPlatforms: ${JSON.stringify(supportedPlatforms)}`);
9696

97-
const {
98-
isSimulator,
99-
isTvOS,
100-
} = expectedPlatform;
97+
const {isSimulator, isTvOS} = expectedPlatform;
10198
const prefix = isTvOS ? 'AppleTV' : 'iPhone';
10299
const suffix = isSimulator ? 'Simulator' : 'OS';
103100
const dstPlatform = `${prefix}${suffix}`;
104101
if (!supportedPlatforms.includes(dstPlatform)) {
105-
throw new Error(`${isSimulator ? 'Simulator' : 'Real device'} architecture is unsupported by the '${app}' application. ` +
106-
`Make sure the correct deployment target has been selected for its compilation in Xcode.`);
102+
throw new Error(
103+
`${
104+
isSimulator ? 'Simulator' : 'Real device'
105+
} architecture is unsupported by the '${app}' application. ` +
106+
`Make sure the correct deployment target has been selected for its compilation in Xcode.`,
107+
);
107108
}
108109
}
109110

110-
async function readResource (resourcePath) {
111+
async function readResource(resourcePath) {
111112
const data = await plist.parsePlistFile(resourcePath);
112113
const result = {};
113114
for (const [key, value] of _.toPairs(data)) {
@@ -116,14 +117,8 @@ async function readResource (resourcePath) {
116117
return result;
117118
}
118119

119-
async function parseLocalizableStrings (opts) {
120-
const {
121-
app,
122-
language = 'en',
123-
localizableStringsDir,
124-
stringFile,
125-
strictMode,
126-
} = opts;
120+
async function parseLocalizableStrings(opts) {
121+
const {app, language = 'en', localizableStringsDir, stringFile, strictMode} = opts;
127122

128123
if (!app) {
129124
const message = `Strings extraction is not supported if 'app' capability is not set`;
@@ -163,7 +158,7 @@ async function parseLocalizableStrings (opts) {
163158
}
164159
}
165160

166-
if (_.isEmpty(resourcePaths) && await fs.exists(String(lprojRoot))) {
161+
if (_.isEmpty(resourcePaths) && (await fs.exists(String(lprojRoot)))) {
167162
const resourceFiles = (await fs.readdir(String(lprojRoot)))
168163
.filter((name) => _.some([STRINGS_RESOURCE, STRINGSDICT_RESOURCE], (x) => name.endsWith(x)))
169164
.map((name) => path.resolve(lprojRoot, name));
@@ -203,10 +198,12 @@ async function parseLocalizableStrings (opts) {
203198
* @param {string} appPath Possible .app bundle root
204199
* @returns {Promise<boolean>} Whether the given path points to an .app bundle
205200
*/
206-
async function isAppBundle (appPath) {
207-
return _.endsWith(_.toLower(appPath), APP_EXT)
208-
&& (await fs.stat(appPath)).isDirectory()
209-
&& await fs.exists(path.join(appPath, 'Info.plist'));
201+
async function isAppBundle(appPath) {
202+
return (
203+
_.endsWith(_.toLower(appPath), APP_EXT) &&
204+
(await fs.stat(appPath)).isDirectory() &&
205+
(await fs.exists(path.join(appPath, 'Info.plist')))
206+
);
210207
}
211208

212209
/**
@@ -218,16 +215,18 @@ async function isAppBundle (appPath) {
218215
* a temporary folder root where the archive has been extracted and the second item
219216
* contains a list of relative paths to matched items
220217
*/
221-
async function findApps (archivePath, appExtensions) {
218+
async function findApps(archivePath, appExtensions) {
222219
const useSystemUnzipEnv = process.env.APPIUM_PREFER_SYSTEM_UNZIP;
223-
const useSystemUnzip = _.isEmpty(useSystemUnzipEnv)
224-
|| !['0', 'false'].includes(_.toLower(useSystemUnzipEnv));
220+
const useSystemUnzip =
221+
_.isEmpty(useSystemUnzipEnv) || !['0', 'false'].includes(_.toLower(useSystemUnzipEnv));
225222
const tmpRoot = await tempDir.openDir();
226223
await zip.extractAllTo(archivePath, tmpRoot, {useSystemUnzip});
227224
const globPattern = `**/*.+(${appExtensions.map((ext) => ext.replace(/^\./, '')).join('|')})`;
228-
const sortedBundleItems = (await fs.glob(globPattern, {
229-
cwd: tmpRoot,
230-
})).sort((a, b) => a.split(path.sep).length - b.split(path.sep).length);
225+
const sortedBundleItems = (
226+
await fs.glob(globPattern, {
227+
cwd: tmpRoot,
228+
})
229+
).sort((a, b) => a.split(path.sep).length - b.split(path.sep).length);
231230
return [tmpRoot, sortedBundleItems];
232231
}
233232

@@ -238,15 +237,23 @@ async function findApps (archivePath, appExtensions) {
238237
* @returns {Promise<string>} The new path to the app bundle.
239238
* The name of the app bundle remains though
240239
*/
241-
async function isolateAppBundle (appRoot) {
240+
async function isolateAppBundle(appRoot) {
242241
const tmpRoot = await tempDir.openDir();
243242
const dstRoot = path.join(tmpRoot, path.basename(appRoot));
244243
await fs.mv(appRoot, dstRoot, {mkdirp: true});
245244
return dstRoot;
246245
}
247246

248247
export {
249-
extractBundleId, verifyApplicationPlatform, parseLocalizableStrings,
250-
SAFARI_BUNDLE_ID, fetchSupportedAppPlatforms, APP_EXT, IPA_EXT,
251-
isAppBundle, findApps, isolateAppBundle, extractBundleVersion,
248+
extractBundleId,
249+
verifyApplicationPlatform,
250+
parseLocalizableStrings,
251+
SAFARI_BUNDLE_ID,
252+
fetchSupportedAppPlatforms,
253+
APP_EXT,
254+
IPA_EXT,
255+
isAppBundle,
256+
findApps,
257+
isolateAppBundle,
258+
extractBundleVersion,
252259
};

lib/commands/alert.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ export default {
7070
default:
7171
throw new Error(
7272
`The 'action' value should be either 'accept', 'dismiss' or 'getButtons'. ` +
73-
`'${action}' is provided instead.`
73+
`'${action}' is provided instead.`,
7474
);
7575
}
7676
},

lib/commands/app-management.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,18 @@ export default {
2020
this.log.info(
2121
`Installing '${srcAppPath}' to the ${this.isRealDevice() ? 'real device' : 'Simulator'} ` +
2222
// @ts-expect-error - do not assign arbitrary properties to `this.opts`
23-
`with UDID '${this.opts.device.udid}'`
23+
`with UDID '${this.opts.device.udid}'`,
2424
);
2525
if (!(await fs.exists(srcAppPath))) {
2626
this.log.errorAndThrow(
27-
`The application at '${srcAppPath}' does not exist or is not accessible`
27+
`The application at '${srcAppPath}' does not exist or is not accessible`,
2828
);
2929
}
3030
// @ts-expect-error - do not assign arbitrary properties to `this.opts`
3131
await this.opts.device.installApp(
3232
srcAppPath,
3333
timeoutMs ?? this.opts.appPushTimeout,
34-
strategy ?? this.opts.appInstallStrategy
34+
strategy ?? this.opts.appInstallStrategy,
3535
);
3636
this.log.info(`Installation of '${srcAppPath}' succeeded`);
3737
},
@@ -61,7 +61,7 @@ export default {
6161
`from the ${this.isRealDevice() ? 'real device' : 'Simulator'} with UDID '${
6262
// @ts-expect-error - do not assign arbitrary properties to `this.opts`
6363
this.opts.device.udid
64-
}'`
64+
}'`,
6565
);
6666
try {
6767
// @ts-expect-error - do not assign arbitrary properties to `this.opts`
@@ -258,7 +258,7 @@ export default {
258258
if (!endpoint) {
259259
throw new errors.InvalidArgumentError(
260260
`Argument value is expected to be a valid number. ` +
261-
`${JSON.stringify(seconds)} has been provided instead`
261+
`${JSON.stringify(seconds)} has been provided instead`,
262262
);
263263
}
264264
return await this.proxyCommand(endpoint, 'POST', params, endpoint !== homescreen);

lib/commands/app-strings.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export default {
1818
language,
1919
stringFile,
2020
strictMode: true,
21-
})
21+
}),
2222
);
2323
},
2424
};

lib/commands/audit.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@ export default {
2222
* @this {XCUITestDriver}
2323
*/
2424
async mobilePerformAccessibilityAudit(auditTypes) {
25-
return /** @type {AccessibilityAuditItem[]} */ (await this.proxyCommand(
26-
'/wda/performAccessibilityAudit', 'POST', {auditTypes}
27-
));
25+
return /** @type {AccessibilityAuditItem[]} */ (
26+
await this.proxyCommand('/wda/performAccessibilityAudit', 'POST', {auditTypes})
27+
);
2828
},
2929
};
3030

lib/commands/certificate.js

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ async function extractCommonName(certBuffer) {
6969
} catch (err) {
7070
throw new Error(
7171
`Cannot parse common name value from the certificate. Is it valid and base64-encoded? ` +
72-
`Original error: ${err.message}`
72+
`Original error: ${err.message}`,
7373
);
7474
} finally {
7575
await fs.rimraf(tempCert.path);
@@ -138,7 +138,7 @@ async function clickElement(driver, locator, options = {}) {
138138
element = await retryInterval(
139139
timeout < lookupDelay ? 1 : timeout / lookupDelay,
140140
lookupDelay,
141-
() => driver.findNativeElementOrElements(locator.type, locator.value, false)
141+
() => driver.findNativeElementOrElements(locator.type, locator.value, false),
142142
);
143143
} catch (err) {
144144
if (skipIfInvisible) {
@@ -190,7 +190,7 @@ async function trustCertificateInPreferences(driver, name) {
190190
element: await driver.findNativeElementOrElements(
191191
'class name',
192192
'XCUIElementTypeTable',
193-
false
193+
false,
194194
),
195195
direction: 'up',
196196
});
@@ -211,7 +211,7 @@ async function trustCertificateInPreferences(driver, name) {
211211
{
212212
timeout: 1000,
213213
skipIfInvisible: true,
214-
}
214+
},
215215
)
216216
) {
217217
await driver.postAcceptAlert();
@@ -244,7 +244,7 @@ async function installPost122Certificate(driver, name) {
244244
{
245245
timeout: 500,
246246
skipIfInvisible: true,
247-
}
247+
},
248248
)
249249
) {
250250
isCertFound = true;
@@ -255,7 +255,7 @@ async function installPost122Certificate(driver, name) {
255255
element: await driver.findNativeElementOrElements(
256256
'class name',
257257
'XCUIElementTypeTable',
258-
false
258+
false,
259259
),
260260
direction: 'up',
261261
});
@@ -314,7 +314,7 @@ export default {
314314
} catch (e) {
315315
this.log.debug(e);
316316
this.log.info(
317-
`The certificate cannot be installed via CLI. ` + `Falling back to UI-based deployment`
317+
`The certificate cannot be installed via CLI. ` + `Falling back to UI-based deployment`,
318318
);
319319
}
320320
} else {
@@ -325,7 +325,7 @@ export default {
325325
} else {
326326
this.log.info(
327327
'pyidevice is not installed on your system. ' +
328-
'Falling back to the (slow) UI-based installation'
328+
'Falling back to the (slow) UI-based installation',
329329
);
330330
}
331331
}
@@ -347,7 +347,7 @@ export default {
347347
} catch (err) {
348348
throw new Error(
349349
`Cannot store the generated config as '${configPath}'. ` +
350-
`Original error: ${err.message}`
350+
`Original error: ${err.message}`,
351351
);
352352
}
353353

@@ -367,12 +367,12 @@ export default {
367367
{
368368
waitMs: TMPSERVER_STARTUP_TIMEOUT,
369369
intervalMs: 300,
370-
}
370+
},
371371
);
372372
this.log.debug(`The temporary web server is running at http://${host}:${tmpPort}`);
373373
} catch (e) {
374374
throw new Error(
375-
`The temporary web server cannot be started at http://${host}:${tmpPort}.`
375+
`The temporary web server cannot be started at http://${host}:${tmpPort}.`,
376376
);
377377
}
378378
if (this.isRealDevice()) {
@@ -410,7 +410,7 @@ export default {
410410
}
411411
if (isCertAlreadyInstalled) {
412412
this.log.info(
413-
`It looks like the '${cn}' certificate has been already added to the CA root`
413+
`It looks like the '${cn}' certificate has been already added to the CA root`,
414414
);
415415
}
416416
} finally {
@@ -419,7 +419,7 @@ export default {
419419
await this.activateApp(this.opts.bundleId);
420420
} catch (e) {
421421
this.log.warn(
422-
`Cannot restore the application '${this.opts.bundleId}'. Original error: ${e.message}`
422+
`Cannot restore the application '${this.opts.bundleId}'. Original error: ${e.message}`,
423423
);
424424
}
425425
}

0 commit comments

Comments
 (0)