refactor(doctor): Remove obsolete iOS-related verifications
DELETE
packages/doctor/lib/carthage-detector.js
-import log from './logger';
-import { resolveExecutablePath } from './utils';
-
-class CarthageDetector {
- static async detect () {
- const carthagePath = await resolveExecutablePath('carthage');
-
- if (!carthagePath) {
- log.debug(`Carthage was not found in PATH: ${process.env.PATH}`);
- return null;
- }
-
- log.debug(`Carthage was found at: ${carthagePath}`);
- return carthagePath;
- }
-}
-
-export default CarthageDetector;

MODIFY
packages/doctor/lib/ios.js
packages/doctor/lib/ios.js
-import { ok, nok, okOptional, nokOptional, authorizeIos, resolveExecutablePath } from './utils'; // eslint-disable-line
-import { fs, util } from '@appium/support';
+import { ok, nok, okOptional, nokOptional, resolveExecutablePath } from './utils'; // eslint-disable-line
+import { fs } from '@appium/support';
import { exec } from 'teen_process';
import { DoctorCheck, FixSkippedError } from './doctor';
import log from './logger';
-import CarthageDetector from './carthage-detector';
import { fixIt } from './prompt';
import EnvVarAndPathCheck from './env';
-import _ from 'lodash';
import 'colors';
let checks = [];
@@ -70,24 +68,8 @@ class XcodeCmdLineToolsCheck extends DoctorCheck {
checks.push(new XcodeCmdLineToolsCheck());
-// Automatically run authorize iOS if requested
-fixes.authorizeIosFix = async function () {
- log.info(`The authorize iOS script need to be run.`);
- let yesno = await fixIt();
- if (yesno === 'yes') {
- await authorizeIos();
- } else {
- log.info(`Skipping you will need to run ${'the authorize iOS'.bold} manually.`);
- throw new FixSkippedError();
- }
-};
-
// Dev Tools Security
class DevToolsSecurityCheck extends DoctorCheck {
- constructor () {
- super({autofix: true});
- }
-
async diagnose () {
const errMess = 'DevToolsSecurity is NOT enabled!';
let stdout;
@@ -100,69 +82,9 @@ class DevToolsSecurityCheck extends DoctorCheck {
return stdout && stdout.match(/enabled/) ? ok('DevToolsSecurity is enabled.')
: nok(errMess);
}
- async fix () {
- return await fixes.authorizeIosFix();
- }
}
checks.push(new DevToolsSecurityCheck());
-// Authorization DB
-class AuthorizationDbCheck extends DoctorCheck {
- constructor () {
- super({autofix: true});
- }
-
- async diagnose () {
- const successMess = 'The Authorization DB is set up properly.';
- const errMess = 'The Authorization DB is NOT set up properly.';
- let stdout;
- try {
- ({stdout} = await exec('security', ['authorizationdb', 'read', 'system.privilege.taskport']));
- } catch (err) {
- log.warn(err);
- return nok(errMess);
- }
- return stdout && (stdout.match(/is-developer/) || stdout.match(/allow/)) ?
- ok(successMess) : nok(errMess);
- }
- async fix () {
- return await fixes.authorizeIosFix();
- }
-}
-checks.push(new AuthorizationDbCheck());
-
-// Check for Carthage (for WDA)
-class CarthageCheck extends DoctorCheck {
- async diagnose () {
- let carthagePath = await CarthageDetector.detect();
-
- let version;
- if (carthagePath) {
- try {
- const {stdout} = await exec(carthagePath, ['version']);
- // 'Please update to the latest Carthage version: 0.33.0. You currently are on 0.32.0\n0.32.0\n' or '0.32.0\n'
- // 0.32.0 is the current version. 0.33.0 is an available newer version.
- version = _.last(stdout.match(/(\d+\.\d+\.\d+)/g));
- if (!util.coerceVersion(version, false)) {
- log.warn(`Cannot parse Carthage version from ${stdout}`);
- }
- } catch (err) {
- log.warn(err);
- }
- }
-
- return carthagePath
- ? ok(`Carthage was found at: ${carthagePath}${ version ? `. Installed version is: ${version}` : ''}`)
- : nok(`Carthage was NOT found!`);
- }
-
- async fix () { // eslint-disable-line require-await
- return `${'[For lower than Appium 1.20.0]'.bold} Please install ${'Carthage'.bold}. Visit https://github.com/Carthage` +
- '/Carthage#installing-carthage for more information.';
- }
-}
-checks.push(new CarthageCheck());
-
checks.push(new EnvVarAndPathCheck('HOME'));
class OptionalLyftCommandCheck extends DoctorCheck {
@@ -238,7 +160,7 @@ checks.push(new OptionalIOSDeployCommandCheck());
export {
fixes, XcodeCheck, XcodeCmdLineToolsCheck, DevToolsSecurityCheck,
- AuthorizationDbCheck, CarthageCheck, OptionalIdbCommandCheck, OptionalApplesimutilsCommandCheck,
+ OptionalIdbCommandCheck, OptionalApplesimutilsCommandCheck,
OptionalIOSDeployCommandCheck, OptionalLyftCommandCheck
};
export default checks;

MODIFY
packages/doctor/lib/utils.js
packages/doctor/lib/utils.js
import B from 'bluebird';
import _inquirer from 'inquirer';
import log from '../lib/logger';
-import authorize from 'authorize-ios';
import { fs, system } from '@appium/support';
import { exec } from 'teen_process';
import { isFunction } from 'lodash';
-// rename to make more sense
-const authorizeIos = authorize;
-
function ok (message) {
return {ok: true, optional: false, message};
}
@@ -112,5 +108,7 @@ async function getNpmPackageInfo (packageName) {
return null;
}
-export { ok, nok, okOptional, nokOptional, inquirer, configureBinaryLog,
- authorizeIos, resolveExecutablePath, getNpmPackageInfo, resetLog };
+export {
+ ok, nok, okOptional, nokOptional, inquirer, configureBinaryLog,
+ resolveExecutablePath, getNpmPackageInfo, resetLog
+};

MODIFY
packages/doctor/package.json
packages/doctor/package.json
"@appium/support": "file:../support",
"@babel/runtime": "7.16.3",
"appium-adb": "8.16.2",
- "authorize-ios": "1.2.1",
"bluebird": "3.7.2",
"colors": "1.4.0",
"inquirer": "8.2.0",

MODIFY
packages/doctor/test/ios-specs.js
packages/doctor/test/ios-specs.js
// transpile:mocha
-import { fixes, XcodeCheck, XcodeCmdLineToolsCheck, DevToolsSecurityCheck,
- AuthorizationDbCheck, CarthageCheck, OptionalApplesimutilsCommandCheck,
- OptionalIdbCommandCheck, OptionalIOSDeployCommandCheck,
- OptionalLyftCommandCheck } from '../lib/ios';
+import {
+ fixes, XcodeCheck, XcodeCmdLineToolsCheck, DevToolsSecurityCheck,
+ OptionalApplesimutilsCommandCheck, OptionalIdbCommandCheck, OptionalIOSDeployCommandCheck,
+ OptionalLyftCommandCheck
+} from '../lib/ios';
import { fs, system } from '@appium/support';
import * as utils from '../lib/utils';
import * as tp from 'teen_process';
import * as prompter from '../lib/prompt';
-import CarthageDetector from '../lib/carthage-detector';
import FixSkippedError from '../lib/doctor';
import log from '../lib/logger';
import B from 'bluebird';
@@ -136,35 +136,8 @@ describe('ios', function () {
].join('\n'));
});
}));
-
- describe('authorizeIosFix', withSandbox({mocks: {utils, prompter}}, (S) => {
- it('fix - yes', async function () {
- let logStub = stubLog(S.sandbox, log, {stripColors: true});
- S.mocks.utils.expects('authorizeIos').once();
- S.mocks.prompter.expects('fixIt').once().resolves('yes');
- await fixes.authorizeIosFix();
- S.verify();
- logStub.output.should.equal([
- 'info: The authorize iOS script need to be run.',
- ].join('\n'));
- });
- it('fix - no', async function () {
- let logStub = stubLog(S.sandbox, log, {stripColors: true});
- S.mocks.utils.expects('authorizeIos').never();
- S.mocks.prompter.expects('fixIt').once().resolves('no');
- await fixes.authorizeIosFix().should.be.rejectedWith(FixSkippedError);
- S.verify();
- logStub.output.should.equal([
- 'info: The authorize iOS script need to be run.',
- 'info: Skipping you will need to run the authorize iOS manually.'
- ].join('\n'));
- });
- }));
describe('DevToolsSecurityCheck', withMocks({fixes, tp}, (mocks) => {
let check = new DevToolsSecurityCheck();
- it('autofix', function () {
- check.autofix.should.be.ok;
- });
it('diagnose - success', async function () {
mocks.tp.expects('exec').once().returns(
B.resolve({stdout: '1234 enabled\n', stderr: ''}));
@@ -194,91 +167,6 @@ describe('ios', function () {
});
mocks.verify();
});
- it('fix', async function () {
- mocks.fixes.expects('authorizeIosFix').once();
- await check.fix();
- mocks.verify();
- });
- }));
- describe('AuthorizationDbCheck', withMocks({fixes, tp, fs, utils, system}, (mocks) => {
- let check = new AuthorizationDbCheck();
- it('autofix', function () {
- check.autofix.should.be.ok;
- });
- it('diagnose - success', async function () {
- mocks.tp.expects('exec').once().returns(
- B.resolve({stdout: '1234 is-developer\n', stderr: ''}));
- (await check.diagnose()).should.deep.equal({
- ok: true,
- optional: false,
- message: 'The Authorization DB is set up properly.'
- });
- mocks.verify();
- });
- it('diagnose - failure', async function () {
- mocks.tp.expects('exec').once().rejects(new Error('Oh No!'));
- (await check.diagnose()).should.deep.equal({
- ok: false,
- optional: false,
- message: 'The Authorization DB is NOT set up properly.'
- });
- mocks.verify();
- });
- it('fix', async function () {
- mocks.fixes.expects('authorizeIosFix').once();
- await check.fix();
- mocks.verify();
- });
- }));
- describe('CarthageCheck', withMocks({CarthageDetector, tp}, (mocks) => {
- let check = new CarthageCheck();
- it('autofix', function () {
- check.autofix.should.not.be.ok;
- });
- it('diagnose - success', async function () {
- mocks.CarthageDetector.expects('detect').once().resolves('/usr/local/bin/carthage');
- mocks.tp.expects('exec').once().returns(
- B.resolve({stdout: 'Please update to the latest Carthage version: 0.33.0. You currently are on 0.32.0\n0.32.0\n', stderr: ''}));
- (await check.diagnose()).should.deep.equal({
- ok: true,
- optional: false,
- message: 'Carthage was found at: /usr/local/bin/carthage. Installed version is: 0.32.0'
- });
- mocks.verify();
- });
- it('diagnose - success - one line carthage version', async function () {
- mocks.CarthageDetector.expects('detect').once().resolves('/usr/local/bin/carthage');
- mocks.tp.expects('exec').once().returns(
- B.resolve({stdout: '0.32.0\n', stderr: ''}));
- (await check.diagnose()).should.deep.equal({
- ok: true,
- optional: false,
- message: 'Carthage was found at: /usr/local/bin/carthage. Installed version is: 0.32.0'
- });
- mocks.verify();
- });
- it('diagnose - success - but error happens', async function () {
- mocks.CarthageDetector.expects('detect').once().resolves('/usr/local/bin/carthage');
- mocks.tp.expects('exec').once().throws(new Error());
- (await check.diagnose()).should.deep.equal({
- ok: true,
- optional: false,
- message: 'Carthage was found at: /usr/local/bin/carthage'
- });
- mocks.verify();
- });
- it('diagnose - failure', async function () {
- mocks.CarthageDetector.expects('detect').once().resolves(null);
- (await check.diagnose()).should.deep.equal({
- ok: false,
- optional: false,
- message: 'Carthage was NOT found!'
- });
- mocks.verify();
- });
- it('fix', async function () {
- removeColors(await check.fix()).should.equal('[For lower than Appium 1.20.0] Please install Carthage. Visit https://github.com/Carthage/Carthage#installing-carthage for more information.');
- });
}));
describe('OptionalLyftCommandCheck', withMocks({tp, utils}, (mocks) => {

refactor(doctor): Remove obsolete iOS-related verifications (#16169)