Skip to content

Commit b74b20a

Browse files
authored
fix(list): Fix calls to list with no arguments (#52)
1 parent 2b41aaf commit b74b20a

File tree

2 files changed

+86
-6
lines changed

2 files changed

+86
-6
lines changed

simctl.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -133,20 +133,20 @@ module.exports = {
133133
},
134134

135135
list: function (options) {
136-
let sublist = ''
136+
const sublist = []
137137
options = options || {}
138138

139139
if (options.devices) {
140-
sublist = 'devices'
140+
sublist.push('devices')
141141
} else if (options.devicetypes) {
142-
sublist = 'devicetypes'
142+
sublist.push('devicetypes')
143143
} else if (options.runtimes) {
144-
sublist = 'runtimes'
144+
sublist.push('runtimes')
145145
} else if (options.pairs) {
146-
sublist = 'pairs'
146+
sublist.push('pairs')
147147
}
148148

149-
const result = spawnSync('xcrun', ['simctl', 'list', sublist, '--json'])
149+
const result = spawnSync('xcrun', ['simctl', 'list'].concat(sublist, ['--json']))
150150

151151
if (result.status === 0) {
152152
try {

test/simctl.js

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,3 +100,83 @@ test('simctl version', (t) => {
100100
const retObj = simctl.simctl_version()
101101
t.assert.ok(retObj[0] >= 400)
102102
})
103+
104+
test('simctl list', async (ctx) => {
105+
ctx.beforeEach((t) => {
106+
spawnMock.mock.resetCalls()
107+
108+
t.mock.method(console, 'error', () => {})
109+
})
110+
111+
await ctx.test('with no arguments', (t) => {
112+
t.assert ||= require('node:assert')
113+
114+
spawnMock.mock.mockImplementationOnce(() => {
115+
return { status: 0, stdout: '{}' }
116+
})
117+
118+
const retObj = simctl.list()
119+
t.assert.deepEqual(spawnMock.mock.calls[0].arguments[1], ['simctl', 'list', '--json'])
120+
t.assert.deepEqual(retObj.json, {})
121+
})
122+
123+
await ctx.test('with devices arguments', (t) => {
124+
t.assert ||= require('node:assert')
125+
126+
spawnMock.mock.mockImplementationOnce(() => {
127+
return { status: 0, stdout: '{}' }
128+
})
129+
130+
const retObj = simctl.list({ devices: true })
131+
t.assert.deepEqual(spawnMock.mock.calls[0].arguments[1], ['simctl', 'list', 'devices', '--json'])
132+
t.assert.deepEqual(retObj.json, {})
133+
})
134+
135+
await ctx.test('with devicetypes arguments', (t) => {
136+
t.assert ||= require('node:assert')
137+
138+
spawnMock.mock.mockImplementationOnce(() => {
139+
return { status: 0, stdout: '{}' }
140+
})
141+
142+
const retObj = simctl.list({ devicetypes: true })
143+
t.assert.deepEqual(spawnMock.mock.calls[0].arguments[1], ['simctl', 'list', 'devicetypes', '--json'])
144+
t.assert.deepEqual(retObj.json, {})
145+
})
146+
147+
await ctx.test('with runtimes arguments', (t) => {
148+
t.assert ||= require('node:assert')
149+
150+
spawnMock.mock.mockImplementationOnce(() => {
151+
return { status: 0, stdout: '{}' }
152+
})
153+
154+
const retObj = simctl.list({ runtimes: true })
155+
t.assert.deepEqual(spawnMock.mock.calls[0].arguments[1], ['simctl', 'list', 'runtimes', '--json'])
156+
t.assert.deepEqual(retObj.json, {})
157+
})
158+
159+
await ctx.test('with pairs arguments', (t) => {
160+
t.assert ||= require('node:assert')
161+
162+
spawnMock.mock.mockImplementationOnce(() => {
163+
return { status: 0, stdout: '{}' }
164+
})
165+
166+
const retObj = simctl.list({ pairs: true })
167+
t.assert.deepEqual(spawnMock.mock.calls[0].arguments[1], ['simctl', 'list', 'pairs', '--json'])
168+
t.assert.deepEqual(retObj.json, {})
169+
})
170+
171+
await ctx.test('with parsing error', (t) => {
172+
t.assert ||= require('node:assert')
173+
174+
spawnMock.mock.mockImplementationOnce(() => {
175+
return { status: 0, stdout: 'This is not valid JSON' }
176+
})
177+
178+
const retObj = simctl.list()
179+
t.assert.match(console.error.mock.calls[0].arguments[0], /SyntaxError: Unexpected token/)
180+
t.assert.equal(retObj.json, undefined)
181+
})
182+
})

0 commit comments

Comments
 (0)