Skip to content
This repository was archived by the owner on Feb 2, 2021. It is now read-only.

Fix simulator started on run with fake device id. #993

Merged
merged 2 commits into from
Aug 14, 2017

Conversation

KristianDD
Copy link
Contributor

This fixes NativeScript/nativescript-cli#2728. Before a simulator with default preference was started when using tns run ios --device "fake" and nothing else happens. Now a descriptive error is show to the user.

SHOULD NOT BE MERGED BEFORE - NativeScript/ios-sim-portable#92

@KristianDD KristianDD self-assigned this Jul 26, 2017
@justcodebuilduser
Copy link

💔

@KristianDD KristianDD force-pushed the kddimitrov/fix-ios-run-fake-device branch from 9b45be3 to 4042ab0 Compare July 26, 2017 16:14
@justcodebuilduser
Copy link

💔

@KristianDD KristianDD force-pushed the kddimitrov/fix-ios-run-fake-device branch from 4042ab0 to b1abe55 Compare July 26, 2017 16:18
@justcodebuilduser
Copy link

💔

try {
await this._startEmulatorIfNecessary(data);
} catch (err) {
const errorMessage = this.getEmulatorError(err, data.platform);
Copy link
Contributor

Choose a reason for hiding this comment

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

Please fix the method description, because you changed the method behavior. (now it fails without help)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Please help me find the place where to update the description. I can't see where inside the method description is included the way it fails. There are a few places inside the method that also fail without help (that`s the reason I made it fail without help here also).

Copy link
Collaborator

Choose a reason for hiding this comment

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

failWithoutHelp means that command's help will not be shown, which is fine at the moment.

Copy link
Contributor

Choose a reason for hiding this comment

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

You're right, just describe as best you can what the method does so it's easy to understand.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm not a big fan of getting 10 rows of description what the method does. The name and the code should talk for itself. Some basic info should be enough. But describing that in case A the situation 1 will happen, and in case B situation 2 will happen is not correct, IMO. In case you are interested in all cases - you can always check the implementation.

}

private async _startEmulatorIfNecessary(data?: Mobile.IDevicesServicesInitializationOptions): Promise<void> {
let deviceInstances = this.getDeviceInstances();
Copy link
Contributor

Choose a reason for hiding this comment

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

deviceInstances is already called once on line 393, so there's no need to call it again here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'd prefer that instead of passing it as an argument, but if you insist I can change it...

Copy link
Contributor

Choose a reason for hiding this comment

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

Please do, because it's easier to read and there's no duplicate code.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm also a fan of getting the deviceInstances here, I see no benefit of additional args of the method in this case.
Just make it const instaed of let

@@ -672,6 +686,17 @@ export class DevicesService extends EventEmitter implements Mobile.IDevicesServi
shouldReturnImmediateResult = shouldReturnImmediateResult || false;
return { shouldReturnImmediateResult: shouldReturnImmediateResult, platform: platform };
}

private getEmulatorError(error: Error, platform: string): string {
let emulatorName = "Emulator";
Copy link
Contributor

Choose a reason for hiding this comment

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

please use constants.ts / DeviceTypes and add "Simulator" there


return `Cannot find connected devices.${EOL}` +
`${emulatorName} start failed with: ${error.message}${EOL}` +
`To list currently connected devices and verify that the specified identifier exists, run '${this.$staticConfig.CLIENT_NAME.toLowerCase()} device'.`;
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggestion: tns device only provides the user with the information about the running devices, but the --device also accepts emulator image names. By that logic we can either tell the user to run tns device android --available-devices or make the tns device command to show the available emulator images.

Copy link
Contributor Author

@KristianDD KristianDD Jul 27, 2017

Choose a reason for hiding this comment

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

I think it will be good to add tns devices --available-devices as it is not visible inside specific platform. Moreover as tns devices lists active devices for both platform, and tns devices ios for specific platform it seems consistent that both should accept --available-devices. @rosen-vladimirov what do you think?

Copy link
Collaborator

Choose a reason for hiding this comment

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

I agree with the change, but you can implement it in another PR :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Created an issue/feature request NativeScript/nativescript-cli#3023

try {
await this._startEmulatorIfNecessary(data);
} catch (err) {
const errorMessage = this.getEmulatorError(err, data.platform);
Copy link
Collaborator

Choose a reason for hiding this comment

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

failWithoutHelp means that command's help will not be shown, which is fine at the moment.

}

private async _startEmulatorIfNecessary(data?: Mobile.IDevicesServicesInitializationOptions): Promise<void> {
let deviceInstances = this.getDeviceInstances();
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm also a fan of getting the deviceInstances here, I see no benefit of additional args of the method in this case.
Just make it const instaed of let

@KristianDD KristianDD force-pushed the kddimitrov/fix-ios-run-fake-device branch from c312324 to 5ff2794 Compare July 31, 2017 16:19
@Plamen5kov Plamen5kov force-pushed the kddimitrov/fix-ios-run-fake-device branch from 5ff2794 to 1533d41 Compare August 14, 2017 10:17
@Plamen5kov Plamen5kov merged commit bf42d51 into master Aug 14, 2017
@Plamen5kov Plamen5kov deleted the kddimitrov/fix-ios-run-fake-device branch August 14, 2017 10:20
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

tns run ios --device fakeID start iOS Simulator
4 participants