appium-chromedriver 5.2.17 → 5.3.0

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/lib/types.ts ADDED
@@ -0,0 +1,101 @@
1
+ export interface ChromedriverOpts {
2
+ host?: string;
3
+ port?: string;
4
+ useSystemExecutable?: boolean;
5
+ executable?: string;
6
+ executableDir?: string;
7
+ bundleId?: string;
8
+ mappingPath?: string;
9
+ cmdArgs?: string[];
10
+ adb?: AdbStub;
11
+ verbose?: boolean;
12
+ logPath?: string;
13
+ disableBuildCheck?: boolean;
14
+ /**
15
+ * Output of the `/json/version` CDP command
16
+ */
17
+ details?: {info?: {Browser: string}};
18
+ isAutodownloadEnabled?: boolean;
19
+ }
20
+
21
+ export type ChromedriverVersionMapping = Record<string, string | null>;
22
+
23
+ export interface SyncOptions {
24
+ /**
25
+ * The list of chromedriver versions to sync. If empty (the default value)
26
+ * then all available chromedrivers are going to be downloaded and extracted
27
+ */
28
+ versions?: string[];
29
+ /**
30
+ * The minumum supported Chrome version that downloaded chromedrivers should
31
+ * support. Can match multiple drivers.
32
+ */
33
+ minBrowserVersion?: string | number;
34
+ /**
35
+ * System information used to filter out the list of the retrieved drivers. If
36
+ * not provided then the script will try to retrieve it.
37
+ */
38
+ osInfo?: OSInfo;
39
+ }
40
+
41
+ /**
42
+ * Information about the current operating system
43
+ */
44
+ export interface OSInfo {
45
+ /**
46
+ * The architecture of the host OS.
47
+ * Can be either `32` or `64`
48
+ */
49
+ arch: string;
50
+ /**
51
+ *
52
+ * The name of the host OS.
53
+ * Can be either `mac`, `windows` or `linux`
54
+ */
55
+ name: string;
56
+ }
57
+
58
+ /**
59
+ * Info about a Chromedriver version
60
+ */
61
+ export interface ChromedriverDetails {
62
+ /**
63
+ * Full url to corresponding driver in the remote storage
64
+ */
65
+ url: string;
66
+ /**
67
+ * CRC of driver archive
68
+ */
69
+ etag: string;
70
+ /**
71
+ * Chromedriver version
72
+ */
73
+ version: string;
74
+ minBrowserVersion: string | null;
75
+ }
76
+
77
+ /**
78
+ * The keys are unique driver identifiers (version/archive name). The corresponding values have {@linkcode ChromedriverDetails} containing chromedriver details
79
+ */
80
+ export type ChromedriverDetailsMapping = Record<string, ChromedriverDetails>;
81
+
82
+ export interface ChromedriverStorageClientOpts {
83
+ chromedriverDir?: string;
84
+ timeout?: number;
85
+ }
86
+
87
+ /**
88
+ * This is an instance of the `ADB` class from the `appium-adb` package.
89
+ * Remove this definition if/when `appium-adb` gets typed properly
90
+ * @see https://github.com/appium/appium-adb
91
+ */
92
+ export type AdbStub = {
93
+ getApiLevel: () => Promise<number>;
94
+ adbPort?: number;
95
+ executable: {
96
+ defaultArgs: string[];
97
+ };
98
+ getForwardList: () => Promise<string[]>;
99
+ removePortForward: (systemPort: string) => Promise<void>;
100
+ getPackageInfo: (pkg: string) => Promise<{versionName: string}>;
101
+ };
package/lib/utils.js CHANGED
@@ -1,17 +1,18 @@
1
1
  import _ from 'lodash';
2
- import { system, fs, node } from '@appium/support';
3
- import { BaseDriver } from '@appium/base-driver';
2
+ import {system, fs, node} from '@appium/support';
3
+ import {BaseDriver} from '@appium/base-driver';
4
4
  import path from 'path';
5
- import { compareVersions } from 'compare-versions';
5
+ import {compareVersions} from 'compare-versions';
6
6
  import axios from 'axios';
7
7
 
