@appium/support 4.0.0 → 4.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +132 -83
- package/build/lib/image-util.d.ts +2 -3
- package/build/lib/image-util.d.ts.map +1 -1
- package/build/lib/image-util.js +19 -6
- package/build/lib/image-util.js.map +1 -1
- package/lib/image-util.js +21 -3
- package/package.json +10 -7
package/README.md
CHANGED
|
@@ -1,62 +1,112 @@
|
|
|
1
1
|
# appium-support
|
|
2
2
|
|
|
3
|
-
Utility functions used to support
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
3
|
+
Utility functions used to support Appium drivers and plugins.
|
|
4
|
+
|
|
5
|
+
# Usage in drivers and plugins
|
|
6
|
+
|
|
7
|
+
It is recommended to have Appium as a peer dependency in driver and plugin packages.
|
|
8
|
+
Add the following line to `peerDependencies` section of your module's `package.json`:
|
|
9
|
+
|
|
10
|
+
```js
|
|
11
|
+
"peerDependencies": {
|
|
12
|
+
"appium": "^<minimum_server_version>"
|
|
13
|
+
}
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
Afterwards import it in your code similarly to the below example:
|
|
17
|
+
|
|
18
|
+
```js
|
|
19
|
+
import {timing, util} from 'appium/support';
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
# Usage in helper modules
|
|
23
|
+
|
|
24
|
+
If you want to use this module in a helper library, which is not a driver or a plugin,
|
|
25
|
+
then add the following line to `dependencies` section of your module's `package.json`:
|
|
26
|
+
|
|
27
|
+
```js
|
|
28
|
+
"dependencies": {
|
|
29
|
+
"@appium/support": "<module_version>"
|
|
30
|
+
}
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
Afterwards import it in your code similarly to the below example:
|
|
34
|
+
|
|
35
|
+
```js
|
|
36
|
+
import {timing, util} from '@appium/support';
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
### Categories
|
|
40
|
+
|
|
41
|
+
All utility functions are split into a bunch of different categories. Each category has its own file under the `lib` folder. All utility functions in these files are documented.
|
|
42
|
+
|
|
43
|
+
#### fs
|
|
44
|
+
|
|
45
|
+
Most of the functions there are just thin wrappers over utility functions available in [Promises API](https://nodejs.org/api/fs.html#promises-api).
|
|
46
|
+
|
|
47
|
+
#### env
|
|
48
|
+
|
|
49
|
+
Several helpers needed by the server to cope with internal dependencies and manifests.
|
|
50
|
+
|
|
51
|
+
#### console
|
|
52
|
+
|
|
53
|
+
Wrappers for the command line interface abstraction used by the Appium server.
|
|
54
|
+
|
|
55
|
+
#### image-util
|
|
56
|
+
|
|
57
|
+
Utilities to work with images. Use [sharp](https://github.com/lovell/sharp) under the hood.
|
|
58
|
+
|
|
59
|
+
#### log-internal
|
|
60
|
+
|
|
61
|
+
Utilities needed for internal Appium log config assistance.
|
|
62
|
+
|
|
63
|
+
#### logging
|
|
64
|
+
|
|
65
|
+
See [below](#logger)
|
|
66
|
+
|
|
67
|
+
#### mjpeg
|
|
68
|
+
|
|
69
|
+
Helpers needed to implement [MJPEG streaming](https://en.wikipedia.org/wiki/Motion_JPEG#Video_streaming).
|
|
70
|
+
|
|
71
|
+
#### net
|
|
72
|
+
|
|
73
|
+
Helpers needed for network interactions, for example, upload and download of files.
|
|
74
|
+
|
|
75
|
+
#### node
|
|
76
|
+
|
|
77
|
+
Set of Node.js-specific utility functions needed, for example, to ensure objects immutability or to calculate their sizes.
|
|
78
|
+
|
|
79
|
+
#### npm
|
|
80
|
+
|
|
81
|
+
Set of [npm](https://en.wikipedia.org/wiki/Npm_(software))-related helpers.
|
|
82
|
+
|
|
83
|
+
#### plist
|
|
84
|
+
|
|
85
|
+
Set of utilities used to read and write data from [plist](https://en.wikipedia.org/wiki/Property_List) files in javascript.
|
|
86
|
+
|
|
87
|
+
#### process
|
|
88
|
+
|
|
89
|
+
Helpers for interactions with system processes. These APIs don't support Windows.
|
|
90
|
+
|
|
91
|
+
#### system
|
|
92
|
+
|
|
93
|
+
Set of helper functions needed to determine properties of the current operating system.
|
|
94
|
+
|
|
95
|
+
#### tempdir
|
|
96
|
+
|
|
97
|
+
Set of helpers that allow interactions with temporary folders.
|
|
98
|
+
|
|
99
|
+
#### timing
|
|
100
|
+
|
|
101
|
+
Helpers that allow to measure execution time.
|
|
102
|
+
|
|
103
|
+
#### util
|
|
104
|
+
|
|
105
|
+
Miscellaneous utilities.
|
|
106
|
+
|
|
107
|
+
#### zip
|
|
108
|
+
|
|
109
|
+
Helpers that allow to work with archives in .ZIP format.
|
|
60
110
|
|
|
61
111
|
|
|
62
112
|
## logger
|
|
@@ -85,10 +135,9 @@ Will produce
|
|
|
85
135
|
warn mymodule a warning
|
|
86
136
|
```
|
|
87
137
|
|
|
88
|
-
|
|
89
138
|
### Environment variables
|
|
90
139
|
|
|
91
|
-
There are two environment variable flags that affect the way `
|
|
140
|
+
There are two environment variable flags that affect the way `logger` works.
|
|
92
141
|
|
|
93
142
|
`_TESTING`
|
|
94
143
|
|
|
@@ -108,43 +157,43 @@ There are two environment variable flags that affect the way `appium-base-driver
|
|
|
108
157
|
`log[level](message)`
|
|
109
158
|
|
|
110
159
|
- logs to `level`
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
160
|
+
```js
|
|
161
|
+
import { logger } from 'appium-support';
|
|
162
|
+
let log = logger.getLogger('mymodule');
|
|
114
163
|
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
164
|
+
log.info('hi!');
|
|
165
|
+
// => info mymodule hi!
|
|
166
|
+
```
|
|
118
167
|
|
|
119
168
|
`log.unwrap()`
|
|
120
169
|
|
|
121
170
|
- retrieves the underlying [npmlog](https://github.com/npm/npmlog) object, in order to manage how logging is done at a low level (e.g., changing output streams, retrieving an array of messages, adding log levels, etc.).
|
|
122
171
|
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
172
|
+
```js
|
|
173
|
+
import { getLogger } from 'appium-base-driver';
|
|
174
|
+
let log = getLogger('mymodule');
|
|
126
175
|
|
|
127
|
-
|
|
176
|
+
log.info('hi!');
|
|
128
177
|
|
|
129
|
-
|
|
178
|
+
let npmlogger = log.unwrap();
|
|
130
179
|
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
180
|
+
// any `npmlog` methods
|
|
181
|
+
let logs = npmlogger.record;
|
|
182
|
+
// logs === [ { id: 0, level: 'info', prefix: 'mymodule', message: 'hi!', messageRaw: [ 'hi!' ] }]
|
|
183
|
+
```
|
|
135
184
|
|
|
136
185
|
`log.errorAndThrow(error)`
|
|
137
186
|
|
|
138
187
|
- logs the error passed in, at `error` level, and then throws the error. If the error passed in is not an instance of [Error](https://nodejs.org/api/errors.html#errors_class_error) (either directly, or a subclass of `Error`) it will be wrapped in a generic `Error` object.
|
|
139
188
|
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
189
|
+
```js
|
|
190
|
+
import { getLogger } from 'appium-base-driver';
|
|
191
|
+
let log = getLogger('mymodule');
|
|
143
192
|
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
193
|
+
// previously there would be two lines
|
|
194
|
+
log.error('This is an error');
|
|
195
|
+
throw new Error('This is an error');
|
|
147
196
|
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
197
|
+
// now is compacted
|
|
198
|
+
log.errorAndThrow('This is an error');
|
|
199
|
+
```
|
|
@@ -3,9 +3,8 @@
|
|
|
3
3
|
*
|
|
4
4
|
* @param {string} base64Image The string with base64 encoded image.
|
|
5
5
|
* Supports all image formats natively supported by Sharp library.
|
|
6
|
-
* @param {sharp.Region} rect The selected region of image
|
|
6
|
+
* @param {import('sharp').Region} rect The selected region of image
|
|
7
7
|
* @return {Promise<string>} base64 encoded string of cropped image
|
|
8
8
|
*/
|
|
9
|
-
export function cropBase64Image(base64Image: string, rect: sharp.Region): Promise<string>;
|
|
10
|
-
import sharp from "sharp";
|
|
9
|
+
export function cropBase64Image(base64Image: string, rect: import('sharp').Region): Promise<string>;
|
|
11
10
|
//# sourceMappingURL=image-util.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"image-util.d.ts","sourceRoot":"","sources":["../../lib/image-util.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"image-util.d.ts","sourceRoot":"","sources":["../../lib/image-util.js"],"names":[],"mappings":"AAoBA;;;;;;;GAOG;AACH,6CALW,MAAM,QAEN,OAAO,OAAO,EAAE,MAAM,GACrB,QAAQ,MAAM,CAAC,CAK1B"}
|
package/build/lib/image-util.js
CHANGED
|
@@ -1,20 +1,33 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
3
|
exports.cropBase64Image = void 0;
|
|
7
|
-
|
|
4
|
+
let _sharp;
|
|
5
|
+
/**
|
|
6
|
+
* @returns {import('sharp')}
|
|
7
|
+
*/
|
|
8
|
+
function requireSharp() {
|
|
9
|
+
if (!_sharp) {
|
|
10
|
+
try {
|
|
11
|
+
_sharp = require('sharp');
|
|
12
|
+
}
|
|
13
|
+
catch (err) {
|
|
14
|
+
throw new Error(`Cannot load the 'sharp' module needed for images processing. ` +
|
|
15
|
+
`Consider visiting https://sharp.pixelplumbing.com/install ` +
|
|
16
|
+
`for troubleshooting. Original error: ${err.message}`);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
return _sharp;
|
|
20
|
+
}
|
|
8
21
|
/**
|
|
9
22
|
* Crop the image by given rectangle (use base64 string as input and output)
|
|
10
23
|
*
|
|
11
24
|
* @param {string} base64Image The string with base64 encoded image.
|
|
12
25
|
* Supports all image formats natively supported by Sharp library.
|
|
13
|
-
* @param {sharp.Region} rect The selected region of image
|
|
26
|
+
* @param {import('sharp').Region} rect The selected region of image
|
|
14
27
|
* @return {Promise<string>} base64 encoded string of cropped image
|
|
15
28
|
*/
|
|
16
29
|
async function cropBase64Image(base64Image, rect) {
|
|
17
|
-
const buf = await (
|
|
30
|
+
const buf = await requireSharp()(Buffer.from(base64Image, 'base64')).extract(rect).toBuffer();
|
|
18
31
|
return buf.toString('base64');
|
|
19
32
|
}
|
|
20
33
|
exports.cropBase64Image = cropBase64Image;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"image-util.js","sourceRoot":"","sources":["../../lib/image-util.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"image-util.js","sourceRoot":"","sources":["../../lib/image-util.js"],"names":[],"mappings":";;;AAAA,IAAI,MAAM,CAAC;AAEX;;GAEG;AACH,SAAS,YAAY;IACnB,IAAI,CAAC,MAAM,EAAE;QACX,IAAI;YACF,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;SAC3B;QAAC,OAAO,GAAG,EAAE;YACZ,MAAM,IAAI,KAAK,CACb,+DAA+D;gBAC/D,4DAA4D;gBAC5D,wCAAwC,GAAG,CAAC,OAAO,EAAE,CACtD,CAAC;SACH;KACF;IACD,OAAO,MAAM,CAAC;AAChB,CAAC;AAED;;;;;;;GAOG;AACI,KAAK,UAAU,eAAe,CAAC,WAAW,EAAE,IAAI;IACrD,MAAM,GAAG,GAAG,MAAM,YAAY,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,WAAW,EAAE,QAAQ,CAAC,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,QAAQ,EAAE,CAAC;IAC9F,OAAO,GAAG,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;AAChC,CAAC;AAHD,0CAGC"}
|
package/lib/image-util.js
CHANGED
|
@@ -1,14 +1,32 @@
|
|
|
1
|
-
|
|
1
|
+
let _sharp;
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @returns {import('sharp')}
|
|
5
|
+
*/
|
|
6
|
+
function requireSharp() {
|
|
7
|
+
if (!_sharp) {
|
|
8
|
+
try {
|
|
9
|
+
_sharp = require('sharp');
|
|
10
|
+
} catch (err) {
|
|
11
|
+
throw new Error(
|
|
12
|
+
`Cannot load the 'sharp' module needed for images processing. ` +
|
|
13
|
+
`Consider visiting https://sharp.pixelplumbing.com/install ` +
|
|
14
|
+
`for troubleshooting. Original error: ${err.message}`
|
|
15
|
+
);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
return _sharp;
|
|
19
|
+
}
|
|
2
20
|
|
|
3
21
|
/**
|
|
4
22
|
* Crop the image by given rectangle (use base64 string as input and output)
|
|
5
23
|
*
|
|
6
24
|
* @param {string} base64Image The string with base64 encoded image.
|
|
7
25
|
* Supports all image formats natively supported by Sharp library.
|
|
8
|
-
* @param {sharp.Region} rect The selected region of image
|
|
26
|
+
* @param {import('sharp').Region} rect The selected region of image
|
|
9
27
|
* @return {Promise<string>} base64 encoded string of cropped image
|
|
10
28
|
*/
|
|
11
29
|
export async function cropBase64Image(base64Image, rect) {
|
|
12
|
-
const buf = await
|
|
30
|
+
const buf = await requireSharp()(Buffer.from(base64Image, 'base64')).extract(rect).toBuffer();
|
|
13
31
|
return buf.toString('base64');
|
|
14
32
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@appium/support",
|
|
3
|
-
"version": "4.0.
|
|
3
|
+
"version": "4.0.2",
|
|
4
4
|
"description": "Support libs used across appium packages",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"automation",
|
|
@@ -42,7 +42,7 @@
|
|
|
42
42
|
},
|
|
43
43
|
"dependencies": {
|
|
44
44
|
"@appium/tsconfig": "^0.3.0",
|
|
45
|
-
"@appium/types": "^0.
|
|
45
|
+
"@appium/types": "^0.12.0",
|
|
46
46
|
"@colors/colors": "1.5.0",
|
|
47
47
|
"@types/archiver": "5.3.2",
|
|
48
48
|
"@types/base64-stream": "1.0.2",
|
|
@@ -55,11 +55,12 @@
|
|
|
55
55
|
"@types/ncp": "2.0.5",
|
|
56
56
|
"@types/npmlog": "4.1.4",
|
|
57
57
|
"@types/pluralize": "0.0.29",
|
|
58
|
-
"@types/semver": "7.
|
|
58
|
+
"@types/semver": "7.5.0",
|
|
59
59
|
"@types/shell-quote": "1.7.1",
|
|
60
60
|
"@types/supports-color": "8.1.1",
|
|
61
61
|
"@types/teen_process": "2.0.0",
|
|
62
62
|
"@types/uuid": "9.0.1",
|
|
63
|
+
"@types/which": "3.0.0",
|
|
63
64
|
"archiver": "5.3.1",
|
|
64
65
|
"axios": "1.4.0",
|
|
65
66
|
"base64-stream": "1.0.0",
|
|
@@ -85,17 +86,19 @@
|
|
|
85
86
|
"read-pkg": "5.2.0",
|
|
86
87
|
"resolve-from": "5.0.0",
|
|
87
88
|
"sanitize-filename": "1.6.3",
|
|
88
|
-
"semver": "7.5.
|
|
89
|
-
"sharp": "0.32.1",
|
|
89
|
+
"semver": "7.5.1",
|
|
90
90
|
"shell-quote": "1.8.1",
|
|
91
91
|
"source-map-support": "0.5.21",
|
|
92
92
|
"supports-color": "8.1.1",
|
|
93
93
|
"teen_process": "2.0.2",
|
|
94
|
-
"type-fest": "3.
|
|
94
|
+
"type-fest": "3.11.1",
|
|
95
95
|
"uuid": "9.0.0",
|
|
96
96
|
"which": "3.0.1",
|
|
97
97
|
"yauzl": "2.10.0"
|
|
98
98
|
},
|
|
99
|
+
"optionalDependencies": {
|
|
100
|
+
"sharp": "0.32.1"
|
|
101
|
+
},
|
|
99
102
|
"engines": {
|
|
100
103
|
"node": "^14.17.0 || ^16.13.0 || >=18.0.0",
|
|
101
104
|
"npm": ">=8"
|
|
@@ -103,7 +106,7 @@
|
|
|
103
106
|
"publishConfig": {
|
|
104
107
|
"access": "public"
|
|
105
108
|
},
|
|
106
|
-
"gitHead": "
|
|
109
|
+
"gitHead": "d0ebbaa0c683eeba04d9d967af2d0fde76197950",
|
|
107
110
|
"typedoc": {
|
|
108
111
|
"entryPoint": "./lib/index.js"
|
|
109
112
|
}
|