@appium/test-support 1.5.0 → 2.0.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.
@@ -1,163 +0,0 @@
1
- /* eslint-disable no-console */
2
- import {fs} from 'appium/support';
3
- import {main as appiumServer} from 'appium';
4
- import getPort from 'get-port';
5
- import {info, success, warning} from 'log-symbols';
6
- import {exec} from 'teen_process';
7
-
8
- const APPIUM_BIN = require.resolve('appium');
9
-
10
- /**
11
- * Creates hooks to install a driver and a plugin and starts an Appium server w/ the given extensions.
12
- * @param {E2ESetupOpts} opts
13
- * @returns {void}
14
- */
15
- export function pluginE2EHarness(opts) {
16
- let {
17
- appiumHome,
18
- before,
19
- after,
20
- serverArgs = {},
21
- driverSource,
22
- driverPackage,
23
- driverName,
24
- driverSpec,
25
- pluginSource,
26
- pluginPackage,
27
- pluginSpec,
28
- pluginName,
29
- port,
30
- host,
31
- } = opts;
32
-
33
- /**
34
- * @type {AppiumServer}
35
- */
36
- let server;
37
-
38
- before(async function () {
39
- const setupAppiumHome = async () => {
40
- /**
41
- * @type {AppiumEnv}
42
- */
43
- const env = {...process.env};
44
-
45
- if (appiumHome) {
46
- env.APPIUM_HOME = appiumHome;
47
- await fs.mkdirp(appiumHome);
48
- console.log(`${info} Set \`APPIUM_HOME\` to ${appiumHome}`);
49
- }
50
-
51
- return env;
52
- };
53
-
54
- /**
55
- *
56
- * @param {AppiumEnv} env
57
- */
58
- const installDriver = async (env) => {
59
- console.log(`${info} Checking if driver "${driverName}" is installed...`);
60
- const driverListArgs = [APPIUM_BIN, 'driver', 'list', '--json'];
61
- console.log(`${info} Running: ${process.execPath} ${driverListArgs.join(' ')}`);
62
- const {stdout: driverListJson} = await exec(process.execPath, driverListArgs, {
63
- env,
64
- });
65
- const installedDrivers = JSON.parse(driverListJson);
66
-
67
- if (!installedDrivers[driverName]?.installed) {
68
- console.log(`${warning} Driver "${driverName}" not installed; installing...`);
69
- const driverArgs = [APPIUM_BIN, 'driver', 'install', '--source', driverSource, driverSpec];
70
- if (driverPackage) {
71
- driverArgs.push('--package', driverPackage);
72
- }
73
- console.log(`${info} Running: ${process.execPath} ${driverArgs.join(' ')}`);
74
- await exec(process.execPath, driverArgs, {
75
- env,
76
- });
77
- }
78
- console.log(`${success} Installed driver "${driverName}"`);
79
- };
80
-
81
- /**
82
- *
83
- * @param {AppiumEnv} env
84
- */
85
- const installPlugin = async (env) => {
86
- console.log(`${info} Checking if plugin "${pluginName}" is installed...`);
87
- const pluginListArgs = [APPIUM_BIN, 'plugin', 'list', '--json'];
88
- const {stdout: pluginListJson} = await exec(process.execPath, pluginListArgs, {
89
- env,
90
- });
91
- const installedPlugins = JSON.parse(pluginListJson);
92
-
93
- if (!installedPlugins[pluginName]?.installed) {
94
- console.log(`${warning} Plugin "${pluginName}" not installed; installing...`);
95
- const pluginArgs = [APPIUM_BIN, 'plugin', 'install', '--source', pluginSource, pluginSpec];
96
- if (pluginPackage) {
97
- pluginArgs.push('--package', pluginPackage);
98
- }
99
- console.log(`${info} Running: ${process.execPath} ${pluginArgs.join(' ')}`);
100
- await exec(process.execPath, pluginArgs, {
101
- env,
102
- });
103
- }
104
- console.log(`${success} Installed plugin "${pluginName}"`);
105
- };
106
-
107
- const createServer = async () => {
108
- if (!port) {
109
- port = await getPort();
110
- }
111
- console.log(`${info} Will use port ${port} for Appium server`);
112
- this.port = port;
113
-
114
- /** @type {import('appium').Args} */
115
- const args = {
116
- port,
117
- address: host,
118
- usePlugins: [pluginName],
119
- useDrivers: [driverName],
120
- appiumHome,
121
- ...serverArgs,
122
- };
123
- server = /** @type {AppiumServer} */ (await appiumServer(args));
124
- };
125
-
126
- const env = await setupAppiumHome();
127
- await installDriver(env);
128
- await installPlugin(env);
129
- await createServer();
130
- });
131
-
132
- after(async function () {
133
- if (server) {
134
- await server.close();
135
- }
136
- });
137
- }
138
-
139
- /**
140
- * @typedef E2ESetupOpts
141
- * @property {string} [appiumHome] - Path to Appium home directory
142
- * @property {Mocha.before} before - Mocha "before all" hook function
143
- * @property {Mocha.after} after - Mocha "after all" hook function
144
- * @property {Partial<import('appium').Args>} [serverArgs] - Arguments to pass to Appium server
145
- * @property {import('appium/types').InstallType & string} driverSource - Source of driver to install
146
- * @property {string} [driverPackage] - Package name of driver to install
147
- * @property {string} driverName - Name of driver to install
148
- * @property {string} driverSpec - Spec of driver to install
149
- * @property {import('appium/types').InstallType & string} pluginSource - Source of plugin to install
150
- * @property {string} [pluginPackage] - Package name of plugin to install
151
- * @property {string} pluginSpec - Spec of plugin to install
152
- * @property {string} pluginName - Name of plugin to install
153
- * @property {number} [port] - Port to use for Appium server
154
- * @property {string} [host] - Host to use for Appium server
155
- */
156
-
157
- /**
158
- * @typedef {import('@appium/types').AppiumServer} AppiumServer
159
- */
160
-
161
- /**
162
- * @typedef {import('appium/types').AppiumEnv} AppiumEnv
163
- */