8
8
*/
9
9
import { tmpdir } from 'os' ;
10
10
import { SymbolKind } from 'vscode-languageserver' ;
11
+ import { FileChangeType } from 'vscode-languageserver-protocol' ;
11
12
import { Position , Range } from 'graphql-language-service-utils' ;
12
13
13
14
import { MessageProcessor } from '../MessageProcessor' ;
@@ -24,7 +25,10 @@ import type { DefinitionQueryResult, Outline } from 'graphql-language-service';
24
25
import { Logger } from '../Logger' ;
25
26
import { pathToFileURL } from 'url' ;
26
27
27
- const baseConfig = { dirpath : __dirname } ;
28
+ jest . mock ( 'fs' , ( ) => ( {
29
+ ...jest . requireActual < typeof import ( 'fs' ) > ( 'fs' ) ,
30
+ readFileSync : jest . fn ( jest . requireActual ( 'fs' ) . readFileSync ) ,
31
+ } ) ) ;
28
32
29
33
describe ( 'MessageProcessor' , ( ) => {
30
34
const logger = new Logger ( tmpdir ( ) ) ;
@@ -48,6 +52,7 @@ describe('MessageProcessor', () => {
48
52
beforeEach ( async ( ) => {
49
53
const gqlConfig = await loadConfig ( { rootDir : __dirname , extensions : [ ] } ) ;
50
54
// loadConfig.mockRestore();
55
+ messageProcessor . _settings = { load : { } } ;
51
56
messageProcessor . _graphQLCache = new GraphQLCache ( {
52
57
configDir : __dirname ,
53
58
config : gqlConfig ,
@@ -480,4 +485,55 @@ export function Example(arg: string) {}`;
480
485
const contents = parseDocument ( text , 'test.js' ) ;
481
486
expect ( contents . length ) . toEqual ( 0 ) ;
482
487
} ) ;
488
+
489
+ describe ( 'handleWatchedFilesChangedNotification' , ( ) => {
490
+ const mockReadFileSync : jest . Mock = jest . requireMock ( 'fs' ) . readFileSync ;
491
+
492
+ beforeEach ( ( ) => {
493
+ mockReadFileSync . mockReturnValue ( '' ) ;
494
+ messageProcessor . _updateGraphQLConfig = jest . fn ( ) ;
495
+ } ) ;
496
+
497
+ it ( 'skips config updates for normal file changes' , async ( ) => {
498
+ await messageProcessor . handleWatchedFilesChangedNotification ( {
499
+ changes : [
500
+ {
501
+ uri : `${ pathToFileURL ( '.' ) } /foo.graphql` ,
502
+ type : FileChangeType . Changed ,
503
+ } ,
504
+ ] ,
505
+ } ) ;
506
+
507
+ expect ( messageProcessor . _updateGraphQLConfig ) . not . toHaveBeenCalled ( ) ;
508
+ } ) ;
509
+
510
+ it ( 'updates config for standard config filename changes' , async ( ) => {
511
+ await messageProcessor . handleWatchedFilesChangedNotification ( {
512
+ changes : [
513
+ {
514
+ uri : `${ pathToFileURL ( '.' ) } /.graphql.config` ,
515
+ type : FileChangeType . Changed ,
516
+ } ,
517
+ ] ,
518
+ } ) ;
519
+
520
+ expect ( messageProcessor . _updateGraphQLConfig ) . toHaveBeenCalled ( ) ;
521
+ } ) ;
522
+
523
+ it ( 'updates config for custom config filename changes' , async ( ) => {
524
+ const customConfigName = 'custom-config-name.yml' ;
525
+ messageProcessor . _settings = { load : { fileName : customConfigName } } ;
526
+
527
+ await messageProcessor . handleWatchedFilesChangedNotification ( {
528
+ changes : [
529
+ {
530
+ uri : `${ pathToFileURL ( '.' ) } /${ customConfigName } ` ,
531
+ type : FileChangeType . Changed ,
532
+ } ,
533
+ ] ,
534
+ } ) ;
535
+
536
+ expect ( messageProcessor . _updateGraphQLConfig ) . toHaveBeenCalled ( ) ;
537
+ } ) ;
538
+ } ) ;
483
539
} ) ;
0 commit comments