@@ -3,9 +3,11 @@ import * as tmp from 'tmp';
33import resolveConfig , {
44 envToBool ,
55 findPackageJson ,
6+ processConfigOption ,
67 ResolveConfigVariables ,
78} from '../resolveConfig' ;
89import { assertion , isNullOrUndefined } from '../utils' ;
10+ import camelCase from 'camelcase' ;
911
1012tmp . setGracefulCleanup ( ) ;
1113
@@ -116,4 +118,50 @@ describe('resolveConfig', () => {
116118 ) . toStrictEqual ( false ) ;
117119 } ) ;
118120 } ) ;
121+
122+ describe ( 'processConfigOptions' , ( ) => {
123+ it ( 'should return a empty object when input was not a object' , ( ) => {
124+ expect ( processConfigOption ( undefined , '' ) ) . toStrictEqual ( { } ) ;
125+
126+ expect ( processConfigOption ( '' , '' ) ) . toStrictEqual ( { } ) ;
127+ } ) ;
128+
129+ it ( 'should return the input with being processed (relative)' , ( ) => {
130+ const filePath = '/some/path/to/somewhere' ;
131+ const downloadDirPath = './relative/' ;
132+ const systemBinaryPath = './sysBinary/' ;
133+ const ccDownloadDir = camelCase ( ResolveConfigVariables . DOWNLOAD_DIR ) ;
134+ const ccSystemBinary = camelCase ( ResolveConfigVariables . SYSTEM_BINARY ) ;
135+ const input = {
136+ [ ccDownloadDir ] : downloadDirPath ,
137+ [ ccSystemBinary ] : systemBinaryPath ,
138+ somethingRandom : 'hello' ,
139+ } ;
140+
141+ const output = processConfigOption ( input , filePath ) ;
142+
143+ expect ( output . somethingRandom ) . toStrictEqual ( 'hello' ) ;
144+ expect ( output [ ccDownloadDir ] ) . toStrictEqual ( '/some/path/to/somewhere/relative' ) ;
145+ expect ( output [ ccSystemBinary ] ) . toStrictEqual ( '/some/path/to/somewhere/sysBinary' ) ;
146+ } ) ;
147+
148+ it ( 'should return the input with being processed (absolute)' , ( ) => {
149+ const filePath = '/some/path/to/somewhere' ;
150+ const downloadDirPath = '/relative/' ;
151+ const systemBinaryPath = '/sysBinary/' ;
152+ const ccDownloadDir = camelCase ( ResolveConfigVariables . DOWNLOAD_DIR ) ;
153+ const ccSystemBinary = camelCase ( ResolveConfigVariables . SYSTEM_BINARY ) ;
154+ const input = {
155+ [ ccDownloadDir ] : downloadDirPath ,
156+ [ ccSystemBinary ] : systemBinaryPath ,
157+ somethingRandom : 'hello' ,
158+ } ;
159+
160+ const output = processConfigOption ( input , filePath ) ;
161+
162+ expect ( output . somethingRandom ) . toStrictEqual ( 'hello' ) ;
163+ expect ( output [ ccDownloadDir ] ) . toStrictEqual ( '/relative' ) ;
164+ expect ( output [ ccSystemBinary ] ) . toStrictEqual ( '/sysBinary' ) ;
165+ } ) ;
166+ } ) ;
119167} ) ;
0 commit comments