@@ -564,7 +564,7 @@ test('mergeWithFileConfig: resolves expected typescript file options', async t =
564564 ts : true ,
565565 tsConfigPath,
566566 eslintConfigId,
567- tsConfig,
567+ tsConfig : manager . tsConfigResolvePaths ( tsConfig , tsConfigPath ) ,
568568 } ;
569569 t . deepEqual ( options , expected ) ;
570570} ) ;
@@ -585,20 +585,52 @@ test('mergeWithFileConfig: resolves expected tsx file options', async t => {
585585 ts : true ,
586586 tsConfigPath,
587587 eslintConfigId,
588- tsConfig,
588+ tsConfig : manager . tsConfigResolvePaths ( tsConfig , tsConfigPath ) ,
589589 } ;
590590 t . deepEqual ( options , expected ) ;
591591} ) ;
592592
593593test ( 'mergeWithFileConfig: uses specified parserOptions.project as tsconfig' , async t => {
594594 const cwd = path . resolve ( 'fixtures' , 'typescript' , 'parseroptions-project' ) ;
595- const filePath = path . resolve ( cwd , 'does-not-matter .ts' ) ;
595+ const filePath = path . resolve ( cwd , 'included-file .ts' ) ;
596596 const expectedTsConfigPath = path . resolve ( cwd , 'projectconfig.json' ) ;
597597 const { options} = await manager . mergeWithFileConfig ( { cwd, filePath} ) ;
598598 t . is ( options . tsConfigPath , expectedTsConfigPath ) ;
599599} ) ;
600600
601- test ( 'mergeWithFileConfig: extends ts config if needed' , async t => {
601+ test ( 'mergeWithFileConfig: correctly resolves relative tsconfigs excluded file' , async t => {
602+ const cwd = path . resolve ( 'fixtures' , 'typescript' , 'relative-configs' ) ;
603+ const excludedFilePath = path . resolve ( cwd , 'excluded-file.ts' ) ;
604+ const excludeTsConfigPath = new RegExp ( `${ slash ( cwd ) } /node_modules/.cache/xo-linter/tsconfig\\..*\\.json[\\/]?$` , 'u' ) ;
605+ const { options} = await manager . mergeWithFileConfig ( { cwd, filePath : excludedFilePath } ) ;
606+ t . regex ( options . tsConfigPath , excludeTsConfigPath ) ;
607+ } ) ;
608+
609+ test ( 'mergeWithFileConfig: correctly resolves relative tsconfigs included file' , async t => {
610+ const cwd = path . resolve ( 'fixtures' , 'typescript' , 'relative-configs' ) ;
611+ const includedFilePath = path . resolve ( cwd , 'included-file.ts' ) ;
612+ const includeTsConfigPath = path . resolve ( cwd , 'config/tsconfig.json' ) ;
613+ const { options} = await manager . mergeWithFileConfig ( { cwd, filePath : includedFilePath } ) ;
614+ t . is ( options . tsConfigPath , includeTsConfigPath ) ;
615+ } ) ;
616+
617+ test ( 'mergeWithFileConfig: uses generated tsconfig if specified parserOptions.project excludes file' , async t => {
618+ const cwd = path . resolve ( 'fixtures' , 'typescript' , 'parseroptions-project' ) ;
619+ const filePath = path . resolve ( cwd , 'excluded-file.ts' ) ;
620+ const expectedTsConfigPath = new RegExp ( `${ slash ( cwd ) } /node_modules/.cache/xo-linter/tsconfig\\..*\\.json[\\/]?$` , 'u' ) ;
621+ const { options} = await manager . mergeWithFileConfig ( { cwd, filePath} ) ;
622+ t . regex ( options . tsConfigPath , expectedTsConfigPath ) ;
623+ } ) ;
624+
625+ test ( 'mergeWithFileConfig: uses generated tsconfig if specified parserOptions.project misses file' , async t => {
626+ const cwd = path . resolve ( 'fixtures' , 'typescript' , 'parseroptions-project' ) ;
627+ const filePath = path . resolve ( cwd , 'missed-by-options-file.ts' ) ;
628+ const expectedTsConfigPath = new RegExp ( `${ slash ( cwd ) } /node_modules/.cache/xo-linter/tsconfig\\..*\\.json[\\/]?$` , 'u' ) ;
629+ const { options} = await manager . mergeWithFileConfig ( { cwd, filePath} ) ;
630+ t . regex ( options . tsConfigPath , expectedTsConfigPath ) ;
631+ } ) ;
632+
633+ test ( 'mergeWithFileConfig: auto generated ts config extends found ts config if file is not covered' , async t => {
602634 const cwd = path . resolve ( 'fixtures' , 'typescript' , 'extends-config' ) ;
603635 const filePath = path . resolve ( cwd , 'does-not-matter.ts' ) ;
604636 const expectedConfigPath = new RegExp ( `${ slash ( cwd ) } /node_modules/.cache/xo-linter/tsconfig\\..*\\.json[\\/]?$` , 'u' ) ;
@@ -610,6 +642,26 @@ test('mergeWithFileConfig: extends ts config if needed', async t => {
610642 t . deepEqual ( expected , options . tsConfig ) ;
611643} ) ;
612644
645+ test ( 'mergeWithFileConfig: used found ts config if file is covered' , async t => {
646+ const cwd = path . resolve ( 'fixtures' , 'typescript' , 'extends-config' ) ;
647+ const filePath = path . resolve ( cwd , 'foo.ts' ) ;
648+ const expectedConfigPath = path . resolve ( cwd , 'tsconfig.json' ) ;
649+ const { options} = await manager . mergeWithFileConfig ( { cwd, filePath} ) ;
650+ t . is ( slash ( options . tsConfigPath ) , expectedConfigPath ) ;
651+ } ) ;
652+
653+ test ( 'mergeWithFileConfig: auto generated ts config extends found ts config if file is explicitly excluded' , async t => {
654+ const cwd = path . resolve ( 'fixtures' , 'typescript' , 'excludes' ) ;
655+ const filePath = path . resolve ( cwd , 'excluded-file.ts' ) ;
656+ const expectedConfigPath = new RegExp ( `${ slash ( cwd ) } /node_modules/.cache/xo-linter/tsconfig\\..*\\.json[\\/]?$` , 'u' ) ;
657+ const expected = {
658+ extends : path . resolve ( cwd , 'tsconfig.json' ) ,
659+ } ;
660+ const { options} = await manager . mergeWithFileConfig ( { cwd, filePath} ) ;
661+ t . regex ( slash ( options . tsConfigPath ) , expectedConfigPath ) ;
662+ t . deepEqual ( expected , options . tsConfig ) ;
663+ } ) ;
664+
613665test ( 'mergeWithFileConfig: creates temp tsconfig if none present' , async t => {
614666 const cwd = path . resolve ( 'fixtures' , 'typescript' ) ;
615667 const expectedConfigPath = new RegExp ( `${ slash ( cwd ) } /node_modules/.cache/xo-linter/tsconfig\\..*\\.json[\\/]?$` , 'u' ) ;
0 commit comments