Skip to content

Commit

Permalink
fix: do not read credentials file in webpack override scenario (#19)
Browse files Browse the repository at this point in the history
fix: do not read credentials file in webpack override scenario
  • Loading branch information
germanattanasio committed May 7, 2019
2 parents ee8ee33 + 0c5b534 commit ec64ae1
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
6 changes: 5 additions & 1 deletion lib/read-credentials-file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ import path = require('path');
const filename: string = 'ibm-credentials.env';

export function readCredentialsFile() {
if (!fs.existsSync) {
return {};
}

// first look for an env variable called IBM_CREDENTIALS_FILE
// it should be the path to the file

Expand Down Expand Up @@ -48,4 +52,4 @@ export function constructFilepath(filepath): string {
}

return filepath;
}
}
17 changes: 17 additions & 0 deletions test/unit/readCredentialsFile.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,23 @@ const readCredentialsFunctions = require('../../lib/read-credentials-file');
const constructFilepath = readCredentialsFunctions.constructFilepath;
const fileExistsAtPath = readCredentialsFunctions.fileExistsAtPath;
const readCredentialsFile = readCredentialsFunctions.readCredentialsFile;
const fs = require('fs');

describe('browser scenario', () => {
const existSync = fs.existsSync;
beforeAll(() => {
fs.existsSync = undefined;
});

it('should return empty object when webpack override fs with empty object', () => {
const cred = readCredentialsFile();
expect(cred).toEqual({});
});

afterAll(() => {
fs.existsSync = existSync;
});
});

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

0 comments on commit ec64ae1

Please sign in to comment.