@@ -698,6 +698,90 @@ describe('writeSchemas indexFiles', () => {
698698 }
699699 } ) ;
700700
701+ it ( 'emits .js import suffixes when tsconfig module is NodeNext' , async ( ) => {
702+ const tempDir = await fs . mkdtemp (
703+ path . join ( os . tmpdir ( ) , 'orval-schema-nodenext-' ) ,
704+ ) ;
705+ const schemaPath = path . join ( tempDir , 'schemas' ) ;
706+
707+ try {
708+ await writeSchemas ( {
709+ schemaPath,
710+ schemas : [
711+ createMockSchema ( 'Pet' ) ,
712+ {
713+ name : 'Owner' ,
714+ model : 'export type Owner = { pet: Pet };' ,
715+ imports : [ { name : 'Pet' } ] ,
716+ schema : { } ,
717+ } ,
718+ ] ,
719+ target : 'src/api' ,
720+ namingConvention : NamingConvention . CAMEL_CASE ,
721+ fileExtension : '.ts' ,
722+ header : '// nodenext' ,
723+ indexFiles : true ,
724+ tsconfig : { compilerOptions : { module : 'NodeNext' } } ,
725+ } ) ;
726+
727+ const ownerContent = await fs . readFile (
728+ path . join ( schemaPath , 'owner.ts' ) ,
729+ 'utf8' ,
730+ ) ;
731+ expect ( ownerContent ) . toContain ( "from './pet.js';" ) ;
732+
733+ const indexContent = await fs . readFile (
734+ path . join ( schemaPath , 'index.ts' ) ,
735+ 'utf8' ,
736+ ) ;
737+ expect ( indexContent ) . toContain ( "export * from './pet.js';" ) ;
738+ expect ( indexContent ) . toContain ( "export * from './owner.js';" ) ;
739+ } finally {
740+ await fs . remove ( tempDir ) ;
741+ }
742+ } ) ;
743+
744+ it ( 'keeps the .ts file extension on imports when allowImportingTsExtensions is true' , async ( ) => {
745+ const tempDir = await fs . mkdtemp (
746+ path . join ( os . tmpdir ( ) , 'orval-schema-allow-ts-' ) ,
747+ ) ;
748+ const schemaPath = path . join ( tempDir , 'schemas' ) ;
749+
750+ try {
751+ await writeSchemas ( {
752+ schemaPath,
753+ schemas : [
754+ createMockSchema ( 'Pet' ) ,
755+ {
756+ name : 'Owner' ,
757+ model : 'export type Owner = { pet: Pet };' ,
758+ imports : [ { name : 'Pet' } ] ,
759+ schema : { } ,
760+ } ,
761+ ] ,
762+ target : 'src/api' ,
763+ namingConvention : NamingConvention . CAMEL_CASE ,
764+ fileExtension : '.gen.ts' ,
765+ header : '// allowImportingTsExtensions' ,
766+ indexFiles : true ,
767+ tsconfig : {
768+ compilerOptions : {
769+ module : 'NodeNext' ,
770+ allowImportingTsExtensions : true ,
771+ } ,
772+ } ,
773+ } ) ;
774+
775+ const ownerContent = await fs . readFile (
776+ path . join ( schemaPath , 'owner.gen.ts' ) ,
777+ 'utf8' ,
778+ ) ;
779+ expect ( ownerContent ) . toContain ( "from './pet.gen.ts';" ) ;
780+ } finally {
781+ await fs . remove ( tempDir ) ;
782+ }
783+ } ) ;
784+
701785 it ( 'normalizes imports to schema name canonical file when importPath is stale' , async ( ) => {
702786 const tempDir = await fs . mkdtemp (
703787 path . join ( os . tmpdir ( ) , 'orval-schema-import-normalize-' ) ,
0 commit comments