From a8042d277d5832a5ed44b8c44564a0ae6e1b437a Mon Sep 17 00:00:00 2001 From: Kazuaki Matsuo Date: Fri, 30 Aug 2024 00:21:32 -0700 Subject: [PATCH] add tests --- lib/commands/simctl.js | 4 ++++ test/unit/commands/simctl-specs.js | 26 ++++++++++++++++++++------ 2 files changed, 24 insertions(+), 6 deletions(-) diff --git a/lib/commands/simctl.js b/lib/commands/simctl.js index 383c94327..492932f23 100644 --- a/lib/commands/simctl.js +++ b/lib/commands/simctl.js @@ -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(',')}`); diff --git a/test/unit/commands/simctl-specs.js b/test/unit/commands/simctl-specs.js index aadff63c8..8eb638ffd 100644 --- a/test/unit/commands/simctl-specs.js +++ b/test/unit/commands/simctl-specs.js @@ -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; }); }); });