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
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion backend/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "yeoman-ui",
"version": "1.1.60",
"version": "1.1.61",
"displayName": "Application Wizard",
"publisher": "SAPOS",
"author": {
Expand Down
6 changes: 5 additions & 1 deletion backend/src/exploregens.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,11 @@ 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

if (_.startsWith(location, "~")) {
location = _.replace(location,"~",envUtils.HOME_DIR);
}
return location;
}

private static readonly INSTALLATION_LOCATION = "ApplicationWizard.installationLocation";
Expand Down
14 changes: 11 additions & 3 deletions backend/tests/exploregens.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import * as npmFetch from 'npm-registry-fetch';
import { mockVscode } from "./mockUtil";
import messages from "../src/exploreGensMessages";
import Environment = require("yeoman-environment");
import * as envutils from "../src/env/utils";
import * as envUtils from "../src/env/utils";

const testYoEnv = {
lookup: () => true,
Expand Down Expand Up @@ -136,7 +136,7 @@ describe('exploregens unit test', () => {
yoEnvMock = sandbox.mock(Environment);
testYoEnvMock = sandbox.mock(testYoEnv);
vscodeCommandsMock = sandbox.mock(testVscode.commands);
envUtilsMock = sandbox.mock(envutils);
envUtilsMock = sandbox.mock(envUtils);
});

afterEach(() => {
Expand Down Expand Up @@ -200,7 +200,7 @@ describe('exploregens unit test', () => {
const customLocation = path.join("home", "user", "projects");
workspaceConfigMock.expects("get").withExactArgs(ExploreGens["INSTALLATION_LOCATION"]).returns(customLocation);
yoEnvMock.expects("createEnv").returns(testYoEnv);
testYoEnvMock.expects("lookup").withArgs({ npmPaths: [path.join(customLocation, envutils.NODE_MODULES)] });
testYoEnvMock.expects("lookup").withArgs({ npmPaths: [path.join(customLocation, envUtils.NODE_MODULES)] });
exploregens["init"](rpc);
});

Expand Down Expand Up @@ -334,6 +334,14 @@ describe('exploregens unit test', () => {
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.

const location = '~/location';
workspaceConfigMock.expects("get").withExactArgs(ExploreGens["INSTALLATION_LOCATION"]).returns(location);
const res = exploregens["getGeneratorsLocationParams"]();
const install_location = _.replace(location,"~",envUtils.HOME_DIR);
expect(res).to.be.equal(`--prefix ${install_location}`);
});
});

it("exec", async () => {
Expand Down