@@ -12,6 +12,13 @@ function getTmpFileName() {
12
12
return path . resolve ( tmpDir , `${ ++ id } .test.generated.ts` ) ;
13
13
}
14
14
15
+ function copyAndGetTmpFileName ( fileToCopyPath : string , newFileName : string ) : string {
16
+ newFileName = `${ ++ id } .test.${ newFileName } ` ;
17
+ const newFilePath = path . resolve ( tmpDir , newFileName ) ;
18
+ fs . copyFileSync ( fileToCopyPath , newFilePath , fs . constants . COPYFILE_EXCL ) ;
19
+ return newFileName ;
20
+ }
21
+
15
22
function cli ( args : string [ ] , cwd : string ) : Promise < { error : ExecException | null ; stdout : string ; stderr : string } > {
16
23
return new Promise ( ( resolve ) => {
17
24
exec (
@@ -171,6 +178,34 @@ describe('CLI options testing', () => {
171
178
expect ( numberOfErrors ) . toEqual ( 0 ) ;
172
179
} ) ;
173
180
181
+ it ( "should import { default as customBaseQuery } from './customBaseQuery' when a local customBaseQuery is provided to --baseQuery" , async ( ) => {
182
+ const localBaseQueryName = copyAndGetTmpFileName ( './test/fixtures/customBaseQuery.ts' , 'localCustomBaseQuery.ts' ) ;
183
+ const fileName = getTmpFileName ( ) ;
184
+ const result = await cli (
185
+ [
186
+ '-h' ,
187
+ `--baseQuery` ,
188
+ `./test/tmp/${ localBaseQueryName } :namedBaseQuery` ,
189
+ '--file' ,
190
+ fileName ,
191
+ `./test/fixtures/petstore.json` ,
192
+ ] ,
193
+ '.'
194
+ ) ;
195
+
196
+ const output = fs . readFileSync ( fileName , { encoding : 'utf-8' } ) ;
197
+
198
+ const strippedLocalBaseQueryName = path . parse ( localBaseQueryName ) . name ;
199
+
200
+ expect ( output ) . not . toContain ( 'fetchBaseQuery' ) ;
201
+ expect ( output ) . toContain ( `import { namedBaseQuery } from './${ strippedLocalBaseQueryName } '` ) ;
202
+
203
+ const expectedErrors = [ MESSAGES . NAMED_EXPORT_MISSING ] ;
204
+
205
+ const numberOfErrors = expectedErrors . filter ( ( msg ) => result . stderr . indexOf ( msg ) > - 1 ) . length ;
206
+ expect ( numberOfErrors ) . toEqual ( 0 ) ;
207
+ } ) ;
208
+
174
209
it ( 'should error out when the specified with path alias is not found' , async ( ) => {
175
210
const result = await cli (
176
211
[ '-h' , `--baseQuery` , `@/hoge/fuga/nonExistantFile` , `./test/fixtures/petstore.json` ] ,
0 commit comments