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

fix: Install generator to location start with tild ~ #535

Merged
merged 2 commits into from
Apr 5, 2021

Conversation

tomer-epstein
Copy link
Contributor

No description provided.

Copy link
Member

@slavik-lvovsky slavik-lvovsky left a comment

Choose a reason for hiding this comment

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

I see several problems:

  1. ~ comes from linux/unix, does not exist in windows
  2. ~~ would give wrong result

@tomer-epstein
Copy link
Contributor Author

tomer-epstein commented Mar 31, 2021

I see several problems:

  1. ~ comes from linux/unix, does not exist in windows
  2. ~~ would give wrong result
  1. Right. if someone will place a tild in windows (in beginning of path) it will be replace with home dir.
  2. Sure. Any wrong path would give wrong result. It replace only the 1st tild. I see this as good solution, any other tild is part of the path.

Copy link
Member

@slavik-lvovsky slavik-lvovsky left a comment

Choose a reason for hiding this comment

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

This , and other similar, setting property were designed to support only full path that user should provide. A path should be valid because today we do not provide validation for it.
We should probably improve the description of the property but not support all available linux path short hands. Especially when this property is used also in windows.

@tomer-epstein
Copy link
Contributor Author

tomer-epstein commented Apr 1, 2021

This , and other similar, setting property were designed to support only full path that user should provide. A path should be valid because today we do not provide validation for it.
We should probably improve the description of the property but not support all available linux path short hands. Especially when this property is used also in windows.

What do u suggest? To drop this fix?
I dont think it is posdible to validate textfield value in the prefrence.

@slavik-lvovsky
Copy link
Member

This , and other similar, setting property were designed to support only full path that user should provide. A path should be valid because today we do not provide validation for it.
We should probably improve the description of the property but not support all available linux path short hands. Especially when this property is used also in windows.

What do u suggest? To drop this fix?
I dont think it is posdible to validate textfield value in the prefrence.

Need to validate a provided path in exploregens.ts. In case that a path does not exist or invalid we should use the npm public installation path.
The description of the property should explain that the installation path must be valid and absolute.

@@ -18,7 +19,8 @@ export enum GenState {

export class ExploreGens {
public static getInstallationLocation(wsConfig: any) {
return _.trim(wsConfig.get(ExploreGens.INSTALLATION_LOCATION));
let location = _.trim(wsConfig.get(ExploreGens.INSTALLATION_LOCATION));
Copy link
Member

Choose a reason for hiding this comment

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

it should be const

@@ -60,6 +61,7 @@ import { fail } from "assert";
describe('exploregens unit test', () => {
let sandbox: any;
Copy link
Member

Choose a reason for hiding this comment

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

type of sandbox should be SinonSandbox
type of every mock should be SinonMock

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Member

Choose a reason for hiding this comment

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

Right, it was like this until Alex Gilin found the best option. We should gradually replace all any by right type

@@ -135,7 +135,7 @@
},
"ApplicationWizard.installationLocation": {
"type": "string",
"markdownDescription": "Install generators in a specified location. If not set, global location is used."
"markdownDescription": "Set the default folder in which generators will be installed. The path to this folder must be valid and absolute. If there is no path defined, the global location will be used."
Copy link
Member

Choose a reason for hiding this comment

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

With this solution we need to mention that the path must exists

Copy link
Contributor Author

Choose a reason for hiding this comment

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

approved by Paola.
must be valid --> means it's exist. (valid)

const res = exploregens["getGeneratorsLocationParams"]();
expect(res).to.be.deep.equal(`--prefix ${TESTVALUE}`);
});

it("location starts with tild ~", () => {
Copy link
Member

Choose a reason for hiding this comment

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

this test should have fsMock.expects("existsSync").withExactArgs(TESTVALUE).returns(false);

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Better not mock it. location is invalid so existSync will return false.

Copy link
Member

Choose a reason for hiding this comment

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

In test environment accidentally this path may exist and the test will fail. It is better to control it with mock

Copy link
Contributor Author

Choose a reason for hiding this comment

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

0.01% that accidentally contains a path equal to '~/notExistLocation'

Copy link
Member

Choose a reason for hiding this comment

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

It is always better 100%, especially for tests.

Copy link
Contributor Author

@tomer-epstein tomer-epstein Apr 5, 2021

Choose a reason for hiding this comment

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

so, in this case it 100% that '~/notExistLocation' will not exist on test system.

@tomer-epstein tomer-epstein force-pushed the DEVXBUGS-8621 branch 4 times, most recently from 105b46a to 9eca4b6 Compare April 4, 2021 18:42
@@ -353,7 +369,7 @@ describe('exploregens unit test', () => {
});

it("recommended array is undefined", () => {
workspaceConfigMock.expects("get").withExactArgs(exploregens["SEARCH_QUERY"]).returns();
workspaceConfigMock.expects("get").withExactArgs(exploregens["SEARCH_QUERY"]).returns("");
Copy link
Member

Choose a reason for hiding this comment

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

it is better to remove .returns("") or .returns() if you do not use the returned value

@@ -318,22 +323,33 @@ describe('exploregens unit test', () => {
});

it("location undefined", () => {
workspaceConfigMock.expects("get").withExactArgs(ExploreGens["INSTALLATION_LOCATION"]).returns();
workspaceConfigMock.expects("get").withExactArgs(ExploreGens["INSTALLATION_LOCATION"]).returns("");
Copy link
Member

Choose a reason for hiding this comment

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

it is better to remove .returns("") or .returns() if you do not use the returned value

@@ -214,7 +219,7 @@ describe('exploregens unit test', () => {
rpcMock.expects("registerMethod").withExactArgs({ func: exploregens["isLegalNoteAccepted"], thisArg: exploregens });
rpcMock.expects("registerMethod").withExactArgs({ func: exploregens["acceptLegalNote"], thisArg: exploregens });

workspaceConfigMock.expects("get").withExactArgs(ExploreGens["INSTALLATION_LOCATION"]).returns();
workspaceConfigMock.expects("get").withExactArgs(ExploreGens["INSTALLATION_LOCATION"]).returns("");
Copy link
Member

Choose a reason for hiding this comment

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

it is better to remove .returns("") or .returns() if you do not use the returned value

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants