Skip to content

Commit

Permalink
test(attach): improve disconnect test
Browse files Browse the repository at this point in the history
  • Loading branch information
gjf7 committed Oct 11, 2024
1 parent e28b0c6 commit 4dcdc39
Showing 1 changed file with 17 additions and 9 deletions.
26 changes: 17 additions & 9 deletions packages/neovim/src/attach/attach.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,19 +154,27 @@ describe('Nvim API', () => {
expect(newLines).toEqual(['line1', 'line2']);
});

it('emits "disconnect" after quit', done => {
it('emits "disconnect" after quit', async () => {
const disconnectMock = jest.fn();
nvim.on('disconnect', disconnectMock);
nvim.quit();

proc.on('close', () => {
expect(disconnectMock.mock.calls.length).toBe(1);
done();
const closePromise = new Promise(resolve => {
proc.on('close', resolve);
});

// Event doesn't actually emit when we quit nvim, but when the child process is killed
if (proc && proc.connected) {
proc.disconnect();
}
});
let timeout: NodeJS.Timeout;

await Promise.race([
closePromise.then(() => clearTimeout(timeout)),
new Promise((_, reject) => {
timeout = setTimeout(
() => reject(new Error('Timeout waiting for nvim to quit')),
5000
);
}),
]);

expect(disconnectMock).toHaveBeenCalledTimes(1);
}, 10000);
});

0 comments on commit 4dcdc39

Please sign in to comment.