Skip to content

Commit

Permalink
add simulator check
Browse files Browse the repository at this point in the history
  • Loading branch information
KazuCocoa committed Aug 30, 2024
1 parent 43434dc commit 2185145
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 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.isSimulator()) {
throw new errors.UnsupportedOperationError(`Only simulator is supported.`);
};

if (!this.opts.udid) {
throw new errors.InvalidArgumentError(`Unknown device or simulator UDID: '${this.opts.udid}'`);
}
Expand Down
12 changes: 12 additions & 0 deletions test/unit/commands/simctl-specs.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ describe('general commands', function () {
describe('simctl', function () {
it('should call xcrun simctl', async function () {
driver.opts.udid = '60EB8FDB-92E0-4895-B466-0153C6DE7BAE';
driver.isSimulator = () => true;
mockSimctl.expects('exec').once().withExactArgs(
'getenv',
{args: ['60EB8FDB-92E0-4895-B466-0153C6DE7BAE', 'HOME']}
Expand All @@ -36,6 +37,7 @@ describe('general commands', function () {

it('should raise an error as not supported command', async function () {
driver.opts.udid = '60EB8FDB-92E0-4895-B466-0153C6DE7BAE';
driver.isSimulator = () => true;
mockSimctl.expects('exec').never();
await driver.mobileSimctl(
'list',
Expand All @@ -45,6 +47,16 @@ describe('general commands', function () {

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

it('should raise an error for non-simulator', async function () {
driver.opts.udid = '60EB8FDB-92E0-4895-B466-0153C6DE7BAE';
driver.isSimulator = () => false;
mockSimctl.expects('exec').never();
await driver.mobileSimctl(
'getenv', ['HOME']
Expand Down

0 comments on commit 2185145

Please sign in to comment.