Skip to content

Commit d1c7f79

Browse files
authored
fix(start): Properly handle xcode-select output (#56)
1 parent 80b55bd commit d1c7f79

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

lib/simctl-extensions.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,13 +66,13 @@ const extensions = {
6666
return
6767
}
6868

69-
res = spawnSync('xcode-select', ['-p'])
69+
res = spawnSync('xcode-select', ['-p'], { encoding: 'utf8' })
7070
if (res.status !== 0) {
7171
console.error('Failed to get Xcode path')
7272
return
7373
}
7474

75-
const simulatorPath = path.join(res.stdout, 'Applications', 'Simulator.app')
75+
const simulatorPath = path.join(res.stdout.trim(), 'Applications', 'Simulator.app')
7676
return spawnSync('open', ['-a', simulatorPath])
7777
} else {
7878
// Xcode 8 or older

test/simctl-extensions.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,12 +119,13 @@ test('start', async (ctx) => {
119119
spawnMock.mock.mockImplementationOnce(() => ({ status: 0, stdout: 'Xcode 13.2.1' }), 0) // xcodebuild -version
120120
spawnMock.mock.mockImplementationOnce(() => ({ status: 0, stdout: JSON.stringify(testJson) }), 1) // xcrun simctl list -j
121121
spawnMock.mock.mockImplementationOnce(() => ({ status: 0 }), 2) // xcrun simctl boot <deviceid>
122-
spawnMock.mock.mockImplementationOnce(() => ({ status: 0, stdout: '/Applications/Xcode.app/Contents/Developer' }), 3) // xcode-select -p
122+
spawnMock.mock.mockImplementationOnce(() => ({ status: 0, stdout: '/Applications/Xcode.app/Contents/Developer\n' }), 3) // xcode-select -p
123123
spawnMock.mock.mockImplementationOnce(() => ({ status: 0 }), 4) // open -a XCODEPATH/Applications/Simulator.app
124124

125125
const retObj = SimCtlExtensions.start(deviceId)
126126
t.assert.deepEqual(retObj, { status: 0 })
127127
t.assert.equal(console.error.mock.calls.length, 0)
128+
t.assert.deepEqual(spawnMock.mock.calls[4].arguments[1], ['-a', '/Applications/Xcode.app/Contents/Developer/Applications/Simulator.app'])
128129
})
129130

130131
await ctx.test('successful start (Xcode < 9)', (t) => {

0 commit comments

Comments
 (0)