@appium/plugin-test-support 1.0.4 → 1.1.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,114 +1,6 @@
1
+ import type { E2ESetupOpts } from './types';
1
2
  /**
2
3
  * Creates hooks to install a driver and a plugin and starts an Appium server w/ the given extensions.
3
- * @param {E2ESetupOpts} opts
4
- * @returns {void}
5
4
  */
6
- export function pluginE2EHarness(opts: E2ESetupOpts): void;
7
- export type E2ESetupOpts = {
8
- /**
9
- * - Path to Appium home directory
10
- */
11
- appiumHome?: string | undefined;
12
- /**
13
- * - Mocha "before all" hook function
14
- */
15
- before: Mocha.HookFunction<Mocha.Hook>;
16
- /**
17
- * - Mocha "after all" hook function
18
- */
19
- after: Mocha.HookFunction<Mocha.Hook>;
20
- /**
21
- * - Arguments to pass to Appium server
22
- */
23
- serverArgs?: Partial<{
24
- subcommand?: import("appium/types").CliCommand | undefined;
25
- configFile?: string | undefined;
26
- showConfig?: boolean | undefined;
27
- showDebugInfo?: boolean | undefined;
28
- shell?: boolean | undefined;
29
- throwInsteadOfExit?: boolean | undefined;
30
- logHandler?: ((...args: any[]) => void) | undefined;
31
- appiumHome?: string | undefined;
32
- showBuildInfo?: boolean | undefined;
33
- address?: string | undefined;
34
- allowCors?: NonNullable<boolean | undefined> | undefined;
35
- allowInsecure?: import("@appium/types").AllowInsecureConfig | undefined;
36
- basePath?: string | undefined;
37
- callbackAddress?: string | undefined;
38
- callbackPort?: number | undefined;
39
- debugLogSpacing?: NonNullable<boolean | undefined> | undefined;
40
- defaultCapabilities?: import("@appium/types").DefaultCapabilitiesConfig | undefined;
41
- denyInsecure?: import("@appium/types").DenyInsecureConfig | undefined;
42
- driver?: import("@appium/types").DriverConfig | undefined;
43
- keepAliveTimeout?: number | undefined;
44
- requestTimeout?: number | undefined;
45
- localTimezone?: NonNullable<boolean | undefined> | undefined;
46
- logFile?: string | undefined;
47
- logFilters?: import("@appium/types").LogFiltersConfig | undefined;
48
- loglevel?: NonNullable<import("@appium/types").LogLevelConfig | undefined> | undefined;
49
- logFormat?: NonNullable<import("@appium/types").LogFormatConfig | undefined> | undefined;
50
- logNoColors?: NonNullable<boolean | undefined> | undefined;
51
- logTimestamp?: NonNullable<boolean | undefined> | undefined;
52
- pluginsImportChunkSize?: number | undefined;
53
- driversImportChunkSize?: number | undefined;
54
- longStacktrace?: NonNullable<boolean | undefined> | undefined;
55
- noPermsCheck?: NonNullable<boolean | undefined> | undefined;
56
- nodeconfig?: import("@appium/types").NodeconfigConfig | undefined;
57
- plugin?: import("@appium/types").PluginConfig | undefined;
58
- port?: number | undefined;
59
- relaxedSecurityEnabled?: NonNullable<boolean | undefined> | undefined;
60
- shutdownTimeout?: number | undefined;
61
- sessionOverride?: NonNullable<boolean | undefined> | undefined;
62
- sslCertificatePath?: string | undefined;
63
- sslKeyPath?: string | undefined;
64
- strictCaps?: NonNullable<boolean | undefined> | undefined;
65
- tmpDir?: string | undefined;
66
- traceDir?: string | undefined;
67
- useDrivers?: import("@appium/types").UseDriversConfig | undefined;
68
- usePlugins?: import("@appium/types").UsePluginsConfig | undefined;
69
- webhook?: string | undefined;
70
- }> | undefined;
71
- /**
72
- * - Source of driver to install
73
- */
74
- driverSource: import("appium/types").InstallType & string;
75
- /**
76
- * - Package name of driver to install
77
- */
78
- driverPackage?: string | undefined;
79
- /**
80
- * - Name of driver to install
81
- */
82
- driverName: string;
83
- /**
84
- * - Spec of driver to install
85
- */
86
- driverSpec: string;
87
- /**
88
- * - Source of plugin to install
89
- */
90
- pluginSource: import("appium/types").InstallType & string;
91
- /**
92
- * - Package name of plugin to install
93
- */
94
- pluginPackage?: string | undefined;
95
- /**
96
- * - Spec of plugin to install
97
- */
98
- pluginSpec: string;
99
- /**
100
- * - Name of plugin to install
101
- */
102
- pluginName: string;
103
- /**
104
- * - Port to use for Appium server
105
- */
106
- port?: number | undefined;
107
- /**
108
- * - Host to use for Appium server
109
- */
110
- host?: string | undefined;
111
- };
112
- export type AppiumServer = import("@appium/types").AppiumServer;
113
- export type AppiumEnv = import("appium/types").AppiumEnv;
5
+ export declare function pluginE2EHarness(opts: E2ESetupOpts): void;
114
6
  //# sourceMappingURL=harness.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"harness.d.ts","sourceRoot":"","sources":["../../lib/harness.js"],"names":[],"mappings":"AAUA;;;;GAIG;AACH,uCAHW,YAAY,GACV,IAAI,CAmIhB;;;;;;;;;;;;;;;;;;;;;;;;uBAnEkD,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;kBA2ExC,OAAO,cAAc,EAAE,WAAW,GAAG,MAAM;;;;;;;;gBAE3C,MAAM;;;;gBACN,MAAM;;;;kBACN,OAAO,cAAc,EAAE,WAAW,GAAG,MAAM;;;;;;;;gBAE3C,MAAM;;;;gBACN,MAAM;;;;;;;;;;2BAMP,OAAO,eAAe,EAAE,YAAY;wBAIpC,OAAO,cAAc,EAAE,SAAS"}
