@@ -154,27 +154,22 @@ describe('Nvim API', () => {
154
154
expect ( newLines ) . toEqual ( [ 'line1' , 'line2' ] ) ;
155
155
} ) ;
156
156
157
- it ( 'emits "disconnect" after quit' , async ( ) => {
158
- const disconnectMock = jest . fn ( ) ;
159
- nvim . on ( 'disconnect' , disconnectMock ) ;
160
- nvim . quit ( ) ;
161
-
162
- const closePromise = new Promise ( resolve => {
163
- proc . on ( 'close' , resolve ) ;
157
+ it ( 'emits "disconnect" after quit' , done => {
158
+ let disconnectCalled = false ;
159
+ nvim . on ( 'disconnect' , ( ) => {
160
+ disconnectCalled = true ;
164
161
} ) ;
165
162
166
- let timeout : NodeJS . Timeout ;
163
+ nvim . quit ( ) ;
167
164
168
- await Promise . race ( [
169
- closePromise . then ( ( ) => clearTimeout ( timeout ) ) ,
170
- new Promise ( ( _ , reject ) => {
171
- timeout = setTimeout (
172
- ( ) => reject ( new Error ( 'Timeout waiting for nvim to quit' ) ) ,
173
- 5000
174
- ) ;
175
- } ) ,
176
- ] ) ;
165
+ proc . on ( 'close' , ( ) => {
166
+ expect ( disconnectCalled ) . toBe ( true ) ;
167
+ done ( ) ;
168
+ } ) ;
177
169
178
- expect ( disconnectMock ) . toHaveBeenCalledTimes ( 1 ) ;
179
- } , 10000 ) ;
170
+ // Event doesn't actually emit when we quit nvim, but when the child process is killed
171
+ if ( proc && proc . connected ) {
172
+ proc . disconnect ( ) ;
173
+ }
174
+ } ) ;
180
175
} ) ;
0 commit comments