diff --git a/lib/helpers.ts b/lib/helpers.ts index e0d98b2..642971a 100644 --- a/lib/helpers.ts +++ b/lib/helpers.ts @@ -63,6 +63,7 @@ export async function convertPlistToJson(plistInput: string): Promise { plutilProcess.kill(9); throw new Error( `Failed to convert plist to JSON: ${err instanceof Error ? err.message : String(err)}`, + {cause: err}, ); } finally { plutilProcess.removeAllListeners(); diff --git a/lib/logger.ts b/lib/logger.ts index 3436974..905394a 100644 --- a/lib/logger.ts +++ b/lib/logger.ts @@ -2,12 +2,4 @@ import appiumLogger from '@appium/logger'; export const LOG_PREFIX = 'simctl'; -function getLogger() { - const logger = global._global_npmlog || appiumLogger; - if (!logger.debug) { - logger.addLevel('debug', 1000, {fg: 'blue', bg: 'black'}, 'dbug'); - } - return logger; -} - -export const log = getLogger(); +export const log = appiumLogger; diff --git a/lib/subcommands/appinfo.ts b/lib/subcommands/appinfo.ts index 8d23283..1024c06 100644 --- a/lib/subcommands/appinfo.ts +++ b/lib/subcommands/appinfo.ts @@ -26,6 +26,7 @@ export async function appInfo(this: Simctl, bundleId: string): Promise } catch (err) { throw new Error( `Cannot retrieve app info for ${bundleId}: ${err instanceof Error ? err.message : String(err)}`, + {cause: err}, ); } } diff --git a/lib/subcommands/bootstatus.ts b/lib/subcommands/bootstatus.ts index 0958930..bff1435 100644 --- a/lib/subcommands/bootstatus.ts +++ b/lib/subcommands/bootstatus.ts @@ -1,4 +1,4 @@ -import {log} from '../logger'; +import {log, LOG_PREFIX} from '../logger'; import {waitForCondition} from 'asyncbox'; import type {Simctl} from '../simctl'; import type {BootMonitorOptions} from '../types'; @@ -79,7 +79,7 @@ export async function startBootMonitor( try { await bootMonitor.stop(); } catch (e: any) { - log.warn(e.message); + log.warn(LOG_PREFIX, e.message); } } }; diff --git a/lib/subcommands/create.ts b/lib/subcommands/create.ts index a89b8ba..e828a60 100644 --- a/lib/subcommands/create.ts +++ b/lib/subcommands/create.ts @@ -42,7 +42,7 @@ export async function createDevice( try { runtimeId = await this.getRuntimeForPlatformVersion(platformVersion, platform); } catch { - log.warn(`Unable to find runtime for iOS '${platformVersion}'. Continuing`); + log.warn(LOG_PREFIX, `Unable to find runtime for iOS '${platformVersion}'. Continuing`); runtimeId = platformVersion; } diff --git a/lib/subcommands/list.ts b/lib/subcommands/list.ts index 7ea9ed3..baeb6cb 100644 --- a/lib/subcommands/list.ts +++ b/lib/subcommands/list.ts @@ -268,7 +268,7 @@ export async function getDeviceTypes(this: Simctl): Promise { const deviceTypes = JSON.parse(stdout.trim()); return deviceTypes.devicetypes.map((type: any) => type.name); } catch (err: any) { - throw new Error(`Unable to get list of device types: ${err.message}`); + throw new Error(`Unable to get list of device types: ${err.message}`, {cause: err}); } } @@ -313,7 +313,7 @@ export async function list(this: Simctl): Promise { try { return JSON.parse(stdout.trim()); } catch (e: any) { - throw new Error(`Unable to parse simctl list: ${e.message}`); + throw new Error(`Unable to parse simctl list: ${e.message}`, {cause: e}); } } diff --git a/package.json b/package.json index c487e61..39d6365 100644 --- a/package.json +++ b/package.json @@ -62,8 +62,13 @@ "@appium/types": "^1.0.0-rc.1", "@semantic-release/changelog": "^6.0.1", "@semantic-release/git": "^10.0.1", + "@types/chai": "^5.2.3", + "@types/chai-as-promised": "^8.0.2", "@types/mocha": "^10.0.1", "@types/node": "^25.0.0", + "@types/semver": "^7.7.1", + "@types/sinon": "^21.0.1", + "@types/which": "^3.0.4", "appium-xcode": "^6.0.0", "chai": "^6.0.0", "chai-as-promised": "^8.0.0", diff --git a/test/e2e/simctl-e2e-specs.ts b/test/e2e/simctl-e2e-specs.ts index aec17bf..9455fad 100644 --- a/test/e2e/simctl-e2e-specs.ts +++ b/test/e2e/simctl-e2e-specs.ts @@ -277,12 +277,15 @@ describe('simctl', function () { expect(fullList.devicetypes.length).to.be.above(1); // at least one type, no matter the version of Xcode, should be an iPhone expect( - fullList.devicetypes.filter((el) => el.identifier.includes('iPhone')).length, + fullList.devicetypes.filter((el: {identifier: string}) => + el.identifier.includes('iPhone'), + ).length, ).to.be.above(0); // at least one runtime should be iOS - expect(fullList.runtimes.filter((el) => el.identifier.includes('iOS')).length).to.be.above( - 0, - ); + expect( + fullList.runtimes.filter((el: {identifier: string}) => el.identifier.includes('iOS')) + .length, + ).to.be.above(0); }); }); diff --git a/tsconfig.json b/tsconfig.json index 56f8c27..1e5a50e 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -4,7 +4,8 @@ "compilerOptions": { "esModuleInterop": true, "outDir": "build", - "types": ["node", "mocha"] + "types": ["node", "mocha"], + "strict": true }, "ts-node": { "transpileOnly": true,