Do not log in test environment
This commit is contained in:
parent
a225d28f75
commit
6d90dd2071
1 changed files with 11 additions and 4 deletions
|
@ -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;
|
||||
|
|
Loading…
Reference in a new issue