Skip to content

Commit 31ef9f7

Browse files
chore: Integrate oxc and release configs (#1030)
1 parent b71aeef commit 31ef9f7

72 files changed

Lines changed: 468 additions & 787 deletions

Some content is hidden

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

.editorconfig

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# editorconfig.org
2+
root = true
3+
4+
[*.{js,cjs,mjs,jsx,ts,cts,mts,tsx,json,jsonc}]
5+
indent_style = space
6+
indent_size = 2
7+
end_of_line = lf
8+
charset = utf-8
9+
trim_trailing_whitespace = true
10+
insert_final_newline = true
11+
max_line_length = 120

.github/workflows/unit-test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,6 @@ jobs:
3737
- run: npm run lint
3838
name: Run linter
3939
- run: npm run format:check
40-
name: Run Prettier check
40+
name: Run format check
4141
- run: npm run test
4242
name: Run unit tests

.releaserc

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

eslint.config.mjs

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

lib/commands/actions.ts

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import type {StringRecord} from '@appium/types';
2+
23
import type {AndroidUiautomator2Driver} from '../driver.js';
34
import type {ActionResult} from './types.js';
45

@@ -39,10 +40,7 @@ export async function mobileScheduleAction(
3940
* @param name - Name of the scheduled action.
4041
* @returns The action execution history containing repeats and step results.
4142
*/
42-
export async function mobileGetActionHistory(
43-
this: AndroidUiautomator2Driver,
44-
name: string,
45-
): Promise<ActionResult> {
43+
export async function mobileGetActionHistory(this: AndroidUiautomator2Driver, name: string): Promise<ActionResult> {
4644
return (await this.uiautomator2.jwproxy.command('/appium/action_history', 'POST', {
4745
name,
4846
})) as ActionResult;
@@ -53,21 +51,15 @@ export async function mobileGetActionHistory(
5351
* @param name - Name of the scheduled action to unschedule.
5452
* @returns The result of unscheduling the action.
5553
*/
56-
export async function mobileUnscheduleAction(
57-
this: AndroidUiautomator2Driver,
58-
name: string,
59-
): Promise<any> {
54+
export async function mobileUnscheduleAction(this: AndroidUiautomator2Driver, name: string): Promise<any> {
6055
return await this.uiautomator2.jwproxy.command('/appium/unschedule_action', 'POST', {name});
6156
}
6257

6358
/**
6459
* Performs a sequence of actions.
6560
* @param actions - Array of action objects to perform. Pointer actions are automatically converted to touch type.
6661
*/
67-
export async function performActions(
68-
this: AndroidUiautomator2Driver,
69-
actions: StringRecord[],
70-
): Promise<void> {
62+
export async function performActions(this: AndroidUiautomator2Driver, actions: StringRecord[]): Promise<void> {
7163
// This is mandatory, since Selenium API uses MOUSE as the default pointer type
7264
const preprocessedActions = actions.map((action) =>
7365
Object.assign(

lib/commands/alert.ts

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,7 @@ export async function getAlertText(this: AndroidUiautomator2Driver): Promise<str
1212
* Accepts the currently displayed alert.
1313
* @param buttonLabel - Optional label of the button to click. If not provided, the button will be detected automatically.
1414
*/
15-
export async function mobileAcceptAlert(
16-
this: AndroidUiautomator2Driver,
17-
buttonLabel?: string,
18-
): Promise<void> {
15+
export async function mobileAcceptAlert(this: AndroidUiautomator2Driver, buttonLabel?: string): Promise<void> {
1916
await this.uiautomator2.jwproxy.command('/alert/accept', 'POST', {buttonLabel});
2017
}
2118

@@ -30,10 +27,7 @@ export async function postAcceptAlert(this: AndroidUiautomator2Driver): Promise<
3027
* Dismisses the currently displayed alert.
3128
* @param buttonLabel - Optional label of the button to click. If not provided, the button will be detected automatically.
3229
*/
33-
export async function mobileDismissAlert(
34-
this: AndroidUiautomator2Driver,
35-
buttonLabel?: string,
36-
): Promise<void> {
30+
export async function mobileDismissAlert(this: AndroidUiautomator2Driver, buttonLabel?: string): Promise<void> {
3731
await this.uiautomator2.jwproxy.command('/alert/dismiss', 'POST', {buttonLabel});
3832
}
3933

lib/commands/app-management.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import {errors} from 'appium/driver.js';
2-
import {APK_EXTENSION} from '../extensions.js';
2+
33
import type {AndroidUiautomator2Driver} from '../driver.js';
4+
import {APK_EXTENSION} from '../extensions.js';
45
import type {InstallOptions} from './types.js';
56

67
/**
@@ -17,8 +18,6 @@ export async function mobileInstallMultipleApks(
1718
if (!Array.isArray(apks) || apks.length === 0) {
1819
throw new errors.InvalidArgumentError('No apks are given to install');
1920
}
20-
const configuredApks = await Promise.all(
21-
apks.map((app) => this.helpers.configureApp(app, [APK_EXTENSION])),
22-
);
21+
const configuredApks = await Promise.all(apks.map((app) => this.helpers.configureApp(app, [APK_EXTENSION])));
2322
await this.adb.installMultipleApks(configuredApks, options);
2423
}

lib/commands/aut.ts

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import {utils} from 'appium-android-driver';
22
import {fs} from 'appium/support.js';
33
import {SETTINGS_HELPER_ID} from 'io.appium.settings';
4+
45
import type {AndroidUiautomator2Driver} from '../driver.js';
56
import {APKS_EXTENSION, APK_EXTENSION} from '../extensions.js';
67
import {SERVER_PACKAGE_ID, SERVER_TEST_PACKAGE_ID} from '../uiautomator2-server/index.js';
@@ -17,10 +18,7 @@ export async function prepareSessionApp(this: AndroidUiautomator2Driver): Promis
1718
// assume is on the device and just launch via the appPackage
1819
this.log.info(`Starting '${this.opts.appPackage}' directly on the device`);
1920
} else {
20-
this.log.info(
21-
`Neither 'app' nor 'appPackage' was set. Starting UiAutomator2 ` +
22-
'without the target application',
23-
);
21+
this.log.info(`Neither 'app' nor 'appPackage' was set. Starting UiAutomator2 ` + 'without the target application');
2422
}
2523
}
2624

@@ -49,9 +47,7 @@ export async function initAUT(this: AndroidUiautomator2Driver): Promise<void> {
4947
try {
5048
otherApps = utils.parseArray(this.opts.otherApps);
5149
} catch (e) {
52-
throw this.log.errorWithException(
53-
`Could not parse "otherApps" capability: ${(e as Error).message}`,
54-
);
50+
throw this.log.errorWithException(`Could not parse "otherApps" capability: ${(e as Error).message}`);
5551
}
5652
otherApps = await Promise.all(
5753
otherApps.map((app) => this.helpers.configureApp(app, [APK_EXTENSION, APKS_EXTENSION])),
@@ -80,9 +76,7 @@ export async function initAUT(this: AndroidUiautomator2Driver): Promise<void> {
8076
}
8177
} else {
8278
if (this.opts.fullReset) {
83-
throw this.log.errorWithException(
84-
'Full reset requires an app capability, use fastReset if app is not provided',
85-
);
79+
throw this.log.errorWithException('Full reset requires an app capability, use fastReset if app is not provided');
8680
}
8781
this.log.debug('No app capability. Assuming it is already on the device');
8882
if (this.opts.fastReset && this.opts.appPackage) {

lib/commands/battery.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,7 @@ import type {BatteryInfo} from './types.js';
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(
10-
'/appium/device/battery_info',
11-
'GET',
12-
{},
13-
)) as {
9+
const result = (await this.uiautomator2.jwproxy.command('/appium/device/battery_info', 'GET', {})) as {
1410
status: BatteryInfo['state'];
1511
level: number;
1612
};

lib/commands/element.ts

Lines changed: 15 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
import {PROTOCOLS} from 'appium/driver.js';
2-
import type {DoSetElementValueOpts} from 'appium-android-driver';
31
import type {Element as AppiumElement, Position, Rect, Size} from '@appium/types';
4-
import type {AndroidUiautomator2Driver} from '../driver.js';
2+
import type {DoSetElementValueOpts} from 'appium-android-driver';
53
import type {Chromedriver} from 'appium-chromedriver';
4+
import {PROTOCOLS} from 'appium/driver.js';
5+
6+
import type {AndroidUiautomator2Driver} from '../driver.js';
67

78
/**
89
* Gets the currently active element.
@@ -23,24 +24,15 @@ export async function getAttribute(
2324
attribute: string,
2425
elementId: string,
2526
): Promise<string> {
26-
return String(
27-
await this.uiautomator2.jwproxy.command(
28-
`/element/${elementId}/attribute/${attribute}`,
29-
'GET',
30-
{},
31-
),
32-
);
27+
return String(await this.uiautomator2.jwproxy.command(`/element/${elementId}/attribute/${attribute}`, 'GET', {}));
3328
}
3429

3530
/**
3631
* Returns whether the element is displayed.
3732
* @param elementId - ID of the element.
3833
* @returns True if the element is displayed, false otherwise.
3934
*/
40-
export async function elementDisplayed(
41-
this: AndroidUiautomator2Driver,
42-
elementId: string,
43-
): Promise<boolean> {
35+
export async function elementDisplayed(this: AndroidUiautomator2Driver, elementId: string): Promise<boolean> {
4436
return toBool(await this.getAttribute('displayed', elementId));
4537
}
4638

@@ -49,10 +41,7 @@ export async function elementDisplayed(
4941
* @param elementId - ID of the element.
5042
* @returns True if the element is enabled, false otherwise.
5143
*/
52-
export async function elementEnabled(
53-
this: AndroidUiautomator2Driver,
54-
elementId: string,
55-
): Promise<boolean> {
44+
export async function elementEnabled(this: AndroidUiautomator2Driver, elementId: string): Promise<boolean> {
5645
return toBool(await this.getAttribute('enabled', elementId));
5746
}
5847

@@ -61,10 +50,7 @@ export async function elementEnabled(
6150
* @param elementId - ID of the element.
6251
* @returns True if the element is selected, false otherwise.
6352
*/
64-
export async function elementSelected(
65-
this: AndroidUiautomator2Driver,
66-
elementId: string,
67-
): Promise<boolean> {
53+
export async function elementSelected(this: AndroidUiautomator2Driver, elementId: string): Promise<boolean> {
6854
return toBool(await this.getAttribute('selected', elementId));
6955
}
7056

@@ -74,27 +60,16 @@ export async function elementSelected(
7460
* @returns The element tag name.
7561
*/
7662
export async function getName(this: AndroidUiautomator2Driver, elementId: string): Promise<string> {
77-
return (await this.uiautomator2.jwproxy.command(
78-
`/element/${elementId}/name`,
79-
'GET',
80-
{},
81-
)) as string;
63+
return (await this.uiautomator2.jwproxy.command(`/element/${elementId}/name`, 'GET', {})) as string;
8264
}
8365

8466
/**
8567
* Gets the element location.
8668
* @param elementId - ID of the element.
8769
* @returns The element position coordinates (x, y).
8870
*/
89-
export async function getLocation(
90-
this: AndroidUiautomator2Driver,
91-
elementId: string,
92-
): Promise<Position> {
93-
return (await this.uiautomator2.jwproxy.command(
94-
`/element/${elementId}/location`,
95-
'GET',
96-
{},
97-
)) as Position;
71+
export async function getLocation(this: AndroidUiautomator2Driver, elementId: string): Promise<Position> {
72+
return (await this.uiautomator2.jwproxy.command(`/element/${elementId}/location`, 'GET', {})) as Position;
9873
}
9974

10075
/**
@@ -110,10 +85,7 @@ export async function getSize(this: AndroidUiautomator2Driver, elementId: string
11085
* Sets the value of an element using the upstream driver API.
11186
* @param params - Options containing the element ID and value to set.
11287
*/
113-
export async function doSetElementValue(
114-
this: AndroidUiautomator2Driver,
115-
params: DoSetElementValueOpts,
116-
): Promise<void> {
88+
export async function doSetElementValue(this: AndroidUiautomator2Driver, params: DoSetElementValueOpts): Promise<void> {
11789
await this.uiautomator2.jwproxy.command(`/element/${params.elementId}/value`, 'POST', params);
11890
}
11991

@@ -156,13 +128,8 @@ export async function click(this: AndroidUiautomator2Driver, element: string): P
156128
* @param element - ID of the element.
157129
* @returns Base64-encoded PNG screenshot of the element.
158130
*/
159-
export async function getElementScreenshot(
160-
this: AndroidUiautomator2Driver,
161-
element: string,
162-
): Promise<string> {
163-
return String(
164-
await this.uiautomator2.jwproxy.command(`/element/${element}/screenshot`, 'GET', {}),
165-
);
131+
export async function getElementScreenshot(this: AndroidUiautomator2Driver, element: string): Promise<string> {
132+
return String(await this.uiautomator2.jwproxy.command(`/element/${element}/screenshot`, 'GET', {}));
166133
}
167134

168135
/**
@@ -178,10 +145,7 @@ export async function clear(this: AndroidUiautomator2Driver, elementId: string):
178145
* @param elementId - ID of the element.
179146
* @returns The element rectangle (x, y, width, height).
180147
*/
181-
export async function getElementRect(
182-
this: AndroidUiautomator2Driver,
183-
elementId: string,
184-
): Promise<Rect> {
148+
export async function getElementRect(this: AndroidUiautomator2Driver, elementId: string): Promise<Rect> {
185149
if (!this.isWebContext()) {
186150
return (await this.uiautomator2.jwproxy.command(`/element/${elementId}/rect`, 'GET')) as Rect;
187151
}

0 commit comments

Comments
 (0)