1
+ {"version":3,"file":"harness.d.ts","sourceRoot":"","sources":["../../lib/harness.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAC,YAAY,EAAY,MAAM,SAAS,CAAC;AAMrD;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,YAAY,GAAG,IAAI,CAoHzD"}
@@ -5,141 +5,98 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.pluginE2EHarness = pluginE2EHarness;
7
7
  /* eslint-disable no-console */
8
+ const node_module_1 = require("node:module");
8
9
  const support_1 = require("appium/support");
9
10
  const appium_1 = require("appium");
10
11
  const get_port_1 = __importDefault(require("get-port"));
11
- // eslint-disable-next-line import/named
12
- const log_symbols_1 = require("log-symbols");
12
+ const log_symbols_1 = __importDefault(require("log-symbols"));
13
13
  const teen_process_1 = require("teen_process");
14
- const APPIUM_BIN = require.resolve('appium');
14
+ const _require = (0, node_module_1.createRequire)(__filename);
15
+ const APPIUM_BIN = _require.resolve('appium');
15
16
  /**
16
17
  * Creates hooks to install a driver and a plugin and starts an Appium server w/ the given extensions.
17
- * @param {E2ESetupOpts} opts
18
- * @returns {void}
19
18
  */
20
19
  function pluginE2EHarness(opts) {
21
- let { appiumHome, before, after, serverArgs = {}, driverSource, driverPackage, driverName, driverSpec, pluginSource, pluginPackage, pluginSpec, pluginName, port, host, } = opts;
22
- /**
23
- * @type {AppiumServer}
24
- */
20
+ const { appiumHome, before, after, serverArgs = {}, driverSource, driverPackage, driverName, driverSpec, pluginSource, pluginPackage, pluginSpec, pluginName, port, host, } = opts;
25
21
  let server;
26
- // eslint-disable-next-line mocha/no-top-level-hooks
27
22
  before(async function () {
23
+ // Lazy-load chai so smoke test (node ./build/lib/index.js --smoke-test) does not require it
28
24
  const chai = await import('chai');
29
- const chaiAsPromised = await import('chai-as-promised');
30
- chai.use(chaiAsPromised.default);
31
- chai.should();
25
+ const chaiAsPromised = (await import('chai-as-promised')).default;
26
+ chai.use(chaiAsPromised);
32
27
  const setupAppiumHome = async () => {
33
- /**
34
- * @type {AppiumEnv}
35
- */
36
28
  const env = { ...process.env };
37
29
  if (appiumHome) {
38
30
  env.APPIUM_HOME = appiumHome;
39
31
  await support_1.fs.mkdirp(appiumHome);
40
- console.log(`${log_symbols_1.info} Set \`APPIUM_HOME\` to ${appiumHome}`);
32
+ console.log(`${log_symbols_1.default.info} Set \`APPIUM_HOME\` to ${appiumHome}`);
41
33
  }
42
34
  return env;
43
35
  };
44
- /**
45
- *
46
- * @param {AppiumEnv} env
47
- */
48
36
  const installDriver = async (env) => {
49
- console.log(`${log_symbols_1.info} Checking if driver "${driverName}" is installed...`);
37
+ console.log(`${log_symbols_1.default.info} Checking if driver "${driverName}" is installed...`);
50
38
  const driverListArgs = [APPIUM_BIN, 'driver', 'list', '--json'];
51
- console.log(`${log_symbols_1.info} Running: ${process.execPath} ${driverListArgs.join(' ')}`);
39
+ console.log(`${log_symbols_1.default.info} Running: ${process.execPath} ${driverListArgs.join(' ')}`);
52
40
  const { stdout: driverListJson } = await (0, teen_process_1.exec)(process.execPath, driverListArgs, {
53
41
  env,
54
42
  });
55
43
  const installedDrivers = JSON.parse(driverListJson);
56
44
  if (!installedDrivers[driverName]?.installed) {
57
- console.log(`${log_symbols_1.warning} Driver "${driverName}" not installed; installing...`);
45
+ console.log(`${log_symbols_1.default.warning} Driver "${driverName}" not installed; installing...`);
58
46
  const driverArgs = [APPIUM_BIN, 'driver', 'install', '--source', driverSource, driverSpec];
59
47
  if (driverPackage) {
60
48
  driverArgs.push('--package', driverPackage);
61
49
  }
62
- console.log(`${log_symbols_1.info} Running: ${process.execPath} ${driverArgs.join(' ')}`);
50
+ console.log(`${log_symbols_1.default.info} Running: ${process.execPath} ${driverArgs.join(' ')}`);
63
51
  await (0, teen_process_1.exec)(process.execPath, driverArgs, {
64
52
  env,
65
53
  });
66
54
  }
67
- console.log(`${log_symbols_1.success} Installed driver "${driverName}"`);
55
+ console.log(`${log_symbols_1.default.success} Installed driver "${driverName}"`);
68
56
  };
69
- /**
70
- *
71
- * @param {AppiumEnv} env
72
- */
73
57
  const installPlugin = async (env) => {
74
- console.log(`${log_symbols_1.info} Checking if plugin "${pluginName}" is installed...`);
58
+ console.log(`${log_symbols_1.default.info} Checking if plugin "${pluginName}" is installed...`);
75
59
  const pluginListArgs = [APPIUM_BIN, 'plugin', 'list', '--json'];
76
60
  const { stdout: pluginListJson } = await (0, teen_process_1.exec)(process.execPath, pluginListArgs, {
77
61
  env,
78
62
  });
79
63
  const installedPlugins = JSON.parse(pluginListJson);
80
64
  if (!installedPlugins[pluginName]?.installed) {
81
- console.log(`${log_symbols_1.warning} Plugin "${pluginName}" not installed; installing...`);
65
+ console.log(`${log_symbols_1.default.warning} Plugin "${pluginName}" not installed; installing...`);
82
66
  const pluginArgs = [APPIUM_BIN, 'plugin', 'install', '--source', pluginSource, pluginSpec];
83
67
  if (pluginPackage) {
84
68
  pluginArgs.push('--package', pluginPackage);
85
69
  }
86
- console.log(`${log_symbols_1.info} Running: ${process.execPath} ${pluginArgs.join(' ')}`);
70
+ console.log(`${log_symbols_1.default.info} Running: ${process.execPath} ${pluginArgs.join(' ')}`);
87
71
  await (0, teen_process_1.exec)(process.execPath, pluginArgs, {
88
72
  env,
89
73
  });
90
74
  }
91
- console.log(`${log_symbols_1.success} Installed plugin "${pluginName}"`);
75
+ console.log(`${log_symbols_1.default.success} Installed plugin "${pluginName}"`);
92
76
  };
93
77
  const createServer = async () => {
94
- if (!port) {
95
- port = await (0, get_port_1.default)();
96
- }
97
- console.log(`${log_symbols_1.info} Will use port ${port} for Appium server`);
98
- this.port = port;
99
- /** @type {import('appium/types').Args} */
78
+ const resolvedPort = port ?? (await (0, get_port_1.default)());
79
+ console.log(`${log_symbols_1.default.info} Will use port ${resolvedPort} for Appium server`);
80
+ this.port = resolvedPort;
100
81
  const args = {
101
- port,
82
+ port: resolvedPort,
102
83
  address: host,
103
84
  usePlugins: [pluginName],
104
85
  useDrivers: [driverName],
105
86
  appiumHome,
106
87
  ...serverArgs,
107
88
  };
108
- server = /** @type {AppiumServer} */ (await (0, appium_1.main)(args));
89
+ server = (await (0, appium_1.main)(args));
109
90
  };
110
91
  const env = await setupAppiumHome();
111
92
  await installDriver(env);
112
93
  await installPlugin(env);
113
94
  await createServer();
114
95
  });
115
- // eslint-disable-next-line mocha/no-top-level-hooks
116
96
  after(async function () {
117
97
  if (server) {
118
98
  await server.close();
119
99
  }
120
100
  });
121
101
  }
122
- /**
123
- * @typedef E2ESetupOpts
124
- * @property {string} [appiumHome] - Path to Appium home directory
125
- * @property {Mocha.before} before - Mocha "before all" hook function
126
- * @property {Mocha.after} after - Mocha "after all" hook function
127
- * @property {Partial<import('appium/types').Args>} [serverArgs] - Arguments to pass to Appium server
128
- * @property {import('appium/types').InstallType & string} driverSource - Source of driver to install
129
- * @property {string} [driverPackage] - Package name of driver to install
130
- * @property {string} driverName - Name of driver to install
131
- * @property {string} driverSpec - Spec of driver to install
132
- * @property {import('appium/types').InstallType & string} pluginSource - Source of plugin to install
133
- * @property {string} [pluginPackage] - Package name of plugin to install
134
- * @property {string} pluginSpec - Spec of plugin to install
135
- * @property {string} pluginName - Name of plugin to install
136
- * @property {number} [port] - Port to use for Appium server
137
- * @property {string} [host] - Host to use for Appium server
138
- */
139
- /**
140
- * @typedef {import('@appium/types').AppiumServer} AppiumServer
141
- */
142
- /**
143
- * @typedef {import('appium/types').AppiumEnv} AppiumEnv
144
- */
145
102
  //# sourceMappingURL=harness.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"harness.js","sourceRoot":"","sources":["../../lib/harness.js"],"names":[],"mappings":";;;;;AAeA,4CAiIC;AAhJD,+BAA+B;AAC/B,4CAAkC;AAClC,mCAA4C;AAC5C,wDAA+B;AAC/B,wCAAwC;AACxC,6CAAmD;AACnD,+CAAkC;AAElC,MAAM,UAAU,GAAG,OAAO,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;AAE7C;;;;GAIG;AACH,SAAgB,gBAAgB,CAAC,IAAI;IACnC,IAAI,EACF,UAAU,EACV,MAAM,EACN,KAAK,EACL,UAAU,GAAG,EAAE,EACf,YAAY,EACZ,aAAa,EACb,UAAU,EACV,UAAU,EACV,YAAY,EACZ,aAAa,EACb,UAAU,EACV,UAAU,EACV,IAAI,EACJ,IAAI,GACL,GAAG,IAAI,CAAC;IAET;;OAEG;IACH,IAAI,MAAM,CAAC;IAEX,oDAAoD;IACpD,MAAM,CAAC,KAAK;QACV,MAAM,IAAI,GAAG,MAAM,MAAM,CAAC,MAAM,CAAC,CAAC;QAClC,MAAM,cAAc,GAAG,MAAM,MAAM,CAAC,kBAAkB,CAAC,CAAC;QACxD,IAAI,CAAC,GAAG,CAAC,cAAc,CAAC,OAAO,CAAC,CAAC;QACjC,IAAI,CAAC,MAAM,EAAE,CAAC;QAEd,MAAM,eAAe,GAAG,KAAK,IAAI,EAAE;YACjC;;eAEG;YACH,MAAM,GAAG,GAAG,EAAC,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C,CAAC;QAEF,MAAM,YAAY,GAAG,KAAK,IAAmB,EAAE;YAC7C,MAAM,YAAY,GAAG,IAAI,IAAI,CAAC,MAAM,IAAA,kBAAO,GAAE,CAAC,CAAC;YAC/C,OAAO,CAAC,GAAG,CAAC,GAAG,qBAAU,CAAC,IAAI,kBAAkB,YAAY,oBAAoB,CAAC,CAAC;YACjF,IAAwC,CAAC,IAAI,GAAG,YAAY,CAAC;YAE9D,MAAM,IAAI,GAAG;gBACX,IAAI,EAAE,YAAY;gBAClB,OAAO,EAAE,IAAI;gBACb,UAAU,EAAE,CAAC,UAAU,CAAC;gBACxB,UAAU,EAAE,CAAC,UAAU,CAAC;gBACxB,UAAU;gBACV,GAAG,UAAU;aACd,CAAC;YACF,MAAM,GAAG,CAAC,MAAM,IAAA,aAAY,EAAC,IAAI,CAAC,CAAiB,CAAC;QACtD,CAAC,CAAC;QAEF,MAAM,GAAG,GAAG,MAAM,eAAe,EAAE,CAAC;QACpC,MAAM,aAAa,CAAC,GAAG,CAAC,CAAC;QACzB,MAAM,aAAa,CAAC,GAAG,CAAC,CAAC;QACzB,MAAM,YAAY,EAAE,CAAC;IACvB,CAAC,CAAC,CAAC;IAEH,KAAK,CAAC,KAAK;QACT,IAAI,MAAM,EAAE,CAAC;YACX,MAAM,MAAM,CAAC,KAAK,EAAE,CAAC;QACvB,CAAC;IACH,CAAC,CAAC,CAAC;AACL,CAAC"}
@@ -0,0 +1,3 @@
1
+ export { pluginE2EHarness } from './harness';
2
+ export type { E2ESetupOpts, AppiumEnv } from './types';
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../lib/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,gBAAgB,EAAC,MAAM,WAAW,CAAC;AAC3C,YAAY,EAAC,YAAY,EAAE,SAAS,EAAC,MAAM,SAAS,CAAC"}
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.pluginE2EHarness = void 0;
4
+ var harness_1 = require("./harness");
5
+ Object.defineProperty(exports, "pluginE2EHarness", { enumerable: true, get: function () { return harness_1.pluginE2EHarness; } });
6
+ // Handle smoke test flag
7
+ if (require.main === module && process.argv[2] === '--smoke-test') {
8
+ process.exit(0);
9
+ }
10
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../lib/index.ts"],"names":[],"mappings":";;;AAAA,qCAA2C;AAAnC,2GAAA,gBAAgB,OAAA;AAGxB,yBAAyB;AACzB,IAAI,OAAO,CAAC,IAAI,KAAK,MAAM,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,cAAc,EAAE,CAAC;IAClE,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAClB,CAAC"}
@@ -0,0 +1,40 @@
1
+ /**
2
+ * Known environment variables concerning Appium
3
+ */
4
+ export interface AppiumEnv extends NodeJS.ProcessEnv {
5
+ APPIUM_HOME?: string;
6
+ }
7
+ /**
8
+ * Options for the plugin E2E harness.
9
+ */
10
+ export interface E2ESetupOpts {
11
+ /** Path to Appium home directory */
12
+ appiumHome?: string;
13
+ /** Mocha "before all" hook function */
14
+ before: (fn: (this: Mocha.Context) => Promise<void>) => void;
15
+ /** Mocha "after all" hook function */
16
+ after: (fn: (this: Mocha.Context) => Promise<void>) => void;
17
+ /** Arguments to pass to Appium server */
18
+ serverArgs?: Record<string, unknown>;
19
+ /** Source of driver to install (e.g. 'local', 'npm') */
20
+ driverSource: string;
21
+ /** Package name of driver to install */
22
+ driverPackage?: string;
23
+ /** Name of driver to install */
24
+ driverName: string;
25
+ /** Spec of driver to install */
26
+ driverSpec: string;
27
+ /** Source of plugin to install (e.g. 'local', 'npm') */
28
+ pluginSource: string;
29
+ /** Package name of plugin to install */
30
+ pluginPackage?: string;
31
+ /** Spec of plugin to install */
32
+ pluginSpec: string;
33
+ /** Name of plugin to install */
34
+ pluginName: string;
35
+ /** Port to use for Appium server */
36
+ port?: number;
37
+ /** Host to use for Appium server */
38
+ host?: string;
39
+ }
40
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../lib/types.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,WAAW,SAAU,SAAQ,MAAM,CAAC,UAAU;IAClD,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAED;;GAEG;AACH,MAAM,WAAW,YAAY;IAC3B,oCAAoC;IACpC,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,uCAAuC;IACvC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC,IAAI,EAAE,KAAK,CAAC,OAAO,KAAK,OAAO,CAAC,IAAI,CAAC,KAAK,IAAI,CAAC;IAC7D,sCAAsC;IACtC,KAAK,EAAE,CAAC,EAAE,EAAE,CAAC,IAAI,EAAE,KAAK,CAAC,OAAO,KAAK,OAAO,CAAC,IAAI,CAAC,KAAK,IAAI,CAAC;IAC5D,yCAAyC;IACzC,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACrC,wDAAwD;IACxD,YAAY,EAAE,MAAM,CAAC;IACrB,wCAAwC;IACxC,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,gCAAgC;IAChC,UAAU,EAAE,MAAM,CAAC;IACnB,gCAAgC;IAChC,UAAU,EAAE,MAAM,CAAC;IACnB,wDAAwD;IACxD,YAAY,EAAE,MAAM,CAAC;IACrB,wCAAwC;IACxC,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,gCAAgC;IAChC,UAAU,EAAE,MAAM,CAAC;IACnB,gCAAgC;IAChC,UAAU,EAAE,MAAM,CAAC;IACnB,oCAAoC;IACpC,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,oCAAoC;IACpC,IAAI,CAAC,EAAE,MAAM,CAAC;CACf"}
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../lib/types.ts"],"names":[],"mappings":""}
package/lib/harness.ts ADDED
@@ -0,0 +1,134 @@
1
+ /* eslint-disable no-console */
2
+ import {createRequire} from 'node:module';
3
+ import {fs} from 'appium/support';
4
+ import {main as appiumServer} from 'appium';
5
+ import getPort from 'get-port';
6
+ import logSymbols from 'log-symbols';
7
+ import {exec} from 'teen_process';
8
+ import type {AppiumServer} from '@appium/types';
9
+ import type {E2ESetupOpts, AppiumEnv} from './types';
10
+
11
+ declare const __filename: string;
12
+ const _require = createRequire(__filename);
13
+ const APPIUM_BIN = _require.resolve('appium') as string;
14
+
15
+ /**
16
+ * Creates hooks to install a driver and a plugin and starts an Appium server w/ the given extensions.
17
+ */
18
+ export function pluginE2EHarness(opts: E2ESetupOpts): void {
19
+ const {
20
+ appiumHome,
21
+ before,
22
+ after,
23
+ serverArgs = {},
24
+ driverSource,
25
+ driverPackage,
26
+ driverName,
27
+ driverSpec,
28
+ pluginSource,
29
+ pluginPackage,
30
+ pluginSpec,
31
+ pluginName,
32
+ port,
33
+ host,
34
+ } = opts;
35
+
36
+ let server: AppiumServer | undefined;
37
+
38
+ before(async function (this: Mocha.Context) {
39
+ // Lazy-load chai so smoke test (node ./build/lib/index.js --smoke-test) does not require it
40
+ const chai = await import('chai');
41
+ const chaiAsPromised = (await import('chai-as-promised')).default;
42
+ chai.use(chaiAsPromised);
43
+
44
+ const setupAppiumHome = async (): Promise<AppiumEnv> => {
45
+ const env: AppiumEnv = {...process.env};
46
+
47
+ if (appiumHome) {
48
+ env.APPIUM_HOME = appiumHome;
49
+ await fs.mkdirp(appiumHome);
50
+ console.log(`${logSymbols.info} Set \`APPIUM_HOME\` to ${appiumHome}`);
51
+ }
52
+
53
+ return env;
54
+ };
55
+
56
+ const installDriver = async (env: AppiumEnv): Promise<void> => {
57
+ console.log(`${logSymbols.info} Checking if driver "${driverName}" is installed...`);
58
+ const driverListArgs = [APPIUM_BIN, 'driver', 'list', '--json'];
59
+ console.log(`${logSymbols.info} Running: ${process.execPath} ${driverListArgs.join(' ')}`);
60
+ const {stdout: driverListJson} = await exec(process.execPath, driverListArgs, {
61
+ env,
62
+ });
63
+ const installedDrivers = JSON.parse(driverListJson) as Record<
64
+ string,
65
+ {installed?: boolean}
66
+ >;
67
+
68
+ if (!installedDrivers[driverName]?.installed) {
69
+ console.log(`${logSymbols.warning} Driver "${driverName}" not installed; installing...`);
70
+ const driverArgs = [APPIUM_BIN, 'driver', 'install', '--source', driverSource, driverSpec];
71
+ if (driverPackage) {
72
+ driverArgs.push('--package', driverPackage);
73
+ }
74
+ console.log(`${logSymbols.info} Running: ${process.execPath} ${driverArgs.join(' ')}`);
75
+ await exec(process.execPath, driverArgs, {
76
+ env,
77
+ });
78
+ }
79
+ console.log(`${logSymbols.success} Installed driver "${driverName}"`);
80
+ };
81
+
82
+ const installPlugin = async (env: AppiumEnv): Promise<void> => {
83
+ console.log(`${logSymbols.info} Checking if plugin "${pluginName}" is installed...`);
84
+ const pluginListArgs = [APPIUM_BIN, 'plugin', 'list', '--json'];
85
+ const {stdout: pluginListJson} = await exec(process.execPath, pluginListArgs, {
86
+ env,
87
+ });
88
+ const installedPlugins = JSON.parse(pluginListJson) as Record<
89
+ string,
90
+ {installed?: boolean}
91
+ >;
92
+
93
+ if (!installedPlugins[pluginName]?.installed) {
94
+ console.log(`${logSymbols.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(`${logSymbols.info} Running: ${process.execPath} ${pluginArgs.join(' ')}`);
100
+ await exec(process.execPath, pluginArgs, {
101
+ env,
102
+ });
103
+ }
104
+ console.log(`${logSymbols.success} Installed plugin "${pluginName}"`);
105
+ };
106
+
107
+ const createServer = async (): Promise<void> => {
108
+ const resolvedPort = port ?? (await getPort());
109
+ console.log(`${logSymbols.info} Will use port ${resolvedPort} for Appium server`);
110
+ (this as Mocha.Context & {port?: number}).port = resolvedPort;
111
+
112
+ const args = {
113
+ port: resolvedPort,
114
+ address: host,
115
+ usePlugins: [pluginName],
116
+ useDrivers: [driverName],
117
+ appiumHome,
118
+ ...serverArgs,
119
+ };
120
+ server = (await appiumServer(args)) as AppiumServer;
121
+ };
122
+
123
+ const env = await setupAppiumHome();
124
+ await installDriver(env);
125
+ await installPlugin(env);
126
+ await createServer();
127
+ });
128
+
129
+ after(async function () {
130
+ if (server) {
131
+ await server.close();
132
+ }
133
+ });
134
+ }
package/lib/index.ts ADDED
@@ -0,0 +1,7 @@
1
+ export {pluginE2EHarness} from './harness';
2
+ export type {E2ESetupOpts, AppiumEnv} from './types';
3
+
4
+ // Handle smoke test flag
5
+ if (require.main === module && process.argv[2] === '--smoke-test') {
6
+ process.exit(0);
7
+ }
package/lib/types.ts ADDED
@@ -0,0 +1,40 @@
1
+ /**
2
+ * Known environment variables concerning Appium
3
+ */
4
+ export interface AppiumEnv extends NodeJS.ProcessEnv {
5
+ APPIUM_HOME?: string;
6
+ }
7
+
8
+ /**
9
+ * Options for the plugin E2E harness.
10
+ */
11
+ export interface E2ESetupOpts {
12
+ /** Path to Appium home directory */
13
+ appiumHome?: string;
14
+ /** Mocha "before all" hook function */
15
+ before: (fn: (this: Mocha.Context) => Promise<void>) => void;
16
+ /** Mocha "after all" hook function */
17
+ after: (fn: (this: Mocha.Context) => Promise<void>) => void;
18
+ /** Arguments to pass to Appium server */
19
+ serverArgs?: Record<string, unknown>;
20
+ /** Source of driver to install (e.g. 'local', 'npm') */
21
+ driverSource: string;
22
+ /** Package name of driver to install */
23
+ driverPackage?: string;
24
+ /** Name of driver to install */
25
+ driverName: string;
26
+ /** Spec of driver to install */
27
+ driverSpec: string;
28
+ /** Source of plugin to install (e.g. 'local', 'npm') */
29
+ pluginSource: string;
30
+ /** Package name of plugin to install */
31
+ pluginPackage?: string;
32
+ /** Spec of plugin to install */
33
+ pluginSpec: string;
34
+ /** Name of plugin to install */
35
+ pluginName: string;
36
+ /** Port to use for Appium server */
37
+ port?: number;
38
+ /** Host to use for Appium server */
39
+ host?: string;
40
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@appium/plugin-test-support",
3
- "version": "1.0.4",
3
+ "version": "1.1.0",
4
4
  "description": "Testing utilities for Appium plugins",
5
5
  "keywords": [
6
6
  "automation",
@@ -23,29 +23,28 @@
23
23
  },
24
24
  "license": "Apache-2.0",
25
25
  "author": "https://github.com/appium",
26
- "main": "index.js",
27
- "types": "build/lib/harness.d.ts",
26
+ "main": "./build/lib/index.js",
27
+ "types": "./build/lib/index.d.ts",
28
28
  "directories": {
29
29
  "lib": "lib"
30
30
  },
31
31
  "files": [
32
+ "build/lib",
32
33
  "lib",
33
- "index.js",
34
- "build",
35
- "tsconfig.json",
36
- "!build/tsconfig.tsbuildinfo"
34
+ "tsconfig.json"
37
35
  ],
38
36
  "scripts": {
39
37
  "test": "npm run test:unit",
40
- "test:smoke": "node ./index.js",
38
+ "test:smoke": "node ./build/lib/index.js --smoke-test",
41
39
  "test:unit": "exit 0"
42
40
  },
41
+ "devDependencies": {
42
+ "@appium/types": "^1.2.1"
43
+ },
43
44
  "dependencies": {
44
- "@appium/types": "^1.1.2",
45
- "get-port": "5.1.1",
46
- "log-symbols": "4.1.0",
47
- "source-map-support": "0.5.21",
48
- "teen_process": "3.0.4"
45
+ "get-port": "7.1.0",
46
+ "log-symbols": "7.0.1",
47
+ "teen_process": "4.0.10"
49
48
  },
50
49
  "peerDependencies": {
51
50
  "appium": "^3.0.0-beta.0",
@@ -58,5 +57,5 @@
58
57
  "publishConfig": {
59
58
  "access": "public"
60
59
  },
61
- "gitHead": "9004554879687ddad51d3afdf8c711b027efbd99"
60
+ "gitHead": "980a121804ae006db879fb6860f627ac36174c15"
62
61
  }
package/tsconfig.json CHANGED
@@ -3,12 +3,12 @@
3
3
  "compilerOptions": {
4
4
  "rootDir": ".",
5
5
  "outDir": "build",
6
- "checkJs": true,
7
6
  "paths": {
8
7
  "@appium/types": ["../types"],
9
- "appium/support": ["../appium/support"]
8
+ "appium/support": ["../support"],
9
+ "appium": ["../appium"]
10
10
  },
11
- "types": ["mocha", "chai", "sinon", "chai-as-promised"]
11
+ "types": ["mocha", "chai", "sinon", "chai-as-promised", "node"]
12
12
  },
13
13
  "include": ["./lib"],
14
14
  "references": [{"path": "../types"}, {"path": "../support"}]
package/index.js DELETED
@@ -1 +0,0 @@
1
- module.exports = require('./build/lib/harness');
package/lib/harness.js DELETED
@@ -1,171 +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
- // eslint-disable-next-line import/named
6
- import {info, success, warning} from 'log-symbols';
7
- import {exec} from 'teen_process';
8
-
9
- const APPIUM_BIN = require.resolve('appium');
10
-
11
- /**
12
- * Creates hooks to install a driver and a plugin and starts an Appium server w/ the given extensions.
13
- * @param {E2ESetupOpts} opts
14
- * @returns {void}
15
- */
16
- export function pluginE2EHarness(opts) {
17
- let {
18
- appiumHome,
19
- before,
20
- after,
21
- serverArgs = {},
22
- driverSource,
23
- driverPackage,
24
- driverName,
25
- driverSpec,
26
- pluginSource,
27
- pluginPackage,
28
- pluginSpec,
29
- pluginName,
30
- port,
31
- host,
32
- } = opts;
33
-
34
- /**
35
- * @type {AppiumServer}
36
- */
37
- let server;
38
-
39
- // eslint-disable-next-line mocha/no-top-level-hooks
40
- before(async function () {
41
- const chai = await import('chai');
42
- const chaiAsPromised = await import('chai-as-promised');
43
- chai.use(chaiAsPromised.default);
44
- chai.should();
45
-
46
- const setupAppiumHome = async () => {
47
- /**
48
- * @type {AppiumEnv}
49
- */
50
- const env = {...process.env};
51
-
52
- if (appiumHome) {
53
- env.APPIUM_HOME = appiumHome;
54
- await fs.mkdirp(appiumHome);
55
- console.log(`${info} Set \`APPIUM_HOME\` to ${appiumHome}`);
56
- }
57
-
58
- return env;
59
- };
60
-
61
- /**
62
- *
63
- * @param {AppiumEnv} env
64
- */
65
- const installDriver = async (env) => {
66
- console.log(`${info} Checking if driver "${driverName}" is installed...`);
67
- const driverListArgs = [APPIUM_BIN, 'driver', 'list', '--json'];
68
- console.log(`${info} Running: ${process.execPath} ${driverListArgs.join(' ')}`);
69
- const {stdout: driverListJson} = await exec(process.execPath, driverListArgs, {
70
- env,
71
- });
72
- const installedDrivers = JSON.parse(driverListJson);
73
-
74
- if (!installedDrivers[driverName]?.installed) {
75
- console.log(`${warning} Driver "${driverName}" not installed; installing...`);
76
- const driverArgs = [APPIUM_BIN, 'driver', 'install', '--source', driverSource, driverSpec];
77
- if (driverPackage) {
78
- driverArgs.push('--package', driverPackage);
79
- }
80
- console.log(`${info} Running: ${process.execPath} ${driverArgs.join(' ')}`);
81
- await exec(process.execPath, driverArgs, {
82
- env,
83
- });
84
- }
85
- console.log(`${success} Installed driver "${driverName}"`);
86
- };
87
-
88
- /**
89
- *
90
- * @param {AppiumEnv} env
91
- */
92
- const installPlugin = async (env) => {
93
- console.log(`${info} Checking if plugin "${pluginName}" is installed...`);
94
- const pluginListArgs = [APPIUM_BIN, 'plugin', 'list', '--json'];
95
- const {stdout: pluginListJson} = await exec(process.execPath, pluginListArgs, {
96
- env,
97
- });
98
- const installedPlugins = JSON.parse(pluginListJson);
99
-
100
- if (!installedPlugins[pluginName]?.installed) {
101
- console.log(`${warning} Plugin "${pluginName}" not installed; installing...`);
102
- const pluginArgs = [APPIUM_BIN, 'plugin', 'install', '--source', pluginSource, pluginSpec];
103
- if (pluginPackage) {
104
- pluginArgs.push('--package', pluginPackage);
105
- }
106
- console.log(`${info} Running: ${process.execPath} ${pluginArgs.join(' ')}`);
107
- await exec(process.execPath, pluginArgs, {
108
- env,
109
- });
110
- }
111
- console.log(`${success} Installed plugin "${pluginName}"`);
112
- };
113
-
114
- const createServer = async () => {
115
- if (!port) {
116
- port = await getPort();
117
- }
118
- console.log(`${info} Will use port ${port} for Appium server`);
119
- this.port = port;
120
-
121
- /** @type {import('appium/types').Args} */
122
- const args = {
123
- port,
124
- address: host,
125
- usePlugins: [pluginName],
126
- useDrivers: [driverName],
127
- appiumHome,
128
- ...serverArgs,
129
- };
130
- server = /** @type {AppiumServer} */ (await appiumServer(args));
131
- };
132
-
133
- const env = await setupAppiumHome();
134
- await installDriver(env);
135
- await installPlugin(env);
136
- await createServer();
137
- });
138
-
139
- // eslint-disable-next-line mocha/no-top-level-hooks
140
- after(async function () {
141
- if (server) {
142
- await server.close();
143
- }
144
- });
145
- }
146
-
147
- /**
148
- * @typedef E2ESetupOpts
149
- * @property {string} [appiumHome] - Path to Appium home directory
150
- * @property {Mocha.before} before - Mocha "before all" hook function
151
- * @property {Mocha.after} after - Mocha "after all" hook function
152
- * @property {Partial<import('appium/types').Args>} [serverArgs] - Arguments to pass to Appium server
153
- * @property {import('appium/types').InstallType & string} driverSource - Source of driver to install
154
- * @property {string} [driverPackage] - Package name of driver to install
155
- * @property {string} driverName - Name of driver to install
156
- * @property {string} driverSpec - Spec of driver to install
157
- * @property {import('appium/types').InstallType & string} pluginSource - Source of plugin to install
158
- * @property {string} [pluginPackage] - Package name of plugin to install
159
- * @property {string} pluginSpec - Spec of plugin to install
160
- * @property {string} pluginName - Name of plugin to install
161
- * @property {number} [port] - Port to use for Appium server
162
- * @property {string} [host] - Host to use for Appium server
163
- */
164
-
165
- /**
166
- * @typedef {import('@appium/types').AppiumServer} AppiumServer
167
- */
168
-
169
- /**
170
- * @typedef {import('appium/types').AppiumEnv} AppiumEnv
171
- */