fix(support): if appium is installed extraneously, do not consider it a dependency
This can happen if someone does something like `npm install --no-save appium`, _or_ if npm changes its shrinkwrap behavior for reasons that cause `appium` to be installed in `$APPIUM_HOME/node_modules` _(cough)_
MODIFY
packages/support/lib/env.js
packages/support/lib/env.js
@@ -40,7 +40,12 @@ export const MANIFEST_RELATIVE_PATH = path.join(
* Note that we are _not_ performing the check "is the currently running Appium the same one as found in the list of dependencies", because I'm not sure it actually matters (assuming the versions are compatible).
* Regardless we may want to make this more robust in the future, as we hit edge cases.
*
- * _Also_ note that if `appium` appears as a dependency in `package.json` _but it is not yet installed_ this function will resolve `false`. This may not be exactly what we want.
+ * _Also_ note that:
+ *
+ * - if `appium` appears as a dependency in `package.json` _but it is not yet installed_ this function will resolve `false`.
+ * - if `appium` _does not appear in `package.json`_, but is installed anyway (extraneous) this function will resolve `false`.
+ *
+ * This may not be exactly what we want.
*
* @param {string} cwd
* @returns {Promise<boolean>}
@@ -57,6 +62,11 @@ export async function hasAppiumDependency(cwd) {
let version;
try {
listResult = await npm.list(cwd, 'appium');
+
+ // short-circuit if `appium` is hanging around but the user hasn't added it to `package.json`.
+ if (listResult?.dependencies?.appium?.extraneous) {
+ return false;
+ }
// if "resolved" is empty, then `appium` is in dependencies, but `npm install` has not been run.
// in other words, this function can resolve `true` even if `resolved` is empty...
resolved = listResult?.dependencies?.appium?.resolved ?? '';

MODIFY
packages/support/test/unit/env.spec.js
packages/support/test/unit/env.spec.js
@@ -254,9 +254,33 @@ describe('env', function () {
MockPkgDir.resolves();
});
- it('should resolve `false``', async function () {
+ it('should resolve `false`', async function () {
await expect(env.hasAppiumDependency('/somewhere')).to.eventually.equal(false);
});
+
+ describe('when it is installed, but extraneous', function () {
+ beforeEach(function () {
+ MockTeenProcess.exec.resolves({
+ stdout: JSON.stringify({
+ version: '0.0.0',
+ name: 'some-pkg',
+ dependencies: {
+ appium: {
+ extraneous: true,
+ version: '2.0.0-beta.25',
+ resolved: 'https://some/appium-tarball.tgz',
+ },
+ },
+ }),
+ stderr: '',
+ code: 0,
+ });
+ });
+
+ it('should resolve `false`', async function () {
+ await expect(env.hasAppiumDependency('/somewhere')).to.eventually.equal(false);
+ });
+ });
});
describe('when `appium` is a dependency of the local package', function () {

fix(support): if appium is installed extraneously, do not consider it a dependency

This can happen if someone does something like `npm install --no-save appium`, _or_ if npm changes its shrinkwrap behavior for reasons that cause `appium` to be installed in `$APPIUM_HOME/node_modules` _(cough)_