1- import { join } from "path" ;
2-
3- import { getHomeDir } from "./getHomeDir" ;
1+ import { getConfigFilepath } from "./getConfigFilepath" ;
2+ import { getCredentialsFilepath } from "./getCredentialsFilepath" ;
43import { getProfileData } from "./getProfileData" ;
5- import { ENV_CONFIG_PATH , ENV_CREDENTIALS_PATH , loadSharedConfigFiles } from "./loadSharedConfigFiles" ;
4+ import { loadSharedConfigFiles } from "./loadSharedConfigFiles" ;
65import { parseIni } from "./parseIni" ;
76import { slurpFile } from "./slurpFile" ;
87
9- jest . mock ( "path " ) ;
10- jest . mock ( "./getHomeDir " ) ;
8+ jest . mock ( "./getConfigFilepath " ) ;
9+ jest . mock ( "./getCredentialsFilepath " ) ;
1110jest . mock ( "./getProfileData" ) ;
1211jest . mock ( "./parseIni" ) ;
1312jest . mock ( "./slurpFile" ) ;
1413
1514describe ( "loadSharedConfigFiles" , ( ) => {
16- const mockSeparator = "/" ;
17- const mockHomeDir = "/mock/home/dir" ;
18-
1915 const mockConfigFilepath = "/mock/file/path/config" ;
2016 const mockCredsFilepath = "/mock/file/path/credentials" ;
21- const mockCustomSharedConfigFiles = {
17+ const mockSharedConfigFiles = {
2218 configFile : mockConfigFilepath ,
2319 credentialsFile : mockCredsFilepath ,
2420 } ;
2521
26- const defaultConfigFilepath = `${ mockHomeDir } /.aws/config` ;
27- const defaultCredsFilepath = `${ mockHomeDir } /.aws/credentials` ;
28- const mockDefaultSharedConfigFiles = {
29- configFile : defaultConfigFilepath ,
30- credentialsFile : defaultCredsFilepath ,
31- } ;
32-
3322 beforeEach ( ( ) => {
34- ( join as jest . Mock ) . mockImplementation ( ( ... args ) => args . join ( mockSeparator ) ) ;
35- ( getHomeDir as jest . Mock ) . mockReturnValue ( mockHomeDir ) ;
23+ ( getConfigFilepath as jest . Mock ) . mockReturnValue ( mockConfigFilepath ) ;
24+ ( getCredentialsFilepath as jest . Mock ) . mockReturnValue ( mockCredsFilepath ) ;
3625 ( parseIni as jest . Mock ) . mockImplementation ( ( args ) => args ) ;
3726 ( getProfileData as jest . Mock ) . mockImplementation ( ( args ) => args ) ;
3827 ( slurpFile as jest . Mock ) . mockImplementation ( ( path ) => Promise . resolve ( path ) ) ;
@@ -45,27 +34,19 @@ describe("loadSharedConfigFiles", () => {
4534
4635 it ( "returns configFile and credentialsFile from default locations" , async ( ) => {
4736 const sharedConfigFiles = await loadSharedConfigFiles ( ) ;
48- expect ( sharedConfigFiles ) . toStrictEqual ( mockDefaultSharedConfigFiles ) ;
49- } ) ;
50-
51- it ( "returns configFile and credentialsFile from locations defined in environment" , async ( ) => {
52- const OLD_ENV = process . env ;
53- process . env = {
54- ...OLD_ENV ,
55- [ ENV_CONFIG_PATH ] : mockConfigFilepath ,
56- [ ENV_CREDENTIALS_PATH ] : mockCredsFilepath ,
57- } ;
58- const sharedConfigFiles = await loadSharedConfigFiles ( { } ) ;
59- expect ( sharedConfigFiles ) . toStrictEqual ( mockCustomSharedConfigFiles ) ;
60- process . env = OLD_ENV ;
37+ expect ( sharedConfigFiles ) . toStrictEqual ( mockSharedConfigFiles ) ;
38+ expect ( getConfigFilepath ) . toHaveBeenCalledWith ( ) ;
39+ expect ( getCredentialsFilepath ) . toHaveBeenCalledWith ( ) ;
6140 } ) ;
6241
6342 it ( "returns configFile and credentialsFile from init if defined" , async ( ) => {
6443 const sharedConfigFiles = await loadSharedConfigFiles ( {
6544 filepath : mockCredsFilepath ,
6645 configFilepath : mockConfigFilepath ,
6746 } ) ;
68- expect ( sharedConfigFiles ) . toStrictEqual ( mockCustomSharedConfigFiles ) ;
47+ expect ( sharedConfigFiles ) . toStrictEqual ( mockSharedConfigFiles ) ;
48+ expect ( getConfigFilepath ) . not . toHaveBeenCalled ( ) ;
49+ expect ( getCredentialsFilepath ) . not . toHaveBeenCalled ( ) ;
6950 } ) ;
7051
7152 describe ( "swallows error and returns empty configuration" , ( ) => {
@@ -86,7 +67,7 @@ describe("loadSharedConfigFiles", () => {
8667 const sharedConfigFiles = await loadSharedConfigFiles ( ) ;
8768 expect ( sharedConfigFiles ) . toStrictEqual ( {
8869 configFile : { } ,
89- credentialsFile : defaultCredsFilepath ,
70+ credentialsFile : mockCredsFilepath ,
9071 } ) ;
9172 } ) ;
9273 } ) ;
0 commit comments