ios-control / simctl Goto Github PK
View Code? Open in Web Editor NEWnode.js library for Xcode simctl utility on macOS
License: MIT License
node.js library for Xcode simctl utility on macOS
License: MIT License
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);
}
Right now it's just text, but parse it into easily used json
We need to use "open" again, but note, it is not iOS Simulator
now (they changed it again), now it is just Simulator
:
open -a 'Simulator' --args -CurrentDeviceUDID <device_udid_here>
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.
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
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
The --json flag is new, and will help immensely with parsing.
First reported here:
ios-control/ios-sim#197
xcrun simctl list devices
Is not reporting iPad Pro as this
iPad Pro (9.7 inch) (94B87E6E-51EA-41BA-BDAD-DDA3246712E3) (Shutdown)
iPad Pro (12.9 inch) (C0F6C6F5-80EA-497C-86AD-02A5176E1D30) (Shutdown)
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.
Fix is to implement #12 so it is more robust than the parser we have.
How to open the device window?
This module depends on a version of shelljs that is listed as containing a security vulnerability per npm audit. GHSA-64g7-mvw6-v9qj
This has since been resolved in the newest version of shellJS
https://github.com/shelljs/shelljs/releases/tag/v0.8.5
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
simctl/lib/simctl-extensions.js
Line 52 in c9bb659
should probably be "Could not get device list" or similar
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)
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
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
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.
ios-sim start --devicetype "..."
# Wait for it to start
ios-sim launch --devicetype "..." "..."
# Observe that the simulator exits & then restarts
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 });
}
}
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.