Skip to content

Commit ec64ae1

Browse files
fix: do not read credentials file in webpack override scenario (#19)
fix: do not read credentials file in webpack override scenario
2 parents ee8ee33 + 0c5b534 commit ec64ae1

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

lib/read-credentials-file.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ import path = require('path');
66
const filename: string = 'ibm-credentials.env';
77

88
export function readCredentialsFile() {
9+
if (!fs.existsSync) {
10+
return {};
11+
}
12+
913
// first look for an env variable called IBM_CREDENTIALS_FILE
1014
// it should be the path to the file
1115

@@ -48,4 +52,4 @@ export function constructFilepath(filepath): string {
4852
}
4953

5054
return filepath;
51-
}
55+
}

test/unit/readCredentialsFile.test.js

+17
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,23 @@ const readCredentialsFunctions = require('../../lib/read-credentials-file');
44
const constructFilepath = readCredentialsFunctions.constructFilepath;
55
const fileExistsAtPath = readCredentialsFunctions.fileExistsAtPath;
66
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+
});
724

825
describe('read ibm credentials file', () => {
926
const locationOfActualFile = __dirname + '/../resources';

0 commit comments

Comments
 (0)