Skip to content
Merged
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
16 changes: 16 additions & 0 deletions simctl.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,22 @@ module.exports = {
return result
},

simctl_version: function () {
const res = spawnSync('xcrun', ['simctl', '--version'])
const versionMatch = /CoreSimulator-(.*)/.exec(res.stdout)
const versionString = versionMatch[1]

return versionString.split('.').map((v) => parseInt(v, 10))
},

xcode_version: function () {
const res = spawnSync('xcodebuild', ['-version'])
const versionMatch = /Xcode (.*)/.exec(res.stdout)
const versionString = versionMatch[1]

return versionString.split('.').map((v) => parseInt(v, 10))
},

create: function (name, deviceTypeId, runtimeId) {
return spawnSync('xcrun', ['simctl', 'create', name, deviceTypeId, runtimeId])
},
Expand Down
25 changes: 25 additions & 0 deletions test/simctl.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ THE SOFTWARE.
const test = require('node:test')
const childProcess = require('child_process')

const originalSpawnSync = childProcess.spawnSync
const spawnMock = test.mock.method(childProcess, 'spawnSync')

const simctl = require('../simctl')
Expand All @@ -35,6 +36,8 @@ test('exports', (t) => {

t.assert.equal(simctl.extensions, SimCtlExtensions)
t.assert.equal(typeof simctl.check_prerequisites, 'function')
t.assert.equal(typeof simctl.simctl_version, 'function')
t.assert.equal(typeof simctl.xcode_version, 'function')
t.assert.equal(typeof simctl.create, 'function')
t.assert.equal(typeof simctl.del, 'function')
t.assert.equal(typeof simctl.erase, 'function')
Expand Down Expand Up @@ -75,3 +78,25 @@ test('check_prerequisites success', (t) => {
const retObj = simctl.check_prerequisites()
t.assert.equal(retObj.stdout, undefined)
})

test('xcode version', (t) => {
t.assert ||= require('node:assert')

spawnMock.mock.mockImplementationOnce((...args) => {
return originalSpawnSync.call(childProcess, ...args)
})

const retObj = simctl.xcode_version()
t.assert.ok(retObj[0] >= 8)
})

test('simctl version', (t) => {
t.assert ||= require('node:assert')

spawnMock.mock.mockImplementationOnce((...args) => {
return originalSpawnSync.call(childProcess, ...args)
})

const retObj = simctl.simctl_version()
t.assert.ok(retObj[0] >= 400)
})