-
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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, | ||
|
@@ -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(() => { | ||
|
@@ -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); | ||
}); | ||
|
||
|
@@ -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 ~", () => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 commentThe 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 commentThe 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 commentThe 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 commentThe 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 commentThe 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 () => { | ||
|
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