From 5627239f3f88fa2fc13fbc5c716fa98d60c69f70 Mon Sep 17 00:00:00 2001 From: Darryl Pogue Date: Tue, 4 Nov 2025 18:50:35 -0800 Subject: [PATCH] fix(list): Fix calls to list with no arguments --- simctl.js | 12 ++++---- test/simctl.js | 80 ++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 86 insertions(+), 6 deletions(-) diff --git a/simctl.js b/simctl.js index b932fab..89e2cc2 100644 --- a/simctl.js +++ b/simctl.js @@ -133,20 +133,20 @@ module.exports = { }, list: function (options) { - let sublist = '' + const sublist = [] options = options || {} if (options.devices) { - sublist = 'devices' + sublist.push('devices') } else if (options.devicetypes) { - sublist = 'devicetypes' + sublist.push('devicetypes') } else if (options.runtimes) { - sublist = 'runtimes' + sublist.push('runtimes') } else if (options.pairs) { - sublist = 'pairs' + sublist.push('pairs') } - const result = spawnSync('xcrun', ['simctl', 'list', sublist, '--json']) + const result = spawnSync('xcrun', ['simctl', 'list'].concat(sublist, ['--json'])) if (result.status === 0) { try { diff --git a/test/simctl.js b/test/simctl.js index 8919732..57248aa 100644 --- a/test/simctl.js +++ b/test/simctl.js @@ -100,3 +100,83 @@ test('simctl version', (t) => { const retObj = simctl.simctl_version() t.assert.ok(retObj[0] >= 400) }) + +test('simctl list', async (ctx) => { + ctx.beforeEach((t) => { + spawnMock.mock.resetCalls() + + t.mock.method(console, 'error', () => {}) + }) + + await ctx.test('with no arguments', (t) => { + t.assert ||= require('node:assert') + + spawnMock.mock.mockImplementationOnce(() => { + return { status: 0, stdout: '{}' } + }) + + const retObj = simctl.list() + t.assert.deepEqual(spawnMock.mock.calls[0].arguments[1], ['simctl', 'list', '--json']) + t.assert.deepEqual(retObj.json, {}) + }) + + await ctx.test('with devices arguments', (t) => { + t.assert ||= require('node:assert') + + spawnMock.mock.mockImplementationOnce(() => { + return { status: 0, stdout: '{}' } + }) + + const retObj = simctl.list({ devices: true }) + t.assert.deepEqual(spawnMock.mock.calls[0].arguments[1], ['simctl', 'list', 'devices', '--json']) + t.assert.deepEqual(retObj.json, {}) + }) + + await ctx.test('with devicetypes arguments', (t) => { + t.assert ||= require('node:assert') + + spawnMock.mock.mockImplementationOnce(() => { + return { status: 0, stdout: '{}' } + }) + + const retObj = simctl.list({ devicetypes: true }) + t.assert.deepEqual(spawnMock.mock.calls[0].arguments[1], ['simctl', 'list', 'devicetypes', '--json']) + t.assert.deepEqual(retObj.json, {}) + }) + + await ctx.test('with runtimes arguments', (t) => { + t.assert ||= require('node:assert') + + spawnMock.mock.mockImplementationOnce(() => { + return { status: 0, stdout: '{}' } + }) + + const retObj = simctl.list({ runtimes: true }) + t.assert.deepEqual(spawnMock.mock.calls[0].arguments[1], ['simctl', 'list', 'runtimes', '--json']) + t.assert.deepEqual(retObj.json, {}) + }) + + await ctx.test('with pairs arguments', (t) => { + t.assert ||= require('node:assert') + + spawnMock.mock.mockImplementationOnce(() => { + return { status: 0, stdout: '{}' } + }) + + const retObj = simctl.list({ pairs: true }) + t.assert.deepEqual(spawnMock.mock.calls[0].arguments[1], ['simctl', 'list', 'pairs', '--json']) + t.assert.deepEqual(retObj.json, {}) + }) + + await ctx.test('with parsing error', (t) => { + t.assert ||= require('node:assert') + + spawnMock.mock.mockImplementationOnce(() => { + return { status: 0, stdout: 'This is not valid JSON' } + }) + + const retObj = simctl.list() + t.assert.match(console.error.mock.calls[0].arguments[0], /SyntaxError: Unexpected token/) + t.assert.equal(retObj.json, undefined) + }) +})