From 2499b49936660280eefaeb26cb3e4e9f82e36c20 Mon Sep 17 00:00:00 2001 From: Christopher Hiller Date: Mon, 17 May 2021 14:11:23 -0700 Subject: [PATCH] fix: e2e-tests - re-add missing fake-plugin dev dep - export a `PROJECT_ROOT` from the `helpers` module; use this where needed (DRY) --- package.json | 1 + packages/appium/test/cli-e2e-specs.js | 6 +----- packages/appium/test/helpers.js | 11 ++++++++--- packages/appium/test/plugin-e2e-specs.js | 9 ++++----- 4 files changed, 14 insertions(+), 13 deletions(-) diff --git a/package.json b/package.json index 8de718b27..9187b7a7a 100644 --- a/package.json +++ b/package.json @@ -42,6 +42,7 @@ "devDependencies": { "@appium/eslint-config-appium": "file:./packages/eslint-config-appium", "@babel/plugin-proposal-class-properties": "^7.13.0", + "@appium/fake-plugin": "^1.0.0", "@babel/register": "^7.13.16", "appium-test-support": "^1.3.3", "asyncbox": "^2.8.0", diff --git a/packages/appium/test/cli-e2e-specs.js b/packages/appium/test/cli-e2e-specs.js index 906cd36a8..0e91523ba 100644 --- a/packages/appium/test/cli-e2e-specs.js +++ b/packages/appium/test/cli-e2e-specs.js @@ -4,15 +4,11 @@ import chai from 'chai'; import chaiAsPromised from 'chai-as-promised'; import { tempDir, fs, mkdirp, util } from 'appium-support'; import { KNOWN_DRIVERS } from '../lib/drivers'; -import findUp from 'find-up'; +import { PROJECT_ROOT as cwd } from './helpers'; chai.should(); chai.use(chaiAsPromised); -// monorepo root. this cannot be hardcoded because: -// 1. we may be in 'build/test' or 'test', depending on our config -// 2. Node.js does not support `__dirname` in an ESM context & Babel doesn't fake it well -const cwd = path.dirname(findUp.sync('.git', {type: 'directory'})); // cannot use `require.resolve()` here (w/o acrobatics) due to the ESM context. // could also derive it from the `package.json` if we wanted const executable = path.join(cwd, 'packages', 'appium', 'build', 'lib', 'main.js'); diff --git a/packages/appium/test/helpers.js b/packages/appium/test/helpers.js index 22a6a9255..1aad1ec95 100644 --- a/packages/appium/test/helpers.js +++ b/packages/appium/test/helpers.js @@ -1,10 +1,15 @@ import path from 'path'; import {insertAppiumPrefixes} from '../lib/utils'; +import findUp from 'find-up'; const TEST_HOST = 'localhost'; const TEST_PORT = 4723; -const TEST_FAKE_APP = path.resolve(__dirname, '..', '..', '..', 'fake-driver', 'test', 'fixtures', - 'app.xml'); + +// monorepo root. this cannot be hardcoded because: +// 1. we may be in 'build/test' or 'test', depending on our config +// 2. Node.js does not support `__dirname` in an ESM context & Babel doesn't fake it well +const PROJECT_ROOT = path.dirname(findUp.sync('.git', {type: 'directory'})); +const TEST_FAKE_APP = path.join(PROJECT_ROOT, 'packages', 'fake-driver', 'test', 'fixtures', 'app.xml'); const BASE_CAPS = { automationName: 'Fake', @@ -18,4 +23,4 @@ const W3C_CAPS = { firstMatch: [{}], }; -export { TEST_FAKE_APP, TEST_HOST, TEST_PORT, BASE_CAPS, W3C_PREFIXED_CAPS, W3C_CAPS }; +export { TEST_FAKE_APP, TEST_HOST, TEST_PORT, BASE_CAPS, W3C_PREFIXED_CAPS, W3C_CAPS, PROJECT_ROOT }; diff --git a/packages/appium/test/plugin-e2e-specs.js b/packages/appium/test/plugin-e2e-specs.js index a7e286bdd..2a481f56e 100644 --- a/packages/appium/test/plugin-e2e-specs.js +++ b/packages/appium/test/plugin-e2e-specs.js @@ -8,16 +8,15 @@ import { remote as wdio } from 'webdriverio'; import axios from 'axios'; import { main as appiumServer } from '../lib/main'; import { DEFAULT_APPIUM_HOME, INSTALL_TYPE_LOCAL, DRIVER_TYPE, PLUGIN_TYPE } from '../lib/extension-config'; -import { W3C_PREFIXED_CAPS, TEST_HOST, TEST_PORT } from './helpers'; +import { W3C_PREFIXED_CAPS, TEST_HOST, TEST_PORT, PROJECT_ROOT } from './helpers'; import { runExtensionCommand } from '../lib/cli/extension'; -import findUp from 'find-up'; chai.should(); chai.use(chaiAsPromised); -const root = path.dirname(findUp.sync('.git', {type: 'directory'})); + // TODO: update when fake-plugin pulled in to monorepo -const FAKE_PLUGIN_DIR = path.join(root, 'node_modules', '@appium', 'fake-plugin'); -const FAKE_DRIVER_DIR = path.join(root, 'packages', 'fake-driver'); +const FAKE_PLUGIN_DIR = path.join(PROJECT_ROOT, 'node_modules', '@appium', 'fake-plugin'); +const FAKE_DRIVER_DIR = path.join(PROJECT_ROOT, 'packages', 'fake-driver'); const TEST_SERVER = `http://${TEST_HOST}:${TEST_PORT}`; const wdOpts = {