@@ -11,30 +11,33 @@ describe('Nvim API', () => {
1111 let proc : ReturnType < typeof testUtil . startNvim > [ 0 ] ;
1212 let nvim : ReturnType < typeof testUtil . startNvim > [ 1 ] ;
1313
14+ /** Incoming requests (from Nvim). */
15+ const requests : { method : string ; args : number [ ] } [ ] = [ ] ;
16+ /** Incoming notifications (from Nvim). */
17+ const notifications : { method : string ; args : number [ ] } [ ] = [ ] ;
18+
1419 before ( async ( ) => {
1520 [ proc , nvim ] = testUtil . startNvim ( ) ;
16- } ) ;
17-
18- after ( ( ) => {
19- testUtil . stopNvim ( ) ;
20- } ) ;
2121
22- let requests : { method : string ; args : number [ ] } [ ] ;
23- let notifications : { method : string ; args : number [ ] } [ ] ;
24-
25- before ( async ( ) => {
22+ // Incoming requests (from Nvim).
2623 nvim . on ( 'request' , ( method , args , resp ) => {
2724 requests . push ( { method, args } ) ;
2825 resp . send ( `received ${ method } (${ args } )` ) ;
2926 } ) ;
27+
28+ // Incoming notifications (from Nvim).
3029 nvim . on ( 'notification' , ( method , args ) => {
3130 notifications . push ( { method, args } ) ;
3231 } ) ;
3332 } ) ;
3433
34+ after ( ( ) => {
35+ testUtil . stopNvim ( ) ;
36+ } ) ;
37+
3538 beforeEach ( ( ) => {
36- requests = [ ] ;
37- notifications = [ ] ;
39+ requests . length = 0 ;
40+ notifications . length = 0 ;
3841 } ) ;
3942
4043 it ( 'failure modes' , async ( ) => {
@@ -101,6 +104,30 @@ describe('Nvim API', () => {
101104 testUtil . stopNvim ( nvim2 ) ;
102105 } ) ;
103106
107+ it ( 'noisy RPC traffic' , async ( ) => {
108+ let requestCount = 0 ;
109+ const oldRequest = nvim . request ;
110+ nvim . request = function (
111+ this : any ,
112+ name : string ,
113+ args : any [ ] = [ ]
114+ ) : Promise < any > {
115+ requestCount = requestCount + 1 ;
116+ return oldRequest . call ( this , name , args ) ;
117+ } ;
118+
119+ for ( let i = 0 ; i < 99 ; i = i + 1 ) {
120+ nvim . command ( 'noswapfile edit test-node-client.lua' ) ;
121+ nvim . command ( 'bwipeout!' ) ;
122+ }
123+
124+ expect ( requestCount ) . toEqual ( 99 * 2 ) ;
125+ // Still alive?
126+ expect ( await nvim . eval ( '1+1' ) ) . toEqual ( 2 ) ;
127+
128+ nvim . request = oldRequest ;
129+ } ) ;
130+
104131 it ( 'can send requests and receive response' , async ( ) => {
105132 const result = await nvim . eval ( '{"k1": "v1", "k2": 2}' ) ;
106133 expect ( result ) . toEqual ( { k1 : 'v1' , k2 : 2 } ) ;
@@ -149,7 +176,7 @@ describe('Nvim API', () => {
149176 end : - 1 ,
150177 strictIndexing : true ,
151178 } ) ;
152- expect ( lines ) . toEqual ( [ ] ) ;
179+ expect ( lines ) . toEqual ( [ '' ] ) ;
153180
154181 buf . setLines ( [ 'line1' , 'line2' ] , { start : 0 , end : 1 } ) ;
155182 const newLines = await buf . getLines ( {
0 commit comments