File tree Expand file tree Collapse file tree 1 file changed +17
-9
lines changed
packages/neovim/src/attach Expand file tree Collapse file tree 1 file changed +17
-9
lines changed Original file line number Diff line number Diff line change @@ -154,19 +154,27 @@ describe('Nvim API', () => {
154
154
expect ( newLines ) . toEqual ( [ 'line1' , 'line2' ] ) ;
155
155
} ) ;
156
156
157
- it ( 'emits "disconnect" after quit' , done => {
157
+ it ( 'emits "disconnect" after quit' , async ( ) => {
158
158
const disconnectMock = jest . fn ( ) ;
159
159
nvim . on ( 'disconnect' , disconnectMock ) ;
160
160
nvim . quit ( ) ;
161
161
162
- proc . on ( 'close' , ( ) => {
163
- expect ( disconnectMock . mock . calls . length ) . toBe ( 1 ) ;
164
- done ( ) ;
162
+ const closePromise = new Promise ( resolve => {
163
+ proc . on ( 'close' , resolve ) ;
165
164
} ) ;
166
165
167
- // Event doesn't actually emit when we quit nvim, but when the child process is killed
168
- if ( proc && proc . connected ) {
169
- proc . disconnect ( ) ;
170
- }
171
- } ) ;
166
+ let timeout : NodeJS . Timeout ;
167
+
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
+ ] ) ;
177
+
178
+ expect ( disconnectMock ) . toHaveBeenCalledTimes ( 1 ) ;
179
+ } , 10000 ) ;
172
180
} ) ;
You can’t perform that action at this time.
0 commit comments