Skip to content

Commit a166217

Browse files
committed
fix: format
1 parent fb88dcd commit a166217

33 files changed

+541
-538
lines changed

.github/workflows/unit-test.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,5 +26,7 @@ jobs:
2626
name: Install dev dependencies
2727
- run: npm run lint
2828
name: Run linter
29+
- run: npm run format:check
30+
name: Run Prettier check
2931
- run: npm run test
3032
name: Run unit tests

lib/commands/app-management.js

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,8 @@
1212
*
1313
* @this {WindowsDriver}
1414
*/
15-
export async function windowsLaunchApp () {
16-
return await this.winAppDriver.sendCommand(
17-
'/appium/app/launch', 'POST', {}
18-
);
15+
export async function windowsLaunchApp() {
16+
return await this.winAppDriver.sendCommand('/appium/app/launch', 'POST', {});
1917
}
2018

2119
/**
@@ -30,10 +28,8 @@ export async function windowsLaunchApp () {
3028
* @this {WindowsDriver}
3129
* @throws {Error} if the app process is not running
3230
*/
33-
export async function windowsCloseApp () {
34-
return await this.winAppDriver.sendCommand(
35-
'/appium/app/close', 'POST', {}
36-
);
31+
export async function windowsCloseApp() {
32+
return await this.winAppDriver.sendCommand('/appium/app/close', 'POST', {});
3733
}
3834

3935
/**

lib/commands/clipboard.js

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { exec } from 'teen_process';
2-
import { errors } from 'appium/driver';
1+
import {exec} from 'teen_process';
2+
import {errors} from 'appium/driver';
33
import _ from 'lodash';
44

55
/**
@@ -23,29 +23,30 @@ const CONTENT_TYPE = Object.freeze({
2323
* @param {string} b64Content base64-encoded clipboard content to set
2424
* @param {ContentTypeEnum} [contentType='text'] The clipboard content type to set
2525
*/
26-
export async function windowsSetClipboard (
27-
b64Content,
28-
contentType = CONTENT_TYPE.plaintext
29-
) {
26+
export async function windowsSetClipboard(b64Content, contentType = CONTENT_TYPE.plaintext) {
3027
if (b64Content && Buffer.from(b64Content, 'base64').toString('base64') !== b64Content) {
31-
throw new errors.InvalidArgumentError(`The 'b64Content' argument must be a valid base64-encoded string`);
28+
throw new errors.InvalidArgumentError(
29+
`The 'b64Content' argument must be a valid base64-encoded string`,
30+
);
3231
}
3332
switch (contentType) {
3433
case CONTENT_TYPE.plaintext:
35-
return await exec('powershell', ['-command',
34+
return await exec('powershell', [
35+
'-command',
3636
`$str=[System.Text.Encoding]::UTF8.GetString([System.Convert]::FromBase64String('${b64Content}'));`,
37-
'Set-Clipboard -Value $str'
37+
'Set-Clipboard -Value $str',
3838
]);
3939
case CONTENT_TYPE.image:
40-
return await exec('powershell', ['-command',
40+
return await exec('powershell', [
41+
'-command',
4142
`$img=[Drawing.Bitmap]::FromStream([IO.MemoryStream][Convert]::FromBase64String('${b64Content}'));`,
4243
'[System.Windows.Forms.Clipboard]::SetImage($img);',
43-
'$img.Dispose();'
44+
'$img.Dispose();',
4445
]);
4546
default:
4647
throw new errors.InvalidArgumentError(
4748
`The clipboard content type '${contentType}' is not known. ` +
48-
`Only the following content types are supported: ${_.values(CONTENT_TYPE)}`
49+
`Only the following content types are supported: ${_.values(CONTENT_TYPE)}`,
4950
);
5051
}
5152
}
@@ -60,29 +61,29 @@ export async function windowsSetClipboard (
6061
* Only PNG images are supported for extraction if set to 'image'.
6162
* @returns {Promise<string>} base64-encoded content of the clipboard
6263
*/
63-
export async function windowsGetClipboard (
64-
contentType = CONTENT_TYPE.plaintext
65-
) {
64+
export async function windowsGetClipboard(contentType = CONTENT_TYPE.plaintext) {
6665
switch (contentType) {
6766
case CONTENT_TYPE.plaintext: {
68-
const {stdout} = await exec('powershell', ['-command',
67+
const {stdout} = await exec('powershell', [
68+
'-command',
6969
'$str=Get-Clipboard;',
70-
'[Convert]::ToBase64String([System.Text.Encoding]::UTF8.GetBytes($str));'
70+
'[Convert]::ToBase64String([System.Text.Encoding]::UTF8.GetBytes($str));',
7171
]);
7272
return _.trim(stdout);
7373
}
7474
case CONTENT_TYPE.image: {
75-
const {stdout} = await exec('powershell', ['-command',
75+
const {stdout} = await exec('powershell', [
76+
'-command',
7677
'$s=New-Object System.IO.MemoryStream;',
7778
'[System.Windows.Forms.Clipboard]::GetImage().Save($s,[System.Drawing.Imaging.ImageFormat]::Png);',
78-
'[System.Convert]::ToBase64String($s.ToArray());'
79+
'[System.Convert]::ToBase64String($s.ToArray());',
7980
]);
8081
return _.trim(stdout);
8182
}
8283
default:
8384
throw new errors.InvalidArgumentError(
8485
`The clipboard content type '${contentType}' is not known. ` +
85-
`Only the following content types are supported: ${_.values(CONTENT_TYPE)}`
86+
`Only the following content types are supported: ${_.values(CONTENT_TYPE)}`,
8687
);
8788
}
8889
}

lib/commands/context.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
1-
import { errors } from 'appium/driver';
1+
import {errors} from 'appium/driver';
22

33
const WINDOWS_CONTEXT = 'NATIVE_APP';
44

5-
export async function getContexts (): Promise<string[]> {
5+
export async function getContexts(): Promise<string[]> {
66
return [WINDOWS_CONTEXT];
77
}
88

9-
export async function getCurrentContext (): Promise<string> {
9+
export async function getCurrentContext(): Promise<string> {
1010
return WINDOWS_CONTEXT;
1111
}
1212

13-
export async function setContext (context: string): Promise<void> {
13+
export async function setContext(context: string): Promise<void> {
1414
if (context !== WINDOWS_CONTEXT) {
1515
throw new errors.NoSuchContextError(
16-
`The Windows Driver only supports '${WINDOWS_CONTEXT}' context.`
16+
`The Windows Driver only supports '${WINDOWS_CONTEXT}' context.`,
1717
);
1818
}
19-
}
19+
}

lib/commands/execute.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import _ from 'lodash';
2-
import { POWER_SHELL_FEATURE } from '../constants';
2+
import {POWER_SHELL_FEATURE} from '../constants';
33

44
const POWER_SHELL_SCRIPT = 'powerShell';
55
const EXECUTE_SCRIPT_PREFIX = 'windows:';
@@ -11,11 +11,13 @@ const EXECUTE_SCRIPT_PREFIX = 'windows:';
1111
* @param {ExecuteMethodArgs} [args]
1212
* @returns {Promise<any>}
1313
*/
14-
export async function execute (script, args) {
14+
export async function execute(script, args) {
1515
if (script === POWER_SHELL_SCRIPT) {
1616
this.assertFeatureEnabled(POWER_SHELL_FEATURE);
1717
return await this.execPowerShell(
18-
/** @type {import('./powershell').ExecPowerShellOptions} */ (preprocessExecuteMethodArgs(args))
18+
/** @type {import('./powershell').ExecPowerShellOptions} */ (
19+
preprocessExecuteMethodArgs(args)
20+
),
1921
);
2022
}
2123

lib/commands/file-movement.js

Lines changed: 42 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,22 @@
11
import _ from 'lodash';
22
import path from 'node:path';
3-
import { errors } from 'appium/driver';
4-
import { fs, mkdirp, util, zip } from 'appium/support';
5-
import { MODIFY_FS_FEATURE } from '../constants';
3+
import {errors} from 'appium/driver';
4+
import {fs, mkdirp, util, zip} from 'appium/support';
5+
import {MODIFY_FS_FEATURE} from '../constants';
66

77
// List of env variables, that can be expanded in path
88
const KNOWN_ENV_VARS = [
9-
'APPDATA', 'LOCALAPPDATA',
10-
'PROGRAMFILES', 'PROGRAMFILES(X86)',
11-
'PROGRAMDATA', 'ALLUSERSPROFILE',
12-
'TEMP', 'TMP',
13-
'HOMEPATH', 'USERPROFILE', 'PUBLIC'
9+
'APPDATA',
10+
'LOCALAPPDATA',
11+
'PROGRAMFILES',
12+
'PROGRAMFILES(X86)',
13+
'PROGRAMDATA',
14+
'ALLUSERSPROFILE',
15+
'TEMP',
16+
'TMP',
17+
'HOMEPATH',
18+
'USERPROFILE',
19+
'PUBLIC',
1420
];
1521

1622
/**
@@ -20,12 +26,13 @@ const KNOWN_ENV_VARS = [
2026
* @param {string} base64Data
2127
* @returns {Promise<void>}
2228
*/
23-
export async function pushFile (remotePath, base64Data) {
29+
export async function pushFile(remotePath, base64Data) {
2430
this.assertFeatureEnabled(MODIFY_FS_FEATURE);
2531
if (remotePath.endsWith(path.sep)) {
2632
throw new errors.InvalidArgumentError(
2733
'It is expected that remote path points to a file rather than a folder. ' +
28-
`'${remotePath}' is given instead`);
34+
`'${remotePath}' is given instead`,
35+
);
2936
}
3037

3138
if (_.isArray(base64Data)) {
@@ -46,7 +53,7 @@ export async function pushFile (remotePath, base64Data) {
4653
* @param {string} remotePath
4754
* @returns {Promise<string>}
4855
*/
49-
export async function pullFile (remotePath) {
56+
export async function pullFile(remotePath) {
5057
const fullPath = resolveToAbsolutePath(remotePath);
5158
await checkFileExists(fullPath);
5259
return (await util.toInMemoryBase64(fullPath)).toString();
@@ -58,12 +65,14 @@ export async function pullFile (remotePath) {
5865
* @param {string} remotePath
5966
* @returns {Promise<string>}
6067
*/
61-
export async function pullFolder (remotePath) {
68+
export async function pullFolder(remotePath) {
6269
const fullPath = resolveToAbsolutePath(remotePath);
6370
await checkFolderExists(fullPath);
64-
return (await zip.toInMemoryZip(fullPath, {
65-
encodeToBase64: true,
66-
})).toString();
71+
return (
72+
await zip.toInMemoryZip(fullPath, {
73+
encodeToBase64: true,
74+
})
75+
).toString();
6776
}
6877

6978
/**
@@ -78,7 +87,7 @@ export async function pullFolder (remotePath) {
7887
* @throws {InvalidArgumentError} If the file to be deleted does not exist or
7988
* remote path is not an absolute path.
8089
*/
81-
export async function windowsDeleteFile (remotePath) {
90+
export async function windowsDeleteFile(remotePath) {
8291
this.assertFeatureEnabled(MODIFY_FS_FEATURE);
8392
const fullPath = resolveToAbsolutePath(remotePath);
8493
await checkFileExists(fullPath);
@@ -97,7 +106,7 @@ export async function windowsDeleteFile (remotePath) {
97106
* @throws {InvalidArgumentError} If the folder to be deleted does not exist or
98107
* remote path is not an absolute path.
99108
*/
100-
export async function windowsDeleteFolder (remotePath) {
109+
export async function windowsDeleteFolder(remotePath) {
101110
this.assertFeatureEnabled(MODIFY_FS_FEATURE);
102111
const fullPath = resolveToAbsolutePath(remotePath);
103112
await checkFolderExists(fullPath);
@@ -109,17 +118,17 @@ export async function windowsDeleteFolder (remotePath) {
109118
* @param {string} remotePath
110119
* @returns {string}
111120
*/
112-
function resolveToAbsolutePath (remotePath) {
113-
const resolvedPath = remotePath.replace(
114-
/%([^%]+)%/g,
115-
(_, key) => KNOWN_ENV_VARS.includes(key.toUpperCase())
121+
function resolveToAbsolutePath(remotePath) {
122+
const resolvedPath = remotePath.replace(/%([^%]+)%/g, (_, key) =>
123+
KNOWN_ENV_VARS.includes(key.toUpperCase())
116124
? /** @type {string} */ (process.env[key.toUpperCase()])
117-
: `%${key}%`
125+
: `%${key}%`,
118126
);
119127

120128
if (!path.isAbsolute(resolvedPath)) {
121-
throw new errors.InvalidArgumentError('It is expected that remote path is absolute. ' +
122-
`'${resolvedPath}' is given instead`);
129+
throw new errors.InvalidArgumentError(
130+
'It is expected that remote path is absolute. ' + `'${resolvedPath}' is given instead`,
131+
);
123132
}
124133
return resolvedPath;
125134
}
@@ -129,15 +138,16 @@ function resolveToAbsolutePath (remotePath) {
129138
* @param {string} remotePath
130139
* @returns {Promise<void>}
131140
*/
132-
async function checkFileExists (remotePath) {
133-
if (!await fs.exists(remotePath)) {
141+
async function checkFileExists(remotePath) {
142+
if (!(await fs.exists(remotePath))) {
134143
throw new errors.InvalidArgumentError(`The remote file '${remotePath}' does not exist.`);
135144
}
136145
const stat = await fs.stat(remotePath);
137146
if (!stat.isFile()) {
138147
throw new errors.InvalidArgumentError(
139148
'It is expected that remote path points to a file rather than a folder. ' +
140-
`'${remotePath}' is given instead`);
149+
`'${remotePath}' is given instead`,
150+
);
141151
}
142152
}
143153

@@ -146,18 +156,19 @@ async function checkFileExists (remotePath) {
146156
* @param {string} remotePath
147157
* @returns {Promise<void>}
148158
*/
149-
async function checkFolderExists (remotePath) {
150-
if (!await fs.exists(remotePath)) {
159+
async function checkFolderExists(remotePath) {
160+
if (!(await fs.exists(remotePath))) {
151161
throw new errors.InvalidArgumentError(`The remote folder '${remotePath}' does not exist.`);
152162
}
153163
const stat = await fs.stat(remotePath);
154164
if (!stat.isDirectory()) {
155165
throw new errors.InvalidArgumentError(
156166
'It is expected that remote path points to a folder rather than a file. ' +
157-
`'${remotePath}' is given instead`);
167+
`'${remotePath}' is given instead`,
168+
);
158169
}
159170
}
160171

161172
/**
162173
* @typedef {import('../driver').WindowsDriver} WindowsDriver
163-
*/
174+
*/

lib/commands/find.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { util } from 'appium/support';
1+
import {util} from 'appium/support';
22

33
/**
44
*
@@ -9,7 +9,7 @@ import { util } from 'appium/support';
99
* @param {string} [context]
1010
* @returns
1111
*/
12-
export async function findElOrEls (strategy, selector, mult, context) {
12+
export async function findElOrEls(strategy, selector, mult, context) {
1313
const endpoint = `/element${context ? `/${util.unwrapElement(context)}/element` : ''}${mult ? 's' : ''}`;
1414
// This is either an array if mult is true or an object if mult is false
1515
return await this.winAppDriver.sendCommand(endpoint, 'POST', {

0 commit comments

Comments
 (0)