File tree Expand file tree Collapse file tree 5 files changed +20
-7
lines changed Expand file tree Collapse file tree 5 files changed +20
-7
lines changed Original file line number Diff line number Diff line change 11import { TEXT_FILE_REGEX } from '../../../../server/utils/fileUtils' ;
22import { apiClient } from '../../../utils/apiClient' ;
3- import { getConfig , isTestEnvironment } from '../../../utils/getConfig' ;
3+ import { getConfig } from '../../../utils/getConfig' ;
4+ import { isTestEnvironment } from '../../../utils/checkTestEnv' ;
45import { handleCreateFile } from './files' ;
56
67const s3BucketUrlBase = getConfig ( 'S3_BUCKET_URL_BASE' ) ;
Original file line number Diff line number Diff line change 1+ import { getEnvVar } from './getConfig' ;
2+
3+ export const isTestEnvironment = getEnvVar ( 'NODE_ENV' ) === 'test' ;
Original file line number Diff line number Diff line change 1+ import { isTestEnvironment } from './checkTestEnv' ;
2+
13/**
2- * Internal function to retrieve env vars, with no error handling.
4+ * Function to retrieve env vars, with no error handling.
35 * @returns String value of env variable or undefined if not found.
46 */
5- function getEnvVar ( key : string ) : string | undefined {
7+ export function getEnvVar ( key : string ) : string | undefined {
68 const configSource = global ?? window ;
79 const env = configSource ?. process ?. env ?? { } ;
810
@@ -16,8 +18,6 @@ interface GetConfigOptions {
1618 throwErrorInTestEnv ?: boolean ; // this is only to test getConfig and should never be set to override defaults
1719}
1820
19- export const isTestEnvironment = getEnvVar ( 'NODE_ENV' ) === 'test' ;
20-
2121const defaultGetConfigOptions : GetConfigOptions = {
2222 warn : ! isTestEnvironment ,
2323 nullishString : false ,
Original file line number Diff line number Diff line change 11import { parseNumber , parseBoolean } from './parseStringToType' ;
22
3+ jest . mock ( './checkTestEnv' , ( ) => ( {
4+ isTestEnvironment : false
5+ } ) ) ;
6+
37describe ( 'parseNumber' , ( ) => {
48 beforeEach ( ( ) => {
59 jest . spyOn ( console , 'warn' ) . mockImplementation ( ( ) => { } ) ;
Original file line number Diff line number Diff line change 1+ import { isTestEnvironment } from './checkTestEnv' ;
12/* eslint-disable consistent-return */
23/**
34 * Parses a string into a number.
@@ -9,7 +10,9 @@ export function parseNumber(
910 nullishNumber = false
1011) : number | undefined {
1112 if ( ! str ) {
12- console . warn ( `parseNumber: got nullish input` ) ;
13+ if ( ! isTestEnvironment ) {
14+ console . warn ( `parseNumber: got nullish input` ) ;
15+ }
1316 return nullishNumber ? 0 : undefined ;
1417 }
1518
@@ -32,7 +35,9 @@ export function parseBoolean(
3235 nullishBool = false
3336) : boolean | undefined {
3437 if ( ! str ) {
35- console . warn ( 'parseBoolean: got nullish input' ) ;
38+ if ( ! isTestEnvironment ) {
39+ console . warn ( 'parseBoolean: got nullish input' ) ;
40+ }
3641 return nullishBool ? false : undefined ;
3742 }
3843
You can’t perform that action at this time.
0 commit comments