Skip to content

Commit d5bcefc

Browse files
authored
fix: format (#981)
* fix: format * correct ts espect error
1 parent 2d29e65 commit d5bcefc

Some content is hidden

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

60 files changed

+838
-704
lines changed

.github/workflows/unit-test.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,5 +36,7 @@ jobs:
3636
name: Install dev dependencies
3737
- run: npm run lint
3838
name: Run linter
39+
- run: npm run format:check
40+
name: Run Prettier check
3941
- run: npm run test
4042
name: Run unit tests

lib/commands/actions.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,9 @@ export async function mobileGetActionHistory(
4343
this: AndroidUiautomator2Driver,
4444
name: string,
4545
): Promise<ActionResult> {
46-
return (await this.uiautomator2.jwproxy.command('/appium/action_history', 'POST', {name})) as ActionResult;
46+
return (await this.uiautomator2.jwproxy.command('/appium/action_history', 'POST', {
47+
name,
48+
})) as ActionResult;
4749
}
4850

4951
/**
@@ -77,8 +79,8 @@ export async function performActions(
7779
pointerType: 'touch',
7880
},
7981
}
80-
: {}
81-
)
82+
: {},
83+
),
8284
);
8385
this.log.debug(`Preprocessed actions: ${JSON.stringify(preprocessedActions, null, ' ')}`);
8486
await this.uiautomator2.jwproxy.command('/actions', 'POST', {
@@ -92,4 +94,3 @@ export async function performActions(
9294
export async function releaseActions(this: AndroidUiautomator2Driver): Promise<void> {
9395
this.log.info('On this platform, releaseActions is a no-op');
9496
}
95-

lib/commands/alert.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,4 +43,3 @@ export async function mobileDismissAlert(
4343
export async function postDismissAlert(this: AndroidUiautomator2Driver): Promise<void> {
4444
await this.mobileDismissAlert();
4545
}
46-

lib/commands/app-management.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ export async function mobileInstallMultipleApks(
1919
if (!_.isArray(apks) || _.isEmpty(apks)) {
2020
throw new errors.InvalidArgumentError('No apks are given to install');
2121
}
22-
const configuredApks = await B.all(apks.map((app) => this.helpers.configureApp(app, [APK_EXTENSION])));
22+
const configuredApks = await B.all(
23+
apks.map((app) => this.helpers.configureApp(app, [APK_EXTENSION])),
24+
);
2325
await this.adb.installMultipleApks(configuredApks, options);
2426
}
25-

lib/commands/battery.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,11 @@ import type {BatteryInfo} from './types';
66
* @returns Battery information including level (0.0-1.0) and state (charging, discharging, etc.).
77
*/
88
export async function mobileGetBatteryInfo(this: AndroidUiautomator2Driver): Promise<BatteryInfo> {
9-
const result = (await this.uiautomator2.jwproxy.command('/appium/device/battery_info', 'GET', {})) as {
9+
const result = (await this.uiautomator2.jwproxy.command(
10+
'/appium/device/battery_info',
11+
'GET',
12+
{},
13+
)) as {
1014
status: BatteryInfo['state'];
1115
level: number;
1216
};
@@ -16,4 +20,3 @@ export async function mobileGetBatteryInfo(this: AndroidUiautomator2Driver): Pro
1620
delete batteryInfo.status;
1721
return batteryInfo as BatteryInfo;
1822
}
19-

lib/commands/clipboard.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ export async function getClipboard(this: AndroidUiautomator2Driver): Promise<str
88
return String(
99
(await this.adb.getApiLevel()) < 29
1010
? await this.uiautomator2.jwproxy.command('/appium/device/get_clipboard', 'POST', {})
11-
: await this.settingsApp.getClipboard()
11+
: await this.settingsApp.getClipboard(),
1212
);
1313
}
1414

@@ -24,6 +24,9 @@ export async function setClipboard(
2424
contentType: 'plaintext' = 'plaintext',
2525
label?: string,
2626
): Promise<void> {
27-
await this.uiautomator2.jwproxy.command('/appium/device/set_clipboard', 'POST', {content, contentType, label});
27+
await this.uiautomator2.jwproxy.command('/appium/device/set_clipboard', 'POST', {
28+
content,
29+
contentType,
30+
label,
31+
});
2832
}
29-

lib/commands/element.ts

Lines changed: 53 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,29 @@ export async function active(this: AndroidUiautomator2Driver): Promise<AppiumEle
2020
* @param elementId - ID of the element.
2121
* @returns The attribute value as a string.
2222
*/
23-
export async function getAttribute(this: AndroidUiautomator2Driver, attribute: string, elementId: string): Promise<string> {
24-
return String(await this.uiautomator2.jwproxy.command(`/element/${elementId}/attribute/${attribute}`, 'GET', {}));
23+
export async function getAttribute(
24+
this: AndroidUiautomator2Driver,
25+
attribute: string,
26+
elementId: string,
27+
): Promise<string> {
28+
return String(
29+
await this.uiautomator2.jwproxy.command(
30+
`/element/${elementId}/attribute/${attribute}`,
31+
'GET',
32+
{},
33+
),
34+
);
2535
}
2636

2737
/**
2838
* Returns whether the element is displayed.
2939
* @param elementId - ID of the element.
3040
* @returns True if the element is displayed, false otherwise.
3141
*/
32-
export async function elementDisplayed(this: AndroidUiautomator2Driver, elementId: string): Promise<boolean> {
42+
export async function elementDisplayed(
43+
this: AndroidUiautomator2Driver,
44+
elementId: string,
45+
): Promise<boolean> {
3346
return toBool(await this.getAttribute('displayed', elementId));
3447
}
3548

@@ -38,7 +51,10 @@ export async function elementDisplayed(this: AndroidUiautomator2Driver, elementI
3851
* @param elementId - ID of the element.
3952
* @returns True if the element is enabled, false otherwise.
4053
*/
41-
export async function elementEnabled(this: AndroidUiautomator2Driver, elementId: string): Promise<boolean> {
54+
export async function elementEnabled(
55+
this: AndroidUiautomator2Driver,
56+
elementId: string,
57+
): Promise<boolean> {
4258
return toBool(await this.getAttribute('enabled', elementId));
4359
}
4460

@@ -47,7 +63,10 @@ export async function elementEnabled(this: AndroidUiautomator2Driver, elementId:
4763
* @param elementId - ID of the element.
4864
* @returns True if the element is selected, false otherwise.
4965
*/
50-
export async function elementSelected(this: AndroidUiautomator2Driver, elementId: string): Promise<boolean> {
66+
export async function elementSelected(
67+
this: AndroidUiautomator2Driver,
68+
elementId: string,
69+
): Promise<boolean> {
5170
return toBool(await this.getAttribute('selected', elementId));
5271
}
5372

@@ -57,16 +76,27 @@ export async function elementSelected(this: AndroidUiautomator2Driver, elementId
5776
* @returns The element tag name.
5877
*/
5978
export async function getName(this: AndroidUiautomator2Driver, elementId: string): Promise<string> {
60-
return (await this.uiautomator2.jwproxy.command(`/element/${elementId}/name`, 'GET', {})) as string;
79+
return (await this.uiautomator2.jwproxy.command(
80+
`/element/${elementId}/name`,
81+
'GET',
82+
{},
83+
)) as string;
6184
}
6285

6386
/**
6487
* Gets the element location.
6588
* @param elementId - ID of the element.
6689
* @returns The element position coordinates (x, y).
6790
*/
68-
export async function getLocation(this: AndroidUiautomator2Driver, elementId: string): Promise<Position> {
69-
return (await this.uiautomator2.jwproxy.command(`/element/${elementId}/location`, 'GET', {})) as Position;
91+
export async function getLocation(
92+
this: AndroidUiautomator2Driver,
93+
elementId: string,
94+
): Promise<Position> {
95+
return (await this.uiautomator2.jwproxy.command(
96+
`/element/${elementId}/location`,
97+
'GET',
98+
{},
99+
)) as Position;
70100
}
71101

72102
/**
@@ -82,7 +112,10 @@ export async function getSize(this: AndroidUiautomator2Driver, elementId: string
82112
* Sets the value of an element using the upstream driver API.
83113
* @param params - Options containing the element ID and value to set.
84114
*/
85-
export async function doSetElementValue(this: AndroidUiautomator2Driver, params: DoSetElementValueOpts): Promise<void> {
115+
export async function doSetElementValue(
116+
this: AndroidUiautomator2Driver,
117+
params: DoSetElementValueOpts,
118+
): Promise<void> {
86119
await this.uiautomator2.jwproxy.command(`/element/${params.elementId}/value`, 'POST', params);
87120
}
88121

@@ -125,8 +158,13 @@ export async function click(this: AndroidUiautomator2Driver, element: string): P
125158
* @param element - ID of the element.
126159
* @returns Base64-encoded PNG screenshot of the element.
127160
*/
128-
export async function getElementScreenshot(this: AndroidUiautomator2Driver, element: string): Promise<string> {
129-
return String(await this.uiautomator2.jwproxy.command(`/element/${element}/screenshot`, 'GET', {}));
161+
export async function getElementScreenshot(
162+
this: AndroidUiautomator2Driver,
163+
element: string,
164+
): Promise<string> {
165+
return String(
166+
await this.uiautomator2.jwproxy.command(`/element/${element}/screenshot`, 'GET', {}),
167+
);
130168
}
131169

132170
/**
@@ -142,7 +180,10 @@ export async function clear(this: AndroidUiautomator2Driver, elementId: string):
142180
* @param elementId - ID of the element.
143181
* @returns The element rectangle (x, y, width, height).
144182
*/
145-
export async function getElementRect(this: AndroidUiautomator2Driver, elementId: string): Promise<Rect> {
183+
export async function getElementRect(
184+
this: AndroidUiautomator2Driver,
185+
elementId: string,
186+
): Promise<Rect> {
146187
if (!this.isWebContext()) {
147188
return (await this.uiautomator2.jwproxy.command(`/element/${elementId}/rect`, 'GET')) as Rect;
148189
}
@@ -177,4 +218,3 @@ export async function mobileReplaceElementValue(
177218
function toBool(value: any): boolean {
178219
return _.isString(value) ? value.toLowerCase() === 'true' : !!value;
179220
}
180-

lib/commands/find.ts

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,18 +31,26 @@ export async function doFindElementOrEls(
3131
const uiautomator2 = this.uiautomator2;
3232
if (params.strategy === 'xpath' && MAGIC_FIRST_VIS_CHILD_SEL.test(params.selector)) {
3333
const elementId = params.context;
34-
return (await uiautomator2.jwproxy.command(`/appium/element/${elementId}/first_visible`, 'GET', {})) as AppiumElement;
34+
return (await uiautomator2.jwproxy.command(
35+
`/appium/element/${elementId}/first_visible`,
36+
'GET',
37+
{},
38+
)) as AppiumElement;
3539
}
3640
if (params.strategy === 'xpath' && MAGIC_SCROLLABLE_SEL.test(params.selector)) {
3741
params.strategy = '-android uiautomator';
3842
params.selector = MAGIC_SCROLLABLE_BY;
3943
}
4044
if (params.strategy === 'css selector') {
4145
params.strategy = '-android uiautomator';
42-
params.selector = new CssConverter(params.selector, this.opts.appPackage).toUiAutomatorSelector();
46+
params.selector = new CssConverter(
47+
params.selector,
48+
this.opts.appPackage,
49+
).toUiAutomatorSelector();
4350
}
44-
return (await uiautomator2.jwproxy.command(`/element${params.multiple ? 's' : ''}`, 'POST', params)) as
45-
| AppiumElement
46-
| AppiumElement[];
51+
return (await uiautomator2.jwproxy.command(
52+
`/element${params.multiple ? 's' : ''}`,
53+
'POST',
54+
params,
55+
)) as AppiumElement | AppiumElement[];
4756
}
48-

lib/commands/gestures.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,9 @@ export async function mobileScrollBackTo(
248248
elementToId?: string,
249249
): Promise<void> {
250250
if (!elementId || !elementToId) {
251-
throw new errors.InvalidArgumentError(`Both elementId and elementToId arguments must be provided`);
251+
throw new errors.InvalidArgumentError(
252+
`Both elementId and elementToId arguments must be provided`,
253+
);
252254
}
253255
await this.uiautomator2.jwproxy.command(
254256
`/appium/element/${util.unwrapElement(elementId)}/scroll_to/${util.unwrapElement(elementToId)}`,
@@ -289,9 +291,13 @@ function toPoint(x?: number, y?: number): Partial<Position> | undefined {
289291
return _.isFinite(x) && _.isFinite(y) ? {x, y} : undefined;
290292
}
291293

292-
function toRect(left?: number, top?: number, width?: number, height?: number): RelativeRect | undefined {
294+
function toRect(
295+
left?: number,
296+
top?: number,
297+
width?: number,
298+
height?: number,
299+
): RelativeRect | undefined {
293300
return [left, top, width, height].some((v) => !_.isFinite(v))
294301
? undefined
295302
: ({left, top, width, height} as RelativeRect);
296303
}
297-

lib/commands/keyboard.ts

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -59,12 +59,16 @@ export async function mobilePressKey(
5959
isLongPress: boolean = false,
6060
source?: number,
6161
): Promise<void> {
62-
await this.uiautomator2.jwproxy.command(`/appium/device/${isLongPress ? 'long_' : ''}press_keycode`, 'POST', {
63-
keycode,
64-
metastate,
65-
flags,
66-
source,
67-
});
62+
await this.uiautomator2.jwproxy.command(
63+
`/appium/device/${isLongPress ? 'long_' : ''}press_keycode`,
64+
'POST',
65+
{
66+
keycode,
67+
metastate,
68+
flags,
69+
source,
70+
},
71+
);
6872
}
6973

7074
/**
@@ -87,7 +91,10 @@ export async function mobileType(
8791
* Sends keys to the current element.
8892
* @param params - Options containing the text to send and optional replace flag.
8993
*/
90-
export async function doSendKeys(this: AndroidUiautomator2Driver, params: SendKeysOpts): Promise<void> {
94+
export async function doSendKeys(
95+
this: AndroidUiautomator2Driver,
96+
params: SendKeysOpts,
97+
): Promise<void> {
9198
await this.uiautomator2.jwproxy.command('/keys', 'POST', params);
9299
}
93100

@@ -104,4 +111,3 @@ export async function keyevent(
104111
this.log.debug(`Ignoring metastate ${metastate}`);
105112
await this.adb.keyevent(keycode);
106113
}
107-

0 commit comments

Comments
 (0)