Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
KazuCocoa committed Aug 30, 2024
1 parent bce40e7 commit a8042d2
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 6 deletions.
4 changes: 4 additions & 0 deletions lib/commands/simctl.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ const commands = {
* @throws {Error} If the simctl subcommand command returns non-zero return code, or the given subcommand was invalid.
*/
async mobileSimctl(command, args = []) {
if (!this.opts.udid) {
throw new errors.InvalidArgumentError(`Unknown device or simulator UDID: '${this.opts.udid}'`);
}

if (!SUBCOMMANDS_HAS_DEVICE.includes(command)) {
throw new errors.InvalidArgumentError(`The given command '${command}' is not supported. ` +
`Available subcommands are ${SUBCOMMANDS_HAS_DEVICE.join(',')}`);
Expand Down
26 changes: 20 additions & 6 deletions test/unit/commands/simctl-specs.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,29 @@ describe('general commands', function () {

describe('simctl', function () {
it('should call xcrun simctl', async function () {
driver.isFeatureEnabled = () => true;
mockSimctl.expects('exec').once().withExactArgs('list', { args: ['devices', 'booted', '--json']});
await driver.mobileSimctl('list', ['devices', 'booted', '--json']);
driver.opts.udid = '60EB8FDB-92E0-4895-B466-0153C6DE7BAE';
mockSimctl.expects('exec').once().withExactArgs(
'getenv',
{args: ['60EB8FDB-92E0-4895-B466-0153C6DE7BAE', 'HOME']}
);
await driver.mobileSimctl('getenv', ['HOME']);
});

it('should raise an error as not allowed', async function () {
driver.isFeatureEnabled = () => false;
it('should raise an error as not supported command', async function () {
driver.opts.udid = '60EB8FDB-92E0-4895-B466-0153C6DE7BAE';
mockSimctl.expects('exec').never();
await driver.mobileSimctl('list', ['devices', 'booted', '--json']).should.eventually.be.rejected;
await driver.mobileSimctl(
'list',
['devices', 'booted', '--json']
).should.eventually.be.rejected;
});

it('should raise an error as no udid', async function () {
driver.opts.udid = null;
mockSimctl.expects('exec').never();
await driver.mobileSimctl(
'getenv', ['HOME']
).should.eventually.be.rejected;
});
});
});

0 comments on commit a8042d2

Please sign in to comment.