@@ -647,3 +647,86 @@ describe('query parameters', () => {
647647 expect ( api ) . toMatchSnapshot ( ) ;
648648 } ) ;
649649} ) ;
650+
651+ describe ( 'esmExtensions option' , ( ) => {
652+ beforeAll ( async ( ) => {
653+ if ( ! ( await isDir ( tmpDir ) ) ) {
654+ await fs . mkdir ( tmpDir , { recursive : true } ) ;
655+ }
656+ } ) ;
657+
658+ afterEach ( async ( ) => {
659+ await rimraf ( `${ tmpDir } /*.ts` , { glob : true } ) ;
660+ } ) ;
661+
662+ test ( 'should convert .ts to .js when esmExtensions is true' , async ( ) => {
663+ await generateEndpoints ( {
664+ apiFile : './fixtures/emptyApi.ts' ,
665+ outputFile : './test/tmp/out.ts' ,
666+ schemaFile : resolve ( __dirname , 'fixtures/petstore.json' ) ,
667+ filterEndpoints : [ ] ,
668+ esmExtensions : true ,
669+ } ) ;
670+ const content = await fs . readFile ( './test/tmp/out.ts' , 'utf8' ) ;
671+ expect ( content ) . toContain ( "import { api } from '../../fixtures/emptyApi.js'" ) ;
672+ } ) ;
673+
674+ test ( 'should convert .mts to .mjs when esmExtensions is true' , async ( ) => {
675+ await generateEndpoints ( {
676+ apiFile : './fixtures/emptyApi.mts' ,
677+ outputFile : './test/tmp/out.ts' ,
678+ schemaFile : resolve ( __dirname , 'fixtures/petstore.json' ) ,
679+ filterEndpoints : [ ] ,
680+ esmExtensions : true ,
681+ } ) ;
682+ const content = await fs . readFile ( './test/tmp/out.ts' , 'utf8' ) ;
683+ expect ( content ) . toContain ( "import { api } from '../../fixtures/emptyApi.mjs'" ) ;
684+ } ) ;
685+
686+ test ( 'should preserve .jsx when esmExtensions is true' , async ( ) => {
687+ await generateEndpoints ( {
688+ apiFile : './fixtures/emptyApi.jsx' ,
689+ outputFile : './test/tmp/out.ts' ,
690+ schemaFile : resolve ( __dirname , 'fixtures/petstore.json' ) ,
691+ filterEndpoints : [ ] ,
692+ esmExtensions : true ,
693+ } ) ;
694+ const content = await fs . readFile ( './test/tmp/out.ts' , 'utf8' ) ;
695+ expect ( content ) . toContain ( "import { api } from '../../fixtures/emptyApi.jsx'" ) ;
696+ } ) ;
697+
698+ test ( 'should convert .tsx to .jsx when esmExtensions is true' , async ( ) => {
699+ await generateEndpoints ( {
700+ apiFile : './fixtures/emptyApi.tsx' ,
701+ outputFile : './test/tmp/out.ts' ,
702+ schemaFile : resolve ( __dirname , 'fixtures/petstore.json' ) ,
703+ filterEndpoints : [ ] ,
704+ esmExtensions : true ,
705+ } ) ;
706+ const content = await fs . readFile ( './test/tmp/out.ts' , 'utf8' ) ;
707+ expect ( content ) . toContain ( "import { api } from '../../fixtures/emptyApi.jsx'" ) ;
708+ } ) ;
709+
710+ test ( 'should strip extensions when esmExtensions is false' , async ( ) => {
711+ await generateEndpoints ( {
712+ apiFile : './fixtures/emptyApi.ts' ,
713+ outputFile : './test/tmp/out.ts' ,
714+ schemaFile : resolve ( __dirname , 'fixtures/petstore.json' ) ,
715+ filterEndpoints : [ ] ,
716+ esmExtensions : false ,
717+ } ) ;
718+ const content = await fs . readFile ( './test/tmp/out.ts' , 'utf8' ) ;
719+ expect ( content ) . toContain ( "import { api } from '../../fixtures/emptyApi'" ) ;
720+ } ) ;
721+
722+ test ( 'should strip extensions when esmExtensions is undefined (default)' , async ( ) => {
723+ await generateEndpoints ( {
724+ apiFile : './fixtures/emptyApi.ts' ,
725+ outputFile : './test/tmp/out.ts' ,
726+ schemaFile : resolve ( __dirname , 'fixtures/petstore.json' ) ,
727+ filterEndpoints : [ ] ,
728+ } ) ;
729+ const content = await fs . readFile ( './test/tmp/out.ts' , 'utf8' ) ;
730+ expect ( content ) . toContain ( "import { api } from '../../fixtures/emptyApi'" ) ;
731+ } ) ;
732+ } ) ;
0 commit comments