@@ -550,6 +550,67 @@ test('caches eslint configs with equivalent options', async () => {
550550 expect ( eslintMock . mock . calculateConfigForFile ) . toHaveBeenCalledTimes ( 1 ) ;
551551} ) ;
552552
553+ test ( 'does not reuse cached eslint instances across effective cwds' , async ( ) => {
554+ const eslintPath = path . join ( __dirname , '../__mocks__/eslint.ts' ) ;
555+ const cwdSpy = vi . spyOn ( process , 'cwd' ) ;
556+
557+ cwdSpy . mockReturnValue ( path . join ( __dirname , 'fixtures' ) ) ;
558+ const eslint = await getESLint ( eslintPath , { fix : true } ) ;
559+
560+ cwdSpy . mockReturnValue ( path . join ( __dirname , 'fixtures/paths' ) ) ;
561+ const otherESLint = await getESLint ( eslintPath , { fix : true } ) ;
562+
563+ cwdSpy . mockRestore ( ) ;
564+
565+ expect ( otherESLint ) . not . toBe ( eslint ) ;
566+ expect ( eslintMock . ESLint ) . toHaveBeenCalledTimes ( 2 ) ;
567+ } ) ;
568+
569+ test ( 'does not reuse cached eslint configs across effective cwds' , async ( ) => {
570+ const fixturePath = path . join (
571+ __dirname ,
572+ 'fixtures/effective-cwd-default-config.js' ,
573+ ) ;
574+ const cwdSpy = vi . spyOn ( process , 'cwd' ) ;
575+
576+ cwdSpy . mockReturnValue ( path . resolve ( __dirname , '..' ) ) ;
577+ await format ( { text : defaultInputText ( ) , filePath : fixturePath } ) ;
578+
579+ cwdSpy . mockReturnValue ( __dirname ) ;
580+ await format ( { text : defaultInputText ( ) , filePath : fixturePath } ) ;
581+
582+ cwdSpy . mockRestore ( ) ;
583+
584+ expect ( eslintMock . mock . calculateConfigForFile ) . toHaveBeenCalledTimes ( 2 ) ;
585+ } ) ;
586+
587+ test ( 'reuses cached eslint configs when an explicit cwd is given' , async ( ) => {
588+ const fixturePath = path . join (
589+ __dirname ,
590+ 'fixtures/explicit-cwd-default-config.js' ,
591+ ) ;
592+ const eslintConfig = { cwd : path . resolve ( __dirname , '..' ) } ;
593+ const cwdSpy = vi . spyOn ( process , 'cwd' ) ;
594+
595+ cwdSpy . mockReturnValue ( path . join ( __dirname , 'fixtures' ) ) ;
596+ await format ( {
597+ text : defaultInputText ( ) ,
598+ filePath : fixturePath ,
599+ eslintConfig,
600+ } ) ;
601+
602+ cwdSpy . mockReturnValue ( path . join ( __dirname , 'fixtures/paths' ) ) ;
603+ await format ( {
604+ text : defaultInputText ( ) ,
605+ filePath : fixturePath ,
606+ eslintConfig : { ...eslintConfig } ,
607+ } ) ;
608+
609+ cwdSpy . mockRestore ( ) ;
610+
611+ expect ( eslintMock . mock . calculateConfigForFile ) . toHaveBeenCalledTimes ( 1 ) ;
612+ } ) ;
613+
553614test ( 'uses caller eslint config on config cache hit' , async ( ) => {
554615 const fixturePath = path . resolve (
555616 './mock/cache-override-test-default-config.js' ,
0 commit comments