@@ -1396,7 +1396,7 @@ describe("FlatESLint", () => {
13961396 } ) ;
13971397
13981398 // Cannot be run properly until cache is implemented
1399- xit ( "should run autofix even if files are cached without autofix results" , async ( ) => {
1399+ it ( "should run autofix even if files are cached without autofix results" , async ( ) => {
14001400 const baseOptions = {
14011401 cwd : path . join ( fixtureDir , ".." ) ,
14021402 overrideConfigFile : true ,
@@ -1470,7 +1470,7 @@ describe("FlatESLint", () => {
14701470 } ) ;
14711471 } ) ;
14721472
1473- xdescribe ( "cache" , ( ) => {
1473+ describe ( "cache" , ( ) => {
14741474
14751475 /**
14761476 * helper method to delete a file without caring about exceptions
@@ -1609,11 +1609,15 @@ describe("FlatESLint", () => {
16091609 assert ( shell . test ( "-f" , path . resolve ( cwd , ".eslintcache" ) ) , "the cache for eslint was created at provided cwd" ) ;
16101610 } ) ;
16111611
1612- it ( "should invalidate the cache if the configuration changed between executions" , async ( ) => {
1613- assert ( ! shell . test ( "-f" , path . resolve ( ".eslintcache" ) ) , "the cache for eslint does not exist" ) ;
1612+ it ( "should invalidate the cache if the overrideConfig changed between executions" , async ( ) => {
1613+ const cwd = getFixturePath ( "cache/src" ) ;
1614+ const cacheLocation = path . resolve ( cwd , ".eslintcache" ) ;
1615+
1616+ assert ( ! shell . test ( "-f" , cacheLocation ) , "the cache for eslint does not exist" ) ;
16141617
16151618 eslint = new FlatESLint ( {
16161619 overrideConfigFile : true ,
1620+ cwd,
16171621
16181622 // specifying cache true the cache will be created
16191623 cache : true ,
@@ -1627,24 +1631,26 @@ describe("FlatESLint", () => {
16271631 ignore : false
16281632 } ) ;
16291633
1630- let spy = sinon . spy ( fs , "readFileSync " ) ;
1634+ let spy = sinon . spy ( fs . promises , "readFile " ) ;
16311635
1632- let file = getFixturePath ( "cache/src" , "test-file.js" ) ;
1636+ let file = path . join ( cwd , "test-file.js" ) ;
16331637
16341638 file = fs . realpathSync ( file ) ;
16351639 const results = await eslint . lintFiles ( [ file ] ) ;
16361640
16371641 for ( const { errorCount, warningCount } of results ) {
16381642 assert . strictEqual ( errorCount + warningCount , 0 , "the file passed without errors or warnings" ) ;
16391643 }
1640- assert . strictEqual ( spy . getCall ( 0 ) . args [ 0 ] , file , "the module read the file because is considered changed" ) ;
1641- assert ( shell . test ( "-f" , path . resolve ( ".eslintcache" ) ) , "the cache for eslint was created" ) ;
1644+
1645+ assert ( spy . calledWith ( file ) , "ESLint should have read the file because it's considered changed" ) ;
1646+ assert ( shell . test ( "-f" , cacheLocation ) , "the cache for eslint should still exist" ) ;
16421647
16431648 // destroy the spy
16441649 sinon . restore ( ) ;
16451650
16461651 eslint = new FlatESLint ( {
16471652 overrideConfigFile : true ,
1653+ cwd,
16481654
16491655 // specifying cache true the cache will be created
16501656 cache : true ,
@@ -1659,20 +1665,23 @@ describe("FlatESLint", () => {
16591665 } ) ;
16601666
16611667 // create a new spy
1662- spy = sinon . spy ( fs , "readFileSync " ) ;
1668+ spy = sinon . spy ( fs . promises , "readFile " ) ;
16631669
16641670 const [ cachedResult ] = await eslint . lintFiles ( [ file ] ) ;
16651671
1666- assert . strictEqual ( spy . getCall ( 0 ) . args [ 0 ] , file , "the module read the file because is considered changed because the config changed") ;
1667- assert . strictEqual ( cachedResult . errorCount , 1 , "since configuration changed the cache was not used an one error was reported" ) ;
1668- assert ( shell . test ( "-f" , path . resolve ( ".eslintcache" ) ) , "the cache for eslint was created " ) ;
1672+ assert ( spy . calledWith ( file ) , "ESLint should have read the file again because is considered changed because the config changed") ;
1673+ assert . strictEqual ( cachedResult . errorCount , 1 , "since configuration changed the cache was not used and one error was reported" ) ;
1674+ assert ( shell . test ( "-f" , cacheLocation ) , "The cache for ESLint should still exist (2) " ) ;
16691675 } ) ;
16701676
16711677 it ( "should remember the files from a previous run and do not operate on them if not changed" , async ( ) => {
1672- assert ( ! shell . test ( "-f" , path . resolve ( ".eslintcache" ) ) , "the cache for eslint does not exist" ) ;
1678+
1679+ const cwd = getFixturePath ( "cache/src" ) ;
1680+ const cacheLocation = path . resolve ( cwd , ".eslintcache" ) ;
16731681
16741682 eslint = new FlatESLint ( {
16751683 overrideConfigFile : true ,
1684+ cwd,
16761685
16771686 // specifying cache true the cache will be created
16781687 cache : true ,
@@ -1686,22 +1695,23 @@ describe("FlatESLint", () => {
16861695 ignore : false
16871696 } ) ;
16881697
1689- let spy = sinon . spy ( fs , "readFileSync " ) ;
1698+ let spy = sinon . spy ( fs . promises , "readFile " ) ;
16901699
16911700 let file = getFixturePath ( "cache/src" , "test-file.js" ) ;
16921701
16931702 file = fs . realpathSync ( file ) ;
16941703
16951704 const result = await eslint . lintFiles ( [ file ] ) ;
16961705
1697- assert . strictEqual ( spy . getCall ( 0 ) . args [ 0 ] , file , "the module read the file because is considered changed" ) ;
1698- assert ( shell . test ( "-f" , path . resolve ( ".eslintcache" ) ) , "the cache for eslint was created" ) ;
1706+ assert ( spy . calledWith ( file ) , "the module read the file because is considered changed" ) ;
1707+ assert ( shell . test ( "-f" , cacheLocation ) , "the cache for eslint was created" ) ;
16991708
17001709 // destroy the spy
17011710 sinon . restore ( ) ;
17021711
17031712 eslint = new FlatESLint ( {
17041713 overrideConfigFile : true ,
1714+ cwd,
17051715
17061716 // specifying cache true the cache will be created
17071717 cache : true ,
@@ -1716,7 +1726,7 @@ describe("FlatESLint", () => {
17161726 } ) ;
17171727
17181728 // create a new spy
1719- spy = sinon . spy ( fs , "readFileSync " ) ;
1729+ spy = sinon . spy ( fs . promises , "readFile " ) ;
17201730
17211731 const cachedResult = await eslint . lintFiles ( [ file ] ) ;
17221732
0 commit comments