GithubHelp home page GithubHelp logo

simctl's Introduction

Build status

library wrapper for Xcode's simctl utility on OS X

Used by ios-sim

Requirements

Xcode 8 or greater

simctl's People

Contributors

airdrummingfool avatar dependabot[bot] avatar erisu avatar marekkalnik avatar shazron avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

simctl's Issues

get 100% code coverage

npm test should show coverage. Look in the coverage folder for an index.html page that will give specifics.

Add required coverage in jest.config.js

unable to get device details, possibly due to shelljs update

It appears the recent update of the shelljs version (in #27) has introduced a regression. This line now throws an error:

Error: Unhandled error. ('[ios-sim] SyntaxError: Unexpected token u in JSON at position 0\n' +
  '    at JSON.parse (<anonymous>)\n' +
  '    at Object.list (/Users/paultomkinson/Documents/textras/repos/textrasnow/node_modules/simctl/simctl.js:173:33)\n' +
  '    at getDeviceFromDeviceTypeId (/Users/paultomkinson/Documents/textras/repos/textrasnow/node_modules/ios-sim/src/lib.js:155:21)\n' +
  '    at /Users/paultomkinson/Documents/textras/repos/textrasnow/node_modules/ios-sim/src/lib.js:460:22\n' +
  '    at withInjectedEnvironmentVariablesToProcess (/Users/paultomkinson/Documents/textras/repos/textrasnow/node_modules/ios-sim/src/lib.js:269:3)\n' +
  '    at /Users/paultomkinson/Documents/textras/repos/textrasnow/node_modules/ios-sim/src/lib.js:457:7\n' +
  '    at tryParseBuffer (/Users/paultomkinson/Documents/textras/repos/textrasnow/node_modules/ios-sim/node_modules/bplist-parser/bplistParser.js:25:5)\n' +
  '    at /Users/paultomkinson/Documents/textras/repos/textrasnow/node_modules/ios-sim/node_modules/bplist-parser/bplistParser.js:33:7\n' +
  '    at FSReqCallback.readFileAfterClose [as oncomplete] (internal/fs/read_file_context.js:63:3)\n')

I noticed that obj itself contained the json string, so I tried changing the code to:

            try {
                obj.json = JSON.parse(obj.output);
            } catch (err) {
                // console.error(err.stack);
                obj.json = JSON.parse(obj.output);
            }

unable to get device details, possibly due to recent update in shelljs version

It appears the recent update of the shelljs version (in #27) has introduced a regression. This line now throws an error:

Error: Unhandled error. ('[ios-sim] SyntaxError: Unexpected token u in JSON at position 0\n' +
  '    at JSON.parse (<anonymous>)\n' +
  '    at Object.list (/Users/{user}/Documents/{project}/node_modules/simctl/simctl.js:173:33)\n' +
  '    at getDeviceFromDeviceTypeId (/Users/{user}/Documents/{project}/node_modules/ios-sim/src/lib.js:155:21)\n' +
  '    at /Users/{user}/Documents/{project}/node_modules/ios-sim/src/lib.js:460:22\n' +
  '    at withInjectedEnvironmentVariablesToProcess (/Users/{user}/Documents/{project}/node_modules/ios-sim/src/lib.js:269:3)\n' +
  '    at /Users/{user}/Documents/{project}/node_modules/ios-sim/src/lib.js:457:7\n' +
  '    at tryParseBuffer (/Users/{user}/Documents/{project}/node_modules/ios-sim/node_modules/bplist-parser/bplistParser.js:25:5)\n' +
  '    at /Users/{user}/Documents/{project}/node_modules/ios-sim/node_modules/bplist-parser/bplistParser.js:33:7\n' +
  '    at FSReqCallback.readFileAfterClose [as oncomplete] (internal/fs/read_file_context.js:63:3)\n')

I noticed that obj itself now contains the json string (obj.output is now undefined), so I tried changing the code to:

            try {
                obj.json = JSON.parse(obj.output);
            } catch (err) {
                // console.error(err.stack);
                obj.json = JSON.parse(obj);
            }

That gave a different error:

Error: Unhandled error. ('[ios-sim] An error was encountered processing the command (domain=com.apple.CoreSimulator.SimError, code=405):\n' +
  'Unable to lookup in current state: Shutdown\n')

So I think there are other bits of logic that are affected by the shelljs update apart from the line of code I saw.

simctl.extensions.start fails to start new simulator if simulator with different deviceId is already running

  1. Call simctl.extensions.start(deviceId1)
  2. Leave simulator running and call simctl.extensions.start(deviceId2)

Simulator does not switch to deviceId2.

When trying to call simctl.install() after second start, the following error is returned...

An error was encountered processing the command (domain=com.apple.CoreSimulator.SimError, code=159):
Invalid device state

The bug occurs in 0.0.8, but works correctly in 0.0.6

This can be seen with the attached node.js app.
simctl-test.zip

// To test, get list of deviceIds from 'xcrun simctl list' and then run the following command twice with diffeent device ids
//node ./index.js {PATH_TO_APP} {DEVICE_ID}
// e.g.
//node ./index.js ~/HelloWorld.app EAA544F1-D533-4168-9F4A-790AFE764DDA
//node ./index.js ~/HelloWorld.app 3F6912C6-1392-40B7-95CC-41A69EC07BCD

[1.1.x & Xcode9] start extension restarts simulator if already running

Expected behavior

This library is used by ios-sim.
To test you can could use ios-sim launch with the proper parameters.
If the simulator is already running, it should just start install/launch the desired app.

Note that that was the normal behavior, that got broken from versions after the 1.0.1

Actual behavior.

The simulator exits, and then starts again, before installing/launching the desired app.
Refer to ios-control/ios-sim#223
However the issue is on this library.

Steps to reproduce the problem

ios-sim start --devicetype "..."
# Wait for it to start
ios-sim launch --devicetype "..." "..."
# Observe that the simulator exits & then restarts

Proposed solutions

The following code replacing the start extension in file `simctl-extensions.js fixes this issue:

    start: function(deviceid) {
        var is_at_least_xcode_9 = false;

        // var command = 'killall Simulator';
        // shell.exec(command, { silent: true });

        command = 'xcodebuild -version';
        var output = shell.exec(command, { silent: true }).output;

        // parse output for Xcode version
        var versionMatch = /Xcode (.*)/.exec(output);
        if (!versionMatch) {
            console.log('Unable to parse xcodebuild version.');
            return;
        } else {
            is_at_least_xcode_9 = (parseInt(versionMatch[1]) >= 9);
        }

        if (is_at_least_xcode_9) {
            // Xcode 9 or greater
            command = util.format('xcrun simctl list -j');
            var res = shell.exec(command, { silent: true });
            if (res.code !== 0) {
                console.log('Unable to parse xcodebuild version.');
                return;
            }
            let output = JSON.parse(res.output);
            // Object.keys(output.devices).reduce( (acc, key) => acc.concat(output.devices[key]), []).find(el => el.udid === deviceid);
            var device = Object.keys(output.devices)
                .reduce( function(acc, key) { return acc.concat(output.devices[key]) }, [])
                .find( function (el) { return el.udid === deviceid });
            // console.log('Simulator device info: ', device);          
            if (device.state === 'Booted') {
                // no need to launch the emulator, it is already running
                console.log('Simulator already running.');
                return;
            }
            command = util.format('xcrun simctl boot "%s"', deviceid);
            shell.exec(command, { silent: true });
            command = 'open `xcode-select -p`/Applications/Simulator.app';
            return shell.exec(command, { silent: true });
        } else {
            // Xcode 8 or older
            // command = util.format('xcrun simctl shutdown booted');
            // shell.exec(command, { silent: true });
            command = util.format('xcrun instruments -w "%s"', deviceid);
            return shell.exec(command, { silent: true });
        }
    }

Reverse the check for Simulator app

In 0.0.8, It checks for Simulator.app (Xcode 6 and below), then iOS Simulator.app (Xcode 7+).

Reverse it to check for iOS Simulator.app first.

Support "== Device Pairs ==" in "simctl list"

Example:

== Device Pairs ==
5FF44272-BBAD-48FF-A10D-BC3B4F5A2EB7 (active, disconnected)
    Watch: Apple Watch Series 2 - 38mm (B4BB8453-349F-4CBF-A5A9-87BE602DB13E) (Shutdown)
    Phone: iPhone 7 (87894360-0337-459E-816E-AE5EFD0A4570) (Shutdown)
8C4F6036-8329-4B48-BF7F-3EC0B4452305 (active, disconnected)
    Watch: Apple Watch Series 2 - 42mm (0C527828-EBF4-4FD0-A66B-200FE716EB37) (Shutdown)
    Phone: iPhone 7 Plus (8D85405B-96CA-4268-87D1-CE594567F5EF) (Shutdown)
F125F8D9-31D7-41AC-A246-902BF0FCC63B (unavailable)
    Watch: Apple Watch - 38mm (3B9DA51F-B68F-4444-A9AE-787192E57836) (Shutdown)
    Phone: iPhone 6s (F7A9D3B2-16FB-4BA0-A4DA-9EFA2D4079EA) (Shutdown)
38F67D27-D764-4FC0-A758-61A81BBF75EC (unavailable)
    Watch: Apple Watch - 42mm (A232151E-E24D-4B27-B978-070305AE9193) (Shutdown)
    Phone: iPhone 6s Plus (B53FDB63-F7B0-4830-A49D-96438D204F08) (Shutdown)
DDEA5CBF-C6A0-41E4-A1C4-D59C4215589E (unavailable)
    Watch: Apple Watch - 38mm (E65BB631-3FD1-41A2-892C-DC4EBBA812ED) (Shutdown)
    Phone: iPhone 6s (3A6334BA-4ECB-47F2-BA82-9D00BBAE1C28) (Shutdown)
3DF9B8EE-46DC-4177-9D7A-3AF064807699 (unavailable)
    Watch: Apple Watch - 42mm (5C7FFD69-2B78-4A29-8A5E-61AB738D8E90) (Shutdown)
    Phone: iPhone 6s Plus (9CB234AA-B642-4FEC-AE69-82C859366F31) (Shutdown)
65B1DA54-D93D-4AC2-8F2D-43843D3E66ED (unavailable)
    Watch: Apple Watch - 38mm (26E6E37E-A530-4ED3-A70A-9D51CC0FF992) (Shutdown)
    Phone: iPhone 6s (EE4EAA23-09EC-4247-AAB1-26F8637685E6) (Shutdown)
463B79D8-1510-4CD5-BA0B-C68D078F0925 (unavailable)
    Watch: Apple Watch - 42mm (A30CC5D7-4BD0-4B8F-ACCC-7C00B0EECB12) (Shutdown)
    Phone: iPhone 6s Plus (E58AEBBD-F0DB-41FC-80C1-489AC823AD9C) (Shutdown)

add non-mocked shelljs test

This is to ensure that the result of a shelljs.exec, if successful, contains the stdout property (among others).

call node -e 'console.log("foo")' and see if the output matches

'Invalid Device State' error

I've published ios-sim 5.0.5 but it is not set to the latest tag (you have to install it explicitly by version). These lines have a problem when used in Apache Cordova cordova emulate ios, there is an Invalid Device State error:
https://github.com/phonegap/simctl/blob/b60bf5b9e0439e22d5d67c3df855c16c23933d0a/lib/simctl-extensions.js#L37-L41

If I take them out and set it to 'Simulator' explicitly it works.

Error:

An error was encountered processing the command (domain=com.apple.CoreSimulator.SimError, code=159):
Invalid device state
An error was encountered processing the command (domain=com.apple.CoreSimulator.SimError, code=159):
Invalid device state

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.