Skip to content

Commit 6d90dd2

Browse files
committed
Do not log in test environment
1 parent a225d28 commit 6d90dd2

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

client/utils/getConfig.js

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,24 @@
1+
function isTestEnvironment() {
2+
// eslint-disable-next-line no-use-before-define
3+
return getConfig('NODE_ENV', { warn: false }) === 'test';
4+
}
5+
16
/**
27
* Returns config item from environment
38
*/
4-
export default function getConfig(key) {
9+
function getConfig(key, options = { warn: !isTestEnvironment() }) {
510
if (key == null) {
611
throw new Error('"key" must be provided to getConfig()');
712
}
813

9-
const __process = (typeof global !== 'undefined' ? global : window).process;
10-
const value = __process.env[key];
14+
const env = (typeof global !== 'undefined' ? global : window)?.process?.env || {};
15+
const value = env[key];
1116

12-
if (value == null) {
17+
if (value == null && options?.warn !== false) {
1318
console.warn(`getConfig("${key}") returned null`);
1419
}
1520

1621
return value;
1722
}
23+
24+
export default getConfig;

0 commit comments

Comments
 (0)