1
1
import { getConfigData } from "./getConfigData" ;
2
2
import { getConfigFilepath } from "./getConfigFilepath" ;
3
3
import { getCredentialsFilepath } from "./getCredentialsFilepath" ;
4
+ import { getHomeDir } from "./getHomeDir" ;
4
5
import { loadSharedConfigFiles } from "./loadSharedConfigFiles" ;
5
6
import { parseIni } from "./parseIni" ;
6
7
import { slurpFile } from "./slurpFile" ;
@@ -10,6 +11,7 @@ jest.mock("./getConfigFilepath");
10
11
jest . mock ( "./getCredentialsFilepath" ) ;
11
12
jest . mock ( "./parseIni" ) ;
12
13
jest . mock ( "./slurpFile" ) ;
14
+ jest . mock ( "./getHomeDir" ) ;
13
15
14
16
describe ( "loadSharedConfigFiles" , ( ) => {
15
17
const mockConfigFilepath = "/mock/file/path/config" ;
@@ -18,13 +20,15 @@ describe("loadSharedConfigFiles", () => {
18
20
configFile : mockConfigFilepath ,
19
21
credentialsFile : mockCredsFilepath ,
20
22
} ;
23
+ const mockHomeDir = "/users/alias" ;
21
24
22
25
beforeEach ( ( ) => {
23
26
( getConfigFilepath as jest . Mock ) . mockReturnValue ( mockConfigFilepath ) ;
24
27
( getCredentialsFilepath as jest . Mock ) . mockReturnValue ( mockCredsFilepath ) ;
25
28
( parseIni as jest . Mock ) . mockImplementation ( ( args ) => args ) ;
26
29
( getConfigData as jest . Mock ) . mockImplementation ( ( args ) => args ) ;
27
30
( slurpFile as jest . Mock ) . mockImplementation ( ( path ) => Promise . resolve ( path ) ) ;
31
+ ( getHomeDir as jest . Mock ) . mockReturnValue ( mockHomeDir ) ;
28
32
} ) ;
29
33
30
34
afterEach ( ( ) => {
@@ -49,6 +53,20 @@ describe("loadSharedConfigFiles", () => {
49
53
expect ( getCredentialsFilepath ) . not . toHaveBeenCalled ( ) ;
50
54
} ) ;
51
55
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
+
52
70
describe ( "swallows error and returns empty configuration" , ( ) => {
53
71
it ( "when readFile throws error" , async ( ) => {
54
72
( slurpFile as jest . Mock ) . mockRejectedValue ( "error" ) ;
0 commit comments