-
Notifications
You must be signed in to change notification settings - Fork 671
feat(shared-ini-file-loader): refactor loadSharedConfigFiles into modular components #3285
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
Merged
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
94d719e
chore: delete existing unit tests
trivikr c8911c1
chore: replace slurpFile with readFile
trivikr 4ee2e09
chore: move getHomeDir to new file
trivikr d2a94f2
chore: move parseIni to it's own file
trivikr f3d449b
chore: move normalizeConfigFile to own folder
trivikr e03f060
chore: move loadSharedConfigFiles to own folder
trivikr 3b05b6c
test: getHomeDir.spec.ts
trivikr 31b695b
test: parseIni.spec.ts
trivikr 803b73f
test: normalizeConfigFile.spec.ts
trivikr 5755926
test: loadSharedConfigFiles.spec.ts
trivikr 8a3b8e2
chore: add slurpFile
trivikr cc2d2ff
chore: call slurpFile from loadSharedConfigFiles
trivikr 8392ebd
chore: convert loadSharedConfigFiles to async
trivikr bd2c825
fix: export getHomeDir
trivikr File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| import { homedir } from "os"; | ||
| import { sep } from "path"; | ||
|
|
||
| import { getHomeDir } from "./getHomeDir"; | ||
|
|
||
| jest.mock("os"); | ||
|
|
||
| describe(getHomeDir.name, () => { | ||
| const mockHOME = "mockHOME"; | ||
| const mockUSERPROFILE = "mockUSERPROFILE"; | ||
| const mockHOMEPATH = "mockHOMEPATH"; | ||
| const mockHOMEDRIVE = "mockHOMEDRIVE"; | ||
| const mockHomeDir = "mockHomeDir"; | ||
|
|
||
| const OLD_ENV = process.env; | ||
|
|
||
| beforeEach(() => { | ||
| (homedir as jest.Mock).mockReturnValue(mockHomeDir); | ||
| process.env = { | ||
| ...OLD_ENV, | ||
| HOME: mockHOME, | ||
| USERPROFILE: mockUSERPROFILE, | ||
| HOMEPATH: mockHOMEPATH, | ||
| HOMEDRIVE: mockHOMEDRIVE, | ||
| }; | ||
| }); | ||
|
|
||
| afterEach(() => { | ||
| process.env = OLD_ENV; | ||
| jest.clearAllMocks(); | ||
| jest.resetModules(); | ||
| }); | ||
|
|
||
| it("returns value in process.env.HOME first", () => { | ||
| expect(getHomeDir()).toEqual(mockHOME); | ||
| }); | ||
|
|
||
| it("returns value in process.env.USERPROFILE second", () => { | ||
| process.env = { ...process.env, HOME: undefined }; | ||
| expect(getHomeDir()).toEqual(mockUSERPROFILE); | ||
| }); | ||
|
|
||
| describe("returns value in HOMEPATH third", () => { | ||
| beforeEach(() => { | ||
| process.env = { ...process.env, HOME: undefined, USERPROFILE: undefined }; | ||
| }); | ||
|
|
||
| it("uses value in process.env.HOMEDRIVE if it's set", () => { | ||
| expect(getHomeDir()).toEqual(`${mockHOMEDRIVE}${mockHOMEPATH}`); | ||
| }); | ||
|
|
||
| it("uses default if process.env.HOMEDRIVE is not set", () => { | ||
| process.env = { ...process.env, HOMEDRIVE: undefined }; | ||
| expect(getHomeDir()).toEqual(`C:${sep}${mockHOMEPATH}`); | ||
| }); | ||
| }); | ||
|
|
||
| it("returns value from homedir fourth", () => { | ||
| process.env = { ...process.env, HOME: undefined, USERPROFILE: undefined, HOMEPATH: undefined }; | ||
| expect(getHomeDir()).toEqual(mockHomeDir); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| import { homedir } from "os"; | ||
| import { sep } from "path"; | ||
|
|
||
| /** | ||
| * Get the HOME directory for the current runtime. | ||
| * | ||
| * @internal | ||
| */ | ||
| export const getHomeDir = (): string => { | ||
| const { HOME, USERPROFILE, HOMEPATH, HOMEDRIVE = `C:${sep}` } = process.env; | ||
|
|
||
| if (HOME) return HOME; | ||
| if (USERPROFILE) return USERPROFILE; | ||
| if (HOMEPATH) return `${HOMEDRIVE}${HOMEPATH}`; | ||
|
|
||
| return homedir(); | ||
| }; | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.