8
- const CD_CDN = process.env.npm_config_chromedriver_cdnurl
9
- || process.env.CHROMEDRIVER_CDNURL
10
- || 'https://chromedriver.storage.googleapis.com';
8
+ const CD_CDN =
9
+ process.env.npm_config_chromedriver_cdnurl ||
10
+ process.env.CHROMEDRIVER_CDNURL ||
11
+ 'https://chromedriver.storage.googleapis.com';
11
12
  const OS = {
12
13
  linux: 'linux',
13
14
  windows: 'win',
14
- mac: 'mac'
15
+ mac: 'mac',
15
16
  };
16
17
  const X64 = '64';
17
18
  const X86 = '32';
@@ -25,7 +26,7 @@ const MODULE_NAME = 'appium-chromedriver';
25
26
  * @returns {string} The full path to module root
26
27
  * @throws {Error} If the current module root folder cannot be determined
27
28
  */
28
- const getModuleRoot = _.memoize(function getModuleRoot () {
29
+ const getModuleRoot = _.memoize(function getModuleRoot() {
29
30
  const root = node.getModuleRootSync(MODULE_NAME, __filename);
30
31
  if (!root) {
31
32
  throw new Error(`Cannot find the root folder of the ${MODULE_NAME} Node.js module`);
@@ -37,27 +38,44 @@ const getModuleRoot = _.memoize(function getModuleRoot () {
37
38
  const CHROMEDRIVER_CHROME_MAPPING = require(path.join(getModuleRoot(), 'config', 'mapping.json'));
38
39
  const CD_BASE_DIR = path.join(getModuleRoot(), 'chromedriver');
39
40
 
40
- function getMostRecentChromedriver (mapping = CHROMEDRIVER_CHROME_MAPPING) {
41
+ /**
42
+ *
43
+ * @param {import('./types').ChromedriverVersionMapping} mapping
44
+ * @returns {string}
45
+ */
46
+ function getMostRecentChromedriver(mapping = CHROMEDRIVER_CHROME_MAPPING) {
41
47
  if (_.isEmpty(mapping)) {
42
48
  throw new Error('Unable to get most recent Chromedriver version from empty mapping');
43
49
  }
44
- return _.last(_.keys(mapping).sort(compareVersions));
50
+ return /** @type {string} */ (_.last(_.keys(mapping).sort(compareVersions)));
45
51
  }
46
52
 
47
- const CD_VER = process.env.npm_config_chromedriver_version
48
- || process.env.CHROMEDRIVER_VERSION
49
- || getMostRecentChromedriver();
53
+ const CD_VER =
54
+ process.env.npm_config_chromedriver_version ||
55
+ process.env.CHROMEDRIVER_VERSION ||
56
+ getMostRecentChromedriver();
50
57
 
51
- async function getChromeVersion (adb, bundleId) {
58
+ /**
59
+ *
60
+ * @param {import('./types').AdbStub} adb
61
+ * @param {string} bundleId
62
+ * @returns
63
+ */
64
+ async function getChromeVersion(adb, bundleId) {
52
65
  const {versionName} = await adb.getPackageInfo(bundleId);
53
66
  return versionName;
54
67
  }
55
68
 
56
- function getChromedriverDir (osName = getOsName()) {
69
+ function getChromedriverDir(osName = getOsName()) {
57
70
  return path.resolve(CD_BASE_DIR, osName);
58
71
  }
59
72
 
60
- async function getChromedriverBinaryPath (osName = getOsName()) {
73
+ /**
74
+ *
75
+ * @param {string} osName
76
+ * @returns {Promise<string>}
77
+ */
78
+ async function getChromedriverBinaryPath(osName = getOsName()) {
61
79
  const rootDir = getChromedriverDir(osName);
62
80
  const pathSuffix = osName === OS.windows ? '.exe' : '';
63
81
  const paths = await fs.glob(`${CD_EXECUTABLE_PREFIX}*${pathSuffix}`, {
@@ -69,23 +87,29 @@ async function getChromedriverBinaryPath (osName = getOsName()) {
69
87
  });
70
88
  return _.isEmpty(paths)
71
89
  ? path.resolve(rootDir, `${CD_EXECUTABLE_PREFIX}${pathSuffix}`)
72
- : _.first(paths);
90
+ : /** @type {string} */ (_.first(paths));
73
91
  }
74
92
 
75
- async function retrieveData (url, headers, opts = {}) {
76
- const {
77
- timeout = 5000,
78
- responseType = 'text',
79
- } = opts;
80
- return (await axios({
81
- url,
82
- headers,
83
- timeout,
84
- responseType,
85
- })).data;
93
+ /**
94
+ *
95
+ * @param {string} url
96
+ * @param {import('axios').AxiosRequestConfig['headers']} headers
97
+ * @param {Pick<import('axios').AxiosRequestConfig, 'timeout'|'responseType'>} opts
98
+ * @returns
99
+ */
100
+ async function retrieveData(url, headers, opts = {}) {
101
+ const {timeout = 5000, responseType = 'text'} = opts;
102
+ return (
103
+ await axios({
104
+ url,
105
+ headers,
106
+ timeout,
107
+ responseType,
108
+ })
109
+ ).data;
86
110
  }
87
111
 
88
- const getOsName = _.memoize(function getOsName () {
112
+ const getOsName = _.memoize(function getOsName() {
89
113
  if (system.isWindows()) {
90
114
  return OS.windows;
91
115
  }
@@ -95,29 +119,49 @@ const getOsName = _.memoize(function getOsName () {
95
119
  return OS.linux;
96
120
  });
97
121
 
98
- const getOsInfo = _.memoize(async function getOsInfo () {
99
- return {
100
- name: getOsName(),
101
- arch: await system.arch(),
102
- };
103
- });
122
+ const getOsInfo = _.memoize(
123
+ /**
124
+ * @returns {Promise<import('./types').OSInfo>}
125
+ */
126
+ async function getOsInfo() {
127
+ return {
128
+ name: getOsName(),
129
+ arch: String(await system.arch()),
130
+ };
131
+ }
132
+ );
104
133
 
105
134
  const getBaseDriverInstance = _.memoize(() => new BaseDriver({}, false));
106
135
 
107
136
  /**
108
137
  * Generates log prefix string
109
138
  *
110
- * @param {object} obj log owner instance
139
+ * @param {any} obj log owner instance
111
140
  * @param {string?} sessionId Optional session identifier
112
141
  * @returns {string}
113
142
  */
114
- function generateLogPrefix (obj, sessionId = null) {
115
- return getBaseDriverInstance().helpers.generateDriverLogPrefix(obj, sessionId);
143
+ function generateLogPrefix(obj, sessionId = null) {
144
+ return getBaseDriverInstance().helpers.generateDriverLogPrefix(
145
+ obj,
146
+ sessionId ? sessionId : undefined
147
+ );
116
148
  }
117
149
 
118
-
119
150
  export {
120
- getChromeVersion, getChromedriverDir, getChromedriverBinaryPath, getOsName,
121
- CD_BASE_DIR, CD_CDN, CD_VER, CHROMEDRIVER_CHROME_MAPPING, getMostRecentChromedriver,
122
- retrieveData, getOsInfo, OS, X64, X86, APPLE_ARM_SUFFIXES, generateLogPrefix,
151
+ getChromeVersion,
152
+ getChromedriverDir,
153
+ getChromedriverBinaryPath,
154
+ getOsName,
155
+ CD_BASE_DIR,
156
+ CD_CDN,
157
+ CD_VER,
158
+ CHROMEDRIVER_CHROME_MAPPING,
159
+ getMostRecentChromedriver,
160
+ retrieveData,
161
+ getOsInfo,
162
+ OS,
163
+ X64,
164
+ X86,
165
+ APPLE_ARM_SUFFIXES,
166
+ generateLogPrefix,
123
167
  };
package/package.json CHANGED
@@ -6,7 +6,7 @@
6
6
  "chrome",
7
7
  "android"
8
8
  ],
9
- "version": "5.2.17",
9
+ "version": "5.3.0",
10
10
  "author": "Appium Contributors",
11
11
  "license": "Apache-2.0",
12
12
  "repository": {
@@ -22,7 +22,8 @@
22
22
  },
23
23
  "lint-staged": {
24
24
  "*.js": [
25
- "eslint --fix"
25
+ "eslint --fix",
26
+ "prettier --write"
26
27
  ]
27
28
  },
28
29
  "prettier": {
@@ -39,11 +40,14 @@
39
40
  "index.js",
40
41
  "install-npm.js",
41
42
  "lib",
42
- "build/index.js",
43
- "build/lib",
43
+ "build",
44
+ "!build/test",
45
+ "!build/tsconfig.tsbuildinfo",
44
46
  "config/mapping.json",
45
- "CHANGELOG.md"
47
+ "CHANGELOG.md",
48
+ "tsconfig.json"
46
49
  ],
50
+ "types": "./build/index.d.ts",
47
51
  "dependencies": {
48
52
  "@appium/base-driver": "^9.1.0",
49
53
  "@appium/support": "^3.0.0",
@@ -60,48 +64,48 @@
60
64
  "teen_process": "^2.0.0",
61
65
  "xpath": "^0.x"
62
66
  },
63
- "pre-commit": [
64
- "precommit-msg",
65
- "precommit-lint"
66
- ],
67
67
  "scripts": {
68
- "build": "rimraf build && babel --out-dir=build/lib lib && babel --out-dir=build index.js",
68
+ "build": "tsc -b",
69
+ "clean": "tsc -b --clean",
69
70
  "dev": "npm run build -- --watch",
70
71
  "lint": "eslint .",
71
72
  "lint:fix": "npm run lint -- --fix",
73
+ "lint-staged": "lint-staged",
72
74
  "postinstall": "node install-npm.js",
73
- "precommit-msg": "echo 'Pre-commit checks...' && exit 0",
74
- "precommit-lint": "lint-staged",
75
- "prepare": "npm run build",
75
+ "prepare": "husky install && npm run build",
76
76
  "test": "mocha --exit --timeout 1m \"./test/unit/**/*-specs.js\"",
77
77
  "e2e-test": "mocha --exit --timeout 10m \"./test/functional/**/*-specs.js\""
78
78
  },
79
79
  "devDependencies": {
80
- "@appium/eslint-config-appium": "^6.0.0",
80
+ "@appium/eslint-config-appium": "^8.0.0",
81
81
  "@appium/test-support": "^3.0.0",
82
- "@babel/cli": "^7.18.10",
83
- "@babel/core": "^7.18.10",
84
- "@babel/eslint-parser": "^7.18.9",
85
- "@babel/plugin-transform-runtime": "^7.18.10",
86
- "@babel/preset-env": "^7.18.10",
87
- "@babel/register": "^7.18.9",
82
+ "@appium/tsconfig": "^0.2.4",
88
83
  "@semantic-release/changelog": "^6.0.1",
89
84
  "@semantic-release/git": "^10.0.1",
90
- "babel-plugin-source-map-support": "^2.2.0",
85
+ "@types/bluebird": "^3.5.38",
86
+ "@types/chai": "^4.3.4",
87
+ "@types/chai-as-promised": "^7.1.5",
88
+ "@types/lodash": "^4.14.191",
89
+ "@types/mocha": "^10.0.1",
90
+ "@types/node": "^18.13.0",
91
+ "@types/sinon": "^10.0.13",
92
+ "@types/teen_process": "^2.0.0",
91
93
  "chai": "^4.1.2",
92
94
  "chai-as-promised": "^7.1.1",
93
95
  "conventional-changelog-conventionalcommits": "^5.0.0",
94
- "eslint": "^7.32.0",
95
- "eslint-config-prettier": "^8.5.0",
96
- "eslint-plugin-import": "^2.26.0",
97
- "eslint-plugin-mocha": "^9.0.0",
98
- "eslint-plugin-promise": "^6.0.0",
99
- "lint-staged": "^13.0.3",
96
+ "eslint": "^8.34.0",
97
+ "eslint-config-prettier": "^8.6.0",
98
+ "eslint-plugin-import": "^2.27.5",
99
+ "eslint-plugin-mocha": "^10.1.0",
100
+ "eslint-plugin-promise": "^6.1.1",
101
+ "husky": "^8.0.3",
102
+ "lint-staged": "^13.1.2",
100
103
  "mocha": "^10.0.0",
101
- "pre-commit": "^1.1.3",
102
- "prettier": "^2.7.1",
104
+ "prettier": "^2.8.4",
103
105
  "rimraf": "^4.0.4",
104
106
  "semantic-release": "^20.0.2",
105
- "sinon": "^15.0.0"
107
+ "sinon": "^15.0.0",
108
+ "ts-node": "^10.9.1",
109
+ "typescript": "^4.9.5"
106
110
  }
107
111
  }
package/tsconfig.json ADDED
@@ -0,0 +1,11 @@
1
+ {
2
+ "extends": "@appium/tsconfig/tsconfig.json",
3
+ "compilerOptions": {
4
+ "strict": true,
5
+ "types": ["node"],
6
+ "outDir": "build",
7
+ "checkJs": true,
8
+ "lib": ["es2020", "dom"]
9
+ },
10
+ "include": ["index.js", "lib"]
11
+ }