Skip to content

Commit

Permalink
Revert "fix: Install generator to location start with tild ~ (#535)"
Browse files Browse the repository at this point in the history
This reverts commit 589812a.
  • Loading branch information
tomer-epstein committed Apr 5, 2021
1 parent 589812a commit 7f1fdb2
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 46 deletions.
4 changes: 2 additions & 2 deletions backend/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "yeoman-ui",
"version": "1.1.61",
"version": "1.1.60",
"displayName": "Application Wizard",
"publisher": "SAPOS",
"author": {
Expand Down Expand Up @@ -135,7 +135,7 @@
},
"ApplicationWizard.installationLocation": {
"type": "string",
"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."
"markdownDescription": "Install generators in a specified location. If not set, global location is used."
},
"ApplicationWizard.autoUpdate": {
"type": "boolean",
Expand Down
4 changes: 1 addition & 3 deletions backend/src/exploregens.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { IChildLogger } from "@vscode-logging/logger";
import { IRpc } from "@sap-devx/webview-rpc/out.ext/rpc-common";
import * as util from "util";
import * as path from "path";
import * as fs from "fs";
import messages from "./exploreGensMessages";
import * as envUtils from "./env/utils";

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

export class ExploreGens {
public static getInstallationLocation(wsConfig: any) {
const location = _.trim(wsConfig.get(ExploreGens.INSTALLATION_LOCATION));
return fs.existsSync(location) ? location : undefined;
return _.trim(wsConfig.get(ExploreGens.INSTALLATION_LOCATION));
}

private static readonly INSTALLATION_LOCATION = "ApplicationWizard.installationLocation";
Expand Down
66 changes: 25 additions & 41 deletions backend/tests/exploregens.spec.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
import * as mocha from "mocha";
import { expect } from "chai";
import { SinonSandbox, SinonMock, createSandbox } from "sinon";
import * as sinon from "sinon";
import * as _ from "lodash";
import * as path from "path";
import * as fs from "fs";
import { IChildLogger } from "@vscode-logging/logger";
import { IRpc, IPromiseCallbacks, IMethod } from "@sap-devx/webview-rpc/out.ext/rpc-common";
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 @@ -59,22 +58,21 @@ import { ExploreGens, GenState } from "../src/exploregens";
import { fail } from "assert";

describe('exploregens unit test', () => {
let sandbox: SinonSandbox;
let rpcMock: SinonMock;
let fsMock: SinonMock;
let workspaceConfigMock: SinonMock;
let exploreGensMock: SinonMock;
let loggerMock: SinonMock;
let npmFetchMock: SinonMock;
let vscodeWindowMock: SinonMock;
let vscodeCommandsMock: SinonMock;
let vscodeWorkspaceMock: SinonMock;
let statusBarMessageMock: SinonMock;
let globalStateMock: SinonMock;
let processMock: SinonMock;
let yoEnvMock: SinonMock;
let testYoEnvMock: SinonMock;
let envUtilsMock: SinonMock;
let sandbox: any;
let rpcMock: any;
let workspaceConfigMock: any;
let exploreGensMock: any;
let loggerMock: any;
let npmFetchMock: any;
let vscodeWindowMock: any;
let vscodeCommandsMock: any;
let vscodeWorkspaceMock: any;
let statusBarMessageMock: any;
let globalStateMock: any;
let processMock: any;
let yoEnvMock: any;
let testYoEnvMock: any;
let envUtilsMock: any;

class TestRpc implements IRpc {
public timeout: number;
Expand Down Expand Up @@ -117,7 +115,7 @@ describe('exploregens unit test', () => {
exploregens.init(rpc);

before(() => {
sandbox = createSandbox();
sandbox = sinon.createSandbox();
});

after(() => {
Expand All @@ -126,7 +124,6 @@ describe('exploregens unit test', () => {

beforeEach(() => {
rpcMock = sandbox.mock(rpc);
fsMock = sandbox.mock(fs);
workspaceConfigMock = sandbox.mock(config);
loggerMock = sandbox.mock(childLogger);
exploreGensMock = sandbox.mock(exploregens);
Expand All @@ -139,12 +136,11 @@ 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(() => {
rpcMock.verify();
fsMock.verify();
workspaceConfigMock.verify();
loggerMock.verify();
exploreGensMock.verify();
Expand Down Expand Up @@ -202,10 +198,9 @@ describe('exploregens unit test', () => {
rpcMock.expects("registerMethod").withExactArgs({ func: exploregens["acceptLegalNote"], thisArg: exploregens });

const customLocation = path.join("home", "user", "projects");
fsMock.expects("existsSync").withExactArgs(customLocation).returns(true);
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 All @@ -219,7 +214,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"]);
workspaceConfigMock.expects("get").withExactArgs(ExploreGens["INSTALLATION_LOCATION"]).returns();
yoEnvMock.expects("createEnv").returns(testYoEnv);
exploregens["init"](rpc);
});
Expand Down Expand Up @@ -323,33 +318,22 @@ describe('exploregens unit test', () => {
});

it("location undefined", () => {
workspaceConfigMock.expects("get").withExactArgs(ExploreGens["INSTALLATION_LOCATION"]);
workspaceConfigMock.expects("get").withExactArgs(ExploreGens["INSTALLATION_LOCATION"]).returns();
const res = exploregens["getGeneratorsLocationParams"]();
expect(res).to.be.equal("-g");
});

it("location is a valid string", () => {
const customLocation = TESTVALUE;
workspaceConfigMock.expects("get").withExactArgs(ExploreGens["INSTALLATION_LOCATION"]).returns(customLocation);
fsMock.expects("existsSync").withExactArgs(customLocation).returns(true);
workspaceConfigMock.expects("get").withExactArgs(ExploreGens["INSTALLATION_LOCATION"]).returns(TESTVALUE);
const res = exploregens["getGeneratorsLocationParams"]();
expect(res).to.be.equal(`--prefix ${TESTVALUE}`);
});

it("location is a string with unnecessary spaces", () => {
const customLocation = ` ${TESTVALUE} `;
workspaceConfigMock.expects("get").withExactArgs(ExploreGens["INSTALLATION_LOCATION"]).returns(customLocation);
fsMock.expects("existsSync").withExactArgs(TESTVALUE).returns(true);
workspaceConfigMock.expects("get").withExactArgs(ExploreGens["INSTALLATION_LOCATION"]).returns(` ${TESTVALUE} `);
const res = exploregens["getGeneratorsLocationParams"]();
expect(res).to.be.deep.equal(`--prefix ${TESTVALUE}`);
});

it("location starts with tild ~", () => {
const location = '~/notExistLocation';
workspaceConfigMock.expects("get").withExactArgs(ExploreGens["INSTALLATION_LOCATION"]).returns(location);
const res = exploregens["getGeneratorsLocationParams"]();
expect(res).to.be.equal("-g");
});
});

it("exec", async () => {
Expand All @@ -369,7 +353,7 @@ describe('exploregens unit test', () => {
});

it("recommended array is undefined", () => {
workspaceConfigMock.expects("get").withExactArgs(exploregens["SEARCH_QUERY"]);
workspaceConfigMock.expects("get").withExactArgs(exploregens["SEARCH_QUERY"]).returns();
const res = exploregens["getRecommendedQuery"]();
expect(res).to.have.lengthOf(0);
});
Expand Down

0 comments on commit 7f1fdb2

Please sign in to comment.