Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/subcommands/list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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[])
Expand Down
2 changes: 1 addition & 1 deletion lib/subcommands/location.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export async function clearLocation(this: Simctl): Promise<void> {
*/
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);
Expand Down
30 changes: 30 additions & 0 deletions test/unit/simctl.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 () {
Expand Down Expand Up @@ -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 {
Expand Down