@@ -48,6 +48,7 @@ describe('MessageProcessor', () => {
48
48
logger,
49
49
graphqlFileExtensions : [ 'graphql' ] ,
50
50
loadConfigOptions : { rootDir : __dirname } ,
51
+ config : null ,
51
52
} ) ;
52
53
53
54
const queryPathUri = pathToFileURL ( `${ __dirname } /__queries__` ) ;
@@ -57,9 +58,10 @@ describe('MessageProcessor', () => {
57
58
}
58
59
}
59
60
` ;
60
-
61
+ let gqlConfig ;
61
62
beforeEach ( async ( ) => {
62
- const gqlConfig = await loadConfig ( { rootDir : __dirname , extensions : [ ] } ) ;
63
+ gqlConfig = await loadConfig ( { rootDir : __dirname , extensions : [ ] } ) ;
64
+
63
65
// loadConfig.mockRestore();
64
66
messageProcessor . _settings = { load : { } } ;
65
67
messageProcessor . _graphQLCache = new GraphQLCache ( {
@@ -460,6 +462,35 @@ describe('MessageProcessor', () => {
460
462
const result = await messageProcessor . handleHoverRequest ( test ) ;
461
463
expect ( result ) . toEqual ( { contents : [ ] } ) ;
462
464
} ) ;
465
+ it ( 'handles provided config' , async ( ) => {
466
+ const msgProcessor = new MessageProcessor ( {
467
+ // @ts -ignore
468
+ connection : {
469
+ workspace : {
470
+ getConfiguration ( ) {
471
+ return { } ;
472
+ } ,
473
+ } ,
474
+ } ,
475
+ logger,
476
+ graphqlFileExtensions : [ 'graphql' ] ,
477
+ loadConfigOptions : { rootDir : __dirname } ,
478
+ config : gqlConfig ,
479
+ } ) ;
480
+ expect ( msgProcessor . _providedConfig ) . toBeTruthy ( ) ;
481
+ await msgProcessor . handleInitializeRequest (
482
+ // @ts -ignore
483
+ {
484
+ rootPath : __dirname ,
485
+ } ,
486
+ null ,
487
+ __dirname ,
488
+ ) ;
489
+ await msgProcessor . handleDidChangeConfiguration ( {
490
+ settings : { } ,
491
+ } ) ;
492
+ expect ( msgProcessor . _graphQLCache ) . toBeTruthy ( ) ;
493
+ } ) ;
463
494
464
495
it ( 'runs workspace symbol requests' , async ( ) => {
465
496
const msgProcessor = new MessageProcessor ( {
@@ -554,7 +585,7 @@ describe('MessageProcessor', () => {
554
585
555
586
beforeEach ( ( ) => {
556
587
mockReadFileSync . mockReturnValue ( '' ) ;
557
- messageProcessor . _updateGraphQLConfig = jest . fn ( ) ;
588
+ messageProcessor . _initializeGraphQLCaches = jest . fn ( ) ;
558
589
} ) ;
559
590
560
591
it ( 'loads config if not initialized' , async ( ) => {
@@ -563,7 +594,9 @@ describe('MessageProcessor', () => {
563
594
const result = await messageProcessor . _loadConfigOrSkip (
564
595
`${ pathToFileURL ( '.' ) } /graphql.config.js` ,
565
596
) ;
566
- expect ( messageProcessor . _updateGraphQLConfig ) . toHaveBeenCalledTimes ( 1 ) ;
597
+ expect ( messageProcessor . _initializeGraphQLCaches ) . toHaveBeenCalledTimes (
598
+ 1 ,
599
+ ) ;
567
600
// we want to return true here to skip further processing, because it's just a config file change
568
601
expect ( result ) . toEqual ( true ) ;
569
602
} ) ;
@@ -574,7 +607,9 @@ describe('MessageProcessor', () => {
574
607
const result = await messageProcessor . _loadConfigOrSkip (
575
608
`${ pathToFileURL ( '.' ) } /file.ts` ,
576
609
) ;
577
- expect ( messageProcessor . _updateGraphQLConfig ) . toHaveBeenCalledTimes ( 1 ) ;
610
+ expect ( messageProcessor . _initializeGraphQLCaches ) . toHaveBeenCalledTimes (
611
+ 1 ,
612
+ ) ;
578
613
// here we have a non-config file, so we don't want to skip, because we need to run diagnostics etc
579
614
expect ( result ) . toEqual ( false ) ;
580
615
} ) ;
@@ -583,15 +618,17 @@ describe('MessageProcessor', () => {
583
618
const result = await messageProcessor . _loadConfigOrSkip (
584
619
`${ pathToFileURL ( '.' ) } /graphql.config.ts` ,
585
620
) ;
586
- expect ( messageProcessor . _updateGraphQLConfig ) . toHaveBeenCalledTimes ( 1 ) ;
621
+ expect ( messageProcessor . _initializeGraphQLCaches ) . toHaveBeenCalledTimes (
622
+ 1 ,
623
+ ) ;
587
624
expect ( result ) . toEqual ( true ) ;
588
625
} ) ;
589
626
it ( 'skips if the server is already initialized' , async ( ) => {
590
627
messageProcessor . _isInitialized = true ;
591
628
const result = await messageProcessor . _loadConfigOrSkip (
592
629
`${ pathToFileURL ( '.' ) } /myFile.ts` ,
593
630
) ;
594
- expect ( messageProcessor . _updateGraphQLConfig ) . not . toHaveBeenCalled ( ) ;
631
+ expect ( messageProcessor . _initializeGraphQLCaches ) . not . toHaveBeenCalled ( ) ;
595
632
expect ( result ) . toEqual ( false ) ;
596
633
} ) ;
597
634
} ) ;
@@ -602,7 +639,7 @@ describe('MessageProcessor', () => {
602
639
603
640
beforeEach ( ( ) => {
604
641
mockReadFileSync . mockReturnValue ( '' ) ;
605
- messageProcessor . _updateGraphQLConfig = jest . fn ( ) ;
642
+ messageProcessor . _initializeGraphQLCaches = jest . fn ( ) ;
606
643
messageProcessor . _loadConfigOrSkip = jest . fn ( ) ;
607
644
} ) ;
608
645
it ( 'updates config for standard config filename changes' , async ( ) => {
@@ -642,7 +679,7 @@ describe('MessageProcessor', () => {
642
679
settings : [ ] ,
643
680
} ) ;
644
681
645
- expect ( messageProcessor . _updateGraphQLConfig ) . toHaveBeenCalled ( ) ;
682
+ expect ( messageProcessor . _initializeGraphQLCaches ) . toHaveBeenCalled ( ) ;
646
683
647
684
await messageProcessor . handleDidOpenOrSaveNotification ( {
648
685
textDocument : {
@@ -653,7 +690,7 @@ describe('MessageProcessor', () => {
653
690
} ,
654
691
} ) ;
655
692
656
- expect ( messageProcessor . _updateGraphQLConfig ) . toHaveBeenCalled ( ) ;
693
+ expect ( messageProcessor . _initializeGraphQLCaches ) . toHaveBeenCalled ( ) ;
657
694
} ) ;
658
695
} ) ;
659
696
@@ -664,7 +701,7 @@ describe('MessageProcessor', () => {
664
701
uri : 'test' ,
665
702
} ) ;
666
703
667
- expect ( messageProcessor . _updateGraphQLConfig ) . not . toHaveBeenCalled ( ) ;
704
+ expect ( messageProcessor . _initializeGraphQLCaches ) . not . toHaveBeenCalled ( ) ;
668
705
expect ( logger . error ) . toHaveBeenCalledWith (
669
706
expect . stringContaining ( 'test missing-config' ) ,
670
707
) ;
@@ -675,7 +712,7 @@ describe('MessageProcessor', () => {
675
712
uri : 'test' ,
676
713
} ) ;
677
714
678
- expect ( messageProcessor . _updateGraphQLConfig ) . not . toHaveBeenCalled ( ) ;
715
+ expect ( messageProcessor . _initializeGraphQLCaches ) . not . toHaveBeenCalled ( ) ;
679
716
expect ( logger . error ) . toHaveBeenCalledWith (
680
717
expect . stringContaining ( 'Project not found for this file' ) ,
681
718
) ;
@@ -686,7 +723,7 @@ describe('MessageProcessor', () => {
686
723
uri : 'test' ,
687
724
} ) ;
688
725
689
- expect ( messageProcessor . _updateGraphQLConfig ) . not . toHaveBeenCalled ( ) ;
726
+ expect ( messageProcessor . _initializeGraphQLCaches ) . not . toHaveBeenCalled ( ) ;
690
727
expect ( logger . error ) . toHaveBeenCalledWith (
691
728
expect . stringContaining ( 'Invalid configuration' ) ,
692
729
) ;
@@ -697,7 +734,7 @@ describe('MessageProcessor', () => {
697
734
uri : 'test' ,
698
735
} ) ;
699
736
700
- expect ( messageProcessor . _updateGraphQLConfig ) . not . toHaveBeenCalled ( ) ;
737
+ expect ( messageProcessor . _initializeGraphQLCaches ) . not . toHaveBeenCalled ( ) ;
701
738
expect ( logger . error ) . toHaveBeenCalledWith (
702
739
expect . stringContaining ( 'test loader-error' ) ,
703
740
) ;
@@ -708,7 +745,7 @@ describe('MessageProcessor', () => {
708
745
uri : 'test' ,
709
746
} ) ;
710
747
711
- expect ( messageProcessor . _updateGraphQLConfig ) . not . toHaveBeenCalled ( ) ;
748
+ expect ( messageProcessor . _initializeGraphQLCaches ) . not . toHaveBeenCalled ( ) ;
712
749
expect ( logger . error ) . toHaveBeenCalledWith (
713
750
expect . stringContaining ( 'test loader-error' ) ,
714
751
) ;
@@ -720,7 +757,7 @@ describe('MessageProcessor', () => {
720
757
721
758
beforeEach ( ( ) => {
722
759
mockReadFileSync . mockReturnValue ( ' query { id }' ) ;
723
- messageProcessor . _updateGraphQLConfig = jest . fn ( ) ;
760
+ messageProcessor . _initializeGraphQLCaches = jest . fn ( ) ;
724
761
messageProcessor . _updateFragmentDefinition = jest . fn ( ) ;
725
762
messageProcessor . _isGraphQLConfigMissing = false ;
726
763
messageProcessor . _isInitialized = true ;
@@ -738,7 +775,7 @@ describe('MessageProcessor', () => {
738
775
] ,
739
776
} ) ;
740
777
741
- expect ( messageProcessor . _updateGraphQLConfig ) . not . toHaveBeenCalled ( ) ;
778
+ expect ( messageProcessor . _initializeGraphQLCaches ) . not . toHaveBeenCalled ( ) ;
742
779
expect ( messageProcessor . _updateFragmentDefinition ) . toHaveBeenCalled ( ) ;
743
780
} ) ;
744
781
} ) ;
0 commit comments