@@ -1158,3 +1158,40 @@ test('supports a custom config file with relative dot slash path for TypeScript'
11581158 t . true ( ( error . stdout as string ) ?. includes ( 'test.js' ) , 'Error should be reported for the test.js file' ) ;
11591159 t . true ( ( error . stdout as string ) ?. includes ( 'no-console' ) , 'The specific TypeScript rule should be mentioned in the output' ) ;
11601160} ) ;
1161+
1162+ test ( 'replaces cache file with directory when file exists at cache path' , async t => {
1163+ const { cwd} = t . context ;
1164+
1165+ // Create a simple TS file that will trigger cache creation
1166+ const filePath = path . join ( cwd , 'test.ts' ) ;
1167+ await fs . writeFile ( filePath , dedent `console.log('hello');\n` , 'utf8' ) ;
1168+
1169+ // Remove the default tsconfig to force cache creation
1170+ const tsConfigPath = path . join ( cwd , 'tsconfig.json' ) ;
1171+ await fs . rm ( tsConfigPath , { force : true } ) ;
1172+
1173+ // Create the cache directory structure up to the parent
1174+ const cacheParentDir = path . join ( cwd , 'node_modules' , '.cache' ) ;
1175+ await fs . mkdir ( cacheParentDir , { recursive : true } ) ;
1176+
1177+ // Create a FILE at the path where XO needs to create a directory
1178+ const cacheDir = path . join ( cacheParentDir , 'xo-linter' ) ;
1179+ await fs . writeFile ( cacheDir , 'this is a file that should be replaced with a directory' , 'utf8' ) ;
1180+
1181+ // Verify the file exists before running XO
1182+ const statsBeforeRun = await fs . stat ( cacheDir ) ;
1183+ t . true ( statsBeforeRun . isFile ( ) , 'Cache path should initially be a file' ) ;
1184+
1185+ // Run XO - this should handle the file-to-directory conversion
1186+ await t . notThrowsAsync ( $ `node ./dist/cli --cwd ${ cwd } ` ) ;
1187+
1188+ // Verify the cache path is now a directory
1189+ const statsAfterRun = await fs . stat ( cacheDir ) ;
1190+ t . true ( statsAfterRun . isDirectory ( ) , 'Cache path should now be a directory' ) ;
1191+
1192+ // Verify the cached tsconfig and the eslint cache file were created
1193+ const cachedFiles = await fs . readdir ( cacheDir ) ;
1194+ t . true ( cachedFiles . includes ( 'tsconfig.xo.json' ) , 'Cached tsconfig should exist' ) ;
1195+ t . true ( cachedFiles . some ( file => file . startsWith ( '.cache' ) ) , 'ESLint cache should exist' ) ;
1196+ } ) ;
1197+
0 commit comments