test(images-plugin): attempt to fix e2e test
MODIFY
packages/base-plugin/test/helpers.js
packages/base-plugin/test/helpers.js
/* eslint-disable no-console */
-import { exec } from 'teen_process';
import { fs } from '@appium/support';
import { main as appiumServer } from 'appium';
import getPort from 'get-port';
import { info, success, warning } from 'log-symbols';
+import { exec } from 'teen_process';
const APPIUM_BIN = require.resolve('appium');
@@ -27,67 +27,116 @@ function e2eSetup (opts = {}) {
} = opts;
before(async function () {
- let env = {...process.env};
+ const setupAppiumHome = async () => {
+ const env = {...process.env};
+
if (appiumHome) {
env.APPIUM_HOME = appiumHome;
await fs.mkdirp(appiumHome);
console.log(`${info} Set \`APPIUM_HOME\` to ${appiumHome}`);
}
- const oldTimeout = this.timeout();
- this.timeout(0);
- try {
+
+ return env;
+ };
+
+ const installDriver = async (env) => {
console.log(`${info} Checking if driver "${driverName}" is installed...`);
- let listArgs = [APPIUM_BIN, 'driver', 'list', '--json'];
- console.log(`${info} Running: ${process.execPath} ${listArgs.join(' ')}`);
- let {stdout} = await exec(process.execPath, listArgs, {
- env
- });
- let installed = JSON.parse(stdout);
+ const driverListArgs = [APPIUM_BIN, 'driver', 'list', '--json'];
+ console.log(
+ `${info} Running: ${process.execPath} ${driverListArgs.join(' ')}`,
+ );
+ const {stdout: driverListJson} = await exec(
+ process.execPath,
+ driverListArgs,
+ {
+ env,
+ },
+ );
+ const installedDrivers = JSON.parse(driverListJson);
- if (!installed[driverName]?.installed) {
- console.log(`${warning} Driver "${driverName}" not installed; installing...`);
- const driverArgs = [APPIUM_BIN, 'driver', 'install', '--source', driverSource, driverSpec];
- console.log(`${info} Running: ${process.execPath} ${driverArgs.join(' ')}`);
+ if (!installedDrivers[driverName]?.installed) {
+ console.log(
+ `${warning} Driver "${driverName}" not installed; installing...`,
+ );
+ const driverArgs = [
+ APPIUM_BIN,
+ 'driver',
+ 'install',
+ '--source',
+ driverSource,
+ driverSpec,
+ ];
if (driverPackage) {
driverArgs.push('--package', driverPackage);
}
+ console.log(
+ `${info} Running: ${process.execPath} ${driverArgs.join(' ')}`,
+ );
await exec(process.execPath, driverArgs, {
- env
+ env,
});
}
console.log(`${success} Installed driver "${driverName}"`);
+ };
+ const installPlugin = async (env) => {
console.log(`${info} Checking if plugin "${pluginName}" is installed...`);
- listArgs = [APPIUM_BIN, 'plugin', 'list', '--json'];
- ({stdout} = await exec(process.execPath, listArgs, {
- env
- }));
- installed = JSON.parse(stdout);
-
- if (!installed[pluginName]?.installed) {
- console.log(`${warning} Plugin "${pluginName}" not installed; installing...`);
- const pluginArgs = [APPIUM_BIN, 'plugin', 'install', '--source', pluginSource, pluginSpec];
- console.log(`${info} Running: ${process.execPath} ${pluginArgs.join(' ')}`);
+ const pluginListArgs = [APPIUM_BIN, 'plugin', 'list', '--json'];
+ const {stdout: pluginListJson} = await exec(
+ process.execPath,
+ pluginListArgs,
+ {
+ env,
+ },
+ );
+ const installedPlugins = JSON.parse(pluginListJson);
+
+ if (!installedPlugins[pluginName]?.installed) {
+ console.log(
+ `${warning} Plugin "${pluginName}" not installed; installing...`,
+ );
+ const pluginArgs = [
+ APPIUM_BIN,
+ 'plugin',
+ 'install',
+ '--source',
+ pluginSource,
+ pluginSpec,
+ ];
if (pluginPackage) {
pluginArgs.push('--package', pluginPackage);
}
+ console.log(
+ `${info} Running: ${process.execPath} ${pluginArgs.join(' ')}`,
+ );
await exec(process.execPath, pluginArgs, {
- env
+ env,
});
}
console.log(`${success} Installed plugin "${pluginName}"`);
+ };
+ const createServer = async () => {
if (!port) {
port = await getPort();
}
console.log(`${info} Will use port ${port} for Appium server`);
this.port = port;
- const args = {port, host, usePlugins: [pluginName], useDrivers: [driverName], ...serverArgs};
+ const args = {
+ port,
+ host,
+ usePlugins: [pluginName],
+ useDrivers: [driverName],
+ ...serverArgs,
+ };
server = await appiumServer(args);
- } finally {
- this.timeout(oldTimeout);
- }
+ };
+
+ const env = await setupAppiumHome();
+ await installDriver(env);
+ await installPlugin(env);
+ await createServer();
});
after(async function () {
@@ -103,3 +152,4 @@ function e2eSetup (opts = {}) {
}
export { e2eSetup };
+

MODIFY
packages/images-plugin/package.json
packages/images-plugin/package.json
"fix": "npm run lint -- --fix",
"lint": "eslint -c ../../.eslintrc --ignore-path ../../.eslintignore .",
"test": "npm run test:unit",
- "test:e2e": "mocha --timeout 20s --slow 10s \"./test/e2e/**/*.spec.js\"",
+ "test:e2e": "mocha --timeout 40s --slow 20s \"./test/e2e/**/*.spec.js\"",
"test:unit": "mocha \"./test/unit/**/*.spec.js\""
},
"dependencies": {

MODIFY
packages/images-plugin/test/e2e/plugin.e2e.spec.js
packages/images-plugin/test/e2e/plugin.e2e.spec.js
@@ -4,12 +4,12 @@ import { MATCH_FEATURES_MODE, GET_SIMILARITY_MODE } from '../../lib/compare';
import { TEST_IMG_1_B64, TEST_IMG_2_B64, APPSTORE_IMG_PATH } from '../fixtures';
import { e2eSetup } from '@appium/base-plugin/build/test/helpers';
-const THIS_PLUGIN_DIR = path.resolve(__dirname, '..', '..');
-const APPIUM_HOME = path.resolve(THIS_PLUGIN_DIR, 'local_appium_home');
-const FAKE_DRIVER_DIR = path.resolve(THIS_PLUGIN_DIR, '..', 'fake-driver');
+const THIS_PLUGIN_DIR = path.join(__dirname, '..', '..');
+const APPIUM_HOME = path.join(THIS_PLUGIN_DIR, 'local_appium_home');
+const FAKE_DRIVER_DIR = path.join(THIS_PLUGIN_DIR, '..', 'fake-driver');
const TEST_HOST = 'localhost';
const TEST_PORT = 4723;
-const TEST_FAKE_APP = path.resolve(APPIUM_HOME, 'node_modules', '@appium', 'fake-driver', 'test', 'fixtures',
+const TEST_FAKE_APP = path.join(APPIUM_HOME, 'node_modules', '@appium', 'fake-driver', 'test', 'fixtures',
'app.xml');
const TEST_CAPS = {
platformName: 'Fake',
@@ -27,6 +27,7 @@ const WDIO_OPTS = {
describe('ImageElementPlugin', function () {
let server, driver = null;
+ // this hook is intended to be run before the hooks created by `e2eSetup`
after(async function () {
if (driver) {
await driver.deleteSession();

test(images-plugin): attempt to fix e2e test