File tree 2 files changed +22
-1
lines changed
2 files changed +22
-1
lines changed Original file line number Diff line number Diff line change @@ -6,6 +6,10 @@ import path = require('path');
6
6
const filename : string = 'ibm-credentials.env' ;
7
7
8
8
export function readCredentialsFile ( ) {
9
+ if ( ! fs . existsSync ) {
10
+ return { } ;
11
+ }
12
+
9
13
// first look for an env variable called IBM_CREDENTIALS_FILE
10
14
// it should be the path to the file
11
15
@@ -48,4 +52,4 @@ export function constructFilepath(filepath): string {
48
52
}
49
53
50
54
return filepath ;
51
- }
55
+ }
Original file line number Diff line number Diff line change @@ -4,6 +4,23 @@ const readCredentialsFunctions = require('../../lib/read-credentials-file');
4
4
const constructFilepath = readCredentialsFunctions . constructFilepath ;
5
5
const fileExistsAtPath = readCredentialsFunctions . fileExistsAtPath ;
6
6
const readCredentialsFile = readCredentialsFunctions . readCredentialsFile ;
7
+ const fs = require ( 'fs' ) ;
8
+
9
+ describe ( 'browser scenario' , ( ) => {
10
+ const existSync = fs . existsSync ;
11
+ beforeAll ( ( ) => {
12
+ fs . existsSync = undefined ;
13
+ } ) ;
14
+
15
+ it ( 'should return empty object when webpack override fs with empty object' , ( ) => {
16
+ const cred = readCredentialsFile ( ) ;
17
+ expect ( cred ) . toEqual ( { } ) ;
18
+ } ) ;
19
+
20
+ afterAll ( ( ) => {
21
+ fs . existsSync = existSync ;
22
+ } ) ;
23
+ } ) ;
7
24
8
25
describe ( 'read ibm credentials file' , ( ) => {
9
26
const locationOfActualFile = __dirname + '/../resources' ;
You can’t perform that action at this time.
0 commit comments