diff --git a/lib/subcommands/list.ts b/lib/subcommands/list.ts index 3295eec..cc79311 100644 --- a/lib/subcommands/list.ts +++ b/lib/subcommands/list.ts @@ -137,8 +137,8 @@ export async function getDevices( continue; } - // the sdk can have dashes (`12-2`) or dots (`12.1`) - const sdk = (platform ? versionMatch[1] : versionMatch[2]).replace('-', '.'); + // the sdk can have dashes (`12-2`, `12-1-1`) or dots (`12.1`, `12.1.1`) + const sdk = (platform ? versionMatch[1] : versionMatch[2]).replace(/-/g, '.'); devices[sdk] = devices[sdk] || []; devices[sdk].push( ...(entries as any[]) diff --git a/lib/subcommands/location.ts b/lib/subcommands/location.ts index 02967e2..de46d40 100644 --- a/lib/subcommands/location.ts +++ b/lib/subcommands/location.ts @@ -38,7 +38,7 @@ export async function clearLocation(this: Simctl): Promise { */ function formatArg(name: string, value: string | number): string { const flt = parseFloat(`${value}`); - if (isNaN(flt)) { + if (!Number.isFinite(flt)) { throw new TypeError(`${name} must be a valid number, got '${value}' instead`); } return flt.toFixed(7); diff --git a/test/unit/simctl.spec.ts b/test/unit/simctl.spec.ts index 315a849..6d4d181 100644 --- a/test/unit/simctl.spec.ts +++ b/test/unit/simctl.spec.ts @@ -96,6 +96,27 @@ describe('simctl', function () { const devices = await simctl.getDevices('12.1'); assert.strictEqual(Object.keys(devices).length, 10); }); + it('should normalize three-part dash-separated SDK runtime keys', async function () { + execStub.returns({ + stdout: JSON.stringify({ + devices: { + 'com.apple.CoreSimulator.SimRuntime.iOS-17-5-1': [ + { + state: 'Shutdown', + isAvailable: true, + name: 'iPhone 15', + udid: '75E34140-18E8-4D1A-9F45-AAC735DF75DF', + }, + ], + }, + }), + }); + + const devices = await simctl.getDevices('17.5.1'); + assert.strictEqual(devices.length, 1); + assert.strictEqual(devices[0].sdk, '17.5.1'); + assert.strictEqual(devices[0].platform, 'iOS'); + }); }); describe('platform defined', function () { it('should get all the devices in the JSON', async function () { @@ -319,6 +340,15 @@ describe('simctl', function () { assert.strictEqual(devices, 'EE76EA77-E975-4198-9859-69DFF74252D2'); }); }); + + describe('#setLocation', function () { + it('should reject non-finite coordinates', async function () { + const simctl = stubSimctl({path: 'xcrun'}); + simctl.udid = '75E34140-18E8-4D1A-9F45-AAC735DF75DF'; + await assert.rejects(() => simctl.setLocation(Infinity, 0), TypeError); + await assert.rejects(() => simctl.setLocation(0, 'Infinity'), TypeError); + }); + }); }); function getModuleRootSync(): string {