Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: do not read credentials file in webpack override scenario #19

Merged
merged 2 commits into from
May 7, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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