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
8 changes: 8 additions & 0 deletions simctl.js
Original file line number Diff line number Diff line change
Expand Up @@ -173,5 +173,13 @@ module.exports = {
} else {
return spawnSync('xcrun', ['simctl', 'help'])
}
},

pair: function (watchDevice, phoneDevice) {
return spawnSync('xcrun', ['simctl', 'pair', watchDevice, phoneDevice])
},

unpair: function (pairUUID) {
return spawnSync('xcrun', ['simctl', 'unpair', pairUUID])
}
}
58 changes: 58 additions & 0 deletions test/simctl.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ test('exports', (t) => {
t.assert.equal(typeof simctl.icloud_sync, 'function')
t.assert.equal(typeof simctl.create, 'function')
t.assert.equal(typeof simctl.help, 'function')
t.assert.equal(typeof simctl.pair, 'function')
t.assert.equal(typeof simctl.unpair, 'function')
})

test('check_prerequisites fail', (t) => {
Expand Down Expand Up @@ -208,3 +210,59 @@ test('simctl help', async (ctx) => {
t.assert.deepEqual(spawnMock.mock.calls[0].arguments[1], ['simctl', 'help', 'launch'])
})
})

test('simctl pair', async (ctx) => {
ctx.beforeEach((t) => {
spawnMock.mock.resetCalls()
})

await ctx.test('with no arguments', (t) => {
t.assert ||= require('node:assert')

spawnMock.mock.mockImplementationOnce(() => {
return { status: 0, stdout: '' }
})

simctl.pair()
t.assert.deepEqual(spawnMock.mock.calls[0].arguments[1], ['simctl', 'pair', undefined, undefined])
})

await ctx.test('with fake watchDevice & phoneDevice', (t) => {
t.assert ||= require('node:assert')

spawnMock.mock.mockImplementationOnce(() => {
return { status: 0, stdout: '' }
})

simctl.pair('foobarWatch', 'foobarPhone')
t.assert.deepEqual(spawnMock.mock.calls[0].arguments[1], ['simctl', 'pair', 'foobarWatch', 'foobarPhone'])
})
})

test('simctl unpair', async (ctx) => {
ctx.beforeEach((t) => {
spawnMock.mock.resetCalls()
})

await ctx.test('with no arguments', (t) => {
t.assert ||= require('node:assert')

spawnMock.mock.mockImplementationOnce(() => {
return { status: 0, stdout: '' }
})

simctl.unpair()
t.assert.deepEqual(spawnMock.mock.calls[0].arguments[1], ['simctl', 'unpair', undefined])
})

await ctx.test('with fake deviceUUID', (t) => {
t.assert ||= require('node:assert')

spawnMock.mock.mockImplementationOnce(() => {
return { status: 0, stdout: '' }
})

simctl.unpair('foobar')
t.assert.deepEqual(spawnMock.mock.calls[0].arguments[1], ['simctl', 'unpair', 'foobar'])
})
})