@@ -11,30 +11,33 @@ describe('Nvim API', () => {
11
11
let proc : ReturnType < typeof testUtil . startNvim > [ 0 ] ;
12
12
let nvim : ReturnType < typeof testUtil . startNvim > [ 1 ] ;
13
13
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
+
14
19
before ( async ( ) => {
15
20
[ proc , nvim ] = testUtil . startNvim ( ) ;
16
- } ) ;
17
-
18
- after ( ( ) => {
19
- testUtil . stopNvim ( ) ;
20
- } ) ;
21
21
22
- let requests : { method : string ; args : number [ ] } [ ] ;
23
- let notifications : { method : string ; args : number [ ] } [ ] ;
24
-
25
- before ( async ( ) => {
22
+ // Incoming requests (from Nvim).
26
23
nvim . on ( 'request' , ( method , args , resp ) => {
27
24
requests . push ( { method, args } ) ;
28
25
resp . send ( `received ${ method } (${ args } )` ) ;
29
26
} ) ;
27
+
28
+ // Incoming notifications (from Nvim).
30
29
nvim . on ( 'notification' , ( method , args ) => {
31
30
notifications . push ( { method, args } ) ;
32
31
} ) ;
33
32
} ) ;
34
33
34
+ after ( ( ) => {
35
+ testUtil . stopNvim ( ) ;
36
+ } ) ;
37
+
35
38
beforeEach ( ( ) => {
36
- requests = [ ] ;
37
- notifications = [ ] ;
39
+ requests . length = 0 ;
40
+ notifications . length = 0 ;
38
41
} ) ;
39
42
40
43
it ( 'failure modes' , async ( ) => {
@@ -101,6 +104,30 @@ describe('Nvim API', () => {
101
104
testUtil . stopNvim ( nvim2 ) ;
102
105
} ) ;
103
106
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
+
104
131
it ( 'can send requests and receive response' , async ( ) => {
105
132
const result = await nvim . eval ( '{"k1": "v1", "k2": 2}' ) ;
106
133
expect ( result ) . toEqual ( { k1 : 'v1' , k2 : 2 } ) ;
@@ -149,7 +176,7 @@ describe('Nvim API', () => {
149
176
end : - 1 ,
150
177
strictIndexing : true ,
151
178
} ) ;
152
- expect ( lines ) . toEqual ( [ ] ) ;
179
+ expect ( lines ) . toEqual ( [ '' ] ) ;
153
180
154
181
buf . setLines ( [ 'line1' , 'line2' ] , { start : 0 , end : 1 } ) ;
155
182
const newLines = await buf . getLines ( {
0 commit comments