@@ -685,6 +685,9 @@ describe('parseAndGenerateServices', () => {
685
685
686
686
describe ( 'cacheLifetime' , ( ) => {
687
687
describe ( 'glob' , ( ) => {
688
+ const project = [ './**/tsconfig.json' , './**/tsconfig.extra.json' ] ;
689
+ // `resolveProjectList()` runs a glob for each pattern
690
+ const expectedGlobCount = project . length ;
688
691
function doParse ( lifetime :CacheDurationSeconds ) :void {
689
692
parser . parseAndGenerateServices ( 'const x = 1' , {
690
693
cacheLifetime :{
@@ -693,52 +696,52 @@ describe('parseAndGenerateServices', () => {
693
696
disallowAutomaticSingleRunInference :true ,
694
697
filePath :join ( FIXTURES_DIR , 'file.ts' ) ,
695
698
tsconfigRootDir :FIXTURES_DIR ,
696
- project : [ './**/tsconfig.json' , './**/tsconfig.extra.json' ] ,
699
+ project,
697
700
} ) ;
698
701
}
699
702
700
703
it ( 'should cache globs if the lifetime is non-zero' , ( ) => {
701
704
doParse ( 30 ) ;
702
- expect ( globbySyncMock ) . toHaveBeenCalledTimes ( 1 ) ;
705
+ expect ( globbySyncMock ) . toHaveBeenCalledTimes ( expectedGlobCount ) ;
703
706
doParse ( 30 ) ;
704
- // shouldn'tcall globby again due to the caching
705
- expect ( globbySyncMock ) . toHaveBeenCalledTimes ( 1 ) ;
707
+ // shouldn'tglob again due to the caching
708
+ expect ( globbySyncMock ) . toHaveBeenCalledTimes ( expectedGlobCount ) ;
706
709
} ) ;
707
710
708
711
it ( 'should not cache globs if the lifetime is zero' , ( ) => {
709
712
doParse ( 0 ) ;
710
- expect ( globbySyncMock ) . toHaveBeenCalledTimes ( 1 ) ;
713
+ expect ( globbySyncMock ) . toHaveBeenCalledTimes ( expectedGlobCount ) ;
711
714
doParse ( 0 ) ;
712
- // shouldcall globby again because we specified immediate cache expiry
713
- expect ( globbySyncMock ) . toHaveBeenCalledTimes ( 2 ) ;
715
+ // shouldglob again because we specified immediate cache expiry
716
+ expect ( globbySyncMock ) . toHaveBeenCalledTimes ( 2 * expectedGlobCount ) ;
714
717
} ) ;
715
718
716
719
it ( 'should evict the cache if the entry expires' , ( ) => {
717
720
hrtimeSpy . mockReturnValueOnce ( [ 1 , 0 ] ) ;
718
721
719
722
doParse ( 30 ) ;
720
- expect ( globbySyncMock ) . toHaveBeenCalledTimes ( 1 ) ;
723
+ expect ( globbySyncMock ) . toHaveBeenCalledTimes ( expectedGlobCount ) ;
721
724
722
725
// wow so much time has passed
723
726
hrtimeSpy . mockReturnValueOnce ( [ Number . MAX_VALUE , 0 ] ) ;
724
727
725
728
doParse ( 30 ) ;
726
- // shouldn'tcall globby again due to the caching
727
- expect ( globbySyncMock ) . toHaveBeenCalledTimes ( 2 ) ;
729
+ // shouldn'tglob again due to the caching
730
+ expect ( globbySyncMock ) . toHaveBeenCalledTimes ( 2 * expectedGlobCount ) ;
728
731
} ) ;
729
732
730
733
it ( 'should infinitely cache if passed Infinity' , ( ) => {
731
734
hrtimeSpy . mockReturnValueOnce ( [ 1 , 0 ] ) ;
732
735
733
736
doParse ( 'Infinity' ) ;
734
- expect ( globbySyncMock ) . toHaveBeenCalledTimes ( 1 ) ;
737
+ expect ( globbySyncMock ) . toHaveBeenCalledTimes ( expectedGlobCount ) ;
735
738
736
739
// wow so much time has passed
737
740
hrtimeSpy . mockReturnValueOnce ( [ Number . MAX_VALUE , 0 ] ) ;
738
741
739
742
doParse ( 'Infinity' ) ;
740
- // shouldn'tcall globby again due to the caching
741
- expect ( globbySyncMock ) . toHaveBeenCalledTimes ( 1 ) ;
743
+ // shouldn'tglob again due to the caching
744
+ expect ( globbySyncMock ) . toHaveBeenCalledTimes ( expectedGlobCount ) ;
742
745
} ) ;
743
746
} ) ;
744
747
} ) ;