File tree 1 file changed +11
-4
lines changed
1 file changed +11
-4
lines changed Original file line number Diff line number Diff line change
1
+ function isTestEnvironment ( ) {
2
+ // eslint-disable-next-line no-use-before-define
3
+ return getConfig ( 'NODE_ENV' , { warn : false } ) === 'test' ;
4
+ }
5
+
1
6
/**
2
7
* Returns config item from environment
3
8
*/
4
- export default function getConfig ( key ) {
9
+ function getConfig ( key , options = { warn : ! isTestEnvironment ( ) } ) {
5
10
if ( key == null ) {
6
11
throw new Error ( '"key" must be provided to getConfig()' ) ;
7
12
}
8
13
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 ] ;
11
16
12
- if ( value == null ) {
17
+ if ( value == null && options ?. warn !== false ) {
13
18
console . warn ( `getConfig("${ key } ") returned null` ) ;
14
19
}
15
20
16
21
return value ;
17
22
}
23
+
24
+ export default getConfig ;
You can’t perform that action at this time.
0 commit comments