-
-
Notifications
You must be signed in to change notification settings - Fork 44
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Add setting geolocation by set-simulator-location as the first method #249
Conversation
lib/simulator-xcode-8.js
Outdated
]); | ||
return true; | ||
} catch (ign) {} | ||
log.warn(`Cannot set geolocation with ${LYFT_SET_LOCATION}, because it is not installed or failed to set.`); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd rather log the warning inside catch
block and additionally print the stderr output. fs.which
should be in separate block, so we could supply more detailed instructions on how to install the tool if it is not installed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it would be also more logical to extract the whole stuff to a separate method/helper function
lib/geolocation.js
Outdated
* into the corresponding edit field, for example '19,0068'. | ||
* @return {boolean} True if the given geolocation was able to set. | ||
*/ | ||
async function execLyftSetLocation (udid, latitude, longitude) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would prefer this function to throw an exception in case of failure rather then returning a boolean result
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same below
lib/geolocation.js
Outdated
* into the corresponding edit field, for example '19,0068'. | ||
* @return {boolean} True if the given geolocation was able to set. | ||
*/ | ||
async function execIbdSetLocation (idb, latitude, longitude) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd rather rename the functions to setLocationWith...
lib/simulator-xcode-8.js
Outdated
`); | ||
log.debug(`Geolocation parameters dialog accepted: ${output}`); | ||
return _.isString(output) && output.trim() === 'true'; | ||
return await execLyftSetLocation(this.udid, latitude, longitude) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The method should throw an error if all the possible set location methods failed
lib/geolocation.js
Outdated
*/ | ||
async function execLyftSetLocation (udid, latitude, longitude) { | ||
async function setLocationWithLyftSetLocation (udid, latitude, longitude) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
setLocationWithLyft
should be enough
lib/geolocation.js
Outdated
*/ | ||
async function execLyftSetLocation (udid, latitude, longitude) { | ||
async function setLocationWithLyftSetLocation (udid, latitude, longitude) { | ||
try { | ||
await fs.which(LYFT_SET_LOCATION); | ||
} catch (e) { | ||
log.info(`'${LYFT_SET_LOCATION}' binary has not been found in your PATH. ` + |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
an exception should be throw here
lib/geolocation.js
Outdated
} catch (e) { | ||
log.warn(`Failed to set geolocation with '${LYFT_SET_LOCATION}'. ` + | ||
throw new Error(`Failed to set geolocation with '${LYFT_SET_LOCATION}'. ` + | ||
`Original error: ${e.message}`); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
e.stderr || e.message
lib/geolocation.js
Outdated
} | ||
log.info(`Cannot set geolocation with idb, because it is not installed`); | ||
return false; | ||
throw new Error('Failed to set geolocation with idb. because it is not installed'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
...with idb because...
lib/geolocation.js
Outdated
@@ -91,9 +87,11 @@ async function execAppleScript (sim, latitude, longitude) { | |||
end tell | |||
`); | |||
log.debug(`Geolocation parameters dialog accepted: ${output}`); | |||
return _.isString(output) && output.trim() === 'true'; | |||
if (_.isString(output) && output.trim() !== 'true') { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if (_.trim(output) !== 'true') {
throw new Error('Failed to set geolocation with AppleScript. Original error: ${output}');
}
lib/geolocation.js
Outdated
*/ | ||
async function execIbdSetLocation (idb, latitude, longitude) { | ||
async function setLocationWithIbdSetLocation (idb, latitude, longitude) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
setLocationWithIdb
should be fine (also there's a typo ;) )
lib/simulator-xcode-8.js
Outdated
return await execLyftSetLocation(this.udid, latitude, longitude) | ||
|| await execIbdSetLocation(this.idb, latitude, longitude) | ||
|| await execAppleScript(this, latitude, longitude); | ||
try { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const locationSetters = [
async () => await setLocationWithLyft(this.udid, latitude, longitude),
async () => await setLocationWithIbdSetLocation(this.idb, latitude, longitude),
...
];
let lastError;
for (const setter of locationSetters) {
try {
await setter();
return true;
} catch (e) {
log.info(e.message);
lastError = e;
}
}
throw lastError;
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
wow...
https://github.com/lyft/set-simulator-location
This works on Xcode 11.2 environment on my env. (against iOS 12 and iOS 13)
Current idb does not work well on Xcode 11 env, so, let's try another way before idb try.