Skip to content
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

Updating the react-native run-ios command to use UDID #6043

Closed
wants to merge 1 commit into from
Closed

Updating the react-native run-ios command to use UDID #6043

wants to merge 1 commit into from

Conversation

icodethings
Copy link

Updating the react-native run-ios command to launch the simulator based off the UUID and to retrieve the list of simulators with the --json flag and therefore removing the reliance on regex parsing and the local-cli/runIOS/parseIOSSimulatorsList.js.

This solves a few problems:

  1. When trying to launch an iOS simulator with just the name when you have other simulators that are similarly named.
    For example, you may have a simulator called 'iPhone 6' and one called 'iPhone 6 + 38mm Apple Watch'.
    If you try and run xcrun instruments -w "iPhone 6" you will get an error Instruments Usage Error : Ambiguous device name/identifier 'iPhone 6'.
  2. If there is a simulator with brackets in it's name (e.g. "iPhone 6 (test 2)") the regex will parse the contents of the contents of the brackets as the UDID.
    This isn't an issue prior to this change for launching the simulator, if that was the only simulator starting with 'iPhone6' as the (test 2) would be stripped from the name. The UDID is used for building the project so it would have failed there too.
  3. It won't launch unavailable simulators. Because we can accurately get the status of each simulator, we can filter out ones that are not in the available state.
    This could be extended to check if they are already booted, or to use the default one as the booted one.

All in all, this feels like a must more robust way of parsing the output of the list of simulators.

Tests
I have tested this with the following setup of simulators:

  • "iPhone 4s" (9.2)
  • "iPhone 5" (9.2)
  • "iPhone 6" (9.2)
  • "iPhone 6" (9.2) + Apple Watch - 38mm
  • "iPhone 6s" (9.2)
  • "iPhone 6 (Plus)" (9.2)

This would previously not work because running xcrun instruments -w "iPhone 6" would match all of the above that start with "iPhone 6" and throw an error.

@facebook-github-bot
Copy link
Contributor

By analyzing the blame information on this pull request, we identified @frantic to be a potential reviewer.

@facebook-github-bot facebook-github-bot added GH Review: review-needed CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. labels Feb 20, 2016
@grabbou
Copy link
Contributor

grabbou commented Feb 22, 2016

CC: @mkonicek @frantic going to test it & leave the feedback since I can reproduce it already in my projects.

@facebook-github-bot
Copy link
Contributor

@icodethings updated the pull request.

@mkonicek
Copy link
Contributor

Why remove the test (parseIOSSimulatorsList-test.js)? Since you updated the parsing code can you also update the test please?

@icodethings
Copy link
Author

@mkonicek I've also removed the parseIOSSimulatorsList.js. Hence removing parseIOSSimulatorsList-test.js.

@icodethings
Copy link
Author

The command that gets the simulator list now returns JSON. We don't need to use regex (inside parseIOSSimulatorsList.js)

@mkonicek
Copy link
Contributor

Sorry for the lack of clarity. I meant adding a test for the new parsing code.

@facebook-github-bot
Copy link
Contributor

@icodethings updated the pull request.

@icodethings
Copy link
Author

I've moved the code that picks the simulator to a separate file and added tests for the function.

};
}

if(simulatorName === null && !match){
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: space after if (everywhere, for consistency with the rest of this file and the codebase)

@mkonicek
Copy link
Contributor

mkonicek commented Mar 1, 2016

Cool, thanks for adding the tests. Good idea with using the --json arg. Just nits now, almost good to go.

@facebook-github-bot
Copy link
Contributor

@icodethings updated the pull request.

@icodethings
Copy link
Author

@mkonicek I've fixed those things up

@grabbou
Copy link
Contributor

grabbou commented Mar 3, 2016

There still seem to be quite a few styling issues here - would be so cool to get that shipped soon since its' finally going to allow running on iPhone 6s (currently there's naming collision)

@icodethings
Copy link
Author

Is there a link to a code style guide??

@mkonicek
Copy link
Contributor

mkonicek commented Mar 3, 2016

Tests are green on master now. I restarted the build to make sure this passes all tests:
https://travis-ci.org/facebook/react-native/builds/113004514

