11import { promises as fspromises } from 'fs' ;
22import * as tmp from 'tmp' ;
3- import resolveConfig , { findPackageJson , ResolveConfigVariables } from '../resolveConfig' ;
3+ import resolveConfig , {
4+ envToBool ,
5+ findPackageJson ,
6+ ResolveConfigVariables ,
7+ } from '../resolveConfig' ;
48import { assertion , isNullOrUndefined } from '../utils' ;
59
610tmp . setGracefulCleanup ( ) ;
@@ -26,6 +30,10 @@ describe('resolveConfig', () => {
2630 const originalDir = process . cwd ( ) ;
2731 let tmpObj : tmp . DirResult ;
2832
33+ afterEach ( ( ) => {
34+ jest . restoreAllMocks ( ) ;
35+ } ) ;
36+
2937 describe ( 'findPackageJson' , ( ) => {
3038 beforeAll ( async ( ) => {
3139 // Set up test project/subproject structure in a temporary directory:
@@ -86,4 +94,26 @@ describe('resolveConfig', () => {
8694 expect ( out . config . inner ) . toBe ( true ) ;
8795 } ) ;
8896 } ) ;
97+
98+ describe ( 'envToBool' , ( ) => {
99+ it ( 'should resolve all supported cases to right booleans' , ( ) => {
100+ expect ( envToBool ( '1' ) ) . toStrictEqual ( true ) ;
101+ expect ( envToBool ( 'on' ) ) . toStrictEqual ( true ) ;
102+ expect ( envToBool ( 'ON' ) ) . toStrictEqual ( true ) ;
103+ expect ( envToBool ( 'yes' ) ) . toStrictEqual ( true ) ;
104+ expect ( envToBool ( 'YES' ) ) . toStrictEqual ( true ) ;
105+ expect ( envToBool ( 'true' ) ) . toStrictEqual ( true ) ;
106+ expect ( envToBool ( 'TRUE' ) ) . toStrictEqual ( true ) ;
107+
108+ expect ( envToBool ( 'anythingelse' ) ) . toStrictEqual ( false ) ;
109+ expect ( envToBool ( 'false' ) ) . toStrictEqual ( false ) ;
110+ } ) ;
111+
112+ it ( 'should return false when input is not a string' , ( ) => {
113+ expect (
114+ // @ts -expect-error "envToBool" only supports "string" as a input
115+ envToBool ( true )
116+ ) . toStrictEqual ( false ) ;
117+ } ) ;
118+ } ) ;
89119} ) ;
0 commit comments