-
Notifications
You must be signed in to change notification settings - Fork 47
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
Conversation
41e662d
to
562b0fe
Compare
562b0fe
to
801dc63
Compare
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 see several problems:
- ~ comes from linux/unix, does not exist in windows
- ~~ would give wrong 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.
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? |
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. |
backend/src/exploregens.ts
Outdated
@@ -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)); |
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 should be const
backend/tests/exploregens.spec.ts
Outdated
@@ -60,6 +61,7 @@ import { fail } from "assert"; | |||
describe('exploregens unit test', () => { | |||
let sandbox: any; |
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.
type of sandbox should be SinonSandbox
type of every mock should be SinonMock
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's the same in all our spec files!
https://github.com/SAP/yeoman-ui/blob/DEVXBUGS-8621/backend/tests/yeomanui.spec.ts#L39
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.
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." |
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 this solution we need to mention that the path must exists
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.
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 ~", () => { |
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.
this test should have fsMock.expects("existsSync").withExactArgs(TESTVALUE).returns(false);
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.
Better not mock it. location is invalid so existSync will return false.
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.
In test environment accidentally this path may exist and the test will fail. It is better to control it with mock
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.
0.01% that accidentally contains a path equal to '~/notExistLocation'
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 is always better 100%, especially for tests.
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.
so, in this case it 100% that '~/notExistLocation' will not exist on test system.
105b46a
to
9eca4b6
Compare
backend/tests/exploregens.spec.ts
Outdated
@@ -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(""); |
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 is better to remove .returns("") or .returns() if you do not use the returned value
backend/tests/exploregens.spec.ts
Outdated
@@ -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(""); |
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 is better to remove .returns("") or .returns() if you do not use the returned value
backend/tests/exploregens.spec.ts
Outdated
@@ -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(""); |
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 is better to remove .returns("") or .returns() if you do not use the returned value
9eca4b6
to
28c87b2
Compare
This reverts commit 589812a.
This reverts commit 589812a.
No description provided.