The style guide is very simple, assumed if (foo) { is obvious, we should probably add it or make ESLint catch it:
https://github.com/facebook/react-native/blob/master/CONTRIBUTING.md#style-guide

describe('findMatchingSimulator', () => {
it('should find simulator', () => {
expect(findMatchingSimulator({
"devices": {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe move this JSON to a const? This way the test cases will be much more readable.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@frantic Each one of these JSON blobs are unique to each test. I was thinking it'd be easier to read if each of them were inside the test. Thoughts?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Personally I find it very hard to read this test file. I believe it will make it easier if you use same inputs for each test – currently the search token ('iPhone 6') and expected result are deeply burrowed inside the test function, and the IDs are very random.

@facebook-github-bot
Copy link
Contributor

@icodethings updated the pull request.

1 similar comment
@facebook-github-bot
Copy link
Contributor

@icodethings updated the pull request.

@icodethings
Copy link
Author

@mkonicek There was one thing around moving the JSON blobs in the test to the top of the document that you can see in the changed files.

Other than that, I've just done a rebase and pushed so we should see test come green soon!

version
};
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Can you kill all the empty lines inside this method?

@mkonicek
Copy link
Contributor

cc @frantic For final review. Looks good to me in general, also has a test now.

Updating the `react-native run-ios` command to launch the simulator based off the UUID and to retrieve the list of simulators with the --json flag and therefor removing the reliance on regex parsing and the `local-cli/runIOS/parseIOSSimulatorsList.js`.

This solves a few problems:
1) 	When trying to launch an iOS simulator with just the name when you have other simulators that are similarly named.
	For example, you may have a simulator called 'iPhone 6' and one called iPhone 6 + 38mm Apple Watch'.
	If you try and run `xcrun instruments -w "iPhone 6"` you will get an error Instruments Usage Error : Ambiguous device name/identifier 'iPhone 6'.

2)	If there is a simulator with brackets in it's name (e.g. "iPhone 6 (test 2)") the regex will parse the contents of the contents of the brackets as the UDID.
	This isn't an issue prior to this change for launching the simulator, but the UDID is used for building the project so it would have failed there.

3)	It won't launch unavailable simulators. Because we can accurately get the status of each simulator, we can filter out ones that are not in the available state.
	This could be extended to check if they are already booted, or to use the default one as the booted one.

All in all, this feels like a must more robust way of parsing the output of the list of simulators.

I've also removed the default of 'iPhone 6' for the currently booted simulator, or the first in the list. If there is a simulator that is booted, we can't boot any others.
@facebook-github-bot
Copy link
Contributor

@icodethings updated the pull request.

1 similar comment
@facebook-github-bot
Copy link
Contributor

@icodethings updated the pull request.

return null;
}
const devices = simulators.devices;
var match;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: use let for consistency?

* @param Object simulators a parsed list from `xcrun simctl list --json devices` command
* @param String|null simulatorName the string with the name of desired simulator. If null, it will use the currently
* booted simulator, or if none are booted, the first in the list.
* @returns {Object} {udid, name, version}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Prefer using @flow, doctype comment types are not typechecked

@ghost
Copy link

ghost commented Apr 6, 2016

@icodethings do you have any updates for this pull request? It's been a while so we wanted to check in and see if you've looked at the requested changes.

@jsierles
Copy link
Contributor

@icodethings Just checking if you have time to update this PR. It would be great to ship this!

@ghost ghost added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Jul 12, 2016
@mbraude
Copy link

mbraude commented Aug 24, 2016

@icodethings @jsierles any way we can get some traction on this so we can merge it in?

@ghost ghost added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Aug 24, 2016
@mkonicek
Copy link
Contributor

mkonicek commented Sep 9, 2016

It looks like the last comments are mostly nits and a comment about the readability of the test.

I'll merge this because quite a few people need the feature.

@facebook-github-bot shipit

@ghost ghost added CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. GH Review: accepted Import Started This pull request has been imported. This does not imply the PR has been approved. and removed GH Review: needs-revision labels Sep 9, 2016
@ghost
Copy link

ghost commented Sep 9, 2016

Thanks for importing. If you are an FB employee go to Phabricator to review internal test results.

@mkonicek
Copy link
Contributor

mkonicek commented Sep 9, 2016

Looks like this has now merge conflicts and needs to be rebased, sorry! @icodethings, @mbraude, @jsierles, @grabbou would you be up for sending a new PR which is just this PR rebased, and using Flow instead of types in JS docs as frantic suggested?

I'll close this PR just so it doesn't stay open indefinitely (there have been no updates from author in a while). A new PR is definitely welcome, this fixes a bug many people will run into!

@mkonicek mkonicek closed this Sep 9, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. Import Started This pull request has been imported. This does not imply the PR has been approved.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants