Do not log in test environment

This commit is contained in:
Andrew Nicolaou 2020-06-13 12:51:26 +02:00
parent a225d28f75
commit 6d90dd2071

View file

@ -1,17 +1,24 @@
function isTestEnvironment() {
// eslint-disable-next-line no-use-before-define
return getConfig('NODE_ENV', { warn: false }) === 'test';
}
/**
* Returns config item from environment
*/
export default function getConfig(key) {
function getConfig(key, options = { warn: !isTestEnvironment() }) {
if (key == null) {
throw new Error('"key" must be provided to getConfig()');
}
const __process = (typeof global !== 'undefined' ? global : window).process;
const value = __process.env[key];
const env = (typeof global !== 'undefined' ? global : window)?.process?.env || {};
const value = env[key];
if (value == null) {
if (value == null && options?.warn !== false) {
console.warn(`getConfig("${key}") returned null`);
}
return value;
}
export default getConfig;