11import { getConfigData } from "./getConfigData" ;
22import { getConfigFilepath } from "./getConfigFilepath" ;
33import { getCredentialsFilepath } from "./getCredentialsFilepath" ;
4+ import { getHomeDir } from "./getHomeDir" ;
45import { loadSharedConfigFiles } from "./loadSharedConfigFiles" ;
56import { parseIni } from "./parseIni" ;
67import { slurpFile } from "./slurpFile" ;
@@ -10,6 +11,7 @@ jest.mock("./getConfigFilepath");
1011jest . mock ( "./getCredentialsFilepath" ) ;
1112jest . mock ( "./parseIni" ) ;
1213jest . mock ( "./slurpFile" ) ;
14+ jest . mock ( "./getHomeDir" ) ;
1315
1416describe ( "loadSharedConfigFiles" , ( ) => {
1517 const mockConfigFilepath = "/mock/file/path/config" ;
@@ -18,13 +20,15 @@ describe("loadSharedConfigFiles", () => {
1820 configFile : mockConfigFilepath ,
1921 credentialsFile : mockCredsFilepath ,
2022 } ;
23+ const mockHomeDir = "/users/alias" ;
2124
2225 beforeEach ( ( ) => {
2326 ( getConfigFilepath as jest . Mock ) . mockReturnValue ( mockConfigFilepath ) ;
2427 ( getCredentialsFilepath as jest . Mock ) . mockReturnValue ( mockCredsFilepath ) ;
2528 ( parseIni as jest . Mock ) . mockImplementation ( ( args ) => args ) ;
2629 ( getConfigData as jest . Mock ) . mockImplementation ( ( args ) => args ) ;
2730 ( slurpFile as jest . Mock ) . mockImplementation ( ( path ) => Promise . resolve ( path ) ) ;
31+ ( getHomeDir as jest . Mock ) . mockReturnValue ( mockHomeDir ) ;
2832 } ) ;
2933
3034 afterEach ( ( ) => {
@@ -49,6 +53,20 @@ describe("loadSharedConfigFiles", () => {
4953 expect ( getCredentialsFilepath ) . not . toHaveBeenCalled ( ) ;
5054 } ) ;
5155
56+ it ( "expands homedir in configFile and credentialsFile from init if defined" , async ( ) => {
57+ const sharedConfigFiles = await loadSharedConfigFiles ( {
58+ filepath : "~/path/credentials" ,
59+ configFilepath : "~/path/config" ,
60+ } ) ;
61+ expect ( sharedConfigFiles ) . toStrictEqual ( {
62+ configFile : "/users/alias/path/config" ,
63+ credentialsFile : "/users/alias/path/credentials" ,
64+ } ) ;
65+ expect ( getHomeDir ) . toHaveBeenCalled ( ) ;
66+ expect ( getConfigFilepath ) . not . toHaveBeenCalled ( ) ;
67+ expect ( getCredentialsFilepath ) . not . toHaveBeenCalled ( ) ;
68+ } ) ;
69+
5270 describe ( "swallows error and returns empty configuration" , ( ) => {
5371 it ( "when readFile throws error" , async ( ) => {
5472 ( slurpFile as jest . Mock ) . mockRejectedValue ( "error" ) ;
0 commit comments